forked from GcsSloop/rclayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
373 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
RCLayout/rclayout/src/main/java/com/gcssloop/widget/RCImageView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2018 GcsSloop | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Last modified 2018-03-20 16:36:45 | ||
* | ||
* GitHub: https://github.com/GcsSloop | ||
* WeiBo: http://weibo.com/GcsSloop | ||
* WebSite: http://www.gcssloop.com | ||
*/ | ||
|
||
package com.gcssloop.widget; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.view.MotionEvent; | ||
import android.widget.ImageView; | ||
|
||
import com.gcssloop.widget.helper.RCHelper; | ||
|
||
/** | ||
* 作用:圆角图片 | ||
* 作者:GcsSloop | ||
*/ | ||
@SuppressLint("AppCompatCustomView") | ||
public class RCImageView extends ImageView { | ||
|
||
RCHelper mRCHelper; | ||
|
||
public RCImageView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public RCImageView(Context context, @Nullable AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public RCImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
mRCHelper = new RCHelper(); | ||
mRCHelper.initAttrs(context, attrs); | ||
} | ||
|
||
@Override | ||
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | ||
super.onSizeChanged(w, h, oldw, oldh); | ||
mRCHelper.onSizeChanged(this, w, h); | ||
} | ||
|
||
@Override | ||
public void draw(Canvas canvas) { | ||
if (mRCHelper.mClipBackground) { | ||
canvas.save(); | ||
canvas.clipPath(mRCHelper.mClipPath); | ||
super.draw(canvas); | ||
canvas.restore(); | ||
} else { | ||
super.draw(canvas); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
canvas.saveLayer(mRCHelper.mLayer, null, Canvas.ALL_SAVE_FLAG); | ||
super.onDraw(canvas); | ||
mRCHelper.onClipDraw(canvas); | ||
canvas.restore(); | ||
} | ||
|
||
@Override | ||
public boolean dispatchTouchEvent(MotionEvent ev) { | ||
if (!mRCHelper.mAreaRegion.contains((int) ev.getX(), (int) ev.getY())) { | ||
return false; | ||
} | ||
return super.dispatchTouchEvent(ev); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.