Fix tapping on divider bar several times makes split sloggish

Make sure it won't introduce redundant fling animation when touch on
divider bar didn't exceed tap threshold. This make sure it won't queue
extra sync transactions with SyncTransactionQueue. Also skip redundant
checks after detected double tap in staged split.

Fix: 186626153
Fix: 179004532
Test: tapping on divider bar of legacy and staged split, it won't make
split sloggish.

Change-Id: I2a326f54f25d77e86fa51bca67b68daca21dedfc
This commit is contained in:
Jerry Chang
2021-04-28 21:41:23 +08:00
parent 8a170b2edf
commit 59f0ef3535
3 changed files with 13 additions and 7 deletions

View File

@@ -110,6 +110,10 @@ public class DividerView extends FrameLayout implements View.OnTouchListener,
return false;
}
if (mDoubleTapDetector.onTouchEvent(event)) {
return true;
}
final int action = event.getAction() & MotionEvent.ACTION_MASK;
final boolean isLandscape = isLandscape();
// Using raw xy to prevent lost track of motion events while moving divider bar.
@@ -136,21 +140,22 @@ public class DividerView extends FrameLayout implements View.OnTouchListener,
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mVelocityTracker.addMovement(event);
releaseTouching();
if (!mMoving) break;
mVelocityTracker.computeCurrentVelocity(1000 /* units */);
final float velocity = isLandscape
? mVelocityTracker.getXVelocity()
: mVelocityTracker.getYVelocity();
releaseTouching();
mMoving = false;
final int position = mSplitLayout.getDividePosition() + touchPos - mStartPos;
final DividerSnapAlgorithm.SnapTarget snapTarget =
mSplitLayout.findSnapTarget(position, velocity, false /* hardDismiss */);
mSplitLayout.snapToTarget(position, snapTarget);
mMoving = false;
break;
}
mDoubleTapDetector.onTouchEvent(event);
return true;
}
@@ -229,7 +234,7 @@ public class DividerView extends FrameLayout implements View.OnTouchListener,
if (mSplitLayout != null) {
mSplitLayout.onDoubleTappedDivider();
}
return false;
return true;
}
}
}

View File

@@ -231,6 +231,7 @@ public class SplitLayout {
}
private void flingDividePosition(int from, int to) {
if (from == to) return;
ValueAnimator animator = ValueAnimator
.ofInt(from, to)
.setDuration(250);

View File

@@ -49,7 +49,6 @@ import android.view.VelocityTracker;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.ViewRootImpl;
import android.view.ViewTreeObserver.InternalInsetsInfo;
import android.view.ViewTreeObserver.OnComputeInternalInsetsListener;
import android.view.WindowManager;
@@ -524,9 +523,10 @@ public class DividerView extends FrameLayout implements OnTouchListener,
case MotionEvent.ACTION_CANCEL:
mVelocityTracker.addMovement(event);
if (!mMoving) break;
x = (int) event.getRawX();
y = (int) event.getRawY();
mVelocityTracker.computeCurrentVelocity(1000);
int position = calculatePosition(x, y);
stopDragging(position, isHorizontalDivision() ? mVelocityTracker.getYVelocity()