Skip to content

Commit 1d1720f

Browse files
John SpurlockAndroid (Google) Code Review
authored andcommitted
Merge "QS: Fix some QS layout issues." into lmp-dev
2 parents 186b869 + bceed06 commit 1d1720f

12 files changed

Lines changed: 389 additions & 47 deletions

File tree

packages/SystemUI/res/values/config.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
<!-- The number of columns that the top level tiles span in the QuickSettings -->
9191
<integer name="quick_settings_user_time_settings_tile_span">1</integer>
9292

93+
<!-- The default tiles to display in QuickSettings -->
94+
<string name="quick_settings_tiles_default" translatable="false">
95+
wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast
96+
</string>
97+
98+
<!-- The tiles to display in QuickSettings -->
99+
<string name="quick_settings_tiles" translatable="false">default</string>
100+
93101
<!-- Whether or not the RSSI tile is capitalized or not. -->
94102
<bool name="quick_settings_rssi_tile_capitalization">true</bool>
95103

packages/SystemUI/src/com/android/systemui/qs/QSPanel.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.android.systemui.statusbar.phone.QSTileHost;
3838

3939
import java.util.ArrayList;
40+
import java.util.Collection;
4041

4142
/** View that represents the quick settings tile panel. **/
4243
public class QSPanel extends ViewGroup {
@@ -186,12 +187,25 @@ private void handleSetTileVisibility(View v, boolean visible) {
186187
v.setVisibility(visible ? VISIBLE : GONE);
187188
}
188189

189-
public void addTile(final QSTile<?> tile) {
190+
public void setTiles(Collection<QSTile<?>> tiles) {
191+
for (TileRecord record : mRecords) {
192+
removeView(record.tileView);
193+
}
194+
mRecords.clear();
195+
for (QSTile<?> tile : tiles) {
196+
addTile(tile);
197+
}
198+
if (isShowingDetail()) {
199+
mDetail.bringToFront();
200+
}
201+
}
202+
203+
private void addTile(final QSTile<?> tile) {
190204
final TileRecord r = new TileRecord();
191205
r.tile = tile;
192206
r.tileView = tile.createTileView(mContext);
193207
r.tileView.setVisibility(View.GONE);
194-
r.tile.setCallback(new QSTile.Callback() {
208+
final QSTile.Callback callback = new QSTile.Callback() {
195209
@Override
196210
public void onStateChanged(QSTile.State state) {
197211
setTileVisibility(r.tileView, state.visible);
@@ -213,7 +227,8 @@ public void onScanStateChanged(boolean state) {
213227
fireScanStateChanged(state);
214228
}
215229
}
216-
});
230+
};
231+
r.tile.setCallback(callback);
217232
final View.OnClickListener click = new View.OnClickListener() {
218233
@Override
219234
public void onClick(View v) {
@@ -227,6 +242,8 @@ public void onClick(View v) {
227242
}
228243
};
229244
r.tileView.init(click, clickSecondary);
245+
r.tile.setListening(mListening);
246+
callback.onStateChanged(r.tile.getState());
230247
r.tile.refreshState();
231248
mRecords.add(r);
232249

packages/SystemUI/src/com/android/systemui/qs/QSTile.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
import com.android.systemui.statusbar.policy.RotationLockController;
3838
import com.android.systemui.statusbar.policy.HotspotController;
3939
import com.android.systemui.statusbar.policy.ZenModeController;
40-
import com.android.systemui.volume.VolumeComponent;
4140

42-
import java.util.List;
41+
import java.util.Collection;
4342
import java.util.Objects;
4443

4544
/**
@@ -134,6 +133,14 @@ public void fireScanStateChanged(boolean state) {
134133
mHandler.obtainMessage(H.SCAN_STATE_CHANGED, state ? 1 : 0, 0).sendToTarget();
135134
}
136135

136+
public void destroy() {
137+
mHandler.sendEmptyMessage(H.DESTROY);
138+
}
139+
140+
public TState getState() {
141+
return mState;
142+
}
143+
137144
// call only on tile worker looper
138145

139146
private void handleSetCallback(Callback callback) {
@@ -181,6 +188,11 @@ protected void handleUserSwitch(int newUserId) {
181188
handleRefreshState(null);
182189
}
183190

191+
protected void handleDestroy() {
192+
setListening(false);
193+
mCallback = null;
194+
}
195+
184196
protected final class H extends Handler {
185197
private static final int SET_CALLBACK = 1;
186198
private static final int CLICK = 2;
@@ -190,6 +202,7 @@ protected final class H extends Handler {
190202
private static final int USER_SWITCH = 6;
191203
private static final int TOGGLE_STATE_CHANGED = 7;
192204
private static final int SCAN_STATE_CHANGED = 8;
205+
private static final int DESTROY = 9;
193206

194207
private H(Looper looper) {
195208
super(looper);
@@ -223,6 +236,11 @@ public void handleMessage(Message msg) {
223236
} else if (msg.what == SCAN_STATE_CHANGED) {
224237
name = "handleScanStateChanged";
225238
handleScanStateChanged(msg.arg1 != 0);
239+
} else if (msg.what == DESTROY) {
240+
name = "handleDestroy";
241+
handleDestroy();
242+
} else {
243+
throw new IllegalArgumentException("Unknown msg: " + msg.what);
226244
}
227245
} catch (Throwable t) {
228246
final String error = "Error in " + name;
@@ -245,7 +263,8 @@ public interface Host {
245263
void collapsePanels();
246264
Looper getLooper();
247265
Context getContext();
248-
List<QSTile<?>> getTiles();
266+
Collection<QSTile<?>> getTiles();
267+
void setCallback(Callback callback);
249268
BluetoothController getBluetoothController();
250269
LocationController getLocationController();
251270
RotationLockController getRotationLockController();
@@ -255,6 +274,10 @@ public interface Host {
255274
CastController getCastController();
256275
FlashlightController getFlashlightController();
257276
KeyguardMonitor getKeyguardMonitor();
277+
278+
public interface Callback {
279+
void onTilesChanged();
280+
}
258281
}
259282

260283
public static class State {

packages/SystemUI/src/com/android/systemui/qs/UsageTracker.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
import android.content.SharedPreferences;
2424

2525
import com.android.systemui.R;
26+
import com.android.systemui.statusbar.policy.Listenable;
2627

27-
public class UsageTracker {
28+
public class UsageTracker implements Listenable {
2829
private static final long MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
2930

3031
private final Context mContext;
3132
private final long mTimeToShowTile;
3233
private final String mPrefKey;
3334
private final String mResetAction;
3435

35-
private BroadcastReceiver mReceiver;
36+
private boolean mRegistered;
3637

3738
public UsageTracker(Context context, Class<?> tile) {
3839
mContext = context;
@@ -42,17 +43,14 @@ public UsageTracker(Context context, Class<?> tile) {
4243
mResetAction = "com.android.systemui.qs." + tile.getSimpleName() + ".usage_reset";
4344
}
4445

45-
public void listenForReset() {
46-
if (mReceiver != null) {
47-
mReceiver = new BroadcastReceiver() {
48-
@Override
49-
public void onReceive(Context context, Intent intent) {
50-
if (mResetAction.equals(intent.getAction())) {
51-
reset();
52-
}
53-
}
54-
};
55-
mContext.registerReceiver(mReceiver, new IntentFilter(mResetAction));
46+
@Override
47+
public void setListening(boolean listen) {
48+
if (listen && !mRegistered) {
49+
mContext.registerReceiver(mReceiver, new IntentFilter(mResetAction));
50+
mRegistered = true;
51+
} else if (!listen && mRegistered) {
52+
mContext.unregisterReceiver(mReceiver);
53+
mRegistered = false;
5654
}
5755
}
5856

@@ -72,4 +70,13 @@ public void reset() {
7270
private SharedPreferences getSharedPrefs() {
7371
return mContext.getSharedPreferences(mContext.getPackageName(), 0);
7472
}
73+
74+
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
75+
@Override
76+
public void onReceive(Context context, Intent intent) {
77+
if (mResetAction.equals(intent.getAction())) {
78+
reset();
79+
}
80+
}
81+
};
7582
}

packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
public class AirplaneModeTile extends QSTile<QSTile.BooleanState> {
3232
private final GlobalSetting mSetting;
3333

34+
private boolean mListening;
35+
3436
public AirplaneModeTile(Host host) {
3537
super(host);
3638

@@ -79,6 +81,8 @@ protected void handleUpdateState(BooleanState state, Object arg) {
7981
}
8082

8183
public void setListening(boolean listening) {
84+
if (mListening == listening) return;
85+
mListening = listening;
8286
if (listening) {
8387
final IntentFilter filter = new IntentFilter();
8488
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);

packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ protected void handleValueChanged(int value) {
4141
}
4242
};
4343
mUsageTracker = new UsageTracker(host.getContext(), ColorInversionTile.class);
44-
mUsageTracker.listenForReset();
44+
mUsageTracker.setListening(true);
45+
}
46+
47+
@Override
48+
protected void handleDestroy() {
49+
super.handleDestroy();
50+
mUsageTracker.setListening(false);
4551
}
4652

4753
@Override

packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616

1717
package com.android.systemui.qs.tiles;
1818

19+
import android.app.ActivityManager;
20+
import android.os.SystemClock;
21+
1922
import com.android.systemui.R;
2023
import com.android.systemui.qs.QSTile;
21-
import com.android.systemui.qs.SecureSetting;
2224
import com.android.systemui.statusbar.policy.FlashlightController;
2325

24-
import android.app.ActivityManager;
25-
import android.os.Handler;
26-
import android.os.Looper;
27-
import android.os.SystemClock;
28-
import android.provider.Settings.Secure;
29-
import android.util.Log;
30-
3126
/** Quick settings tile: Control flashlight **/
3227
public class FlashlightTile extends QSTile<QSTile.BooleanState> implements
3328
FlashlightController.FlashlightListener {
@@ -45,6 +40,12 @@ public FlashlightTile(Host host) {
4540
mFlashlightController.addListener(this);
4641
}
4742

43+
@Override
44+
protected void handleDestroy() {
45+
super.handleDestroy();
46+
mFlashlightController.removeListener(this);
47+
}
48+
4849
@Override
4950
protected BooleanState newTileState() {
5051
return new BooleanState();

packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ public HotspotTile(Host host) {
3535
super(host);
3636
mController = host.getHotspotController();
3737
mUsageTracker = new UsageTracker(host.getContext(), HotspotTile.class);
38-
mUsageTracker.listenForReset();
38+
mUsageTracker.setListening(true);
39+
}
40+
41+
@Override
42+
protected void handleDestroy() {
43+
super.handleDestroy();
44+
mUsageTracker.setListening(false);
3945
}
4046

4147
@Override

0 commit comments

Comments
 (0)