fix: 修改拖动时子View被缩放的问题
This commit is contained in:
@@ -44,7 +44,7 @@ public class SplitLayout extends ViewGroup {
|
|||||||
private static final float INVAID_SPLITPOSITION = Float.MIN_VALUE;
|
private static final float INVAID_SPLITPOSITION = Float.MIN_VALUE;
|
||||||
private static final int DEFAULT_SPLIT_HANDLE_SIZE_DP = 16;
|
private static final int DEFAULT_SPLIT_HANDLE_SIZE_DP = 16;
|
||||||
private static final int DEFAULT_CHILD_MIN_SIZE_DP = 32;
|
private static final int DEFAULT_CHILD_MIN_SIZE_DP = 32;
|
||||||
private static final int[] PRESSED_STATE_SET = { android.R.attr.state_pressed };
|
private static final int[] PRESSED_STATE_SET = {android.R.attr.state_pressed};
|
||||||
private static final int[] EMPTY_STATE_SET = {};
|
private static final int[] EMPTY_STATE_SET = {};
|
||||||
|
|
||||||
private int mOrientation;
|
private int mOrientation;
|
||||||
@@ -96,8 +96,8 @@ public class SplitLayout extends ViewGroup {
|
|||||||
mHandleDrawable = a.getDrawable(R.styleable.SplitLayout_splitHandleDrawable);
|
mHandleDrawable = a.getDrawable(R.styleable.SplitLayout_splitHandleDrawable);
|
||||||
if (mHandleDrawable == null) {
|
if (mHandleDrawable == null) {
|
||||||
StateListDrawable stateListDrawable = new StateListDrawable();
|
StateListDrawable stateListDrawable = new StateListDrawable();
|
||||||
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(getResources().getColor(R.color.draw_progress_bg_color)));
|
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(getResources().getColor(R.color.draw_progress_bg_color)));
|
||||||
stateListDrawable.addState(new int[] {}, new ColorDrawable(getResources().getColor(R.color.material_pink_500)));
|
stateListDrawable.addState(new int[]{}, new ColorDrawable(getResources().getColor(R.color.material_pink_500)));
|
||||||
stateListDrawable.setEnterFadeDuration(150);
|
stateListDrawable.setEnterFadeDuration(150);
|
||||||
stateListDrawable.setExitFadeDuration(150);
|
stateListDrawable.setExitFadeDuration(150);
|
||||||
mHandleDrawable = stateListDrawable;
|
mHandleDrawable = stateListDrawable;
|
||||||
@@ -135,9 +135,9 @@ public class SplitLayout extends ViewGroup {
|
|||||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||||
// 重置子View的最小值
|
// 重置子View的最小值
|
||||||
if (mOrientation == VERTICAL) {
|
if (mOrientation == VERTICAL) {
|
||||||
mChildMinSize = heightSize/3;
|
mChildMinSize = heightSize / 3;
|
||||||
} else {
|
} else {
|
||||||
mChildMinSize = widthSize/3;
|
mChildMinSize = widthSize / 3;
|
||||||
}
|
}
|
||||||
if (widthSize > 0 && heightSize > 0) {
|
if (widthSize > 0 && heightSize > 0) {
|
||||||
mWidth = widthSize;
|
mWidth = widthSize;
|
||||||
@@ -191,7 +191,7 @@ public class SplitLayout extends ViewGroup {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
return super.onInterceptTouchEvent(ev)||ev.getPointerCount() == splitDragTouchCount;
|
return super.onInterceptTouchEvent(ev) || ev.getPointerCount() == splitDragTouchCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -265,7 +265,7 @@ public class SplitLayout extends ViewGroup {
|
|||||||
// 分别记录当前两个子View的画面
|
// 分别记录当前两个子View的画面
|
||||||
getBitmapFromChildView();
|
getBitmapFromChildView();
|
||||||
// 判断所有手指是否都到了另外一个子View内
|
// 判断所有手指是否都到了另外一个子View内
|
||||||
View tmpView = (switchLongPressChildView == mChild0)? mChild1:mChild0;
|
View tmpView = (switchLongPressChildView == mChild0) ? mChild1 : mChild0;
|
||||||
if (isEventAllInChildView(tmpView, ev)) {
|
if (isEventAllInChildView(tmpView, ev)) {
|
||||||
// 多个触控位置全部移动到另外的View中,并且此前状态不是已切换状态,开始切换快照图片
|
// 多个触控位置全部移动到另外的View中,并且此前状态不是已切换状态,开始切换快照图片
|
||||||
if (!hasSwitchChild) {
|
if (!hasSwitchChild) {
|
||||||
@@ -286,7 +286,7 @@ public class SplitLayout extends ViewGroup {
|
|||||||
}
|
}
|
||||||
} else { // 尚未进入拖动切换流程
|
} else { // 尚未进入拖动切换流程
|
||||||
// 用户使用多指点击,需要实时判断点击时间是否足够长按时间,满足时,再判断是否和按下时点击的View相同
|
// 用户使用多指点击,需要实时判断点击时间是否足够长按时间,满足时,再判断是否和按下时点击的View相同
|
||||||
if (mChildLongPressTime>0 && System.currentTimeMillis() - mChildLongPressTime >= LONG_PRESS_TIME ) {
|
if (mChildLongPressTime > 0 && System.currentTimeMillis() - mChildLongPressTime >= LONG_PRESS_TIME) {
|
||||||
if (isEventAllInChildView(switchLongPressChildView, ev)) {
|
if (isEventAllInChildView(switchLongPressChildView, ev)) {
|
||||||
// 震动提示用户,开始支持拖动移动
|
// 震动提示用户,开始支持拖动移动
|
||||||
performHapticFeedback(HapticFeedbackConstants.DRAG_START);
|
performHapticFeedback(HapticFeedbackConstants.DRAG_START);
|
||||||
@@ -350,9 +350,9 @@ public class SplitLayout extends ViewGroup {
|
|||||||
|
|
||||||
private boolean isUnderSplitHandle(float x, float y) {
|
private boolean isUnderSplitHandle(float x, float y) {
|
||||||
if (mOrientation == VERTICAL) {
|
if (mOrientation == VERTICAL) {
|
||||||
return y >= (mSplitPosition - (mHandleSize*2)) && y <= (mSplitPosition + (mHandleSize*2));
|
return y >= (mSplitPosition - (mHandleSize * 2)) && y <= (mSplitPosition + (mHandleSize * 2));
|
||||||
} else {
|
} else {
|
||||||
return x >= (mSplitPosition - (mHandleSize*20)) && x <= (mSplitPosition + (mHandleSize*20));
|
return x >= (mSplitPosition - (mHandleSize * 20)) && x <= (mSplitPosition + (mHandleSize * 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -418,9 +418,9 @@ public class SplitLayout extends ViewGroup {
|
|||||||
mHandleDrawable.setBounds(splitPosition - mHandleSize / 2, 0, splitPosition + mHandleSize / 2, mHeight);
|
mHandleDrawable.setBounds(splitPosition - mHandleSize / 2, 0, splitPosition + mHandleSize / 2, mHeight);
|
||||||
}
|
}
|
||||||
if (mIsDragging) {
|
if (mIsDragging) {
|
||||||
canvas.drawRect(mHandleDrawable.getBounds(),splitPressBgPaint);
|
canvas.drawRect(mHandleDrawable.getBounds(), splitPressBgPaint);
|
||||||
} else {
|
} else {
|
||||||
canvas.drawRect(mHandleDrawable.getBounds(),splitBgPaint);
|
canvas.drawRect(mHandleDrawable.getBounds(), splitBgPaint);
|
||||||
}
|
}
|
||||||
mHandleDrawable.draw(canvas);
|
mHandleDrawable.draw(canvas);
|
||||||
}
|
}
|
||||||
@@ -499,10 +499,10 @@ public class SplitLayout extends ViewGroup {
|
|||||||
|
|
||||||
// 获取当前两个子View的Bitmap截图,用于在拖动过程中的实时绘制
|
// 获取当前两个子View的Bitmap截图,用于在拖动过程中的实时绘制
|
||||||
private void getBitmapFromChildView() {
|
private void getBitmapFromChildView() {
|
||||||
if (mChild0!=null) {
|
if (mChild0 != null) {
|
||||||
cachedBitmapArray[0] = loadBitmapFromViewBySystem(mChild0);
|
cachedBitmapArray[0] = loadBitmapFromViewBySystem(mChild0);
|
||||||
}
|
}
|
||||||
if (mChild1!=null) {
|
if (mChild1 != null) {
|
||||||
cachedBitmapArray[1] = loadBitmapFromViewBySystem(mChild1);
|
cachedBitmapArray[1] = loadBitmapFromViewBySystem(mChild1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -510,12 +510,41 @@ public class SplitLayout extends ViewGroup {
|
|||||||
// 获取高斯模糊的bitmap图片
|
// 获取高斯模糊的bitmap图片
|
||||||
private Bitmap getBlurBitmap() {
|
private Bitmap getBlurBitmap() {
|
||||||
// 先获取当前界面的整体截图
|
// 先获取当前界面的整体截图
|
||||||
|
getBitmapFromChildView(); // 先获取两个子View的截图
|
||||||
|
// 将截图绘制到cachedCanvas上
|
||||||
|
cachedCanvas.drawColor(getContext().getColor(android.R.color.transparent), PorterDuff.Mode.CLEAR);
|
||||||
|
if (cachedBitmapArray != null) {
|
||||||
|
Rect child0Rect = new Rect();
|
||||||
|
Rect child1Rect = new Rect();
|
||||||
|
if (mOrientation == VERTICAL) {
|
||||||
|
child0Rect.set(0, 0, getWidth(), (int) (mSplitPosition - mHandleSize / 2));
|
||||||
|
child1Rect.set(0, (int) (mSplitPosition + mHandleSize / 2), getWidth(), getHeight());
|
||||||
|
} else {
|
||||||
|
child0Rect.set(0, 0, (int) (mSplitPosition - mHandleSize / 2), getHeight());
|
||||||
|
child1Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
|
||||||
|
}
|
||||||
|
cachedCanvas.drawBitmap(cachedBitmapArray[0], null, child0Rect, null);
|
||||||
|
// cachedCanvas.drawBitmap(((BitmapDrawable)getContext().getDrawable(R.drawable.icon_app)).getBitmap(),
|
||||||
|
// child0Rect.centerX() - (getContext().getDrawable(R.drawable.icon_app).getBounds().width()/2),
|
||||||
|
// child0Rect.centerY() - (getContext().getDrawable(R.drawable.icon_app).getBounds().height()/2), null);
|
||||||
|
cachedCanvas.drawBitmap(cachedBitmapArray[1], null, child1Rect, null);
|
||||||
|
// cachedCanvas.drawRect(child1Rect, mPaint);
|
||||||
|
// cachedCanvas.drawBitmap(((BitmapDrawable)getContext().getDrawable(R.drawable.icon_app)).getBitmap(),
|
||||||
|
// child1Rect.centerX() - (getContext().getDrawable(R.drawable.icon_app).getBounds().width()/2),
|
||||||
|
// child1Rect.centerY() - (getContext().getDrawable(R.drawable.icon_app).getBounds().height()/2), null);
|
||||||
|
Bitmap blurBitmap = UtilBitmap.blurBitmap(getContext(), cachedBitmap, 20f);
|
||||||
|
cachedCanvas.drawColor(getContext().getColor(android.R.color.transparent), PorterDuff.Mode.CLEAR);
|
||||||
|
cachedCanvas.drawBitmap(blurBitmap, 0, 0, null);
|
||||||
|
return blurBitmap;
|
||||||
|
} else {
|
||||||
Bitmap currentBitmap = loadBitmapFromViewBySystem(this);
|
Bitmap currentBitmap = loadBitmapFromViewBySystem(this);
|
||||||
return UtilBitmap.blurBitmap(getContext(), currentBitmap, 20f);
|
return UtilBitmap.blurBitmap(getContext(), currentBitmap, 20f);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*此方法直接截取屏幕指定view区域的内容
|
* 此方法直接截取屏幕指定view区域的内容
|
||||||
|
*
|
||||||
* @param view 需要截取屏幕的图片view
|
* @param view 需要截取屏幕的图片view
|
||||||
* @return Bitmap
|
* @return Bitmap
|
||||||
*/
|
*/
|
||||||
@@ -558,7 +587,7 @@ public class SplitLayout extends ViewGroup {
|
|||||||
|
|
||||||
// 设置两个子View的快照的显示,可反转
|
// 设置两个子View的快照的显示,可反转
|
||||||
public void resetChildSnapshotBitmap(Canvas canvas, boolean isReverse) {
|
public void resetChildSnapshotBitmap(Canvas canvas, boolean isReverse) {
|
||||||
if (cachedBitmapArray!= null&&cachedBitmapArray.length>1) {
|
if (cachedBitmapArray != null && cachedBitmapArray.length > 1) {
|
||||||
cachedCanvas.drawColor(getContext().getColor(android.R.color.transparent), PorterDuff.Mode.CLEAR);
|
cachedCanvas.drawColor(getContext().getColor(android.R.color.transparent), PorterDuff.Mode.CLEAR);
|
||||||
Rect child0Rect = new Rect();
|
Rect child0Rect = new Rect();
|
||||||
Rect child1Rect = new Rect();
|
Rect child1Rect = new Rect();
|
||||||
@@ -579,9 +608,9 @@ public class SplitLayout extends ViewGroup {
|
|||||||
child0Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
|
child0Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cachedCanvas.drawBitmap(cachedBitmapArray[0], new Rect(0,0, cachedBitmapArray[0].getWidth(), cachedBitmapArray[0].getHeight()), child0Rect, mPaint);
|
cachedCanvas.drawBitmap(cachedBitmapArray[0], new Rect(0, 0, cachedBitmapArray[0].getWidth(), cachedBitmapArray[0].getHeight()), child0Rect, mPaint);
|
||||||
cachedCanvas.drawRect(child0Rect, mPaint);
|
cachedCanvas.drawRect(child0Rect, mPaint);
|
||||||
cachedCanvas.drawBitmap(cachedBitmapArray[1], new Rect(0,0, cachedBitmapArray[1].getWidth(), cachedBitmapArray[1].getHeight()), child1Rect, mPaint);
|
cachedCanvas.drawBitmap(cachedBitmapArray[1], new Rect(0, 0, cachedBitmapArray[1].getWidth(), cachedBitmapArray[1].getHeight()), child1Rect, mPaint);
|
||||||
cachedCanvas.drawRect(child1Rect, mPaint);
|
cachedCanvas.drawRect(child1Rect, mPaint);
|
||||||
canvas.drawBitmap(cachedBitmap, 0, 0, mPaint);
|
canvas.drawBitmap(cachedBitmap, 0, 0, mPaint);
|
||||||
}
|
}
|
||||||
@@ -589,7 +618,7 @@ public class SplitLayout extends ViewGroup {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置子View的最小宽度
|
* 设置子View的最小宽度
|
||||||
* */
|
*/
|
||||||
public int getmChildMinSize() {
|
public int getmChildMinSize() {
|
||||||
return mChildMinSize;
|
return mChildMinSize;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user