Merge "Simplify GlobalActionsFlatLayout and fix dismiss"

This commit is contained in:
Aran Ink
2020-02-14 19:18:32 +00:00
committed by Android (Google) Code Review
6 changed files with 131 additions and 249 deletions

View File

@@ -2830,13 +2830,13 @@
"logout" = Logout the current user
-->
<string-array translatable="false" name="config_globalActionsList">
<item>emergency</item>
<item>power</item>
<item>restart</item>
<item>lockdown</item>
<item>logout</item>
<item>bugreport</item>
<item>screenshot</item>
<item>emergency</item>
</string-array>
<!-- Number of milliseconds to hold a wake lock to ensure that drawing is fully

View File

@@ -2,15 +2,17 @@
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/global_actions_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/global_actions_grid_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingBottom="@dimen/global_actions_grid_container_shadow_offset"
android:layout_marginBottom="@dimen/global_actions_grid_container_negative_shadow_offset">
<com.android.systemui.globalactions.GlobalActionsFlatLayout
@@ -25,65 +27,20 @@
android:gravity="top | center_horizontal"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingBottom="@dimen/global_actions_grid_container_shadow_offset"
android:layout_marginTop="@dimen/global_actions_top_margin"
android:layout_marginBottom="@dimen/global_actions_grid_container_negative_shadow_offset">
android:layout_marginTop="@dimen/global_actions_top_margin">
<LinearLayout
android:layout_height="wrap_content"
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layoutDirection="ltr"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_marginBottom="@dimen/global_actions_grid_container_bottom_margin">
<!-- For separated items-->
<LinearLayout
android:id="@+id/separated_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/global_actions_grid_side_margin"
android:layout_marginRight="@dimen/global_actions_grid_side_margin"
android:paddingLeft="@dimen/global_actions_grid_horizontal_padding"
android:paddingRight="@dimen/global_actions_grid_horizontal_padding"
android:paddingTop="@dimen/global_actions_grid_vertical_padding"
android:paddingBottom="@dimen/global_actions_grid_vertical_padding"
android:orientation="vertical"
android:gravity="center"
android:translationZ="@dimen/global_actions_translate"
/>
<!-- Grid of action items -->
<com.android.systemui.globalactions.ListGridLayout
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="right"
android:layout_marginRight="@dimen/global_actions_grid_side_margin"
android:translationZ="@dimen/global_actions_translate"
android:paddingLeft="@dimen/global_actions_grid_horizontal_padding"
android:paddingRight="@dimen/global_actions_grid_horizontal_padding"
android:paddingTop="@dimen/global_actions_grid_vertical_padding"
android:paddingBottom="@dimen/global_actions_grid_vertical_padding"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layoutDirection="locale"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layoutDirection="locale"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layoutDirection="locale"
/>
</com.android.systemui.globalactions.ListGridLayout>
</LinearLayout>
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/global_actions_grid_side_margin"
android:layout_marginRight="@dimen/global_actions_grid_side_margin"
android:paddingLeft="@dimen/global_actions_grid_horizontal_padding"
android:paddingRight="@dimen/global_actions_grid_horizontal_padding"
android:paddingTop="@dimen/global_actions_grid_vertical_padding"
android:paddingBottom="@dimen/global_actions_grid_vertical_padding"
android:orientation="horizontal"
android:gravity="left"
android:translationZ="@dimen/global_actions_translate" />
</com.android.systemui.globalactions.GlobalActionsFlatLayout>
<LinearLayout
@@ -110,8 +67,7 @@
android:layout_marginLeft="@dimen/global_actions_grid_horizontal_padding"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/global_actions_panel">
</LinearLayout>
app:layout_constraintTop_toBottomOf="@id/global_actions_panel"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@@ -57,7 +57,10 @@ public abstract class MultiListLayout extends LinearLayout {
}
protected void setSeparatedViewVisibility(boolean visible) {
getSeparatedView().setVisibility(visible ? View.VISIBLE : View.GONE);
ViewGroup separatedView = getSeparatedView();
if (separatedView != null) {
separatedView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
}
/**

View File

@@ -343,45 +343,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
} else {
mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
}
mAirplaneModeOn = new ToggleAction(
R.drawable.ic_lock_airplane_mode,
R.drawable.ic_lock_airplane_mode_off,
R.string.global_actions_toggle_airplane_mode,
R.string.global_actions_airplane_mode_on_status,
R.string.global_actions_airplane_mode_off_status) {
void onToggle(boolean on) {
if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
mIsWaitingForEcmExit = true;
// Launch ECM exit dialog
Intent ecmDialogIntent =
new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(ecmDialogIntent);
} else {
changeAirplaneModeSystemSetting(on);
}
}
@Override
protected void changeStateFromPress(boolean buttonOn) {
if (!mHasTelephony) return;
// In ECM mode airplane state cannot be changed
if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
mState = buttonOn ? State.TurningOn : State.TurningOff;
mAirplaneState = mState;
}
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return false;
}
};
mAirplaneModeOn = new AirplaneModeAction();
onAirplaneModeChanged();
mItems = new ArrayList<Action>();
@@ -545,7 +507,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
@Override
public boolean shouldBeSeparated() {
return !shouldShowControls();
return true;
}
@Override
@@ -1339,6 +1301,48 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
}
}
private class AirplaneModeAction extends ToggleAction {
AirplaneModeAction() {
super(
R.drawable.ic_lock_airplane_mode,
R.drawable.ic_lock_airplane_mode_off,
R.string.global_actions_toggle_airplane_mode,
R.string.global_actions_airplane_mode_on_status,
R.string.global_actions_airplane_mode_off_status);
}
void onToggle(boolean on) {
if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
mIsWaitingForEcmExit = true;
// Launch ECM exit dialog
Intent ecmDialogIntent =
new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(ecmDialogIntent);
} else {
changeAirplaneModeSystemSetting(on);
}
}
@Override
protected void changeStateFromPress(boolean buttonOn) {
if (!mHasTelephony) return;
// In ECM mode airplane state cannot be changed
if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
mState = buttonOn ? State.TurningOn : State.TurningOff;
mAirplaneState = mState;
}
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return false;
}
}
private class SilentModeToggleAction extends ToggleAction {
public SilentModeToggleAction() {
super(R.drawable.ic_audio_vol_mute,
@@ -1561,6 +1565,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
private ControlsUiController mControlsUiController;
private ViewGroup mControlsView;
private ViewGroup mContainerView;
ActionsDialog(Context context, MyAdapter adapter,
GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
@@ -1678,6 +1683,14 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
mScrimAlpha = ScrimController.BUSY_SCRIM_ALPHA;
}
getWindow().setBackgroundDrawable(mBackgroundDrawable);
if (mControlsView != null) {
mContainerView = findViewById(com.android.systemui.R.id.global_actions_container);
mContainerView.setOnTouchListener((v, e) -> {
dismiss();
return true;
});
}
}
private void fixNavBarClipping() {
@@ -1900,14 +1913,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
return isPanelDebugModeEnabled(context);
}
/**
* Determines whether the Global Actions menu should use a separated view for emergency actions.
*/
private static boolean shouldUseSeparatedView() {
return true;
}
private boolean shouldShowControls() {
return !mKeyguardManager.isDeviceLocked()
&& mControlsUiController.getAvailable();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 The Android Open Source Project
* 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.
@@ -23,164 +23,62 @@ import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.HardwareBgDrawable;
import com.android.systemui.R;
/**
* Single row implementation of the button layout created by the global actions dialog.
* Flat, single-row implementation of the button layout created by the global actions dialog.
*/
public class GlobalActionsFlatLayout extends GlobalActionsLayout {
private static final int MAX_ITEMS = 4;
public GlobalActionsFlatLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mBackgroundsSet = true;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// backgrounds set only once, the first time onMeasure is called after inflation
// if (getListView() != null && !mBackgroundsSet) {
// setBackgrounds();
// mBackgroundsSet = true;
// }
}
@VisibleForTesting
protected void setupListView() {
ListGridLayout listView = getListView();
listView.setExpectedCount(Math.min(2, mAdapter.countListItems()));
listView.setReverseSublists(shouldReverseSublists());
listView.setReverseItems(shouldReverseListItems());
listView.setSwapRowsAndColumns(shouldSwapRowsAndColumns());
protected boolean shouldReverseListItems() {
int rotation = getCurrentRotation();
if (rotation == ROTATION_NONE) {
return false;
}
if (getCurrentLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
return rotation == ROTATION_LANDSCAPE;
}
return rotation == ROTATION_SEASCAPE;
}
@Override
public void onUpdateList() {
setupListView();
super.onUpdateList();
updateSeparatedItemSize();
}
/**
* If the separated view contains only one item, expand the bounds of that item to take up the
* entire view, so that the whole thing is touch-able.
*/
@VisibleForTesting
protected void updateSeparatedItemSize() {
ViewGroup separated = getSeparatedView();
if (separated.getChildCount() == 0) {
return;
}
View firstChild = separated.getChildAt(0);
ViewGroup.LayoutParams childParams = firstChild.getLayoutParams();
if (separated.getChildCount() == 1) {
childParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
childParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
} else {
childParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
childParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
}
}
@Override
protected ListGridLayout getListView() {
return (ListGridLayout) super.getListView();
}
@Override
protected void removeAllListViews() {
ListGridLayout list = getListView();
if (list != null) {
list.removeAllItems();
}
protected HardwareBgDrawable getBackgroundDrawable(int backgroundColor) {
return null;
}
@Override
protected void addToListView(View v, boolean reverse) {
ListGridLayout list = getListView();
if (list != null) {
list.addItem(v);
// only add items to the list view if we haven't hit our max yet
if (getListView().getChildCount() < MAX_ITEMS) {
super.addToListView(v, reverse);
}
}
@Override
public void removeAllItems() {
ViewGroup separatedList = getSeparatedView();
ListGridLayout list = getListView();
if (separatedList != null) {
separatedList.removeAllViews();
}
if (list != null) {
list.removeAllItems();
}
}
/**
* Determines whether the ListGridLayout should fill sublists in the reverse order.
* Used to account for sublist ordering changing between landscape and seascape views.
*/
@VisibleForTesting
protected boolean shouldReverseSublists() {
if (getCurrentRotation() == ROTATION_SEASCAPE) {
return true;
}
return false;
}
/**
* Determines whether the ListGridLayout should fill rows first instead of columns.
* Used to account for vertical/horizontal changes due to landscape or seascape rotations.
*/
@VisibleForTesting
protected boolean shouldSwapRowsAndColumns() {
if (getCurrentRotation() == ROTATION_NONE) {
return false;
}
return true;
}
@Override
protected boolean shouldReverseListItems() {
int rotation = getCurrentRotation();
boolean reverse = false; // should we add items to parents in the reverse order?
if (rotation == ROTATION_NONE
|| rotation == ROTATION_SEASCAPE) {
reverse = !reverse; // if we're in portrait or seascape, reverse items
}
if (getCurrentLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
reverse = !reverse; // if we're in an RTL language, reverse items (again)
}
return reverse;
protected float getGridItemSize() {
return getContext().getResources().getDimension(R.dimen.global_actions_grid_item_height);
}
@VisibleForTesting
protected float getAnimationDistance() {
int rows = getListView().getRowCount();
float gridItemSize = getContext().getResources().getDimension(
com.android.systemui.R.dimen.global_actions_grid_item_height);
return rows * gridItemSize / 2;
return getGridItemSize() / 2;
}
@Override
public float getAnimationOffsetX() {
switch (getCurrentRotation()) {
case ROTATION_LANDSCAPE:
return getAnimationDistance();
case ROTATION_SEASCAPE:
return -getAnimationDistance();
default: // Portrait
return 0;
}
return 0;
}
@Override
public float getAnimationOffsetY() {
if (getCurrentRotation() == ROTATION_NONE) {
return getAnimationDistance();
}
return 0;
return -getAnimationDistance();
}
}

View File

@@ -42,16 +42,30 @@ public abstract class GlobalActionsLayout extends MultiListLayout {
}
private void setBackgrounds() {
int gridBackgroundColor = getResources().getColor(
ViewGroup listView = getListView();
int listBgColor = getResources().getColor(
R.color.global_actions_grid_background, null);
int separatedBackgroundColor = getResources().getColor(
R.color.global_actions_separated_background, null);
HardwareBgDrawable listBackground = new HardwareBgDrawable(true, true, getContext());
HardwareBgDrawable separatedBackground = new HardwareBgDrawable(true, true, getContext());
listBackground.setTint(gridBackgroundColor);
separatedBackground.setTint(separatedBackgroundColor);
getListView().setBackground(listBackground);
getSeparatedView().setBackground(separatedBackground);
HardwareBgDrawable listBackground = getBackgroundDrawable(listBgColor);
if (listBackground != null) {
listView.setBackground(listBackground);
}
ViewGroup separatedView = getSeparatedView();
if (separatedView != null) {
int separatedBgColor = getResources().getColor(
R.color.global_actions_separated_background, null);
HardwareBgDrawable separatedBackground = getBackgroundDrawable(separatedBgColor);
if (separatedBackground != null) {
getSeparatedView().setBackground(separatedBackground);
}
}
}
protected HardwareBgDrawable getBackgroundDrawable(int backgroundColor) {
HardwareBgDrawable background = new HardwareBgDrawable(true, true, getContext());
background.setTint(backgroundColor);
return background;
}
@Override
@@ -74,10 +88,16 @@ public abstract class GlobalActionsLayout extends MultiListLayout {
}
protected void addToSeparatedView(View v, boolean reverse) {
if (reverse) {
getSeparatedView().addView(v, 0);
ViewGroup separated = getSeparatedView();
if (separated != null) {
if (reverse) {
separated.addView(v, 0);
} else {
separated.addView(v);
}
} else {
getSeparatedView().addView(v);
// if no separated view exists, just use the list view
addToListView(v, reverse);
}
}