Search in sources :

Example 11 with KeyButtonView

use of com.android.systemui.statusbar.policy.KeyButtonView in project android_frameworks_base by crdroidandroid.

the class PhoneStatusBar method handleLongPressBackRecents.

/**
     * This handles long-press of both back and recents.  They are
     * handled together to capture them both being long-pressed
     * at the same time to exit screen pinning (lock task).
     *
     * When accessibility mode is on, only a long-press from recents
     * is required to exit.
     *
     * In all other circumstances we try to pass through long-press events
     * for Back, so that apps can still use it.  Which can be from two things.
     * 1) Not currently in screen pinning (lock task).
     * 2) Back is long-pressed without recents.
     */
private boolean handleLongPressBackRecents(View v) {
    try {
        boolean sendBackLongPress = false;
        IActivityManager activityManager = ActivityManagerNative.getDefault();
        boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
        boolean inLockTaskMode = activityManager.isInLockTaskMode();
        if (inLockTaskMode && !touchExplorationEnabled) {
            long time = System.currentTimeMillis();
            // long-pressed 'together'
            if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
                activityManager.stopLockTaskMode();
                return true;
            } else if (v.getId() == R.id.back) {
                // If we aren't pressing recents right now then they presses
                // won't be together, so send the standard long-press action.
                sendBackLongPress = true;
            }
            mLastLockToAppLongPress = time;
        } else {
            // If this is back still need to handle sending the long-press event.
            if (v.getId() == R.id.back) {
                sendBackLongPress = true;
            } else if (touchExplorationEnabled && inLockTaskMode) {
                // When in accessibility mode a long press that is recents (not back)
                // should stop lock task.
                activityManager.stopLockTaskMode();
                return true;
            } else if (v.getId() == R.id.recent_apps) {
                return handleLongPressRecents();
            }
        }
        if (sendBackLongPress) {
            KeyButtonView keyButtonView = (KeyButtonView) v;
            keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
            keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
            return true;
        }
    } catch (RemoteException e) {
        Log.d(TAG, "Unable to reach activity manager", e);
    }
    return false;
}
Also used : KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Aggregations

KeyButtonView (com.android.systemui.statusbar.policy.KeyButtonView)11 ViewGroup (android.view.ViewGroup)8 View (android.view.View)7 Nullable (android.annotation.Nullable)5 LayoutInflater (android.view.LayoutInflater)5 RemoteException (android.os.RemoteException)3 IActivityManager (android.app.IActivityManager)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 LayoutTransition (android.animation.LayoutTransition)1 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 CustomTheme (android.content.res.CustomTheme)1 Point (android.graphics.Point)1 MotionEvent (android.view.MotionEvent)1 OnClickListener (android.view.View.OnClickListener)1 OnLongClickListener (android.view.View.OnLongClickListener)1 LayoutParams (android.view.ViewGroup.LayoutParams)1