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

Commit 761562d8 authored by Matthew Ng's avatar Matthew Ng
Browse files

Refactored rotation code from nav bar fragment to its button

Moved the rotation button in nav bar logic to its own button.

Test: atest NavigationBarRotationContextTest
Bug: 116041410
Change-Id: I7bb3c4c4a1637b52a7219c1074c09403c9505734
parent a941ce73
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -288,4 +288,10 @@ public class ButtonDispatcher {
            }
        }
    }

    /**
     * Executes when button is detached from window.
     */
    protected void onDestroy() {
    }
}
+51 −0
Original line number Diff line number Diff line
@@ -18,8 +18,10 @@ package com.android.systemui.statusbar.phone;

import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.NonNull;
import android.content.Context;
import android.view.View;

import com.android.systemui.statusbar.policy.KeyButtonDrawable;
import com.android.systemui.statusbar.policy.KeyButtonView;

@@ -29,6 +31,9 @@ import com.android.systemui.statusbar.policy.KeyButtonView;
 */
public class ContextualButton extends ButtonDispatcher {

    private ContextButtonListener mListener;
    private ContextualButtonGroup mGroup;

    protected final @DrawableRes int mIconResId;

    /**
@@ -64,6 +69,48 @@ public class ContextualButton extends ButtonDispatcher {
            currentDrawable.clearAnimationCallbacks();
            currentDrawable.resetAnimation();
        }

        if (mListener != null) {
            mListener.onVisibilityChanged(this, visibility == View.VISIBLE);
        }
    }

    public void setListener(ContextButtonListener listener) {
        mListener = listener;
    }

    /**
     * Show this button based on its priority compared to other buttons in the group. If not
     * attached to a group it will set its own visibility to be visible.
     * @return if visible
     */
    public boolean show() {
        if (mGroup == null) {
            setVisibility(View.VISIBLE);
            return true;
        }
        return mGroup.setButtonVisiblity(getId(), true /* visible */) == View.VISIBLE;
    }

    /**
     * Hide this button.
     * @return if visible
     */
    public boolean hide() {
        if (mGroup == null) {
            setVisibility(View.INVISIBLE);
            return false;
        }
        return mGroup.setButtonVisiblity(getId(), false /* visible */) != View.VISIBLE;
    }

    /**
     * Called when this button was added to the group. Keep a reference to the group to show based
     * on priority compared to other buttons.
     * @param group the holder of all the buttons
     */
    void attachToGroup(@NonNull ContextualButtonGroup group) {
        mGroup = group;
    }

    protected KeyButtonDrawable getNewDrawable() {
@@ -79,4 +126,8 @@ public class ContextualButton extends ButtonDispatcher {
    protected Context getContext() {
        return getCurrentView().getContext();
    }

    public interface ContextButtonListener {
        void onVisibilityChanged(ContextualButton button, boolean visible);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ public class ContextualButtonGroup extends ButtonDispatcher {
     * @param button the button added to the group
     */
    public void addButton(@NonNull ContextualButton button) {
        button.attachToGroup(this);
        mButtonData.add(new ButtonData(button));
    }

+44 −388

File changed.

Preview size limit exceeded, changes collapsed.

+7 −19
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.animation.PropertyValuesHolder;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.DrawableRes;
import android.annotation.StyleRes;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.res.Configuration;
@@ -271,7 +270,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        final ContextualButton imeSwitcherButton = new ContextualButton(R.id.ime_switcher,
                R.drawable.ic_ime_switcher_default);
        final RotationContextButton rotateSuggestionButton = new RotationContextButton(
                R.id.rotate_suggestion, R.drawable.ic_sysbar_rotate_button,
                R.id.rotate_suggestion, R.drawable.ic_sysbar_rotate_button, getContext(),
                R.style.RotateButtonCCWStart90);
        final ContextualButton accessibilityButton =
                new ContextualButton(R.id.accessibility_button,
@@ -418,8 +417,9 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        return mButtonDispatchers.get(R.id.accessibility_button);
    }

    public ButtonDispatcher getRotateSuggestionButton() {
        return mButtonDispatchers.get(R.id.rotate_suggestion);
    public RotationContextButton getRotateSuggestionButton() {
        return (RotationContextButton) mContextualButtonGroup
                .getContextButton(R.id.rotate_suggestion);
    }

    public SparseArray<ButtonDispatcher> getButtonDispatchers() {
@@ -746,27 +746,12 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        mContextualButtonGroup.setButtonVisiblity(R.id.menu, show);
    }

    public void updateRotateSuggestionButtonStyle(@StyleRes int style) {
        RotationContextButton button = (RotationContextButton) mContextualButtonGroup
                .getContextButton(R.id.rotate_suggestion);
        button.setStyle(style);
        button.updateIcon();
    }

    public void setAccessibilityButtonState(final boolean visible, final boolean longClickable) {
        mLongClickableAccessibilityButton = longClickable;
        getAccessibilityButton().setLongClickable(longClickable);
        mContextualButtonGroup.setButtonVisiblity(R.id.accessibility_button, visible);
    }

    public int setRotateButtonVisibility(boolean visible) {
        return mContextualButtonGroup.setButtonVisiblity(R.id.rotate_suggestion, visible);
    }

    public boolean isRotateButtonVisible() {
        return getRotateSuggestionButton().isVisible();
    }

    void hideRecentsOnboarding() {
        mRecentsOnboarding.hide(true);
    }
@@ -1058,6 +1043,9 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
            mGestureHelper.destroy();
        }
        setUpSwipeUpOnboarding(false);
        for (int i = 0; i < mButtonDispatchers.size(); ++i) {
            mButtonDispatchers.valueAt(i).onDestroy();
        }
    }

    private void setUpSwipeUpOnboarding(boolean connectedToOverviewProxy) {
Loading