Search in sources :

Example 1 with KeyButtonView

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

the class NavbarEditor method updateKeys.

/**
     * Updates the buttons according to the
     * key arrangement stored in settings provider
     */
@SuppressWarnings("unchecked")
protected void updateKeys() {
    String saved = Settings.System.getString(mContext.getContentResolver(), Settings.System.NAV_BUTTONS);
    if (saved == null) {
        saved = "empty|back|home|recent|empty|menu0";
    }
    int cc = 0;
    ArrayList<Integer> idMap = (ArrayList<Integer>) mIds.clone();
    if (mVertical)
        Collections.reverse(idMap);
    visibleCount = 0;
    for (String buttons : saved.split("\\|")) {
        KeyButtonView curView = (KeyButtonView) mParent.findViewById(idMap.get(cc));
        boolean isSmallButton = ArrayUtils.contains(NavbarEditor.smallButtonIds, curView.getId());
        curView.setInfo(buttons, mVertical);
        if (!curView.getTag().equals(NAVBAR_EMPTY) && !isSmallButton) {
            visibleCount++;
        }
        cc++;
    }
    if (isDevicePhone()) {
        adjustPadding();
    }
}
Also used : KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) ArrayList(java.util.ArrayList)

Example 2 with KeyButtonView

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

the class NavbarEditor method adjustPadding.

/**
     * Accommodates the padding between keys based on
     * number of keys in use.
     */
private void adjustPadding() {
    ViewGroup viewParent = (ViewGroup) mParent.findViewById(R.id.mid_nav_buttons);
    int sCount = visibleCount;
    for (int v = 0; v < viewParent.getChildCount(); v++) {
        View cView = viewParent.getChildAt(v);
        if (cView instanceof KeyButtonView) {
            View nextPadding = viewParent.getChildAt(v + 1);
            if (nextPadding != null) {
                View nextKey = viewParent.getChildAt(v + 2);
                String nextTag = NAVBAR_EMPTY;
                if (nextKey != null) {
                    nextTag = (String) nextKey.getTag();
                }
                String curTag = (String) cView.getTag();
                if (nextKey != null && nextTag != null && curTag != null && !curTag.equals(NAVBAR_EMPTY)) {
                    if (!nextTag.equals(NAVBAR_EMPTY)) {
                        nextPadding.setVisibility(View.VISIBLE);
                    } else {
                        if (sCount > 1) {
                            nextPadding.setVisibility(View.VISIBLE);
                        } else {
                            nextPadding.setVisibility(View.GONE);
                        }
                    }
                    sCount--;
                } else {
                    nextPadding.setVisibility(View.GONE);
                }
            }
        }
    }
}
Also used : KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) View(android.view.View) TextView(android.widget.TextView)

Example 3 with KeyButtonView

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

the class NavigationBarInflaterView method inflateButton.

@Nullable
protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape, int indexInParent) {
    LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater;
    float size = extractSize(buttonSpec);
    String button = extractButton(buttonSpec);
    View v = null;
    if (HOME.equals(button)) {
        v = inflater.inflate(R.layout.home, parent, false);
        if (landscape && isSw600Dp()) {
            setupLandButton(v);
        }
    } else if (BACK.equals(button)) {
        v = inflater.inflate(R.layout.back, parent, false);
        if (landscape && isSw600Dp()) {
            setupLandButton(v);
        }
    } else if (RECENT.equals(button)) {
        v = inflater.inflate(R.layout.recent_apps, parent, false);
        if (landscape && isSw600Dp()) {
            setupLandButton(v);
        }
    } else if (MENU_IME.equals(button)) {
        v = inflater.inflate(R.layout.menu_ime, parent, false);
    } else if (NAVSPACE.equals(button)) {
        v = inflater.inflate(R.layout.nav_key_space, parent, false);
    } else if (CLIPBOARD.equals(button)) {
        v = inflater.inflate(R.layout.clipboard, parent, false);
    } else if (button.startsWith(KEY)) {
        String uri = extractImage(button);
        int code = extractKeycode(button);
        v = inflater.inflate(R.layout.custom_key, parent, false);
        ((KeyButtonView) v).setCode(code);
        if (uri != null) {
            ((KeyButtonView) v).loadAsync(uri);
        }
    } else {
        return null;
    }
    if (size != 0) {
        ViewGroup.LayoutParams params = v.getLayoutParams();
        params.width = (int) (params.width * size);
    }
    parent.addView(v);
    addToDispatchers(v, landscape);
    View lastView = landscape ? mLastRot90 : mLastRot0;
    if (lastView != null) {
        v.setAccessibilityTraversalAfter(lastView.getId());
    }
    if (landscape) {
        mLastRot90 = v;
    } else {
        mLastRot0 = v;
    }
    return v;
}
Also used : KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) View(android.view.View) Nullable(android.annotation.Nullable)

