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