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

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

Merge "Fix longpress on Menu showing IME."

parents e93a4921 804eb858
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -106,15 +106,6 @@
            android:layout_centerInParent="true"
            />

        <com.android.systemui.statusbar.KeyButtonView android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_toLeftOf="@+id/menu"
            android:paddingLeft="4dip"
            android:paddingRight="4dip"
            android:src="@drawable/status_bar_back"
            systemui:keyCode="4"
            />
        <com.android.systemui.statusbar.KeyButtonView android:id="@+id/menu"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
@@ -136,11 +127,20 @@
        <com.android.systemui.statusbar.KeyButtonView android:id="@+id/home"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:paddingLeft="4dip"
            android:paddingRight="4dip"
            android:layout_toLeftOf="@+id/back"
            android:src="@drawable/status_bar_home"
            systemui:keyCode="3"
            />
        <com.android.systemui.statusbar.KeyButtonView android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:paddingLeft="4dip"
            android:paddingRight="4dip"
            android:src="@drawable/status_bar_back"
            systemui:keyCode="4"
            />
</RelativeLayout>
+27 −6
Original line number Diff line number Diff line
@@ -25,10 +25,12 @@ import android.os.SystemClock;
import android.os.ServiceManager;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.HapticFeedbackConstants;
import android.view.IWindowManager;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.ImageView;
import android.widget.RemoteViews.RemoteView;

@@ -37,9 +39,22 @@ import com.android.systemui.R;
public class KeyButtonView extends ImageView {
    IWindowManager mWindowManager;
    long mDownTime;
    boolean mSending;
    boolean mSending, mLongPressed;
    int mCode;
    int mRepeat;
    Runnable mCheckLongPress = new Runnable() {
        public void run() {
            Slog.d("KeyButtonView", "longpress");
            if (isPressed()) {
                mLongPressed = true;
                mRepeat++;
                sendEvent(KeyEvent.ACTION_DOWN,
                        KeyEvent.FLAG_FROM_SYSTEM
                        | KeyEvent.FLAG_VIRTUAL_HARD_KEY
                        | KeyEvent.FLAG_LONG_PRESS);
            }
        }
    };

    public KeyButtonView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
@@ -69,12 +84,16 @@ public class KeyButtonView extends ImageView {

        switch (action) {
            case MotionEvent.ACTION_DOWN:
                Slog.d("KeyButtonView", "press");
                mDownTime = SystemClock.uptimeMillis();
                mRepeat = 0;
                mSending = true;
                mLongPressed = false;
                sendEvent(KeyEvent.ACTION_DOWN,
                        KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_SOFT_KEYBOARD, mDownTime);
                        KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, mDownTime);
                setPressed(true);
                removeCallbacks(mCheckLongPress);
                postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
                break;
            case MotionEvent.ACTION_MOVE:
                if (mSending) {
@@ -83,19 +102,21 @@ public class KeyButtonView extends ImageView {
                    if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) {
                        mSending = false;
                        sendEvent(KeyEvent.ACTION_UP,
                                KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_SOFT_KEYBOARD
                                KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY
                                        | KeyEvent.FLAG_CANCELED);
                        setPressed(false);
                        removeCallbacks(mCheckLongPress);
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                if (mSending) {
                setPressed(false);
                if (mSending && !mLongPressed) {
                    mSending = false;
                    sendEvent(KeyEvent.ACTION_UP,
                            KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_SOFT_KEYBOARD);
                    setPressed(false);
                            KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY);
                    removeCallbacks(mCheckLongPress);
                }
                break;
        }