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

Commit 4c90669f authored by David van Tonder's avatar David van Tonder Committed by Gerrit Code Review
Browse files

Merge "Pie controls: Tweaking UX for pie service (1/2)" into cm-10.1

parents e6200089 fa46b51f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2552,6 +2552,16 @@ public final class Settings {
         */
        public static final String PIE_SIZE = "pie_size";

        /**
         * Sensitivity for triggering the pie controls.
         *  1 = hard
         *  ...
         *  3 = easy
         *  Default: 3
         * @hide
         */
        public static final String PIE_SENSITIVITY = "pie_sensitivity";

        /**
         * Quick Settings Panel Tiles to Use
         *
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The CyanogenMod Project (Jens Doll)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.android.internal.util.pie;

/**
 * Constants needed for the pie service.
 *
 * @see PiePosition
 */
public final class PieServiceConstants {

    private PieServiceConstants() {
        // no object allowed
    }

    /**
     * Mask for coding positions within the flags of
     * {@code updatePieActivationListener()}.
     * <p>
     * Positions are specified by {@code PiePosition.FLAG}.
     */
    public static final int POSITION_MASK = 0x0000000f;

    /**
     * Mask for coding sensitivity within the flags of
     * {@code updatePieActivationListener()}.
     * <p>
     * Sensitivity influences the speed of the swipe, the trigger area, and trigger distance that
     * is needed to activate the pie.
     */
    public static final int SENSITIVITY_MASK = 0x70000000;

    /**
     * Number of bits to shift left, to get a integer within the {@link #SENSITIVITY_MASK}.
     */
    public static final int SENSITIVITY_SHIFT = 28;

    /**
     * No sensitivity specified at all, the service may choose a sensitivity level on its own.
     */
    public static final int SENSITIVITY_NONE = 0;

    /**
     * Default sensitivity, picked by the pie service automatically. 
     */
    public static final int SENSITIVITY_DEFAULT = 2;

    /**
     * Lowest valid sensitivity value.
     */
    public static final int SENSITIVITY_LOWEST = 1;

    /**
     * Highest sensitivity value.
     */
    public static final int SENSITIVITY_HIGHEST = 4;

}
+2 −2
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@

    <!-- Pie service: Distance a swipe must travel to be recognized as pie swipe.
         Used by the pie service. -->
    <dimen name="pie_trigger_distance">10dp</dimen>
    <dimen name="pie_trigger_distance">12dp</dimen>

    <!-- Pie service: This is the distance a swipe can travel orthogonally to its actual swipe
         direction to be still recognized as pie swipe.
@@ -359,5 +359,5 @@
    <dimen name="pie_perpendicular_distance">15dp</dimen>

    <!-- Pie service: Thickness of the active trigger fields around the screen border -->
    <dimen name="pie_trigger_thickness">6dp</dimen>
    <dimen name="pie_trigger_thickness">12dp</dimen>
</resources>
+13 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.widget.Toast;

import com.android.internal.util.cm.DevUtils;
import com.android.internal.util.pie.PiePosition;
import com.android.internal.util.pie.PieServiceConstants;
import com.android.systemui.R;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.NavigationButtons;
@@ -215,6 +216,8 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, PieVi
            // trigger setupListener()
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.PIE_POSITIONS), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.PIE_SENSITIVITY), false, this);
        }

        @Override
