Skip to content

Commit

Permalink
Refactor how we show rotation button in fully gestural mode.
Browse files Browse the repository at this point in the history
Fixes: 132201048
Test: manual
Change-Id: I56d04dfabb4db741cd5dce72f01439c777d668c5
  • Loading branch information
Tracy Zhou committed May 27, 2019
1 parent e02360b commit 24fd028
Show file tree
Hide file tree
Showing 12 changed files with 781 additions and 540 deletions.
36 changes: 0 additions & 36 deletions packages/SystemUI/res/layout/start_contextual.xml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/SystemUI/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
<!-- Nav bar button default ordering/layout -->
<string name="config_navBarLayout" translatable="false">left[.5W],back[1WC];home;recent[1WC],right[.5W]</string>
<string name="config_navBarLayoutQuickstep" translatable="false">back[1.7WC];home;contextual[1.7WC]</string>
<string name="config_navBarLayoutHandle" translatable="false">start_contextual[40AC];home_handle;ime_switcher[40AC]</string>
<string name="config_navBarLayoutHandle" translatable="false">back[40AC];home_handle;ime_switcher[40AC]</string>

<bool name="quick_settings_show_full_alarm">false</bool>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright (C) 2019 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.statusbar.phone;

import android.content.Context;
import android.graphics.PixelFormat;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;

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

/** Containing logic for the rotation button on the physical left bottom corner of the screen. */
public class FloatingRotationButton implements RotationButton {

private final Context mContext;
private final WindowManager mWindowManager;
private final KeyButtonView mKeyButtonView;
private KeyButtonDrawable mKeyButtonDrawable;
private boolean mIsShowing;
private boolean mCanShow = true;

private RotationButtonController mRotationButtonController;

FloatingRotationButton(Context context) {
mContext = context;
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mKeyButtonView = (KeyButtonView) LayoutInflater.from(mContext).inflate(
R.layout.rotate_suggestion, null);
}

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

@Override
public View getCurrentView() {
return mKeyButtonView;
}

@Override
public boolean show() {
if (!mCanShow || mIsShowing) {
return false;
}
mIsShowing = true;
int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
float density = mContext.getResources().getDisplayMetrics().density;
int diameter = (int) density * 48;
int margin = (int) density * 4;
final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(diameter, diameter,
margin, margin, WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, flags,
PixelFormat.TRANSLUCENT);
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
lp.setTitle("FloatingRotationButton");
switch (mWindowManager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_0:
lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
break;
case Surface.ROTATION_90:
lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
break;
case Surface.ROTATION_180:
lp.gravity = Gravity.TOP | Gravity.RIGHT;
break;
case Surface.ROTATION_270:
lp.gravity = Gravity.TOP | Gravity.LEFT;
break;
default:
break;
}
updateIcon();
mWindowManager.addView(mKeyButtonView, lp);
if (mKeyButtonDrawable != null && mKeyButtonDrawable.canAnimate()) {
mKeyButtonDrawable.resetAnimation();
mKeyButtonDrawable.startAnimation();
}
return true;
}

@Override
public boolean hide() {
if (!mIsShowing) {
return false;
}
mWindowManager.removeViewImmediate(mKeyButtonView);
mRotationButtonController.cleanUp();
mIsShowing = false;
return true;
}

@Override
public boolean isVisible() {
return mIsShowing;
}

@Override
public void updateIcon() {
if (!mIsShowing) {
return;
}
mKeyButtonDrawable = getImageDrawable();
mKeyButtonView.setImageDrawable(mKeyButtonDrawable);
mKeyButtonDrawable.setCallback(mKeyButtonView);
if (mKeyButtonDrawable != null && mKeyButtonDrawable.canAnimate()) {
mKeyButtonDrawable.resetAnimation();
mKeyButtonDrawable.startAnimation();
}
}

@Override
public void setOnClickListener(View.OnClickListener onClickListener) {
mKeyButtonView.setOnClickListener(onClickListener);
}

@Override
public void setOnHoverListener(View.OnHoverListener onHoverListener) {
mKeyButtonView.setOnHoverListener(onHoverListener);
}

@Override
public KeyButtonDrawable getImageDrawable() {
Context context = new ContextThemeWrapper(mContext.getApplicationContext(),
mRotationButtonController.getStyleRes());
return KeyButtonDrawable.create(context, R.drawable.ic_sysbar_rotate_button,
false /* shadow */, true /* hasOvalBg */);
}

@Override
public void setDarkIntensity(float darkIntensity) {
mKeyButtonView.setDarkIntensity(darkIntensity);
}

@Override
public void setCanShowRotationButton(boolean canShow) {
mCanShow = canShow;
if (!mCanShow) {
hide();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void onConnectionChanged(boolean isConnected) {
@Override
public void onQuickStepStarted() {
// Use navbar dragging as a signal to hide the rotate button
mNavigationBarView.getRotateSuggestionButton().setRotateSuggestionButtonState(false);
mNavigationBarView.getRotationButtonController().setRotateSuggestionButtonState(false);

// Hide the notifications panel when quick step starts
mStatusBar.collapsePanel(true /* animate */);
Expand Down Expand Up @@ -333,16 +333,16 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

// Currently there is no accelerometer sensor on non-default display.
if (mIsOnDefaultDisplay) {
final RotationContextButton rotationButton =
mNavigationBarView.getRotateSuggestionButton();
rotationButton.setListener(mRotationButtonListener);
rotationButton.addRotationCallback(mRotationWatcher);
mNavigationBarView.getRotateSuggestionButton().setListener(mRotationButtonListener);

final RotationButtonController rotationButtonController =
mNavigationBarView.getRotationButtonController();
rotationButtonController.addRotationCallback(mRotationWatcher);

// Reset user rotation pref to match that of the WindowManager if starting in locked
// mode. This will automatically happen when switching from auto-rotate to locked mode.
if (display != null && rotationButton.isRotationLocked()) {
final int winRotation = display.getRotation();
rotationButton.setRotationLockedAtAngle(winRotation);
if (display != null && rotationButtonController.isRotationLocked()) {
rotationButtonController.setRotationLockedAtAngle(display.getRotation());
}
} else {
mDisabledFlags2 |= StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
Expand Down Expand Up @@ -458,34 +458,34 @@ public void setWindowState(
if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));

updateSystemUiStateFlags(-1);
mNavigationBarView.getRotateSuggestionButton()
.onNavigationBarWindowVisibilityChange(isNavBarWindowVisible());
mNavigationBarView.getRotationButtonController().onNavigationBarWindowVisibilityChange(
isNavBarWindowVisible());
}
}

@Override
public void onRotationProposal(final int rotation, boolean isValid) {
final int winRotation = mNavigationBarView.getDisplay().getRotation();
final boolean rotateSuggestionsDisabled = RotationContextButton
final boolean rotateSuggestionsDisabled = RotationButtonController
.hasDisable2RotateSuggestionFlag(mDisabledFlags2);
final RotationButtonController rotationButtonController =
mNavigationBarView.getRotationButtonController();
final RotationButton rotationButton = rotationButtonController.getRotationButton();

if (RotationContextButton.DEBUG_ROTATION) {
Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
+ ", winRotation=" + Surface.rotationToString(winRotation)
+ ", isValid=" + isValid + ", mNavBarWindowState="
+ StatusBarManager.windowStateToString(mNavigationBarWindowState)
+ ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
+ ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" :
mNavigationBarView.getRotateSuggestionButton().isVisible()));
+ ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null"
: rotationButton.isVisible()));
}

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

View rotationButton = mNavigationBarView.getRotateSuggestionButton().getCurrentView();
if (rotationButton != null && rotationButton.isAttachedToWindow()) {
mNavigationBarView.getRotateSuggestionButton()
.onRotationProposal(rotation, winRotation, isValid);
}
rotationButtonController.onRotationProposal(rotation, winRotation, isValid);
}

