Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 828e56ea authored by Adam Powell's avatar Adam Powell
Browse files

Squish!

Take touch point size into account during the detection of scaling
gestures. Average together the major/minor axes of the size.

Add a config resource for tuning the minimum span requred to begin
(or end) a scale. This may be altered in a device-specific overlay
for devices that deviate too far from their assigned density bucket.

Change-Id: I2986888e9427a7e4cb56717d59c4fa7858ba9ca7
parent d65afc65
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ public class ScaleGestureDetector {
    private long mPrevTime;
    private boolean mInProgress;
    private int mSpanSlop;
    private int mMinSpan;

    /**
     * Consistency verifier for debugging purposes.
@@ -149,6 +150,8 @@ public class ScaleGestureDetector {
        mContext = context;
        mListener = listener;
        mSpanSlop = ViewConfiguration.get(context).getScaledTouchSlop() * 2;
        mMinSpan = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.config_minScalingSpan);
    }

    /**
@@ -209,8 +212,12 @@ public class ScaleGestureDetector {
        float devSumX = 0, devSumY = 0;
        for (int i = 0; i < count; i++) {
            if (skipIndex == i) continue;
            devSumX += Math.abs(event.getX(i) - focusX);
            devSumY += Math.abs(event.getY(i) - focusY);

            // touchMajor/Minor are axes of an ellipse; average them together and
            // convert the resulting 'diameter' into a radius.
            final float touchSize = (event.getTouchMajor(i) + event.getTouchMinor(i)) / 4;
            devSumX += Math.abs(event.getX(i) - focusX) + touchSize;
            devSumY += Math.abs(event.getY(i) - focusY) + touchSize;
        }
        final float devX = devSumX / div;
        final float devY = devSumY / div;
@@ -228,7 +235,7 @@ public class ScaleGestureDetector {
        final boolean wasInProgress = mInProgress;
        mFocusX = focusX;
        mFocusY = focusY;
        if (mInProgress && (span == 0 || configChanged)) {
        if (mInProgress && (span < mMinSpan || configChanged)) {
            mListener.onScaleEnd(this);
            mInProgress = false;
            mInitialSpan = span;
@@ -238,7 +245,7 @@ public class ScaleGestureDetector {
            mPrevSpanY = mCurrSpanY = spanY;
            mInitialSpan = mPrevSpan = mCurrSpan = span;
        }
        if (!mInProgress && span != 0 &&
        if (!mInProgress && span > mMinSpan &&
                (wasInProgress || Math.abs(span - mInitialSpan) > mSpanSlop)) {
            mPrevSpanX = mCurrSpanX = spanX;
            mPrevSpanY = mCurrSpanY = spanY;
+6 −0
Original line number Diff line number Diff line
@@ -925,4 +925,10 @@

    <!--  Maximum number of supported users -->
    <integer name="config_multiuserMaximumUsers">1</integer>

    <!-- Minimum span needed to begin a touch scaling gesture.
         This also takes into account the size of any active touch points.
         Devices with screens that deviate too far from their assigned density
         bucket should consider tuning this value in a device-specific overlay. -->
    <dimen name="config_minScalingSpan">25mm</dimen>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -1112,6 +1112,8 @@
  <java-symbol type="layout" name="media_route_list_item_collapse_group" />
  <java-symbol type="string" name="bluetooth_a2dp_audio_route_name" />

  <java-symbol type="dimen" name="config_minScalingSpan" />

  <!-- From android.policy -->
  <java-symbol type="anim" name="app_starting_exit" />
  <java-symbol type="anim" name="lock_screen_behind_enter" />