From cb654cb1722d72062461eaa604d077e0368ddb23 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Thu, 25 Feb 2016 15:43:07 -0500 Subject: [PATCH] Fix drag to add tiles showing too many times It was appearing from the night tile being unavailable and causing extra nulls in the list. Fix the night mode tile so the nulls don't happen. Also fix the null handling to avoid this happening with other bad specs. Bug: 27061683 Change-Id: I48f769c06ed17c2ff1f166434857ec1faff14d02 --- .../src/com/android/systemui/Prefs.java | 2 ++ .../systemui/qs/customize/TileAdapter.java | 5 ++++- .../qs/customize/TileQueryHelper.java | 13 +++++++++-- .../statusbar/phone/AutoTileManager.java | 22 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/Prefs.java b/packages/SystemUI/src/com/android/systemui/Prefs.java index 1471622321551..9f2745b9ac24e 100644 --- a/packages/SystemUI/src/com/android/systemui/Prefs.java +++ b/packages/SystemUI/src/com/android/systemui/Prefs.java @@ -48,6 +48,7 @@ public final class Prefs { Key.QS_DATA_SAVER_ADDED, Key.QS_INVERT_COLORS_ADDED, Key.QS_WORK_ADDED, + Key.QS_NIGHT_ADDED, }) public @interface Key { String OVERVIEW_SEARCH_APP_WIDGET_ID = "searchAppWidgetId"; @@ -68,6 +69,7 @@ public final class Prefs { String QS_DATA_SAVER_ADDED = "QsDataSaverAdded"; String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded"; String QS_WORK_ADDED = "QsWorkAdded"; + String QS_NIGHT_ADDED = "QsNightAdded"; } public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java index 876f41798521b..c6c497ffde75d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java @@ -107,7 +107,10 @@ public class TileAdapter extends RecyclerView.Adapter implements TileSta mOtherTiles = new ArrayList(mAllTiles); mTiles.clear(); for (int i = 0; i < mCurrentSpecs.size(); i++) { - mTiles.add(getAndRemoveOther(mCurrentSpecs.get(i))); + final TileInfo tile = getAndRemoveOther(mCurrentSpecs.get(i)); + if (tile != null) { + mTiles.add(tile); + } } mTiles.add(null); mTiles.addAll(mOtherTiles); diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java index c3610d93e1933..aa85f784fe4bc 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java @@ -28,11 +28,14 @@ import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; import android.service.quicksettings.TileService; +import com.android.systemui.Prefs; +import com.android.systemui.Prefs.Key; import com.android.systemui.R; import com.android.systemui.qs.QSTile; import com.android.systemui.qs.QSTile.DrawableIcon; import com.android.systemui.qs.external.CustomTile; import com.android.systemui.statusbar.phone.QSTileHost; +import com.android.systemui.tuner.TunerService; import java.util.ArrayList; import java.util.Collection; @@ -54,7 +57,8 @@ public class TileQueryHelper { } private void addSystemTiles(QSTileHost host) { - boolean hasColorMod = host.getNightModeController().isEnabled(); + boolean hasColorMod = Prefs.getBoolean(host.getContext(), Key.QS_NIGHT_ADDED, false) + && TunerService.isTunerEnabled(host.getContext()); String possible = mContext.getString(R.string.quick_settings_tiles_default) + ",hotspot,inversion,saver,work,cast" + (hasColorMod ? ",night" : ""); String[] possibleTiles = possible.split(","); @@ -88,7 +92,12 @@ public class TileQueryHelper { qsHandler.post(new Runnable() { @Override public void run() { - new QueryTilesTask().execute(); + mainHandler.post(new Runnable() { + @Override + public void run() { + new QueryTilesTask().execute(); + } + }); } }); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java index b74247960fc71..6d0fbb15ca64b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java @@ -24,6 +24,7 @@ import com.android.systemui.statusbar.policy.DataSaverController; import com.android.systemui.statusbar.policy.DataSaverController.Listener; import com.android.systemui.statusbar.policy.HotspotController; import com.android.systemui.statusbar.policy.HotspotController.Callback; +import com.android.systemui.statusbar.policy.NightModeController; /** * Manages which tiles should be automatically added to QS. @@ -66,12 +67,33 @@ public class AutoTileManager { if (!Prefs.getBoolean(context, Key.QS_WORK_ADDED, false)) { host.getManagedProfileController().addCallback(mProfileCallback); } + if (!Prefs.getBoolean(context, Key.QS_NIGHT_ADDED, false)) { + host.getNightModeController().addListener(mNightModeListener); + } } public void destroy() { // TODO: Remove any registered listeners. } + private final NightModeController.Listener mNightModeListener = + new NightModeController.Listener() { + @Override + public void onNightModeChanged() { + mHost.addTile("night"); + Prefs.putBoolean(mContext, Key.QS_NIGHT_ADDED, true); + mHandler.post(new Runnable() { + @Override + public void run() { + mHost.getNightModeController().removeListener(mNightModeListener); + } + }); + } + + @Override + public void onTwilightAutoChanged() { } + }; + private final ManagedProfileController.Callback mProfileCallback = new ManagedProfileController.Callback() { @Override