Align QSCustomizer with QSPanel

Align shapes and positions

Test: manual
Bug: 171319433
Change-Id: Iee2ddb2617d38315071545ee765d623255ce0e4a
This commit is contained in:
Fabian Kozynski
2021-03-01 13:09:09 -05:00
parent b56fc740bb
commit b637656fb8
8 changed files with 122 additions and 43 deletions

View File

@@ -91,9 +91,6 @@
<!-- The number of columns in the QuickSettings -->
<integer name="quick_settings_num_columns">3</integer>
<!-- The number of columns in the Quick Settings customizer -->
<integer name="quick_settings_edit_num_columns">@integer/quick_settings_num_columns</integer>
<!-- The number of rows in the QuickSettings -->
<integer name="quick_settings_max_rows">3</integer>

View File

@@ -18,7 +18,6 @@ package com.android.systemui.qs
import android.content.Context
import android.util.AttributeSet
import com.android.systemui.R
open class SideLabelTileLayout(
context: Context,
@@ -28,9 +27,6 @@ open class SideLabelTileLayout(
override fun updateResources(): Boolean {
return super.updateResources().also {
mMaxAllowedRows = 4
mCellMarginHorizontal = (mCellMarginHorizontal * 1.2).toInt()
mCellMarginVertical = mCellMarginHorizontal
mMaxCellHeight = context.resources.getDimensionPixelSize(R.dimen.qs_quick_tile_size)
}
}

View File

@@ -16,19 +16,19 @@ package com.android.systemui.qs.customize;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import com.android.systemui.plugins.qs.QSIconView;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.qs.tileimpl.QSTileView;
public class CustomizeTileView extends QSTileView {
public class CustomizeTileView extends QSTileView implements TileAdapter.CustomizeView {
private boolean mShowAppLabel;
public CustomizeTileView(Context context, QSIconView icon) {
super(context, icon);
}
@Override
public void setShowAppLabel(boolean showAppLabel) {
mShowAppLabel = showAppLabel;
mSecondLine.setVisibility(showAppLabel ? View.VISIBLE : View.GONE);
@@ -41,10 +41,6 @@ public class CustomizeTileView extends QSTileView {
mSecondLine.setVisibility(mShowAppLabel ? View.VISIBLE : View.GONE);
}
public TextView getAppLabel() {
return mSecondLine;
}
@Override
protected boolean animationsEnabled() {
return false;
@@ -54,4 +50,9 @@ public class CustomizeTileView extends QSTileView {
public boolean isLongClickable() {
return false;
}
@Override
public void changeState(QSTile.State state) {
handleStateChanged(state);
}
}

View File

@@ -0,0 +1,50 @@
package com.android.systemui.qs.customize
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.View
import com.android.systemui.plugins.qs.QSIconView
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.qs.tileimpl.QSTileViewHorizontal
/**
* Class for displaying tiles in [QSCustomizer] with the new design (labels on the side).
*
* This is a class parallel to [CustomizeTileView], but inheriting from [QSTileViewHorizontal].
*/
class CustomizeTileViewHorizontal(
context: Context,
icon: QSIconView
) : QSTileViewHorizontal(context, icon),
TileAdapter.CustomizeView {
private var showAppLabel = false
override fun setShowAppLabel(showAppLabel: Boolean) {
this.showAppLabel = showAppLabel
mSecondLine.visibility = if (showAppLabel) View.VISIBLE else View.GONE
mLabel.isSingleLine = showAppLabel
}
override fun handleStateChanged(state: QSTile.State) {
super.handleStateChanged(state)
mSecondLine.visibility = if (showAppLabel) View.VISIBLE else View.GONE
}
override fun animationsEnabled(): Boolean {
return false
}
override fun isLongClickable(): Boolean {
return false
}
override fun changeState(state: QSTile.State) {
handleStateChanged(state)
}
override fun newTileBackground(): Drawable? {
super.newTileBackground()
return paintDrawable
}
}

View File

@@ -14,6 +14,8 @@
package com.android.systemui.qs.customize;
import static com.android.systemui.qs.dagger.QSFlagsModule.QS_LABELS_FLAG;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
@@ -30,6 +32,7 @@ import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup;
@@ -41,6 +44,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.qs.QSEditEvent;
import com.android.systemui.qs.QSTileHost;
import com.android.systemui.qs.customize.TileAdapter.Holder;
@@ -49,11 +53,13 @@ import com.android.systemui.qs.customize.TileQueryHelper.TileStateListener;
import com.android.systemui.qs.dagger.QSScope;
import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.tileimpl.QSIconViewImpl;
import com.android.systemui.qs.tileimpl.QSTileView;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
/** */
@QSScope
@@ -75,7 +81,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
private static final int ACTION_ADD = 1;
private static final int ACTION_MOVE = 2;
private static final int NUM_COLUMNS_ID = R.integer.quick_settings_edit_num_columns;
private static final int NUM_COLUMNS_ID = R.integer.quick_settings_num_columns;
private final Context mContext;
@@ -102,9 +108,11 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
private final AccessibilityDelegateCompat mAccessibilityDelegate;
private RecyclerView mRecyclerView;
private int mNumColumns;
private final boolean mUseHorizontalTiles;
@Inject
public TileAdapter(Context context, QSTileHost qsHost, UiEventLogger uiEventLogger) {
public TileAdapter(Context context, QSTileHost qsHost, UiEventLogger uiEventLogger,
@Named(QS_LABELS_FLAG) boolean useHorizontalTiles) {
mContext = context;
mHost = qsHost;
mUiEventLogger = uiEventLogger;
@@ -114,6 +122,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
mMinNumTiles = context.getResources().getInteger(R.integer.quick_settings_min_num_tiles);
mNumColumns = context.getResources().getInteger(NUM_COLUMNS_ID);
mAccessibilityDelegate = new TileAdapterDelegate();
mUseHorizontalTiles = useHorizontalTiles;
}
@Override
@@ -271,7 +280,10 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
}
FrameLayout frame = (FrameLayout) inflater.inflate(R.layout.qs_customize_tile_frame, parent,
false);
frame.addView(new CustomizeTileView(context, new QSIconViewImpl(context)));
View view = mUseHorizontalTiles
? new CustomizeTileViewHorizontal(context, new QSIconViewImpl(context))
: new CustomizeTileView(context, new QSIconViewImpl(context));
frame.addView(view);
return new Holder(frame);
}
@@ -354,8 +366,9 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
}
info.state.expandedAccessibilityClassName = "";
holder.mTileView.handleStateChanged(info.state);
holder.mTileView.setShowAppLabel(position > mEditIndex && !info.isSystem);
// The holder has a tileView, therefore this call is not null
holder.getTileAsCustomizeView().changeState(info.state);
holder.getTileAsCustomizeView().setShowAppLabel(position > mEditIndex && !info.isSystem);
holder.mTileView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
holder.mTileView.setClickable(true);
holder.mTileView.setOnClickListener(null);
@@ -534,25 +547,34 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
}
public class Holder extends ViewHolder {
private CustomizeTileView mTileView;
private QSTileView mTileView;
public Holder(View itemView) {
super(itemView);
if (itemView instanceof FrameLayout) {
mTileView = (CustomizeTileView) ((FrameLayout) itemView).getChildAt(0);
mTileView.setBackground(null);
mTileView = (QSTileView) ((FrameLayout) itemView).getChildAt(0);
if (mTileView instanceof CustomizeTileView) {
mTileView.setBackground(null);
}
mTileView.getIcon().disableAnimation();
mTileView.setTag(this);
ViewCompat.setAccessibilityDelegate(mTileView, mAccessibilityDelegate);
}
}
@Nullable
public CustomizeView getTileAsCustomizeView() {
return (CustomizeView) mTileView;
}
public void clearDrag() {
itemView.clearAnimation();
mTileView.findViewById(R.id.tile_label).clearAnimation();
mTileView.findViewById(R.id.tile_label).setAlpha(1);
mTileView.getAppLabel().clearAnimation();
mTileView.getAppLabel().setAlpha(.6f);
if (mTileView instanceof CustomizeTileView) {
mTileView.findViewById(R.id.tile_label).clearAnimation();
mTileView.findViewById(R.id.tile_label).setAlpha(1);
mTileView.getAppLabel().clearAnimation();
mTileView.getAppLabel().setAlpha(.6f);
}
}
public void startDrag() {
@@ -560,12 +582,14 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
.setDuration(DRAG_LENGTH)
.scaleX(DRAG_SCALE)
.scaleY(DRAG_SCALE);
mTileView.findViewById(R.id.tile_label).animate()
.setDuration(DRAG_LENGTH)
.alpha(0);
mTileView.getAppLabel().animate()
.setDuration(DRAG_LENGTH)
.alpha(0);
if (mTileView instanceof CustomizeTileView) {
mTileView.findViewById(R.id.tile_label).animate()
.setDuration(DRAG_LENGTH)
.alpha(0);
mTileView.getAppLabel().animate()
.setDuration(DRAG_LENGTH)
.alpha(0);
}
}
public void stopDrag() {
@@ -573,12 +597,14 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
.setDuration(DRAG_LENGTH)
.scaleX(1)
.scaleY(1);
mTileView.findViewById(R.id.tile_label).animate()
.setDuration(DRAG_LENGTH)
.alpha(1);
mTileView.getAppLabel().animate()
.setDuration(DRAG_LENGTH)
.alpha(.6f);
if (mTileView instanceof CustomizeTileView) {
mTileView.findViewById(R.id.tile_label).animate()
.setDuration(DRAG_LENGTH)
.alpha(1);
mTileView.getAppLabel().animate()
.setDuration(DRAG_LENGTH)
.alpha(.6f);
}
}
boolean canRemove() {
@@ -722,7 +748,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
int position = mCurrentDrag.getAdapterPosition();
if (position == RecyclerView.NO_POSITION) return;
TileInfo info = mTiles.get(position);
mCurrentDrag.mTileView.setShowAppLabel(
((CustomizeView) mCurrentDrag.mTileView).setShowAppLabel(
position > mEditIndex && !info.isSystem);
mCurrentDrag.stopDrag();
mCurrentDrag = null;
@@ -782,4 +808,9 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
public void onSwiped(ViewHolder viewHolder, int direction) {
}
};
interface CustomizeView {
void setShowAppLabel(boolean showAppLabel);
void changeState(@NonNull QSTile.State state);
}
}

View File

@@ -174,4 +174,8 @@ public class QSTileView extends QSTileBaseView {
mLabelContainer.setClickable(false);
mLabelContainer.setLongClickable(false);
}
public TextView getAppLabel() {
return mSecondLine;
}
}

View File

@@ -35,13 +35,13 @@ import com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState
// Placeholder
private const val CORNER_RADIUS = 40f
class QSTileViewHorizontal(
open class QSTileViewHorizontal(
context: Context,
icon: QSIconView
) : QSTileView(context, icon, false) {
private var paintDrawable: PaintDrawable? = null
private var paintColor = Color.TRANSPARENT
protected var paintDrawable: PaintDrawable? = null
private var paintColor = Color.WHITE
private var paintAnimator: ValueAnimator? = null
init {
@@ -103,7 +103,7 @@ class QSTileViewHorizontal(
mSecondLine.setTextColor(mLabel.textColors)
mLabelContainer.background = null
val allowAnimations = animationsEnabled() && paintColor != Color.TRANSPARENT
val allowAnimations = animationsEnabled() && paintColor != Color.WHITE
val newColor = getCircleColor(state.state)
if (allowAnimations) {
animateToNewState(newColor)

View File

@@ -49,7 +49,7 @@ public class TileAdapterTest extends SysuiTestCase {
MockitoAnnotations.initMocks(this);
TestableLooper.get(this).runWithLooper(() -> mTileAdapter =
new TileAdapter(mContext, mQSTileHost, new UiEventLoggerFake()));
new TileAdapter(mContext, mQSTileHost, new UiEventLoggerFake(), /* qsFlag */false));
}
@Test