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

Commit 7e6571f1 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Use long press of KeyButtonView to invoke assist

This makes sure that accessibility is handled properly.

Bug: 18778078
Change-Id: I967b387aabff973b5a9fea649a805540ee08eea8
parent 9a600725
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -583,7 +583,7 @@
    <dimen name="managed_profile_toast_padding">4dp</dimen>

    <!-- Thickness of the assist disclosure beams -->
    <dimen name="assist_disclosure_thickness">4dp</dimen>
    <dimen name="assist_disclosure_thickness">3dp</dimen>

    <!-- Thickness of the shadows of the assist disclosure beams -->
    <dimen name="assist_disclosure_shadow_thickness">1.5dp</dimen>
+1 −8
Original line number Diff line number Diff line
@@ -125,14 +125,11 @@ public class AssistManager {
        }
    }

    public void onGestureInvoked(boolean vibrate) {
    public void onGestureInvoked() {
        if (mAssistComponent == null) {
            return;
        }

        if (vibrate) {
            vibrate();
        }
        final boolean isService = isAssistantService();
        if (isService || !isVoiceSessionRunning()) {
            showOrb();
@@ -290,10 +287,6 @@ public class AssistManager {
        v.setImageDrawable(null);
    }

    private void vibrate() {
        mView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    }

    private boolean isAssistantService() {
        return mAssistComponent == null ?
                false : mAssistComponent.equals(getVoiceInteractorComponentName());
+12 −25
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import com.android.systemui.EventLogConstants;
import com.android.systemui.EventLogTags;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.SwipeHelper;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
@@ -676,8 +677,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            mNotificationPanelDebugText.setVisibility(View.VISIBLE);
        }

        updateShowSearchHoldoff();

        try {
            boolean showNav = mWindowManagerService.hasNavigationBar();
            if (DEBUG) Log.v(TAG, "hasNavigationBar=" + showNav);
@@ -1013,11 +1012,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        return mStatusBarWindow;
    }

    public void invokeAssistGesture(boolean vibrate) {
        mHandler.removeCallbacks(mInvokeAssist);
        mAssistManager.onGestureInvoked(vibrate);
    }

    public int getStatusBarHeight() {
        if (mNaturalBarHeight < 0) {
            final Resources res = mContext.getResources();
@@ -1044,31 +1038,28 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
    };

    private int mShowSearchHoldoff = 0;
    private Runnable mInvokeAssist = new Runnable() {
        public void run() {
    private final View.OnLongClickListener mLongPressHomeListener
            = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (shouldDisableNavbarGestures()) {
                return false;
            }
            mAssistManager.prepareBeforeInvocation();
            invokeAssistGesture(true /* vibrate */);
            mAssistManager.onGestureInvoked();
            awakenDreams();
            if (mNavigationBarView != null) {
                mNavigationBarView.abortCurrentGesture();
            }
            return true;
        }
    };

    View.OnTouchListener mHomeActionListener = new View.OnTouchListener() {
    private final View.OnTouchListener mHomeActionListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    if (!shouldDisableNavbarGestures()) {
                        mHandler.removeCallbacks(mInvokeAssist);
                        mHandler.postDelayed(mInvokeAssist, mShowSearchHoldoff);
                    }
                    break;

                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    mHandler.removeCallbacks(mInvokeAssist);
                    awakenDreams();
                    break;
            }
@@ -1096,6 +1087,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mNavigationBarView.getBackButton().setLongClickable(true);
        mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener);
        mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);
        mNavigationBarView.getHomeButton().setOnLongClickListener(mLongPressHomeListener);
        mAssistManager.onConfigurationChanged();
    }

@@ -1236,10 +1228,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
    }

    private void updateShowSearchHoldoff() {
        mShowSearchHoldoff = ViewConfiguration.getLongPressTimeout();
    }

    private void updateNotificationShade() {
        if (mStackScroller == null) return;

@@ -2922,7 +2910,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,

        updateResources();
        repositionNavigationBar();
        updateShowSearchHoldoff();
        updateRowStates();
        mIconController.updateResources();
        mScreenPinningRequest.onConfigurationChanged();
+7 −13
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public class KeyButtonView extends ImageView {
                if (isLongClickable()) {
                    // Just an old-fashioned ImageView
                    performLongClick();
                } else {
                } else if (mSupportsLongpress) {
                    sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
                    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
                }
@@ -92,7 +92,7 @@ public class KeyButtonView extends ImageView {
        super.onInitializeAccessibilityNodeInfo(info);
        if (mCode != 0) {
            info.addAction(new AccessibilityNodeInfo.AccessibilityAction(ACTION_CLICK, null));
            if (mSupportsLongpress) {
            if (mSupportsLongpress || isLongClickable()) {
                info.addAction(
                        new AccessibilityNodeInfo.AccessibilityAction(ACTION_LONG_CLICK, null));
            }
@@ -115,7 +115,7 @@ public class KeyButtonView extends ImageView {
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
            playSoundEffect(SoundEffectConstants.CLICK);
            return true;
        } else if (action == ACTION_LONG_CLICK && mCode != 0 && mSupportsLongpress) {
        } else if (action == ACTION_LONG_CLICK && mCode != 0) {
            sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
            sendEvent(KeyEvent.ACTION_UP, 0);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
@@ -144,10 +144,8 @@ public class KeyButtonView extends ImageView {
                    // Provide the same haptic feedback that the system offers for virtual keys.
                    performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                }
                if (mSupportsLongpress) {
                removeCallbacks(mCheckLongPress);
                postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
                }
                break;
            case MotionEvent.ACTION_MOVE:
                x = (int)ev.getX();
@@ -162,9 +160,7 @@ public class KeyButtonView extends ImageView {
                if (mCode != 0) {
                    sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
                }
                if (mSupportsLongpress) {
                removeCallbacks(mCheckLongPress);
                }
                break;
            case MotionEvent.ACTION_UP:
                final boolean doIt = isPressed();
@@ -183,9 +179,7 @@ public class KeyButtonView extends ImageView {
                        performClick();
                    }
                }
                if (mSupportsLongpress) {
                removeCallbacks(mCheckLongPress);
                }
                break;
        }