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

Commit 55537eac authored by Sukesh Ram's avatar Sukesh Ram
Browse files

Replace Contextual Rotation Button with Floating Action Button

When foldable is in 3 button, the rotation button
 is covered by device camera cutout on rotation.

This CL replaces Contextual Rotation Button with
Floating Action Button for taskbar and navbar.

Flag: NONE
Test: Manually tested on Felix & panther.
Bug: 324070001
Change-Id: I8c5b61033f0b32b6557b96d572d8de66d3e77e4c
parent 2061cece
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import java.util.function.Supplier;
 * Contains logic that deals with showing a rotate suggestion button with animation.
 */
public class RotationButtonController {
    public static final boolean DEBUG_ROTATION = false;

    private static final String TAG = "RotationButtonController";
    private static final int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
+9 −21
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.HOME_B
import static com.android.systemui.navigationbar.NavBarHelper.transitionMode;
import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
import static com.android.systemui.shared.recents.utilities.Utilities.isLargeScreen;
import static com.android.systemui.shared.rotation.RotationButtonController.DEBUG_ROTATION;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_ALLOW_GESTURE_IGNORING_BAR_VISIBILITY;
@@ -121,7 +122,6 @@ import com.android.systemui.navigationbar.NavigationModeController.ModeChangedLi
import com.android.systemui.navigationbar.buttons.ButtonDispatcher;
import com.android.systemui.navigationbar.buttons.DeadZone;
import com.android.systemui.navigationbar.buttons.KeyButtonView;
import com.android.systemui.navigationbar.buttons.RotationContextButton;
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
import com.android.systemui.navigationbar.gestural.QuickswitchOrientedNavHandle;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
@@ -135,7 +135,6 @@ import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shade.domain.interactor.PanelExpansionInteractor;
import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
import com.android.systemui.shared.recents.utilities.Utilities;
import com.android.systemui.shared.rotation.RotationButton;
import com.android.systemui.shared.rotation.RotationButtonController;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.SysUiStatsLog;
@@ -658,8 +657,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
            // When in gestural and the IME is showing, don't use the nearest region since it will
            // take gesture space away from the IME
            info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
            info.touchableRegion.set(getButtonLocations(false /* includeFloatingButtons */,
                    false /* inScreen */, false /* useNearestRegion */));
            info.touchableRegion.set(
                    getButtonLocations(false /* inScreen */, false /* useNearestRegion */));
        };

        mRegionSamplingHelper = new RegionSamplingHelper(mView,
@@ -795,10 +794,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        repositionNavigationBar(mCurrentRotation);
        mView.setUpdateActiveTouchRegionsCallback(
                () -> mOverviewProxyService.onActiveNavBarRegionChanges(
                        getButtonLocations(
                                true /* includeFloatingButtons */,
                                true /* inScreen */,
                                true /* useNearestRegion */)));
                        getButtonLocations(true /* inScreen */, true /* useNearestRegion */)));

        mView.getViewTreeObserver().addOnComputeInternalInsetsListener(
                mOnComputeInternalInsetsListener);
@@ -1135,16 +1131,14 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
                .hasDisable2RotateSuggestionFlag(mDisabledFlags2);
        final RotationButtonController rotationButtonController =
                mView.getRotationButtonController();
        final RotationButton rotationButton = rotationButtonController.getRotationButton();

        if (RotationContextButton.DEBUG_ROTATION) {
        if (DEBUG_ROTATION) {
            Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
                    + ", isValid=" + isValid + ", mNavBarWindowState="
                    + StatusBarManager.windowStateToString(mNavigationBarWindowState)
                    + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
                    + ", isRotateButtonVisible=" + rotationButton.isVisible());
                    + ", isRotateButtonVisible="
                    + rotationButtonController.getRotationButton().isVisible());
        }

        // Respect the disabled flag, no need for action as flag change callback will handle hiding
        if (rotateSuggestionsDisabled) return;

