Align tiles between QSPanel and QSCustomizer
Give the tiles in QSCustomizer the same margin (half of qs_tile_margin_horizontal in each side) and set the RecyclerView padding to be the same as QSPanel's TileLayout margin. That way, the tiles align when QSCustomizer opens (only in portrait) and the animation looks better. Test: manual, multiple densities Fixes: 164207558 Change-Id: Ied960c9292c93c09f5ef04853d3b1a25bd778237
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
@@ -282,7 +283,7 @@ public class QSContainerImpl extends FrameLayout {
|
||||
View view = getChildAt(i);
|
||||
if (view == mStatusBarBackground || view == mBackgroundGradient
|
||||
|| view == mQSCustomizer) {
|
||||
// Some views are always full width
|
||||
// Some views are always full width or have dependent padding
|
||||
continue;
|
||||
}
|
||||
LayoutParams lp = (LayoutParams) view.getLayoutParams();
|
||||
@@ -291,6 +292,9 @@ public class QSContainerImpl extends FrameLayout {
|
||||
if (view == mQSPanelContainer) {
|
||||
// QS panel lays out some of its content full width
|
||||
mQSPanel.setContentMargins(mContentPaddingStart, mContentPaddingEnd);
|
||||
Pair<Integer, Integer> margins = mQSPanel.getVisualSideMargins();
|
||||
// Apply paddings based on QSPanel
|
||||
mQSCustomizer.setContentPaddings(margins.first, margins.second);
|
||||
} else if (view == mHeader) {
|
||||
// The header contains the QQS panel which needs to have special padding, to
|
||||
// visually align them.
|
||||
|
||||
@@ -25,12 +25,12 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PointF;
|
||||
import android.metrics.LogMaker;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Pair;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -1077,6 +1077,10 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
updateTileLayoutMargins();
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getVisualSideMargins() {
|
||||
return new Pair(mVisualMarginStart, mUsingHorizontalLayout ? 0 : mVisualMarginEnd);
|
||||
}
|
||||
|
||||
private void updateTileLayoutMargins() {
|
||||
int marginEnd = mVisualMarginEnd;
|
||||
if (mUsingHorizontalLayout) {
|
||||
|
||||
@@ -132,6 +132,7 @@ public class QSCustomizer extends LinearLayout implements OnMenuItemClickListene
|
||||
layout.setSpanSizeLookup(mTileAdapter.getSizeLookup());
|
||||
mRecyclerView.setLayoutManager(layout);
|
||||
mRecyclerView.addItemDecoration(mTileAdapter.getItemDecoration());
|
||||
mRecyclerView.addItemDecoration(mTileAdapter.getMarginItemDecoration());
|
||||
DefaultItemAnimator animator = new DefaultItemAnimator();
|
||||
animator.setMoveDuration(TileAdapter.MOVE_DURATION);
|
||||
mRecyclerView.setItemAnimator(animator);
|
||||
@@ -221,6 +222,22 @@ public class QSCustomizer extends LinearLayout implements OnMenuItemClickListene
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the padding for the RecyclerView. Also, updates the margin between the tiles in the
|
||||
* {@link TileAdapter}.
|
||||
*/
|
||||
public void setContentPaddings(int paddingStart, int paddingEnd) {
|
||||
int halfMargin = mContext.getResources()
|
||||
.getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal) / 2;
|
||||
mTileAdapter.changeHalfMargin(halfMargin);
|
||||
mRecyclerView.setPaddingRelative(
|
||||
paddingStart,
|
||||
mRecyclerView.getPaddingTop(),
|
||||
paddingEnd,
|
||||
mRecyclerView.getPaddingBottom()
|
||||
);
|
||||
}
|
||||
|
||||
private void queryTiles() {
|
||||
mTileQueryHelper.queryTiles(mHost);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -75,6 +76,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
private final List<TileInfo> mTiles = new ArrayList<>();
|
||||
private final ItemTouchHelper mItemTouchHelper;
|
||||
private final ItemDecoration mDecoration;
|
||||
private final MarginTileDecoration mMarginDecoration;
|
||||
private final int mMinNumTiles;
|
||||
private int mEditIndex;
|
||||
private int mTileDividerIndex;
|
||||
@@ -97,6 +99,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
mUiEventLogger = uiEventLogger;
|
||||
mItemTouchHelper = new ItemTouchHelper(mCallbacks);
|
||||
mDecoration = new TileItemDecoration(context);
|
||||
mMarginDecoration = new MarginTileDecoration();
|
||||
mMinNumTiles = context.getResources().getInteger(R.integer.quick_settings_min_num_tiles);
|
||||
mAccessibilityDelegate = new TileAdapterDelegate();
|
||||
}
|
||||
@@ -123,6 +126,14 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
return mDecoration;
|
||||
}
|
||||
|
||||
public ItemDecoration getMarginItemDecoration() {
|
||||
return mMarginDecoration;
|
||||
}
|
||||
|
||||
public void changeHalfMargin(int halfMargin) {
|
||||
mMarginDecoration.setHalfMargin(halfMargin);
|
||||
}
|
||||
|
||||
public void saveSpecs(QSTileHost host) {
|
||||
List<String> newSpecs = new ArrayList<>();
|
||||
clearAccessibilityState();
|
||||
@@ -596,7 +607,6 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
mDrawable = context.getDrawable(R.drawable.qs_customize_tile_decoration);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
@@ -624,6 +634,25 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
}
|
||||
}
|
||||
|
||||
private static class MarginTileDecoration extends ItemDecoration {
|
||||
private int mHalfMargin;
|
||||
|
||||
public void setHalfMargin(int halfMargin) {
|
||||
mHalfMargin = halfMargin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
|
||||
@NonNull RecyclerView parent, @NonNull State state) {
|
||||
if (view instanceof TextView) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
} else {
|
||||
outRect.left = mHalfMargin;
|
||||
outRect.right = mHalfMargin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final ItemTouchHelper.Callback mCallbacks = new ItemTouchHelper.Callback() {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user