Merge "Fix margins around tiles in QSCustomizer" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4b12edf91e
@@ -20,9 +20,11 @@ import static com.android.systemui.qs.customize.QSCustomizer.EXTRA_QS_CUSTOMIZIN
|
|||||||
import static com.android.systemui.qs.customize.QSCustomizer.MENU_RESET;
|
import static com.android.systemui.qs.customize.QSCustomizer.MENU_RESET;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import android.widget.Toolbar.OnMenuItemClickListener;
|
import android.widget.Toolbar.OnMenuItemClickListener;
|
||||||
|
|
||||||
@@ -139,6 +141,20 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
|
|||||||
RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
|
RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
|
||||||
// Do not read row and column every time it changes.
|
// Do not read row and column every time it changes.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void calculateItemDecorationsForChild(View child, Rect outRect) {
|
||||||
|
// There's only a single item decoration that cares about the itemOffsets, so
|
||||||
|
// we just call it manually so they are never cached. This way, it's updated as the
|
||||||
|
// tiles are moved around.
|
||||||
|
// It only sets the left and right margin and only cares about tiles (not TextView).
|
||||||
|
if (!(child instanceof TextView)) {
|
||||||
|
outRect.setEmpty();
|
||||||
|
mTileAdapter.getMarginItemDecoration().getItemOffsets(outRect, child,
|
||||||
|
recyclerView, new RecyclerView.State());
|
||||||
|
((LayoutParams) child.getLayoutParams()).leftMargin = outRect.left;
|
||||||
|
((LayoutParams) child.getLayoutParams()).rightMargin = outRect.right;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
layout.setSpanSizeLookup(mTileAdapter.getSizeLookup());
|
layout.setSpanSizeLookup(mTileAdapter.getSizeLookup());
|
||||||
recyclerView.setLayoutManager(layout);
|
recyclerView.setLayoutManager(layout);
|
||||||
|
|||||||
@@ -690,9 +690,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
|||||||
if (parent.getLayoutManager() == null) return;
|
if (parent.getLayoutManager() == null) return;
|
||||||
|
|
||||||
GridLayoutManager lm = ((GridLayoutManager) parent.getLayoutManager());
|
GridLayoutManager lm = ((GridLayoutManager) parent.getLayoutManager());
|
||||||
SpanSizeLookup span = lm.getSpanSizeLookup();
|
int column = ((GridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanIndex();
|
||||||
ViewHolder holder = parent.getChildViewHolder(view);
|
|
||||||
int column = span.getSpanIndex(holder.getBindingAdapterPosition(), lm.getSpanCount());
|
|
||||||
|
|
||||||
if (view instanceof TextView) {
|
if (view instanceof TextView) {
|
||||||
super.getItemOffsets(outRect, view, parent, state);
|
super.getItemOffsets(outRect, view, parent, state);
|
||||||
@@ -702,14 +700,30 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
|||||||
// columns).
|
// columns).
|
||||||
outRect.left = mHalfMargin;
|
outRect.left = mHalfMargin;
|
||||||
outRect.right = mHalfMargin;
|
outRect.right = mHalfMargin;
|
||||||
} else if (column == 0) {
|
|
||||||
// Leftmost column when not using side margins. Should only have margin on the
|
|
||||||
// right.
|
|
||||||
outRect.right = mHalfMargin;
|
|
||||||
} else {
|
} else {
|
||||||
// Rightmost column when not using side margins. Should only have margin on the
|
// Leftmost or rightmost column
|
||||||
// left.
|
if (parent.isLayoutRtl()) {
|
||||||
outRect.left = mHalfMargin;
|
if (column == 0) {
|
||||||
|
// Rightmost column
|
||||||
|
outRect.left = mHalfMargin;
|
||||||
|
outRect.right = 0;
|
||||||
|
} else {
|
||||||
|
// Leftmost column
|
||||||
|
outRect.left = 0;
|
||||||
|
outRect.right = mHalfMargin;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Non RTL
|
||||||
|
if (column == 0) {
|
||||||
|
// Leftmost column
|
||||||
|
outRect.left = 0;
|
||||||
|
outRect.right = mHalfMargin;
|
||||||
|
} else {
|
||||||
|
// Rightmost column
|
||||||
|
outRect.left = mHalfMargin;
|
||||||
|
outRect.right = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user