资源简介
核心代码:
public class RevealLayout extends LinearLayout implements Runnable{
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private float mCenterX,mCenterY;
private int[] mLocation = new int[2];
private int INVALIDATE_DURATION = 40;
private int mTargetHeight,mTargetWidth;
private int mRevealRadius = 0,mRevealRadiusGap,mMaxRadius;
private int mMinBetweenWidthAndHeight,mMaxBetweenWidthAndHeight;
private boolean mIsPressed;
private boolean mShouldDoAnimation;
private View mTargetView;
private DispatchUpTouchEventRunnable mDispatchUpTouchEventRunnable = new DispatchUpTouchEventRunnable();
public RevealLayout(Context context) {
super(context);
init();
}
public RevealLayout(Context context, AttributeSet attrs){
super(context,attrs);
init();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public RevealLayout(Context context, AttributeSet attrs, int defStyleAttr){
super(context,attrs,defStyleAttr);
init();
}
public void init(){
setWillNotDraw(false);
mPaint.setColor(getResources().getColor(R.color.reveal_color));
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
this.getLocationOnScreen(mLocation);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if(mTargetView == null || !mShouldDoAnimation || mTargetWidth <= 0)
return;
if(mRevealRadius > mMinBetweenWidthAndHeight / 2)
mRevealRadius = mRevealRadiusGap * 4;
else
mRevealRadius = mRevealRadiusGap;
int[] location = new int[2];
this.getLocationOnScreen(mLocation);
mTargetView.getLocationOnScreen(location);
int top = location[1] - mLocation[1];
int left = location[0] - mLocation[0];
int right = left mTargetView.getMeasuredWidth();
int bottom = top mTargetView.getMeasuredHeight();
canvas.save();
canvas.clipRect(left, top, right, bottom);
canvas.drawCircle(mCenterX, mCenterY, mRevealRadius, mPaint);
canvas.restore();
if(mRevealRadius <= mMaxRadius)
postInvalidateDelayed(INVALIDATE_DURATION, left, top, right, bottom);
else if(!mIsPressed){
mShouldDoAnimation = false;
postInvalidateDelayed(INVALIDATE_DURATION, left, top, right, bottom);
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int x = (int)event.getRawX();
int y = (int)event.getRawY();
int action = event.getAction();
switch(action){
case MotionEvent.ACTION_DOWN:
View targetView = getTargetView(this,x,y);
if(targetView != null && targetView.isEnabled()){
mTargetView = targetView;
initParametersForChild(event,targetView);
postInvalidateDelayed(INVALIDATE_DURATION);
}
break;
case MotionEvent.ACTION_UP:
mIsPressed = false;
postInvalidateDelayed(INVALIDATE_DURATION);
mDispatchUpTouchEventRunnable.event = event;
postDelayed(mDispatchUpTouchEventRunnable, 40);
break;
case MotionEvent.ACTION_CANCEL:
mIsPressed = false;
postInvalidateDelayed(INVALIDATE_DURATION);
break;
}
return super.dispatchTouchEvent(event);
}
public View getTargetView(View view,int x,int y){
View target = null;
ArrayList<View> views = view.getTouchables();
for(View child : views)
if(isTouchPointInView(child,x,y)){
target = child;
break;
}
return target;
}
public boolean isTouchPointInView(View child,int x,int y){
int[] location = new int[2];
child.getLocationOnScreen(location);
int top = location[1];
int left = location[0];
int right = left child.getMeasuredWidth();
int bottom = top child.getMeasuredHeight();
if(child.isClickable() && y>=top && y<= bottom && x >= left && x<= right)
return true;
else
return false;
}
public void initParametersForChild(MotionEvent event,View view){
mCenterX = event.getX();
mCenterY = event.getY();
mTargetWidth = view.getMeasuredWidth();
mTargetHeight = view.getMeasuredHeight();
mMinBetweenWidthAndHeight = Math.min(mTargetWidth, mTargetHeight);
mMaxBetweenWidthAndHeight = Math.max(mTargetWidth, mTargetHeight);
mRevealRadius = 0;
mRevealRadiusGap = mMinBetweenWidthAndHeight / 8;
mIsPressed = true;
mShouldDoAnimation = true;
int[] location = new int[2];
view.getLocationOnScreen(location);
int left = location[0] - mLocation[0];
int mTransformedCenterX = (int)mCenterX - left;
mMaxRadius = Math.max(mTransformedCenterX, mTargetWidth - mTransformedCenterX);
}
@Override
public void run() {
super.performClick();
}
@Override
public boolean performClick() {
postDelayed(this,40);
return true;
}
private class DispatchUpTouchEventRunnable implements Runnable{
public MotionEvent event;
@Override
public void run() {
if(mTargetView.isEnabled() && mTargetView.isClickable())
return;
if(isTouchPointInView(mTargetView, (int)event.getRawX(), (int)event.getRawX()))
mTargetView.performClick();
}
}
}
代码片段和文件信息
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package android.support.v7.appcompat;
public final class R {
public static final class anim {
public static final int abc_fade_in = 0x7f040000;
public static final int abc_fade_out = 0x7f040001;
public static final int abc_slide_in_bottom = 0x7f040002;
public static final int abc_slide_in_top = 0x7f040003;
public static final int abc_slide_out_bottom = 0x7f040004;
public static final int abc_slide_out_top = 0x7f040005;
}
public static final class attr {
public static final int actionBarDivider = 0x7f01000f;
public static final int actionBarItemBackground = 0x7f010010;
public static final in
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 475 2015-01-17 08:28 MyRevealLayout\.classpath
文件 850 2015-01-17 08:28 MyRevealLayout\.project
文件 177 2015-01-17 08:28 MyRevealLayout\.settings\org.eclipse.jdt.core.prefs
文件 885 2015-01-17 09:56 MyRevealLayout\AndroidManifest.xm
文件 885 2015-01-17 09:56 MyRevealLayout\bin\AndroidManifest.xm
文件 629 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$anim.class
文件 5136 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$attr.class
文件 763 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$bool.class
文件 594 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$color.class
文件 1530 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$dimen.class
文件 5191 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$drawable.class
文件 2556 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$id.class
文件 445 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$integer.class
文件 1629 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$layout.class
文件 1141 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$string.class
文件 9582 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$st
文件 6541 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R$st
文件 1015 2015-01-18 14:35 MyRevealLayout\bin\classes\android\support\v7\appcompat\R.class
文件 515 2015-01-18 14:35 MyRevealLayout\bin\classes\com\android\chaos\MainActivity.class
文件 1267 2015-01-18 14:35 MyRevealLayout\bin\classes\com\android\chaos\RevealLayout$DispatchUpTouchEventRunnable.class
文件 6035 2015-01-18 14:35 MyRevealLayout\bin\classes\com\android\chaos\RevealLayout.class
文件 361 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\BuildConfig.class
文件 623 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$anim.class
文件 5130 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$attr.class
文件 757 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$bool.class
文件 624 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$color.class
文件 1622 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$dimen.class
文件 5220 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$drawable.class
文件 2650 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$id.class
文件 439 2015-01-18 14:35 MyRevealLayout\bin\classes\com\example\myreveallayout\R$integer.class
............此处省略87个文件信息
- 上一篇:android 白天 夜间模式切换
- 下一篇:ClientDemoServer
相关资源
- android端 用户点击选择拍照或打开相册
- Android-Camera2api实现点击拍照长按录制
- Android实现点击获取验证码60秒后重新
- 使用JSP内置对象:1、设计教师与学生
- 点击或自动改变圆的颜色
- android点击查看大图,ViewPager实现左右
- Android中RecyclerView点击item展开列表详细
- 计算机图形学实验 鼠标点击画直线
- android点击界面产生气泡,气泡效果
- android中listview的item滑动删除效果已解
- Android中实现WebView点击图片放大显示
- android listview点击保持背景颜色,实现
- android自动点击(批处理bat)
- Android 高德地图自定义点聚合marker图片
- 连续点击返回键,退出app(android)
- 点击图片动态生成video播放器
- android WIN8系统 磁贴点击下沉倾斜效果
- 客户端首页广告栏位循环 并支持点击
- 下拉刷新上拉或点击加载更多
- 按钮点击的水波纹效果
- android 声波及点击水波纹 雷达扫描效
- 广告轮播图自动循环滚动和点击事件
- android listview item背景色点击效果
-
Java ap
plet 显示图片 并点击按钮 图片 - Android 可全屏拖动,响应点击事件的
- android输入数据点击按钮就可以传递到
- Android 高德地图自定义点聚合marker图片
- android 通知栏跳转
- 编写java程序,在文本框输入字符串,
- Android 动态添加标签及其点击事件
评论
共有 条评论