@@ -351,8 +354,17 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, PieVi

        mPieTriggerSlots = Settings.System.getInt(resolver,
                Settings.System.PIE_POSITIONS, PiePosition.BOTTOM.FLAG);

        int sensitivity = Settings.System.getInt(resolver,
                Settings.System.PIE_SENSITIVITY, 3);
        if (sensitivity < PieServiceConstants.SENSITIVITY_LOWEST
                || sensitivity > PieServiceConstants.SENSITIVITY_HIGHEST) {
            sensitivity = PieServiceConstants.SENSITIVITY_DEFAULT;
        }

        mPieManager.updatePieActivationListener(mPieActivationListener,
                mPieTriggerSlots & mPieTriggerMask);
                sensitivity<<PieServiceConstants.SENSITIVITY_SHIFT
                | mPieTriggerSlots & mPieTriggerMask);
    }

    private void setupNavigationItems() {
+46 −14
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
 */
package com.android.server.pie;

import static com.android.internal.util.pie.PieServiceConstants.SENSITIVITY_HIGHEST;
import static com.android.internal.util.pie.PieServiceConstants.SENSITIVITY_LOWEST;

import android.graphics.Point;
import android.os.SystemClock;
import android.util.Slog;
@@ -35,9 +38,15 @@ public class PieGestureTracker {
    public final static long TRIGGER_TIME_MS = 140;
    public final static int PIXEL_SWIPE_OFFTAKE_SLOP = 2;

    private final int mTriggerThickness;
    private final int mTriggerDistance;
    private final int mPerpendicularDistance;
    private final int mBaseThickness;
    private final int mBaseTriggerDistance;
    private final int mBasePerpendicularDistance;

    private int mThickness;
    private int mTriggerDistance;
    private int mPerpendicularDistance;
    private int mGracePeriodDistance;
    private long mTimeOut;

    private int mDisplayWidth;
    private int mDisplayHeight;
@@ -59,9 +68,29 @@ public class PieGestureTracker {
        if (DEBUG) {
            Slog.d(TAG, "init: " + thickness + "," + distance);
        }
        mTriggerThickness = thickness;
        mTriggerDistance = distance;
        mPerpendicularDistance = perpendicular;
        mBaseThickness = thickness;
        mBaseTriggerDistance = distance;
        mBasePerpendicularDistance = perpendicular;
        setSensitivity(0);
    }

    private void setSensitivity(int sensitivity) {
        float factor = 0.0f;
        if (sensitivity >= 1) {
             factor = (sensitivity - 1) / 4.0f;
        }
        if (DEBUG) {
            Slog.d(TAG, "sensitivity: " + sensitivity + " => factor:" + factor);
        }
        // default values (without overlay):
        // 140ms ... 210ms
        mTimeOut = (long) (TRIGGER_TIME_MS * (factor + 1.0f));
        // 12dp ... 18dp
        mThickness = (int) (mBaseThickness * (factor + 1.0f));
        // 12dp ... 6dp
        mTriggerDistance = (int) (mBaseTriggerDistance * (1.0f - factor));
        mPerpendicularDistance = (int) (mBasePerpendicularDistance * (1.0f - factor));
        mGracePeriodDistance = (int) (mThickness / 3.0f);
    }

    public void setOnActivationListener(OnActivationListener listener) {
@@ -82,32 +111,35 @@ public class PieGestureTracker {
        }
    }

    public boolean start(MotionEvent motionEvent, int positions) {
    public boolean start(MotionEvent motionEvent, int positions, int sensitivity) {
        final int x = (int) motionEvent.getX();
        final float fx = motionEvent.getX() / mDisplayWidth;
        final int y = (int) motionEvent.getY();
        final float fy = motionEvent.getY() / mDisplayHeight;

        // calculate trigger geometry based on sensitivity
        setSensitivity(sensitivity);

        if ((positions & PiePosition.LEFT.FLAG) != 0) {
            if (x < mTriggerThickness && fy > 0.1f && fy < 0.9f) {
            if (x < mThickness && fy > 0.1f && fy < 0.9f) {
                startWithPosition(motionEvent, PiePosition.LEFT);
                return true;
            }
        }
        if ((positions & PiePosition.BOTTOM.FLAG) != 0) {
            if (y > mDisplayHeight - mTriggerThickness && fx > 0.1f && fx < 0.9f) {
            if (y > mDisplayHeight - mThickness && fx > 0.1f && fx < 0.9f) {
                startWithPosition(motionEvent, PiePosition.BOTTOM);
                return true;
            }
        }
        if ((positions & PiePosition.RIGHT.FLAG) != 0) {
            if (x > mDisplayWidth - mTriggerThickness && fy > 0.1f && fy < 0.9f) {
            if (x > mDisplayWidth - mThickness && fy > 0.1f && fy < 0.9f) {
                startWithPosition(motionEvent, PiePosition.RIGHT);
                return true;
            }
        }
        if ((positions & PiePosition.TOP.FLAG) != 0) {
            if (y < mTriggerThickness && fx > 0.1f && fx < 0.9f) {
            if (y < mThickness && fx > 0.1f && fx < 0.9f) {
                startWithPosition(motionEvent, PiePosition.TOP);
                return true;
            }
@@ -126,14 +158,14 @@ public class PieGestureTracker {
        mInitialY = (int) motionEvent.getY();
        switch (position) {
            case LEFT:
                mGracePeriod = (int) (mTriggerDistance / 3.0f);
                mGracePeriod = mGracePeriodDistance;
                mOffTake = mInitialX - PIXEL_SWIPE_OFFTAKE_SLOP;
                break;
            case BOTTOM:
                mOffTake = mInitialY + PIXEL_SWIPE_OFFTAKE_SLOP;
                break;
            case RIGHT:
                mGracePeriod = mDisplayWidth - (int) (mTriggerDistance / 3.0f);
                mGracePeriod = mDisplayWidth - mGracePeriodDistance;
                mOffTake = mInitialX + PIXEL_SWIPE_OFFTAKE_SLOP;
                break;
            case TOP:
@@ -144,7 +176,7 @@ public class PieGestureTracker {
    }

    public boolean move(MotionEvent motionEvent) {
        if (!mActive || motionEvent.getEventTime() - mDownTime > TRIGGER_TIME_MS) {
        if (!mActive || motionEvent.getEventTime() - mDownTime > mTimeOut) {
            Slog.d(TAG, "pie gesture timeout: " + (motionEvent.getEventTime() - mDownTime));
            mActive = false;
            return false;
Loading