Merge "Prototype remove labels in QS"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f426672fc2
@@ -50,4 +50,6 @@ public abstract class QSTileView extends LinearLayout {
|
||||
public abstract void onStateChanged(State state);
|
||||
|
||||
public abstract int getDetailY();
|
||||
|
||||
public void setShowLabels(boolean show) {}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
private int mMinRows = 1;
|
||||
private int mMaxColumns = TileLayout.NO_MAX_COLUMNS;
|
||||
|
||||
private boolean mShowLabels = true;
|
||||
|
||||
public PagedTileLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mScroller = new Scroller(context, SCROLL_CUBIC);
|
||||
@@ -82,6 +84,16 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
}
|
||||
private int mLastMaxHeight = -1;
|
||||
|
||||
@Override
|
||||
public void setShowLabels(boolean show) {
|
||||
mShowLabels = show;
|
||||
for (TilePage p : mPages) {
|
||||
p.setShowLabels(show);
|
||||
}
|
||||
mDistributeTiles = true;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public void saveInstanceState(Bundle outState) {
|
||||
outState.putInt(CURRENT_PAGE, getCurrentItem());
|
||||
}
|
||||
@@ -219,6 +231,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
.inflate(R.layout.qs_paged_page, this, false);
|
||||
page.setMinRows(mMinRows);
|
||||
page.setMaxColumns(mMaxColumns);
|
||||
page.setShowLabels(mShowLabels);
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
@@ -829,6 +829,8 @@ public class QSPanel extends LinearLayout implements Tunable {
|
||||
default void setExpansion(float expansion) {}
|
||||
|
||||
int getNumVisibleTiles();
|
||||
|
||||
default void setShowLabels(boolean show) {}
|
||||
}
|
||||
|
||||
interface OnConfigurationChangedListener {
|
||||
|
||||
@@ -52,6 +52,8 @@ import javax.inject.Named;
|
||||
*/
|
||||
@QSScope
|
||||
public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
||||
public static final String QS_REMOVE_LABELS = "sysui_remove_labels";
|
||||
|
||||
private final QSSecurityFooter mQsSecurityFooter;
|
||||
private final TunerService mTunerService;
|
||||
private final QSCustomizerController mQsCustomizerController;
|
||||
@@ -120,6 +122,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
||||
updateMediaDisappearParameters();
|
||||
|
||||
mTunerService.addTunable(mView, QS_SHOW_BRIGHTNESS);
|
||||
mTunerService.addTunable(mTunable, QS_REMOVE_LABELS);
|
||||
mView.updateResources();
|
||||
if (mView.isListening()) {
|
||||
refreshAllTiles();
|
||||
@@ -132,6 +135,13 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean switchTileLayout(boolean force) {
|
||||
boolean result = super.switchTileLayout(force);
|
||||
getTileLayout().setShowLabels(mShowLabels);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QSTileRevealController createTileRevealController() {
|
||||
return mQsTileRevealControllerFactory.create(
|
||||
@@ -140,6 +150,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
||||
|
||||
@Override
|
||||
protected void onViewDetached() {
|
||||
mTunerService.removeTunable(mTunable);
|
||||
mTunerService.removeTunable(mView);
|
||||
mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
||||
if (mBrightnessMirrorController != null) {
|
||||
@@ -305,5 +316,21 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
||||
public boolean isExpanded() {
|
||||
return mView.isExpanded();
|
||||
}
|
||||
|
||||
private TunerService.Tunable mTunable = new TunerService.Tunable() {
|
||||
@Override
|
||||
public void onTuningChanged(String key, String newValue) {
|
||||
if (QS_REMOVE_LABELS.equals(key)) {
|
||||
boolean newShowLabels = "0".equals(newValue);
|
||||
if (mShowLabels == newShowLabels) return;
|
||||
mShowLabels = newShowLabels;
|
||||
for (TileRecord t : mRecords) {
|
||||
t.tileView.setShowLabels(mShowLabels);
|
||||
}
|
||||
getTileLayout().setShowLabels(mShowLabels);
|
||||
mView.requestLayout();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
||||
private float mRevealExpansion;
|
||||
|
||||
private final QSHost.Callback mQSHostCallback = this::setTiles;
|
||||
protected boolean mShowLabels = true;
|
||||
|
||||
private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener =
|
||||
new QSPanel.OnConfigurationChangedListener() {
|
||||
@@ -183,6 +184,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
||||
final TileRecord r = new TileRecord();
|
||||
r.tile = tile;
|
||||
r.tileView = mHost.createTileView(tile, collapsedView);
|
||||
r.tileView.setShowLabels(mShowLabels);
|
||||
mView.addTile(r);
|
||||
mRecords.add(r);
|
||||
mCachedSpecs = getTilesSpecs();
|
||||
|
||||
@@ -26,6 +26,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
protected int mColumns;
|
||||
protected int mCellWidth;
|
||||
protected int mCellHeight;
|
||||
protected int mMaxCellHeight;
|
||||
protected int mCellMarginHorizontal;
|
||||
protected int mCellMarginVertical;
|
||||
protected int mSidePadding;
|
||||
@@ -35,6 +36,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
private int mCellMarginTop;
|
||||
protected boolean mListening;
|
||||
protected int mMaxAllowedRows = 3;
|
||||
private boolean mShowLabels;
|
||||
|
||||
// Prototyping with less rows
|
||||
private final boolean mLessRows;
|
||||
@@ -49,10 +51,17 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
public TileLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setFocusableInTouchMode(true);
|
||||
mLessRows = (Settings.System.getInt(context.getContentResolver(), "qs_less_rows", 0) != 0)
|
||||
|| useQsMediaPlayer(context);
|
||||
mShowLabels = Settings.Secure.getInt(context.getContentResolver(),
|
||||
QSPanelController.QS_REMOVE_LABELS, 0) == 0;
|
||||
mLessRows = ((Settings.System.getInt(context.getContentResolver(), "qs_less_rows", 0) != 0)
|
||||
|| useQsMediaPlayer(context));
|
||||
updateResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowLabels(boolean show) {
|
||||
mShowLabels = show;
|
||||
updateResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,12 +126,15 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
public boolean updateResources() {
|
||||
final Resources res = mContext.getResources();
|
||||
mResourceColumns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns));
|
||||
mCellHeight = mContext.getResources().getDimensionPixelSize(R.dimen.qs_tile_height);
|
||||
mMaxCellHeight = mContext.getResources().getDimensionPixelSize(R.dimen.qs_tile_height);
|
||||
mCellMarginHorizontal = res.getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal);
|
||||
mCellMarginVertical= res.getDimensionPixelSize(R.dimen.qs_tile_margin_vertical);
|
||||
if (!mShowLabels && mCellMarginVertical == 0) {
|
||||
mCellMarginVertical = mCellMarginHorizontal;
|
||||
}
|
||||
mCellMarginTop = res.getDimensionPixelSize(R.dimen.qs_tile_margin_top);
|
||||
mMaxAllowedRows = Math.max(1, getResources().getInteger(R.integer.quick_settings_max_rows));
|
||||
if (mLessRows) mMaxAllowedRows = Math.max(mMinRows, mMaxAllowedRows - 1);
|
||||
if (mLessRows && mShowLabels) mMaxAllowedRows = Math.max(mMinRows, mMaxAllowedRows - 1);
|
||||
if (updateColumns()) {
|
||||
requestLayout();
|
||||
return true;
|
||||
@@ -153,10 +165,12 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
|
||||
// Measure each QS tile.
|
||||
View previousView = this;
|
||||
int verticalMeasure = exactly(getCellHeight());
|
||||
for (TileRecord record : mRecords) {
|
||||
if (record.tileView.getVisibility() == GONE) continue;
|
||||
record.tileView.measure(exactly(mCellWidth), exactly(mCellHeight));
|
||||
record.tileView.measure(exactly(mCellWidth), verticalMeasure);
|
||||
previousView = record.tileView.updateAccessibilityOrder(previousView);
|
||||
mCellHeight = record.tileView.getMeasuredHeight();
|
||||
}
|
||||
|
||||
// Only include the top margin in our measurement if we have more than 1 row to show.
|
||||
@@ -180,9 +194,10 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
// Add the cell margin in order to divide easily by the height + the margin below
|
||||
+ mCellMarginVertical;
|
||||
final int previousRows = mRows;
|
||||
mRows = availableHeight / (mCellHeight + mCellMarginVertical);
|
||||
if (mRows < mMinRows) {
|
||||
mRows = mMinRows;
|
||||
mRows = availableHeight / (getCellHeight() + mCellMarginVertical);
|
||||
final int minRows = mShowLabels ? mMinRows : mMinRows + 1;
|
||||
if (mRows < minRows) {
|
||||
mRows = minRows;
|
||||
} else if (mRows >= mMaxAllowedRows) {
|
||||
mRows = mMaxAllowedRows;
|
||||
}
|
||||
@@ -201,6 +216,9 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
return MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
|
||||
}
|
||||
|
||||
private int getCellHeight() {
|
||||
return mShowLabels ? mMaxCellHeight : mMaxCellHeight / 2;
|
||||
}
|
||||
|
||||
protected void layoutTileRecords(int numRecords) {
|
||||
final boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.animation.Animator.AnimatorListener;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextThemeWrapper;
|
||||
@@ -47,6 +48,7 @@ import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer;
|
||||
public class QSCustomizer extends LinearLayout {
|
||||
|
||||
static final int MENU_RESET = Menu.FIRST;
|
||||
static final int MENU_REMOVE_LABELS = Menu.FIRST + 1;
|
||||
static final String EXTRA_QS_CUSTOMIZING = "qs_customizing";
|
||||
|
||||
private final QSDetailClipper mClipper;
|
||||
@@ -75,6 +77,11 @@ public class QSCustomizer extends LinearLayout {
|
||||
|
||||
toolbar.getMenu().add(Menu.NONE, MENU_RESET, 0,
|
||||
mContext.getString(com.android.internal.R.string.reset));
|
||||
if (Build.IS_ENG || Build.IS_USERDEBUG) {
|
||||
// Prototype menu item
|
||||
toolbar.getMenu().add(Menu.NONE, MENU_REMOVE_LABELS, Menu.NONE, "Remove labels")
|
||||
.setCheckable(true);
|
||||
}
|
||||
toolbar.setTitle(R.string.qs_edit);
|
||||
mRecyclerView = findViewById(android.R.id.list);
|
||||
mTransparentView = findViewById(R.id.customizer_transparent_view);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.qs.customize;
|
||||
|
||||
import static com.android.systemui.qs.customize.QSCustomizer.EXTRA_QS_CUSTOMIZING;
|
||||
import static com.android.systemui.qs.customize.QSCustomizer.MENU_REMOVE_LABELS;
|
||||
import static com.android.systemui.qs.customize.QSCustomizer.MENU_RESET;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
@@ -36,6 +37,7 @@ import com.android.systemui.keyguard.ScreenLifecycle;
|
||||
import com.android.systemui.plugins.qs.QSTile;
|
||||
import com.android.systemui.qs.QSEditEvent;
|
||||
import com.android.systemui.qs.QSFragment;
|
||||
import com.android.systemui.qs.QSPanelController;
|
||||
import com.android.systemui.qs.QSTileHost;
|
||||
import com.android.systemui.qs.dagger.QSScope;
|
||||
import com.android.systemui.statusbar.phone.LightBarController;
|
||||
@@ -43,6 +45,7 @@ import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
import com.android.systemui.util.ViewController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -62,6 +65,7 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
|
||||
private final ConfigurationController mConfigurationController;
|
||||
private final UiEventLogger mUiEventLogger;
|
||||
private final Toolbar mToolbar;
|
||||
private final TunerService mTunerService;
|
||||
|
||||
private final OnMenuItemClickListener mOnMenuItemClickListener = new OnMenuItemClickListener() {
|
||||
@Override
|
||||
@@ -69,6 +73,11 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
|
||||
if (item.getItemId() == MENU_RESET) {
|
||||
mUiEventLogger.log(QSEditEvent.QS_EDIT_RESET);
|
||||
reset();
|
||||
} else if (item.getItemId() == MENU_REMOVE_LABELS) {
|
||||
item.setChecked(!item.isChecked());
|
||||
mTunerService.setValue(
|
||||
QSPanelController.QS_REMOVE_LABELS, item.isChecked() ? "1" : "0");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -93,11 +102,19 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
|
||||
}
|
||||
};
|
||||
|
||||
private final TunerService.Tunable mTunable = new TunerService.Tunable() {
|
||||
@Override
|
||||
public void onTuningChanged(String key, String newValue) {
|
||||
mToolbar.getMenu().findItem(MENU_REMOVE_LABELS).setChecked(!("0".equals(newValue)));
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
protected QSCustomizerController(QSCustomizer view, TileQueryHelper tileQueryHelper,
|
||||
QSTileHost qsTileHost, TileAdapter tileAdapter, ScreenLifecycle screenLifecycle,
|
||||
KeyguardStateController keyguardStateController, LightBarController lightBarController,
|
||||
ConfigurationController configurationController, UiEventLogger uiEventLogger) {
|
||||
ConfigurationController configurationController, UiEventLogger uiEventLogger,
|
||||
TunerService tunerService) {
|
||||
super(view);
|
||||
mTileQueryHelper = tileQueryHelper;
|
||||
mQsTileHost = qsTileHost;
|
||||
@@ -109,11 +126,14 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
|
||||
mUiEventLogger = uiEventLogger;
|
||||
|
||||
mToolbar = mView.findViewById(com.android.internal.R.id.action_bar);
|
||||
|
||||
mTunerService = tunerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onViewAttached() {
|
||||
mView.updateNavBackDrop(getResources().getConfiguration(), mLightBarController);
|
||||
mTunerService.addTunable(mTunable, QSPanelController.QS_REMOVE_LABELS);
|
||||
|
||||
mConfigurationController.addCallback(mConfigurationListener);
|
||||
|
||||
@@ -143,6 +163,7 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
|
||||
|
||||
@Override
|
||||
protected void onViewDetached() {
|
||||
mTunerService.removeTunable(mTunable);
|
||||
mTileQueryHelper.setListener(null);
|
||||
mToolbar.setOnMenuItemClickListener(null);
|
||||
mConfigurationController.removeCallback(mConfigurationListener);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class QSTileBaseView extends com.android.systemui.plugins.qs.QSTileView {
|
||||
|
||||
private static final String TAG = "QSTileBaseView";
|
||||
private static final int ICON_MASK_ID = com.android.internal.R.string.config_icon_mask;
|
||||
private final H mHandler = new H();
|
||||
protected final Handler mHandler = new H();
|
||||
private final int[] mLocInScreen = new int[2];
|
||||
private final FrameLayout mIconFrame;
|
||||
protected QSIconView mIcon;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class QSTileView extends QSTileBaseView {
|
||||
protected TextView mSecondLine;
|
||||
private ImageView mPadLock;
|
||||
private int mState;
|
||||
private ViewGroup mLabelContainer;
|
||||
protected ViewGroup mLabelContainer;
|
||||
private View mExpandIndicator;
|
||||
private View mExpandSpace;
|
||||
private ColorStateList mColorLabelDefault;
|
||||
@@ -151,4 +151,9 @@ public class QSTileView extends QSTileBaseView {
|
||||
mLabelContainer.setClickable(false);
|
||||
mLabelContainer.setLongClickable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowLabels(boolean show) {
|
||||
mHandler.post(() -> mLabelContainer.setVisibility(show ? VISIBLE : GONE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public class QSPanelControllerTest extends SysuiTestCase {
|
||||
when(mQSPanel.isAttachedToWindow()).thenReturn(true);
|
||||
when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
|
||||
when(mQSPanel.createRegularTileLayout()).thenReturn(mPagedTileLayout);
|
||||
when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
|
||||
when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
|
||||
when(mQSTileHost.createTileView(eq(mQSTile), anyBoolean())).thenReturn(mQSTileView);
|
||||
when(mToggleSliderViewControllerFactory.create(any(), any()))
|
||||
|
||||
@@ -24,12 +24,14 @@ import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.dump.DumpManager
|
||||
import com.android.systemui.media.MediaHost
|
||||
import com.android.systemui.plugins.qs.QSTile
|
||||
import com.android.systemui.plugins.qs.QSTileView
|
||||
import com.android.systemui.qs.customize.QSCustomizerController
|
||||
import com.android.systemui.qs.logging.QSLogger
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.anyBoolean
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.any
|
||||
@@ -59,6 +61,8 @@ class QuickQSPanelControllerTest : SysuiTestCase() {
|
||||
private lateinit var tile: QSTile
|
||||
@Mock
|
||||
private lateinit var tileLayout: TileLayout
|
||||
@Mock
|
||||
private lateinit var tileView: QSTileView
|
||||
|
||||
private lateinit var controller: QuickQSPanelController
|
||||
|
||||
@@ -68,6 +72,7 @@ class QuickQSPanelControllerTest : SysuiTestCase() {
|
||||
|
||||
`when`(quickQSPanel.tileLayout).thenReturn(tileLayout)
|
||||
`when`(quickQSPanel.dumpableTag).thenReturn("")
|
||||
`when`(qsTileHost.createTileView(any(), anyBoolean())).thenReturn(tileView)
|
||||
|
||||
controller = QuickQSPanelController(
|
||||
quickQSPanel,
|
||||
|
||||
Reference in New Issue
Block a user