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

Commit 518a67b2 authored by Daniel Sandler's avatar Daniel Sandler Committed by Android (Google) Code Review
Browse files

Merge "Remove longpress support from the software Home key."

parents 3e1cee60 44a4616b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@
                android:layout_height="match_parent"
                android:src="@drawable/ic_sysbar_home"
                systemui:keyCode="3"
                systemui:keyRepeat="false"
                android:layout_weight="0"
                systemui:glowBackground="@drawable/ic_sysbar_highlight"
                android:contentDescription="@string/accessibility_home"
@@ -148,6 +149,7 @@
                android:layout_width="match_parent"
                android:src="@drawable/ic_sysbar_home_land"
                systemui:keyCode="3"
                systemui:keyRepeat="false"
                android:layout_weight="0"
                android:contentDescription="@string/accessibility_home"
                systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
+4 −0
Original line number Diff line number Diff line
@@ -16,7 +16,11 @@

<resources>
    <declare-styleable name="KeyButtonView">
        <!-- key code to send when pressed; if absent or 0, no key is sent -->
        <attr name="keyCode" format="integer" />
        <!-- does this button generate longpress / repeat events? -->
        <attr name="keyRepeat" format="boolean" />
        <!-- drawable to use for a swelling, glowing background on press -->
        <attr name="glowBackground" format="reference" />
    </declare-styleable>
    <declare-styleable name="ToggleSlider">
+21 −8
Original line number Diff line number Diff line
@@ -57,11 +57,12 @@ public class KeyButtonView extends ImageView {
    int mTouchSlop;
    Drawable mGlowBG;
    float mGlowAlpha = 0f, mGlowScale = 1f, mDrawingAlpha = 1f;
    boolean mSupportsLongpress = true;

    Runnable mCheckLongPress = new Runnable() {
        public void run() {
            if (isPressed()) {

                // Slog.d("KeyButtonView", "longpressed: " + this);
                if (mCode != 0) {
                    mRepeat++;
                    sendEvent(KeyEvent.ACTION_DOWN,
@@ -90,6 +91,8 @@ public class KeyButtonView extends ImageView {

        mCode = a.getInteger(R.styleable.KeyButtonView_keyCode, 0);
        
        mSupportsLongpress = a.getBoolean(R.styleable.KeyButtonView_keyRepeat, true);

        mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground);
        if (mGlowBG != null) {
            mDrawingAlpha = 0.5f;
@@ -207,11 +210,19 @@ public class KeyButtonView extends ImageView {
                mDownTime = SystemClock.uptimeMillis();
                mRepeat = 0;
                mSending = true;
                setPressed(true);
                sendEvent(KeyEvent.ACTION_DOWN,
                        KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, mDownTime);
                setPressed(true);
                if (mSupportsLongpress) {
                    removeCallbacks(mCheckLongPress);
                    postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
                } else {
                    mSending = false;
                    sendEvent(KeyEvent.ACTION_UP,
                            KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, mDownTime);
                    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
                    playSoundEffect(SoundEffectConstants.CLICK);
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (mSending) {
@@ -230,8 +241,10 @@ public class KeyButtonView extends ImageView {
                    sendEvent(KeyEvent.ACTION_UP,
                            KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY
                                | KeyEvent.FLAG_CANCELED);
                    if (mSupportsLongpress) {
                        removeCallbacks(mCheckLongPress);
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
                final boolean doIt = isPressed();
@@ -239,15 +252,15 @@ public class KeyButtonView extends ImageView {
                if (mSending) {
                    mSending = false;
                    final int flags = KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY;
                    if (mSupportsLongpress) {
                        removeCallbacks(mCheckLongPress);
                    }

                    if (mCode != 0) {
                        if (doIt) {
                            sendEvent(KeyEvent.ACTION_UP, flags);
                            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
                            playSoundEffect(SoundEffectConstants.CLICK);
                        } else {
                            sendEvent(KeyEvent.ACTION_UP, flags | KeyEvent.FLAG_CANCELED);
                        }
                    } else {
                        // no key code, just a regular ImageView