Merge "Work on QS layouts"
This commit is contained in:
@@ -21,14 +21,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.android.systemui.qs.QuickTileLayout
|
||||
android:id="@+id/quick_tile_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/qs_quick_actions_height"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/qs_quick_actions_padding"
|
||||
android:paddingEnd="@dimen/qs_quick_actions_padding" />
|
||||
|
||||
<view
|
||||
class="com.android.systemui.qs.PagedTileLayout$TilePage"
|
||||
android:id="@+id/tile_page"
|
||||
|
||||
@@ -38,4 +38,6 @@
|
||||
while the stack is not focused. -->
|
||||
<item name="recents_layout_unfocused_range_min" format="float" type="integer">-2</item>
|
||||
<item name="recents_layout_unfocused_range_max" format="float" type="integer">1.5</item>
|
||||
|
||||
<integer name="quick_settings_num_columns">4</integer>
|
||||
</resources>
|
||||
|
||||
@@ -18,4 +18,6 @@
|
||||
<!-- The maximum count of notifications on Keyguard. The rest will be collapsed in an overflow
|
||||
card. -->
|
||||
<integer name="keyguard_max_notification_count">3</integer>
|
||||
|
||||
<integer name="quick_settings_num_columns">3</integer>
|
||||
</resources>
|
||||
|
||||
@@ -134,9 +134,7 @@
|
||||
<dimen name="pull_span_min">25dp</dimen>
|
||||
|
||||
<dimen name="qs_tile_height">88dp</dimen>
|
||||
<dimen name="qs_new_tile_height">100dp</dimen>
|
||||
<dimen name="qs_quick_actions_height">88dp</dimen>
|
||||
<dimen name="qs_quick_actions_padding">25dp</dimen>
|
||||
<dimen name="qs_tile_margin">16dp</dimen>
|
||||
<dimen name="qs_quick_tile_size">48dp</dimen>
|
||||
<dimen name="qs_quick_tile_padding">12dp</dimen>
|
||||
<dimen name="qs_date_anim_translation">44.5dp</dimen>
|
||||
|
||||
@@ -62,27 +62,32 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
|
||||
@Override
|
||||
public int getOffsetTop(TileRecord tile) {
|
||||
return ((ViewGroup) tile.tileView.getParent()).getTop();
|
||||
return ((ViewGroup) tile.tileView.getParent()).getTop() + getTop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTile(TileRecord tile) {
|
||||
mTiles.add(tile);
|
||||
distributeTiles();
|
||||
postDistributeTiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTile(TileRecord tile) {
|
||||
if (mTiles.remove(tile)) {
|
||||
distributeTiles();
|
||||
postDistributeTiles();
|
||||
}
|
||||
}
|
||||
|
||||
private void postDistributeTiles() {
|
||||
removeCallbacks(mDistribute);
|
||||
post(mDistribute);
|
||||
}
|
||||
|
||||
private void distributeTiles() {
|
||||
if (DEBUG) Log.d(TAG, "Distributing tiles");
|
||||
final int NP = mPages.size();
|
||||
for (int i = 0; i < NP; i++) {
|
||||
mPages.get(i).clear();
|
||||
mPages.get(i).removeAllViews();
|
||||
}
|
||||
int index = 0;
|
||||
final int NT = mTiles.size();
|
||||
@@ -107,10 +112,15 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateResources() {
|
||||
public boolean updateResources() {
|
||||
boolean changed = false;
|
||||
for (int i = 0; i < mPages.size(); i++) {
|
||||
mPages.get(i).updateResources();
|
||||
changed |= mPages.get(i).updateResources();
|
||||
}
|
||||
if (changed) {
|
||||
distributeTiles();
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,6 +139,13 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
setMeasuredDimension(getMeasuredWidth(), maxHeight + mPageIndicator.getMeasuredHeight());
|
||||
}
|
||||
|
||||
private final Runnable mDistribute = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
distributeTiles();
|
||||
}
|
||||
};
|
||||
|
||||
public static class TilePage extends TileLayout {
|
||||
private int mMaxRows = 3;
|
||||
|
||||
@@ -137,21 +154,19 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
||||
updateResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateResources() {
|
||||
if (super.updateResources()) {
|
||||
mMaxRows = mColumns != 3 ? 2 : 3;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setMaxRows(int maxRows) {
|
||||
mMaxRows = maxRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCellHeight() {
|
||||
return mContext.getResources().getDimensionPixelSize(R.dimen.qs_new_tile_height);
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
if (DEBUG) Log.d(TAG, "Clearing page");
|
||||
removeAllViews();
|
||||
mRecords.clear();
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return mRecords.size() >= mColumns * mMaxRows;
|
||||
}
|
||||
|
||||
@@ -557,8 +557,6 @@ public class QSPanel extends FrameLayout implements Tunable {
|
||||
public static final class TileRecord extends Record {
|
||||
public QSTile<?> tile;
|
||||
public QSTileBaseView tileView;
|
||||
public int row;
|
||||
public int col;
|
||||
public boolean scanState;
|
||||
public boolean openingDetail;
|
||||
}
|
||||
@@ -607,6 +605,6 @@ public class QSPanel extends FrameLayout implements Tunable {
|
||||
void addTile(TileRecord tile);
|
||||
void removeTile(TileRecord tile);
|
||||
int getOffsetTop(TileRecord tile);
|
||||
void updateResources();
|
||||
boolean updateResources();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,10 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
mHandler.obtainMessage(H.ADD_CALLBACK, callback).sendToTarget();
|
||||
}
|
||||
|
||||
public void removeCallbacks() {
|
||||
mHandler.sendEmptyMessage(H.REMOVE_CALLBACKS);
|
||||
}
|
||||
|
||||
public void click() {
|
||||
mHandler.sendEmptyMessage(H.CLICK);
|
||||
}
|
||||
@@ -188,6 +192,10 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
handleRefreshState(null);
|
||||
}
|
||||
|
||||
private void handleRemoveCallbacks() {
|
||||
mCallbacks.clear();
|
||||
}
|
||||
|
||||
protected void handleSecondaryClick() {
|
||||
// Default to normal click.
|
||||
handleClick();
|
||||
@@ -285,6 +293,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
private static final int SCAN_STATE_CHANGED = 9;
|
||||
private static final int DESTROY = 10;
|
||||
private static final int CLEAR_STATE = 11;
|
||||
private static final int REMOVE_CALLBACKS = 12;
|
||||
|
||||
private H(Looper looper) {
|
||||
super(looper);
|
||||
@@ -296,7 +305,10 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
try {
|
||||
if (msg.what == ADD_CALLBACK) {
|
||||
name = "handleAddCallback";
|
||||
handleAddCallback((QSTile.Callback)msg.obj);
|
||||
handleAddCallback((QSTile.Callback) msg.obj);
|
||||
} else if (msg.what == REMOVE_CALLBACKS) {
|
||||
name = "handleRemoveCallbacks";
|
||||
handleRemoveCallbacks();
|
||||
} else if (msg.what == CLICK) {
|
||||
name = "handleClick";
|
||||
if (mState.disabledByPolicy) {
|
||||
|
||||
@@ -145,8 +145,9 @@ public class QuickQSPanel extends QSPanel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateResources() {
|
||||
public boolean updateResources() {
|
||||
// No resources here.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.res.Resources;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.qs.QSPanel.QSTileLayout;
|
||||
import com.android.systemui.qs.QSPanel.TileRecord;
|
||||
@@ -21,6 +20,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
protected int mColumns;
|
||||
private int mCellWidth;
|
||||
private int mCellHeight;
|
||||
private int mCellMargin;
|
||||
|
||||
protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
|
||||
|
||||
@@ -54,52 +54,33 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
super.removeAllViews();
|
||||
}
|
||||
|
||||
public void updateResources() {
|
||||
public boolean updateResources() {
|
||||
final Resources res = mContext.getResources();
|
||||
final int columns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns));
|
||||
mCellHeight = getCellHeight();
|
||||
mCellWidth = (int) (mCellHeight * TILE_ASPECT);
|
||||
mCellHeight = mContext.getResources().getDimensionPixelSize(R.dimen.qs_tile_height);
|
||||
mCellMargin = res.getDimensionPixelSize(R.dimen.qs_tile_margin);
|
||||
if (mColumns != columns) {
|
||||
mColumns = columns;
|
||||
postInvalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getCellHeight() {
|
||||
return mContext.getResources().getDimensionPixelSize(R.dimen.qs_tile_height);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int numTiles = mRecords.size();
|
||||
final int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int r = -1;
|
||||
int c = -1;
|
||||
int rows = 0;
|
||||
for (TileRecord record : mRecords) {
|
||||
if (record.tileView.getVisibility() == GONE) continue;
|
||||
// wrap to next column if we've reached the max # of columns
|
||||
// also don't allow dual + single tiles on the same row
|
||||
if (r == -1 || c == (mColumns - 1)) {
|
||||
r++;
|
||||
c = 0;
|
||||
} else {
|
||||
c++;
|
||||
}
|
||||
record.row = r;
|
||||
record.col = c;
|
||||
rows = r + 1;
|
||||
}
|
||||
final int rows = (numTiles + mColumns - 1) / mColumns;
|
||||
mCellWidth = (width - (mCellMargin * (mColumns + 1))) / mColumns;
|
||||
|
||||
View previousView = this;
|
||||
for (TileRecord record : mRecords) {
|
||||
if (record.tileView.getVisibility() == GONE) continue;
|
||||
final int cw = mCellWidth;
|
||||
final int ch = mCellHeight;
|
||||
record.tileView.measure(exactly(cw), exactly(ch));
|
||||
record.tileView.measure(exactly(mCellWidth), exactly(mCellHeight));
|
||||
previousView = record.tileView.updateAccessibilityOrder(previousView);
|
||||
}
|
||||
int h = rows == 0 ? 0 : getRowTop(rows);
|
||||
setMeasuredDimension(width, h);
|
||||
setMeasuredDimension(width, (mCellHeight + mCellMargin) * rows + mCellMargin);
|
||||
}
|
||||
|
||||
private static int exactly(int size) {
|
||||
@@ -110,37 +91,32 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final int w = getWidth();
|
||||
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
|
||||
for (TileRecord record : mRecords) {
|
||||
if (record.tileView.getVisibility() == GONE) continue;
|
||||
final int cols = getColumnCount(record.row);
|
||||
final int cw = mCellWidth;
|
||||
final int extra = (w - cw * cols) / (cols + 1);
|
||||
int left = record.col * cw + (record.col + 1) * extra;
|
||||
final int top = getRowTop(record.row);
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
for (int i = 0; i < mRecords.size(); i++, column++) {
|
||||
if (column == mColumns) {
|
||||
row++;
|
||||
column -= mColumns;
|
||||
}
|
||||
TileRecord record = mRecords.get(i);
|
||||
int left = getColumnStart(column);
|
||||
final int top = getRowTop(row);
|
||||
int right;
|
||||
int tileWith = record.tileView.getMeasuredWidth();
|
||||
if (isRtl) {
|
||||
right = w - left;
|
||||
left = right - tileWith;
|
||||
left = right - mCellWidth;
|
||||
} else {
|
||||
right = left + tileWith;
|
||||
right = left + mCellWidth;
|
||||
}
|
||||
record.tileView.layout(left, top, right, top + record.tileView.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
private int getRowTop(int row) {
|
||||
if (row <= 0) return 0;
|
||||
return row * mCellHeight;
|
||||
return row * (mCellHeight + mCellMargin) + mCellMargin;
|
||||
}
|
||||
|
||||
private int getColumnCount(int row) {
|
||||
int cols = 0;
|
||||
for (TileRecord record : mRecords) {
|
||||
if (record.tileView.getVisibility() == GONE) continue;
|
||||
if (record.row == row) cols++;
|
||||
}
|
||||
return cols;
|
||||
private int getColumnStart(int column) {
|
||||
return column * (mCellWidth + mCellMargin) + mCellMargin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.android.systemui.qs.PagedTileLayout.TilePage;
|
||||
import com.android.systemui.qs.QSPanel.QSTileLayout;
|
||||
import com.android.systemui.qs.QSPanel.TileRecord;
|
||||
import com.android.systemui.qs.QSTile;
|
||||
import com.android.systemui.qs.QuickTileLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -42,7 +41,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class NonPagedTileLayout extends LinearLayout implements QSTileLayout, OnTouchListener {
|
||||
|
||||
private QuickTileLayout mQuickTiles;
|
||||
private final ArrayList<TilePage> mPages = new ArrayList<>();
|
||||
private final ArrayList<TileRecord> mTiles = new ArrayList<TileRecord>();
|
||||
private CustomQSPanel mPanel;
|
||||
@@ -58,8 +56,6 @@ public class NonPagedTileLayout extends LinearLayout implements QSTileLayout, On
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mQuickTiles = (QuickTileLayout) findViewById(R.id.quick_tile_layout);
|
||||
mQuickTiles.setVisibility(View.GONE);
|
||||
TilePage page = (PagedTileLayout.TilePage) findViewById(R.id.tile_page);
|
||||
page.setMaxRows(3 /* First page only gets 3 */);
|
||||
mPages.add(page);
|
||||
@@ -95,7 +91,6 @@ public class NonPagedTileLayout extends LinearLayout implements QSTileLayout, On
|
||||
}
|
||||
|
||||
private void distributeTiles() {
|
||||
mQuickTiles.removeAllViews();
|
||||
final int NP = mPages.size();
|
||||
for (int i = 0; i < NP; i++) {
|
||||
mPages.get(i).removeAllViews();
|
||||
@@ -124,7 +119,8 @@ public class NonPagedTileLayout extends LinearLayout implements QSTileLayout, On
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateResources() {
|
||||
public boolean updateResources() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,24 +129,20 @@ public class NonPagedTileLayout extends LinearLayout implements QSTileLayout, On
|
||||
case DragEvent.ACTION_DRAG_LOCATION:
|
||||
float x = event.getX();
|
||||
float y = event.getY();
|
||||
if (contains(mQuickTiles, x, y)) {
|
||||
// TODO: Reset to pre-drag state.
|
||||
} else {
|
||||
final int NP = mPages.size();
|
||||
for (int i = 0; i < NP; i++) {
|
||||
TilePage page = mPages.get(i);
|
||||
if (contains(page, x, y)) {
|
||||
x -= page.getLeft();
|
||||
y -= page.getTop();
|
||||
final int NC = page.getChildCount();
|
||||
for (int j = 0; j < NC; j++) {
|
||||
View child = page.getChildAt(j);
|
||||
if (contains(child, x, y)) {
|
||||
mPanel.tileSelected((QSTile<?>) child.getTag(), mCurrentClip);
|
||||
}
|
||||
final int NP = mPages.size();
|
||||
for (int i = 0; i < NP; i++) {
|
||||
TilePage page = mPages.get(i);
|
||||
if (contains(page, x, y)) {
|
||||
x -= page.getLeft();
|
||||
y -= page.getTop();
|
||||
final int NC = page.getChildCount();
|
||||
for (int j = 0; j < NC; j++) {
|
||||
View child = page.getChildAt(j);
|
||||
if (contains(child, x, y)) {
|
||||
mPanel.tileSelected((QSTile<?>) child.getTag(), mCurrentClip);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.android.systemui.qs.customize.TileAdapter.TileSelectedListener;
|
||||
import com.android.systemui.statusbar.phone.PhoneStatusBar;
|
||||
import com.android.systemui.statusbar.phone.QSTileHost;
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog;
|
||||
import com.android.systemui.tuner.QSPagingSwitch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -145,7 +144,8 @@ public class QSCustomizer extends LinearLayout implements OnMenuItemClickListene
|
||||
|
||||
private void reset() {
|
||||
ArrayList<String> tiles = new ArrayList<>();
|
||||
for (String tile : QSPagingSwitch.QS_PAGE_TILES.split(",")) {
|
||||
String defTiles = mContext.getString(R.string.quick_settings_tiles_default);
|
||||
for (String tile : defTiles.split(",")) {
|
||||
tiles.add(tile);
|
||||
}
|
||||
mQsPanel.setTiles(tiles);
|
||||
|
||||
@@ -37,13 +37,11 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.qs.QSTile;
|
||||
import com.android.systemui.qs.QSTile.Icon;
|
||||
import com.android.systemui.qs.external.CustomTile;
|
||||
import com.android.systemui.statusbar.phone.QSTileHost;
|
||||
import com.android.systemui.tuner.QSPagingSwitch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -74,8 +72,9 @@ public class TileAdapter extends BaseAdapter {
|
||||
}
|
||||
mCurrentTiles = tileSpecs;
|
||||
final TileGroup group = new TileGroup("com.android.settings", mContext);
|
||||
// TODO: Pull this list from a more authoritative place.
|
||||
String[] possibleTiles = QSPagingSwitch.QS_PAGE_TILES.split(",");
|
||||
String possible = mContext.getString(R.string.quick_settings_tiles_default)
|
||||
+ ",user,hotspot,inversion";
|
||||
String[] possibleTiles = possible.split(",");
|
||||
for (int i = 0; i < possibleTiles.length; i++) {
|
||||
final String spec = possibleTiles[i];
|
||||
if (spec.startsWith("q")) {
|
||||
|
||||
@@ -295,6 +295,7 @@ public final class QSTileHost implements QSTile.Host, Tunable {
|
||||
if (mTiles.containsKey(tileSpec)) {
|
||||
QSTile<?> tile = mTiles.get(tileSpec);
|
||||
if (DEBUG) Log.d(TAG, "Adding " + tile);
|
||||
tile.removeCallbacks();
|
||||
newTiles.put(tileSpec, tile);
|
||||
} else {
|
||||
if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.android.systemui.tuner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.systemui.statusbar.phone.QSTileHost;
|
||||
|
||||
public class QSPagingSwitch extends TunerSwitch {
|
||||
|
||||
public static final String QS_PAGE_TILES =
|
||||
"dnd,cell,battery,user,rotation,flashlight,location,"
|
||||
+ "hotspot,inversion,cast";
|
||||
|
||||
public QSPagingSwitch(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistBoolean(boolean value) {
|
||||
Settings.Secure.putString(getContext().getContentResolver(), QSTileHost.TILES_SETTING,
|
||||
value ? QS_PAGE_TILES : "default");
|
||||
return super.persistBoolean(value);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user