Example 4 with KeyButtonView

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

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();
                // When exiting refresh disabled flags.
                mNavigationBarView.setDisabledFlags(mDisabled1, true);
                return true;
            } else if ((v.getId() == R.id.back) && !mNavigationBarView.getRecentsButton().getCurrentView().isPressed()) {
                // 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();
                // When exiting refresh disabled flags.
                mNavigationBarView.setDisabledFlags(mDisabled1, true);
                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)

Example 5 with KeyButtonView

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

the class NavbarEditor method onTouch.

@Override
public boolean onTouch(final View view, MotionEvent event) {
    if (!NavigationBarView.getEditMode() || (mDialog != null && mDialog.isShowing())) {
        return false;
    }
    float curPos = 0;
    if (!mVertical) {
        curPos = event.getRawX();
    } else {
        curPos = event.getRawY();
    }
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int[] screenLoc = new int[2];
        view.setPressed(true);
        view.getLocationOnScreen(screenLoc);
        // Store the starting view position in the parent's tag
        if (!mVertical) {
            mParent.setTag(Float.valueOf(screenLoc[0]));
        } else {
            mParent.setTag(Float.valueOf(screenLoc[1]));
        }
        view.postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        view.setPressed(false);
        if (!mLongPressed || ArrayUtils.contains(smallButtonIds, view.getId())) {
            return false;
        }
        view.bringToFront();
        ViewGroup viewParent = (ViewGroup) view.getParent();
        float buttonSize = 0;
        if (!mVertical) {
            buttonSize = view.getWidth();
        } else {
            buttonSize = view.getHeight();
        }
        // Prevents user from dragging view outside of bounds
        if ((!mVertical && ((curPos) > (viewParent.getWidth() + viewParent.getLeft()) || (curPos - buttonSize / 2 <= viewParent.getLeft()))) || (mVertical && ((curPos > (viewParent.getHeight() + viewParent.getTop())) || (curPos < viewParent.getTop())))) {
            return false;
        }
        if (!mVertical) {
            view.setX(curPos - viewParent.getLeft() - buttonSize / 2);
        } else {
            view.setY(curPos - viewParent.getTop() - buttonSize / 2);
        }
        int affectedViewPosition = findInterceptingViewIndex(curPos, view);
        if (affectedViewPosition == -1) {
            return false;
        }
        switchId(mIds.indexOf(view.getId()), affectedViewPosition, view);
    } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
        view.setPressed(false);
        view.removeCallbacks(mCheckLongPress);
        if (!mLongPressed && !view.getTag().equals("home")) {
            final ButtonAdapter list = new ButtonAdapter(ArrayUtils.contains(smallButtonIds, view.getId()) ? true : false);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(mContext.getString(R.string.navbar_dialog_title));
            builder.setAdapter(list, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ((KeyButtonView) view).setInfo(list.getItem(which).toString(), mVertical);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            mDialog = builder.create();
            mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            mDialog.setCanceledOnTouchOutside(false);
            mDialog.show();
            mLongPressed = false;
            return true;
        }
        mLongPressed = false;
        // Reset the dragged view to its original location
        ViewGroup vParent = (ViewGroup) view.getParent();
        if (!mVertical) {
            view.setX((Float) mParent.getTag() - vParent.getLeft());
        } else {
            view.setY((Float) mParent.getTag() - vParent.getTop());
        }
    }
    return true;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ViewGroup(android.view.ViewGroup) KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView)

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