@@ -1903,14 +1897,11 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
    }

    /**
     * @param includeFloatingButtons Whether to include the floating rotation and overlay button in
     *                               the region for all the buttons
     * @param inScreenSpace Whether to return values in screen space or window space
     * @param useNearestRegion Whether to use the nearest region instead of the actual button bounds
     * @return
     */
    Region getButtonLocations(boolean includeFloatingButtons, boolean inScreenSpace,
            boolean useNearestRegion) {
    Region getButtonLocations(boolean inScreenSpace, boolean useNearestRegion) {
        if (useNearestRegion && !inScreenSpace) {
            // We currently don't support getting the nearest region in anything but screen space
            useNearestRegion = false;
@@ -1928,13 +1919,10 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        updateButtonLocation(
                region, touchRegionCache, mView.getAccessibilityButton(), inScreenSpace,
                useNearestRegion);
        if (includeFloatingButtons && mView.getFloatingRotationButton().isVisible()) {
        if (mView.getFloatingRotationButton().isVisible()) {
            // Note: this button is floating so the nearest region doesn't apply
            updateButtonLocation(
                    region, mView.getFloatingRotationButton().getCurrentView(), inScreenSpace);
        } else {
            updateButtonLocation(region, touchRegionCache, mView.getRotateSuggestionButton(),
                    inScreenSpace, useNearestRegion);
        }
        return region;
    }
+2 −21
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ import com.android.systemui.navigationbar.buttons.ContextualButtonGroup;
import com.android.systemui.navigationbar.buttons.DeadZone;
import com.android.systemui.navigationbar.buttons.KeyButtonDrawable;
import com.android.systemui.navigationbar.buttons.NearestTouchFrame;
import com.android.systemui.navigationbar.buttons.RotationContextButton;
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
import com.android.systemui.recents.Recents;
import com.android.systemui.res.R;
@@ -153,7 +152,6 @@ public class NavigationBarView extends FrameLayout {
    private ShadeViewController mShadeViewController;
    @Nullable
    private PanelExpansionInteractor mPanelExpansionInteractor;
    private RotationContextButton mRotationContextButton;
    private FloatingRotationButton mFloatingRotationButton;
    private RotationButtonController mRotationButtonController;

@@ -293,8 +291,6 @@ public class NavigationBarView extends FrameLayout {
                        R.drawable.ic_sysbar_accessibility_button);
        mContextualButtonGroup.addButton(imeSwitcherButton);
        mContextualButtonGroup.addButton(accessibilityButton);
        mRotationContextButton = new RotationContextButton(R.id.rotate_suggestion,
                mLightContext, R.drawable.ic_sysbar_rotate_button_ccw_start_0);
        mFloatingRotationButton = new FloatingRotationButton(mContext,
                R.string.accessibility_rotate_button,
                R.layout.rotate_suggestion,
@@ -433,10 +429,6 @@ public class NavigationBarView extends FrameLayout {
        return mButtonDispatchers.get(R.id.accessibility_button);
    }

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

    public ButtonDispatcher getHomeHandle() {
        return mButtonDispatchers.get(R.id.home_handle);
    }
@@ -483,18 +475,8 @@ public class NavigationBarView extends FrameLayout {
     * Updates the rotation button based on the current navigation mode.
     */
    void updateRotationButton() {
        if (isGesturalMode(mNavBarMode)) {
            mContextualButtonGroup.removeButton(R.id.rotate_suggestion);
            mButtonDispatchers.remove(R.id.rotate_suggestion);
        mRotationButtonController.setRotationButton(mFloatingRotationButton,
                mRotationButtonListener);
        } else if (mContextualButtonGroup.getContextButton(R.id.rotate_suggestion) == null) {
            mContextualButtonGroup.addButton(mRotationContextButton);
            mButtonDispatchers.put(R.id.rotate_suggestion, mRotationContextButton);
            mRotationButtonController.setRotationButton(mRotationContextButton,
                    mRotationButtonListener);
        }
        mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers);
    }

    public KeyButtonDrawable getBackDrawable() {
@@ -1143,7 +1125,6 @@ public class NavigationBarView extends FrameLayout {
        dumpButton(pw, "home", getHomeButton());
        dumpButton(pw, "handle", getHomeHandle());
        dumpButton(pw, "rcnt", getRecentsButton());
        dumpButton(pw, "rota", getRotateSuggestionButton());
        dumpButton(pw, "a11y", getAccessibilityButton());
        dumpButton(pw, "ime", getImeSwitchButton());

+0 −79
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.navigationbar.buttons;

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

import com.android.systemui.shared.rotation.RotationButton;
import com.android.systemui.shared.rotation.RotationButtonController;

/** Containing logic for the rotation button in nav bar. */
public class RotationContextButton extends ContextualButton implements RotationButton {
    public static final boolean DEBUG_ROTATION = false;

    private RotationButtonController mRotationButtonController;

    /**
     * @param lightContext the context to use to load the icon resource
     */
    public RotationContextButton(@IdRes int buttonResId, Context lightContext,
            @DrawableRes int iconResId) {
        super(buttonResId, lightContext, iconResId);
    }

    @Override
    public void setRotationButtonController(RotationButtonController rotationButtonController) {
        mRotationButtonController = rotationButtonController;
    }

    @Override
    public void setUpdatesCallback(RotationButtonUpdatesCallback updatesCallback) {
        setListener((button, visible) -> {
            if (updatesCallback != null) {
                updatesCallback.onVisibilityChanged(visible);
            }
        });
    }

    @Override
    public void setVisibility(int visibility) {
        super.setVisibility(visibility);

        // Start the rotation animation once it becomes visible
        final KeyButtonDrawable currentDrawable = getImageDrawable();
        if (visibility == View.VISIBLE && currentDrawable != null) {
            currentDrawable.resetAnimation();
            currentDrawable.startAnimation();
        }
    }

    @Override
    protected KeyButtonDrawable getNewDrawable(int lightIconColor, int darkIconColor) {
        return KeyButtonDrawable.create(mRotationButtonController.getContext(),
                lightIconColor, darkIconColor, mRotationButtonController.getIconResId(),
                false /* shadow */, null /* ovalBackgroundColor */);
    }

    @Override
    public boolean acceptRotationProposal() {
        View currentView = getCurrentView();
        return currentView != null && currentView.isAttachedToWindow();
    }
}