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

Commit 549a2087 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I72f64c5f,Id2cbd681

* changes:
  Add @Override annotation to onTouchEvent
  Use KEYCODE_UNKNOWN constant instead of zero
parents 731faaf8 311748a5
Loading
Loading
Loading
Loading
+11 −9
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.policy;
package com.android.systemui.statusbar.policy;


import static android.view.Display.INVALID_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.KeyEvent.KEYCODE_UNKNOWN;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK;


@@ -101,7 +102,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.KeyButtonView,
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.KeyButtonView,
                defStyle, 0);
                defStyle, 0);


        mCode = a.getInteger(R.styleable.KeyButtonView_keyCode, 0);
        mCode = a.getInteger(R.styleable.KeyButtonView_keyCode, KEYCODE_UNKNOWN);


        mSupportsLongpress = a.getBoolean(R.styleable.KeyButtonView_keyRepeat, true);
        mSupportsLongpress = a.getBoolean(R.styleable.KeyButtonView_keyRepeat, true);
        mPlaySounds = a.getBoolean(R.styleable.KeyButtonView_playSound, true);
        mPlaySounds = a.getBoolean(R.styleable.KeyButtonView_playSound, true);
@@ -124,7 +125,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {


    @Override
    @Override
    public boolean isClickable() {
    public boolean isClickable() {
        return mCode != 0 || super.isClickable();
        return mCode != KEYCODE_UNKNOWN || super.isClickable();
    }
    }


    public void setCode(int code) {
    public void setCode(int code) {
@@ -163,7 +164,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
    @Override
    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);
        super.onInitializeAccessibilityNodeInfo(info);
        if (mCode != 0) {
        if (mCode != KEYCODE_UNKNOWN) {
            info.addAction(new AccessibilityNodeInfo.AccessibilityAction(ACTION_CLICK, null));
            info.addAction(new AccessibilityNodeInfo.AccessibilityAction(ACTION_CLICK, null));
            if (mSupportsLongpress || isLongClickable()) {
            if (mSupportsLongpress || isLongClickable()) {
                info.addAction(
                info.addAction(
@@ -182,13 +183,13 @@ public class KeyButtonView extends ImageView implements ButtonInterface {


    @Override
    @Override
    public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
    public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
        if (action == ACTION_CLICK && mCode != 0) {
        if (action == ACTION_CLICK && mCode != KEYCODE_UNKNOWN) {
            sendEvent(KeyEvent.ACTION_DOWN, 0, SystemClock.uptimeMillis());
            sendEvent(KeyEvent.ACTION_DOWN, 0, SystemClock.uptimeMillis());
            sendEvent(KeyEvent.ACTION_UP, 0);
            sendEvent(KeyEvent.ACTION_UP, 0);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
            playSoundEffect(SoundEffectConstants.CLICK);
            playSoundEffect(SoundEffectConstants.CLICK);
            return true;
            return true;
        } else if (action == ACTION_LONG_CLICK && mCode != 0) {
        } else if (action == ACTION_LONG_CLICK && mCode != KEYCODE_UNKNOWN) {
            sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
            sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
            sendEvent(KeyEvent.ACTION_UP, 0);
            sendEvent(KeyEvent.ACTION_UP, 0);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
@@ -197,6 +198,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        return super.performAccessibilityActionInternal(action, arguments);
        return super.performAccessibilityActionInternal(action, arguments);
    }
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
    public boolean onTouchEvent(MotionEvent ev) {
        final boolean showSwipeUI = mOverviewProxyService.shouldShowSwipeUpUI();
        final boolean showSwipeUI = mOverviewProxyService.shouldShowSwipeUpUI();
        final int action = ev.getAction();
        final int action = ev.getAction();
@@ -218,7 +220,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
                // Use raw X and Y to detect gestures in case a parent changes the x and y values
                // Use raw X and Y to detect gestures in case a parent changes the x and y values
                mTouchDownX = (int) ev.getRawX();
                mTouchDownX = (int) ev.getRawX();
                mTouchDownY = (int) ev.getRawY();
                mTouchDownY = (int) ev.getRawY();
                if (mCode != 0) {
                if (mCode != KEYCODE_UNKNOWN) {
                    sendEvent(KeyEvent.ACTION_DOWN, 0, mDownTime);
                    sendEvent(KeyEvent.ACTION_DOWN, 0, mDownTime);
                } else {
                } else {
                    // Provide the same haptic feedback that the system offers for virtual keys.
                    // Provide the same haptic feedback that the system offers for virtual keys.
@@ -249,7 +251,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
                break;
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_CANCEL:
                setPressed(false);
                setPressed(false);
                if (mCode != 0) {
                if (mCode != KEYCODE_UNKNOWN) {
                    sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
                    sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
                }
                }
                removeCallbacks(mCheckLongPress);
                removeCallbacks(mCheckLongPress);
@@ -269,7 +271,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
                    // and it feels weird to sometimes get a release haptic and other times not.
                    // and it feels weird to sometimes get a release haptic and other times not.
                    performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY_RELEASE);
                    performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY_RELEASE);
                }
                }
                if (mCode != 0) {
                if (mCode != KEYCODE_UNKNOWN) {
                    if (doIt) {
                    if (doIt) {
                        sendEvent(KeyEvent.ACTION_UP, 0);
                        sendEvent(KeyEvent.ACTION_UP, 0);
                        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
                        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
@@ -299,7 +301,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        sendEvent(action, flags, SystemClock.uptimeMillis());
        sendEvent(action, flags, SystemClock.uptimeMillis());
    }
    }


    void sendEvent(int action, int flags, long when) {
    private void sendEvent(int action, int flags, long when) {
        mMetricsLogger.write(new LogMaker(MetricsEvent.ACTION_NAV_BUTTON_EVENT)
        mMetricsLogger.write(new LogMaker(MetricsEvent.ACTION_NAV_BUTTON_EVENT)
                .setType(MetricsEvent.TYPE_ACTION)
                .setType(MetricsEvent.TYPE_ACTION)
                .setSubtype(mCode)
                .setSubtype(mCode)