/** Restores the System UI flags saved state to {@link NavigationBarFragment}. */
Expand Down Expand Up @@ -593,7 +593,7 @@ public void disable(int displayId, int state1, int state2, boolean animate) {
private void setDisabled2Flags(int state2) {
// Method only called on change of disable2 flags
if (mNavigationBarView != null) {
mNavigationBarView.getRotateSuggestionButton().onDisable2FlagChanged(state2);
mNavigationBarView.getRotationButtonController().onDisable2FlagChanged(state2);
}
}

Expand Down Expand Up @@ -862,8 +862,8 @@ private void updateAccessibilityServicesState(AccessibilityManager accessibility
boolean[] feedbackEnabled = new boolean[1];
int a11yFlags = getA11yButtonState(feedbackEnabled);

mNavigationBarView.getRotateSuggestionButton()
.setAccessibilityFeedbackEnabled(feedbackEnabled[0]);
mNavigationBarView.getRotationButtonController().setAccessibilityFeedbackEnabled(
feedbackEnabled[0]);

boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0;
boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class NavigationBarInflaterView extends FrameLayout
public static final String RIGHT = "right";
public static final String CONTEXTUAL = "contextual";
public static final String IME_SWITCHER = "ime_switcher";
public static final String START_CONTEXTUAL = "start_contextual";

public static final String GRAVITY_SEPARATOR = ";";
public static final String BUTTON_SEPARATOR = ",";
Expand Down Expand Up @@ -395,8 +394,6 @@ private View createView(String buttonSpec, ViewGroup parent, LayoutInflater infl
v = inflater.inflate(R.layout.home_handle, parent, false);
} else if (IME_SWITCHER.equals(button)) {
v = inflater.inflate(R.layout.ime_switcher, parent, false);
} else if (START_CONTEXTUAL.equals(button)) {
v = inflater.inflate(R.layout.start_contextual, parent, false);
} else if (button.startsWith(KEY)) {
String uri = extractImage(button);
int code = extractKeycode(button);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void applyDarkIntensity(float darkIntensity) {
for (int i = buttonDispatchers.size() - 1; i >= 0; i--) {
buttonDispatchers.valueAt(i).setDarkIntensity(darkIntensity);
}
mView.getRotationButtonController().setDarkIntensity(darkIntensity);
if (mAutoDim) {
applyLightsOut(false, true);
}
Expand Down

0 comments on commit 24fd028

Please sign in to comment.