diff --git a/.idea/emulatorDisplays.xml b/.idea/emulatorDisplays.xml
new file mode 100644
index 0000000..2785e11
--- /dev/null
+++ b/.idea/emulatorDisplays.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automotive/src/main/AndroidManifest.xml b/automotive/src/main/AndroidManifest.xml
index b0c2496..0e7dc6a 100644
--- a/automotive/src/main/AndroidManifest.xml
+++ b/automotive/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
android:required="true" />
+
0 && System.currentTimeMillis() - mChildLongPressTime >= LONG_PRESS_TIME ) {
+ if (isEventAllInChildView(switchLongPressChildView, ev)) {
+ // 震动提示用户,开始支持拖动移动
+ performHapticFeedback(HapticFeedbackConstants.DRAG_START);
+ mIsSwitching = true;
+ mIsSwitchStart = false;
+ } else { // 划出当前View,则重置长按初始时间为0,且初始点按的childView也置为null
+ mChildLongPressTime = 0;
+ switchLongPressChildView = null;
+ }
+ }
+ }
+ }
+ break;
+ case MotionEvent.ACTION_POINTER_UP:
+ if (hasSwitchChild) {
+ switchChildViewPosition();
+ }
+ hasSwitchChild = false;
+ mIsSwitching = false;
+ mIsSwitchStart = false;
+ switchLongPressChildView = null;
+ mChildLongPressTime = 0;
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ if (mIsDragging) {
+ mHandleDrawable.setState(EMPTY_STATE_SET);
+ if (mOrientation == VERTICAL) {
+ float deltaY = y - mLastMotionY;
+ updateSplitPositionWithDelta(deltaY);
+ } else {
+ float deltaX = x - mLastMotionX;
+ updateSplitPositionWithDelta(deltaX);
+ }
+ mLastMotionX = x;
+ mLastMotionY = y;
+ mIsDragging = false;
+ }
+ break;
}
+ return mIsDragging || mIsSwitchStart || mIsSwitching || ev.getActionMasked() == MotionEvent.ACTION_DOWN || ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
+ }
- break;
+ public boolean isEventAllInChildView(View childView, MotionEvent event) {
+ if (childView == null || event == null) {
+ return false;
+ }
+ int left = childView.getLeft();
+ int top = childView.getTop();
+ int right = childView.getRight();
+ int bottom = childView.getBottom();
+
+ for (int i = 0; i < event.getPointerCount(); i++) {
+ // 有任意一个点不在当前View内,则返回false
+ if (event.getX(i) < left || event.getX(i) > right || event.getY(i) < top || event.getY(i) > bottom) {
+ return false;
+ }
}
- return mIsDragging;
+ return true;
}
private boolean isUnderSplitHandle(float x, float y) {
@@ -268,19 +373,25 @@ public class SplitLayout extends ViewGroup {
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(cachedBitmapArray[0], null, child0Rect, null);
cachedCanvas.drawRect(child0Rect, mPaint);
- 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.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);
+// 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);
canvas.drawBitmap(cachedBitmap, 0, 0, null);
}
+ } else if (mIsSwitching) { // 开始拖动切换
+ if (hasSwitchChild) {
+ resetChildSnapshotBitmap(canvas, true);
+ } else {
+ resetChildSnapshotBitmap(canvas, false);
+ }
}
}
@@ -357,12 +468,6 @@ public class SplitLayout extends ViewGroup {
// 获取当前两个子View的Bitmap截图,用于在拖动过程中的实时绘制
private void getBitmapFromChildView() {
- // 先回收已有的缓存图片
- for (Bitmap bitmap: cachedBitmapArray) {
- if (bitmap != null) {
- bitmap.recycle();
- }
- }
if (mChild0!=null) {
cachedBitmapArray[0] = loadBitmapFromViewBySystem(mChild0);
}
@@ -396,6 +501,7 @@ public class SplitLayout extends ViewGroup {
return dragForgroundColor;
}
+ // 切换两个子View的位置
public void switchChildViewPosition() {
checkChildren();
removeAllViews();
@@ -406,4 +512,35 @@ public class SplitLayout extends ViewGroup {
mChild1 = tempView;
requestLayout();
}
+
+ // 设置两个子View的快照的显示,可反转
+ public void resetChildSnapshotBitmap(Canvas canvas, boolean isReverse) {
+ 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();
+ if (mOrientation == VERTICAL) {
+ if (!isReverse) {
+ child0Rect.set(0, 0, getWidth(), (int) (mSplitPosition - mHandleSize / 2));
+ child1Rect.set(0, (int) (mSplitPosition + mHandleSize / 2), getWidth(), getHeight());
+ } else {
+ child1Rect.set(0, 0, getWidth(), (int) (mSplitPosition - mHandleSize / 2));
+ child0Rect.set(0, (int) (mSplitPosition + mHandleSize / 2), getWidth(), getHeight());
+ }
+ } else {
+ if (!isReverse) {
+ child0Rect.set(0, 0, (int) (mSplitPosition - mHandleSize / 2), getHeight());
+ child1Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
+ } else {
+ child1Rect.set(0, 0, (int) (mSplitPosition - mHandleSize / 2), getHeight());
+ child0Rect.set((int) (mSplitPosition + mHandleSize / 2), 0, getWidth(), getHeight());
+ }
+ }
+ cachedCanvas.drawBitmap(cachedBitmapArray[0], null, child0Rect, null);
+ cachedCanvas.drawRect(child0Rect, mPaint);
+ cachedCanvas.drawBitmap(cachedBitmapArray[1], null, child1Rect, null);
+ cachedCanvas.drawRect(child1Rect, mPaint);
+ canvas.drawBitmap(cachedBitmap, 0, 0, null);
+ }
+ }
}
diff --git a/automotive/src/main/res/drawable-xxhdpi/vertical_line.9.png b/automotive/src/main/res/drawable-xxhdpi/vertical_line.9.png
new file mode 100644
index 0000000..8c96d47
Binary files /dev/null and b/automotive/src/main/res/drawable-xxhdpi/vertical_line.9.png differ
diff --git a/automotive/src/main/res/layout/activity_split_layout.xml b/automotive/src/main/res/layout/activity_split_layout.xml
index bcca7e5..aa03710 100644
--- a/automotive/src/main/res/layout/activity_split_layout.xml
+++ b/automotive/src/main/res/layout/activity_split_layout.xml
@@ -41,14 +41,13 @@
android:layout_height="match_parent"
android:layout_marginBottom="48dp"
app:splitFraction="0.3"
- app:splitHandleDrawable="@drawable/split_drawable"
- app:splitDragForgroundColor="@color/material_yellow_500"
+ app:splitHandleDrawable="@drawable/vertical_line"
+ app:splitDragForgroundColor="@color/draw_progress_bg_color"
app:splitOrientation="horizontal">
+ android:layout_height="match_parent">
+
+
+
+