From ba2318eff373a729f9768b146350a001dd22e4c5 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 8 Dec 2015 09:04:23 -0500 Subject: [PATCH] Remove visibility from tiles, make them always visible Some tiles are statically not available on boot, etc. based on hardware availability or settings, but most are just always visible. Change-Id: Ib1a45ef5b029fe710f9957cb997496dcb14f5875 --- packages/SystemUI/AndroidManifest.xml | 7 -- .../com/android/systemui/qs/PagedTileLayout.java | 5 -- .../src/com/android/systemui/qs/QSPanel.java | 19 +---- .../src/com/android/systemui/qs/QSTile.java | 9 +- .../src/com/android/systemui/qs/QuickQSPanel.java | 5 -- .../src/com/android/systemui/qs/TileLayout.java | 5 -- .../src/com/android/systemui/qs/UsageTracker.java | 99 ---------------------- .../systemui/qs/customize/BlankCustomTile.java | 2 - .../systemui/qs/customize/CustomQSPanel.java | 7 +- .../systemui/qs/customize/NonPagedTileLayout.java | 6 -- .../android/systemui/qs/customize/TileAdapter.java | 3 + .../systemui/qs/tiles/AirplaneModeTile.java | 1 - .../com/android/systemui/qs/tiles/BatteryTile.java | 1 - .../android/systemui/qs/tiles/BluetoothTile.java | 6 +- .../com/android/systemui/qs/tiles/CastTile.java | 15 +++- .../android/systemui/qs/tiles/CellularTile.java | 6 +- .../systemui/qs/tiles/ColorInversionTile.java | 37 +------- .../com/android/systemui/qs/tiles/CustomTile.java | 1 - .../src/com/android/systemui/qs/tiles/DndTile.java | 6 +- .../android/systemui/qs/tiles/FlashlightTile.java | 4 +- .../com/android/systemui/qs/tiles/HotspotTile.java | 49 +---------- .../com/android/systemui/qs/tiles/IntentTile.java | 1 - .../android/systemui/qs/tiles/LocationTile.java | 16 +++- .../systemui/qs/tiles/RotationLockTile.java | 3 +- .../com/android/systemui/qs/tiles/UserTile.java | 24 +++--- .../com/android/systemui/qs/tiles/WifiTile.java | 6 +- .../android/systemui/qs/tiles/WorkModeTile.java | 10 +-- .../systemui/statusbar/phone/PhoneStatusBar.java | 14 +++ .../systemui/statusbar/phone/QSTileHost.java | 40 +++++++-- 29 files changed, 123 insertions(+), 284 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/qs/UsageTracker.java diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 2f79adfcb8e8..2e65656546c3 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -180,13 +180,6 @@ - - - - - - > tiles) { for (TileRecord record : mRecords) { mTileLayout.removeTile(record); @@ -325,8 +316,6 @@ public class QSPanel extends FrameLayout implements Tunable { } private void drawTile(TileRecord r, QSTile.State state) { - final int visibility = state.visible ? VISIBLE : GONE; - setTileVisibility(r, visibility); r.tileView.onStateChanged(state); } @@ -338,7 +327,6 @@ public class QSPanel extends FrameLayout implements Tunable { final TileRecord r = new TileRecord(); r.tile = tile; r.tileView = createTileView(tile); - r.tileView.setVisibility(View.GONE); final QSTile.Callback callback = new QSTile.Callback() { @Override public void onStateChanged(QSTile.State state) { @@ -517,9 +505,7 @@ public class QSPanel extends FrameLayout implements Tunable { private void logTiles() { for (int i = 0; i < mRecords.size(); i++) { TileRecord tileRecord = mRecords.get(i); - if (tileRecord.tile.getState().visible) { - MetricsLogger.visible(mContext, tileRecord.tile.getMetricsCategory()); - } + MetricsLogger.visible(mContext, tileRecord.tile.getMetricsCategory()); } } @@ -556,8 +542,6 @@ public class QSPanel extends FrameLayout implements Tunable { public void handleMessage(Message msg) { if (msg.what == SHOW_DETAIL) { handleShowDetail((Record)msg.obj, msg.arg1 != 0); - } else if (msg.what == SET_TILE_VISIBILITY) { - handleSetTileVisibility((TileRecord) msg.obj, msg.arg1); } } } @@ -621,7 +605,6 @@ public class QSPanel extends FrameLayout implements Tunable { public interface QSTileLayout { void addTile(TileRecord tile); void removeTile(TileRecord tile); - void setTileVisibility(TileRecord tile, int visibility); int getOffsetTop(TileRecord tile); void updateResources(); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java index 7f74a12ad288..39f0c5578e8e 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java @@ -320,8 +320,10 @@ public abstract class QSTile implements Listenable { public interface Host { void startActivityDismissingKeyguard(Intent intent); void startActivityDismissingKeyguard(PendingIntent intent); + void startRunnableDismissingKeyguard(Runnable runnable); void warn(String message, Throwable t); void collapsePanels(); + void openPanels(); Looper getLooper(); Context getContext(); Collection> getTiles(); @@ -338,6 +340,7 @@ public abstract class QSTile implements Listenable { UserSwitcherController getUserSwitcherController(); UserInfoController getUserInfoController(); BatteryController getBatteryController(); + void removeTile(String tileSpec); public interface Callback { void onTilesChanged(); @@ -444,7 +447,6 @@ public abstract class QSTile implements Listenable { } public static class State { - public boolean visible; public Icon icon; public CharSequence label; public CharSequence contentDescription; @@ -454,14 +456,12 @@ public abstract class QSTile implements Listenable { public boolean copyTo(State other) { if (other == null) throw new IllegalArgumentException(); if (!other.getClass().equals(getClass())) throw new IllegalArgumentException(); - final boolean changed = other.visible != visible - || !Objects.equals(other.icon, icon) + final boolean changed = !Objects.equals(other.icon, icon) || !Objects.equals(other.label, label) || !Objects.equals(other.contentDescription, contentDescription) || !Objects.equals(other.autoMirrorDrawable, autoMirrorDrawable) || !Objects.equals(other.dualLabelContentDescription, dualLabelContentDescription); - other.visible = visible; other.icon = icon; other.label = label; other.contentDescription = contentDescription; @@ -477,7 +477,6 @@ public abstract class QSTile implements Listenable { protected StringBuilder toStringBuilder() { final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('['); - sb.append("visible=").append(visible); sb.append(",icon=").append(icon); sb.append(",label=").append(label); sb.append(",contentDescription=").append(contentDescription); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java index a5c8d9191654..fe8ce9bd799d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java @@ -140,11 +140,6 @@ public class QuickQSPanel extends QSPanel { } @Override - public void setTileVisibility(TileRecord tile, int visibility) { - tile.tileView.setVisibility(visibility); - } - - @Override public int getOffsetTop(TileRecord tile) { return 0; } diff --git a/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java index e82396e19d2a..ff111776ed85 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/TileLayout.java @@ -54,11 +54,6 @@ public class TileLayout extends ViewGroup implements QSTileLayout { super.removeAllViews(); } - @Override - public void setTileVisibility(TileRecord tile, int visibility) { - tile.tileView.setVisibility(visibility); - } - public void updateResources() { final Resources res = mContext.getResources(); final int columns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns)); diff --git a/packages/SystemUI/src/com/android/systemui/qs/UsageTracker.java b/packages/SystemUI/src/com/android/systemui/qs/UsageTracker.java deleted file mode 100644 index e64f6a0afdda..000000000000 --- a/packages/SystemUI/src/com/android/systemui/qs/UsageTracker.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.qs; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; - -import com.android.systemui.Prefs; -import com.android.systemui.R; -import com.android.systemui.statusbar.phone.SystemUIDialog; -import com.android.systemui.statusbar.policy.Listenable; - -public class UsageTracker implements Listenable { - private static final long MILLIS_PER_DAY = 1000 * 60 * 60 * 24; - - private final Context mContext; - private final long mTimeToShowTile; - @Prefs.Key private final String mPrefKey; - private final String mResetAction; - - private boolean mRegistered; - - public UsageTracker(Context context, @Prefs.Key String prefKey, Class tile, - int timeoutResource) { - mContext = context; - mPrefKey = prefKey; - mTimeToShowTile = MILLIS_PER_DAY * mContext.getResources().getInteger(timeoutResource); - mResetAction = "com.android.systemui.qs." + tile.getSimpleName() + ".usage_reset"; - } - - @Override - public void setListening(boolean listen) { - if (listen && !mRegistered) { - mContext.registerReceiver(mReceiver, new IntentFilter(mResetAction)); - mRegistered = true; - } else if (!listen && mRegistered) { - mContext.unregisterReceiver(mReceiver); - mRegistered = false; - } - } - - public boolean isRecentlyUsed() { - long lastUsed = Prefs.getLong(mContext, mPrefKey, 0L /* defaultValue */); - return (System.currentTimeMillis() - lastUsed) < mTimeToShowTile; - } - - public void trackUsage() { - Prefs.putLong(mContext, mPrefKey, System.currentTimeMillis()); - } - - public void reset() { - Prefs.remove(mContext, mPrefKey); - } - - public void showResetConfirmation(String title, final Runnable onConfirmed) { - final SystemUIDialog d = new SystemUIDialog(mContext); - d.setTitle(title); - d.setMessage(mContext.getString(R.string.quick_settings_reset_confirmation_message)); - d.setNegativeButton(android.R.string.cancel, null); - d.setPositiveButton(R.string.quick_settings_reset_confirmation_button, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - reset(); - if (onConfirmed != null) { - onConfirmed.run(); - } - } - }); - d.setCanceledOnTouchOutside(true); - d.show(); - } - - private BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (mResetAction.equals(intent.getAction())) { - reset(); - } - } - }; -} diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/BlankCustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/customize/BlankCustomTile.java index a4ff6852374a..95ff611d7419 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/BlankCustomTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/BlankCustomTile.java @@ -72,12 +72,10 @@ public class BlankCustomTile extends QSTile { try { PackageManager pm = mContext.getPackageManager(); ServiceInfo info = pm.getServiceInfo(mComponent, 0); - state.visible = true; state.icon = new DrawableIcon(info.loadIcon(pm)); state.label = info.loadLabel(pm).toString(); state.contentDescription = state.label; } catch (Exception e) { - state.visible = false; } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java index 422ae4d31691..8dda9ba51083 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java @@ -176,13 +176,16 @@ public class CustomQSPanel extends QSPanel { if (mTiles.get(i).startsWith(CustomTile.PREFIX)) { mCurrentTiles.add(BlankCustomTile.create(mHost, mTiles.get(i))); } else { - mCurrentTiles.add(mHost.createTile(mTiles.get(i))); + QSTile tile = mHost.createTile(mTiles.get(i)); + if (tile != null) { + mCurrentTiles.add(tile); + } } mCurrentTiles.get(mCurrentTiles.size() - 1).setTileSpec(mTiles.get(i)); } super.setTiles(mCurrentTiles); } - + public void addTile(String spec) { mTiles.add(spec); setTilesInternal(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/NonPagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/customize/NonPagedTileLayout.java index f2b5d1ca8854..3acbed865dc8 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/NonPagedTileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/NonPagedTileLayout.java @@ -118,12 +118,6 @@ public class NonPagedTileLayout extends LinearLayout implements QSTileLayout, On } @Override - public void setTileVisibility(TileRecord tile, int visibility) { - // All tiles visible here, so that they can be re-arranged. - tile.tileView.setVisibility(View.VISIBLE); - } - - @Override public int getOffsetTop(TileRecord tile) { // No touch feedback, so this isn't required. return 0; 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 144b202f5248..6706c7aace12 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java @@ -88,6 +88,9 @@ public class TileAdapter extends BaseAdapter { } Log.d(TAG, "Trying " + spec); final QSTile tile = host.createTile(spec); + if (tile == null) { + continue; + } // Bad, bad, very bad. tile.setListening(true); tile.clearState(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java index 49f8d1c20413..fc802dde9797 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java @@ -73,7 +73,6 @@ public class AirplaneModeTile extends QSTile { final int value = arg instanceof Integer ? (Integer)arg : mSetting.getValue(); final boolean airplaneMode = value != 0; state.value = airplaneMode; - state.visible = true; state.label = mContext.getString(R.string.airplane_mode); if (airplaneMode) { state.icon = mEnable; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BatteryTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BatteryTile.java index 8f9655d65d15..84eac65a54e7 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BatteryTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BatteryTile.java @@ -73,7 +73,6 @@ public class BatteryTile extends QSTile implements BatteryControll int level = (arg != null) ? (Integer) arg : mLevel; String percentage = NumberFormat.getPercentInstance().format((double) level / 100.0); - state.visible = true; state.icon = new Icon() { @Override public Drawable getDrawable(Context context) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java index ae10051eb269..cfc09a0153bf 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java @@ -85,11 +85,9 @@ public class BluetoothTile extends QSTile { @Override protected void handleUpdateState(BooleanState state, Object arg) { - final boolean supported = mController.isBluetoothSupported(); final boolean enabled = mController.isBluetoothEnabled(); final boolean connected = mController.isBluetoothConnected(); final boolean connecting = mController.isBluetoothConnecting(); - state.visible = supported; state.value = enabled; state.autoMirrorDrawable = false; if (enabled) { @@ -141,6 +139,10 @@ public class BluetoothTile extends QSTile { } } + public static boolean isSupported(Host host) { + return host.getBluetoothController().isBluetoothSupported(); + } + private final BluetoothController.Callback mCallback = new BluetoothController.Callback() { @Override public void onBluetoothStateChange(boolean enabled) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java index 48b74a4566a5..a8e139c1cd43 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java @@ -23,12 +23,10 @@ import android.util.Log; import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.ViewGroup; - import com.android.internal.logging.MetricsLogger; import com.android.systemui.R; import com.android.systemui.qs.QSDetailItems; import com.android.systemui.qs.QSDetailItems.Item; -import com.android.systemui.qs.QSPanel; import com.android.systemui.qs.QSTile; import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.CastController.CastDevice; @@ -87,14 +85,23 @@ public class CastTile extends QSTile { @Override protected void handleClick() { + if (mKeyguard.isSecure() && !mKeyguard.canSkipBouncer()) { + mHost.startRunnableDismissingKeyguard(new Runnable() { + @Override + public void run() { + MetricsLogger.action(mContext, getMetricsCategory()); + showDetail(true); + mHost.openPanels(); + } + }); + return; + } MetricsLogger.action(mContext, getMetricsCategory()); showDetail(true); } @Override protected void handleUpdateState(BooleanState state, Object arg) { - state.visible = !mKeyguard.isSecure() || !mKeyguard.isShowing() - || mKeyguard.canSkipBouncer() || QSPanel.isTheNewQS(mContext); state.label = mContext.getString(R.string.quick_settings_cast_title); state.value = false; state.autoMirrorDrawable = false; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java index 959ccf0297e0..5fb76c8334e2 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java @@ -87,8 +87,6 @@ public class CellularTile extends QSTile { @Override protected void handleUpdateState(SignalState state, Object arg) { - state.visible = mController.hasMobileDataFeature(); - if (!state.visible) return; CallbackInfo cb = (CallbackInfo) arg; if (cb == null) { cb = mSignalCallback.mInfo; @@ -138,6 +136,10 @@ public class CellularTile extends QSTile { return string; } + public static boolean isSupported(Host host) { + return host.getNetworkController().hasMobileDataFeature(); + } + private static final class CallbackInfo { boolean enabled; boolean wifiEnabled; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java index 2f9a496d9602..f73ee354443d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java @@ -17,14 +17,10 @@ package com.android.systemui.qs.tiles; import android.provider.Settings.Secure; - import com.android.internal.logging.MetricsLogger; -import com.android.systemui.Prefs; import com.android.systemui.R; -import com.android.systemui.qs.QSPanel; import com.android.systemui.qs.QSTile; import com.android.systemui.qs.SecureSetting; -import com.android.systemui.qs.UsageTracker; /** Quick settings tile: Invert colors **/ public class ColorInversionTile extends QSTile { @@ -34,7 +30,6 @@ public class ColorInversionTile extends QSTile { private final AnimationIcon mDisable = new AnimationIcon(R.drawable.ic_invert_colors_disable_animation); private final SecureSetting mSetting; - private final UsageTracker mUsageTracker; private boolean mListening; @@ -45,28 +40,14 @@ public class ColorInversionTile extends QSTile { Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED) { @Override protected void handleValueChanged(int value, boolean observedChange) { - if (value != 0 || observedChange) { - mUsageTracker.trackUsage(); - } - if (mListening) { - handleRefreshState(value); - } + handleRefreshState(value); } }; - mUsageTracker = new UsageTracker(host.getContext(), - Prefs.Key.COLOR_INVERSION_TILE_LAST_USED, ColorInversionTile.class, - R.integer.days_to_show_color_inversion_tile); - if (mSetting.getValue() != 0 && !mUsageTracker.isRecentlyUsed()) { - mUsageTracker.trackUsage(); - } - mUsageTracker.setListening(true); - mSetting.setListening(true); } @Override protected void handleDestroy() { super.handleDestroy(); - mUsageTracker.setListening(false); mSetting.setListening(false); } @@ -77,7 +58,7 @@ public class ColorInversionTile extends QSTile { @Override public void setListening(boolean listening) { - mListening = listening; + mSetting.setListening(listening); } @Override @@ -95,23 +76,9 @@ public class ColorInversionTile extends QSTile { } @Override - protected void handleLongClick() { - if (mState.value) return; // don't allow usage reset if inversion is active - final String title = mContext.getString(R.string.quick_settings_reset_confirmation_title, - mState.label); - mUsageTracker.showResetConfirmation(title, new Runnable() { - @Override - public void run() { - refreshState(); - } - }); - } - - @Override protected void handleUpdateState(BooleanState state, Object arg) { final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue(); final boolean enabled = value != 0; - state.visible = enabled || mUsageTracker.isRecentlyUsed() || QSPanel.isTheNewQS(mContext); state.value = enabled; state.label = mContext.getString(R.string.quick_settings_inversion_label); state.icon = enabled ? mEnable : mDisable; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java index b63cdec13e83..bb74f341b89d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java @@ -174,7 +174,6 @@ public class CustomTile extends QSTile { @Override protected void handleUpdateState(State state, Object arg) { - state.visible = true; Drawable drawable = mTile.getIcon().loadDrawable(mContext); drawable.setTint(mContext.getColor(android.R.color.white)); state.icon = new DrawableIcon(drawable); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java index 781ab1c7363c..d96f735301e5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java @@ -29,7 +29,6 @@ import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.ViewGroup; import android.widget.Toast; - import com.android.internal.logging.MetricsLogger; import com.android.systemui.Prefs; import com.android.systemui.R; @@ -126,7 +125,6 @@ public class DndTile extends QSTile { final boolean newValue = zen != Global.ZEN_MODE_OFF; final boolean valueChanged = state.value != newValue; state.value = newValue; - state.visible = isVisible(mContext); switch (zen) { case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: state.icon = ResourceIcon.get(R.drawable.ic_qs_dnd_on); @@ -215,6 +213,10 @@ public class DndTile extends QSTile { } }; + public static boolean isSupported(Host host) { + return isVisible(host.getContext()); + } + private final class DndDetailAdapter implements DetailAdapter, OnAttachStateChangeListener { @Override diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java index 21cbef21c22a..12c12980b065 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java @@ -17,7 +17,6 @@ package com.android.systemui.qs.tiles; import android.app.ActivityManager; - import com.android.internal.logging.MetricsLogger; import com.android.systemui.R; import com.android.systemui.qs.QSTile; @@ -71,7 +70,8 @@ public class FlashlightTile extends QSTile implements @Override protected void handleUpdateState(BooleanState state, Object arg) { - state.visible = mFlashlightController.isAvailable(); + // TODO: Flashlight available handling... +// state.visible = mFlashlightController.isAvailable(); state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label); if (arg instanceof UserBoolean) { boolean value = ((UserBoolean) arg).value; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java index 79084ae73e3c..250d5674bb6e 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java @@ -16,16 +16,9 @@ package com.android.systemui.qs.tiles; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - import com.android.internal.logging.MetricsLogger; -import com.android.systemui.Prefs; import com.android.systemui.R; -import com.android.systemui.qs.QSPanel; import com.android.systemui.qs.QSTile; -import com.android.systemui.qs.UsageTracker; import com.android.systemui.statusbar.policy.HotspotController; /** Quick settings tile: Hotspot **/ @@ -36,19 +29,15 @@ public class HotspotTile extends QSTile { new AnimationIcon(R.drawable.ic_hotspot_disable_animation); private final HotspotController mController; private final Callback mCallback = new Callback(); - private final UsageTracker mUsageTracker; public HotspotTile(Host host) { super(host); mController = host.getHotspotController(); - mUsageTracker = newUsageTracker(host.getContext()); - mUsageTracker.setListening(true); } @Override protected void handleDestroy() { super.handleDestroy(); - mUsageTracker.setListening(false); } @Override @@ -75,22 +64,7 @@ public class HotspotTile extends QSTile { } @Override - protected void handleLongClick() { - if (mState.value) return; // don't allow usage reset if hotspot is active - final String title = mContext.getString(R.string.quick_settings_reset_confirmation_title, - mState.label); - mUsageTracker.showResetConfirmation(title, new Runnable() { - @Override - public void run() { - refreshState(); - } - }); - } - - @Override protected void handleUpdateState(BooleanState state, Object arg) { - state.visible = (mController.isHotspotSupported() && mUsageTracker.isRecentlyUsed()) - || QSPanel.isTheNewQS(mContext); state.label = mContext.getString(R.string.quick_settings_hotspot_label); if (arg instanceof Boolean) { @@ -98,7 +72,7 @@ public class HotspotTile extends QSTile { } else { state.value = mController.isHotspotEnabled(); } - state.icon = state.visible && state.value ? mEnable : mDisable; + state.icon = state.value ? mEnable : mDisable; } @Override @@ -115,31 +89,10 @@ public class HotspotTile extends QSTile { } } - private static UsageTracker newUsageTracker(Context context) { - return new UsageTracker(context, Prefs.Key.HOTSPOT_TILE_LAST_USED, HotspotTile.class, - R.integer.days_to_show_hotspot_tile); - } - private final class Callback implements HotspotController.Callback { @Override public void onHotspotChanged(boolean enabled) { refreshState(enabled); } }; - - /** - * This will catch broadcasts for changes in hotspot state so we can show - * the hotspot tile for a number of days after use. - */ - public static class APChangedReceiver extends BroadcastReceiver { - private UsageTracker mUsageTracker; - - @Override - public void onReceive(Context context, Intent intent) { - if (mUsageTracker == null) { - mUsageTracker = newUsageTracker(context); - } - mUsageTracker.trackUsage(); - } - } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/IntentTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/IntentTile.java index c7f2284c07a6..0883445891a4 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/IntentTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/IntentTile.java @@ -124,7 +124,6 @@ public class IntentTile extends QSTile { } // Save the last one in case we need it later. mLastIntent = intent; - state.visible = intent.getBooleanExtra("visible", true); state.contentDescription = intent.getStringExtra("contentDescription"); state.label = intent.getStringExtra("label"); state.icon = null; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java index 0e2672ca4da1..08540f69ff6e 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java @@ -18,7 +18,6 @@ package com.android.systemui.qs.tiles; import com.android.internal.logging.MetricsLogger; import com.android.systemui.R; -import com.android.systemui.qs.QSPanel; import com.android.systemui.qs.QSTile; import com.android.systemui.statusbar.policy.KeyguardMonitor; import com.android.systemui.statusbar.policy.LocationController; @@ -60,6 +59,20 @@ public class LocationTile extends QSTile { @Override protected void handleClick() { + if (mKeyguard.isSecure() && mKeyguard.isShowing()) { + mHost.startRunnableDismissingKeyguard(new Runnable() { + @Override + public void run() { + final boolean wasEnabled = (Boolean) mState.value; + mHost.openPanels(); + MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); + mController.setLocationEnabled(!wasEnabled); + mEnable.setAllowAnimation(true); + mDisable.setAllowAnimation(true); + } + }); + return; + } final boolean wasEnabled = (Boolean) mState.value; MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); mController.setLocationEnabled(!wasEnabled); @@ -74,7 +87,6 @@ public class LocationTile extends QSTile { // Work around for bug 15916487: don't show location tile on top of lock screen. After the // bug is fixed, this should be reverted to only hiding it on secure lock screens: // state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing()); - state.visible = !mKeyguard.isShowing() || QSPanel.isTheNewQS(mContext); state.value = locationEnabled; if (locationEnabled) { state.icon = mEnable; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java index 1a26a4dad39e..d85cf605c851 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java @@ -72,7 +72,8 @@ public class RotationLockTile extends QSTile { final boolean rotationLocked = arg != null ? ((UserBoolean) arg).value : mController.isRotationLocked(); final boolean userInitiated = arg != null ? ((UserBoolean) arg).userInitiated : false; - state.visible = mController.isRotationLockAffordanceVisible(); + // TODO: Handle accessibility rotation lock and whatnot. +// state.visible = mController.isRotationLockAffordanceVisible(); if (state.value == rotationLocked && state.contentDescription != null) { // No change and initialized, no need to update all the values. return; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserTile.java index 3c5ab8d491b7..d29cae4caace 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserTile.java @@ -67,17 +67,19 @@ public class UserTile extends QSTile implements UserInfoController @Override protected void handleUpdateState(State state, Object arg) { final Pair p = arg != null ? (Pair) arg : mLastUpdate; - state.visible = p != null; - if (!state.visible) return; - state.label = p.first; - // TODO: Better content description. - state.contentDescription = p.first; - state.icon = new Icon() { - @Override - public Drawable getDrawable(Context context) { - return p.second; - } - }; + if (p != null) { + state.label = p.first; + // TODO: Better content description. + state.contentDescription = p.first; + state.icon = new Icon() { + @Override + public Drawable getDrawable(Context context) { + return p.second; + } + }; + } else { + // TODO: Default state. + } } @Override diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/WifiTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/WifiTile.java index 5228081d42cb..48b4096c8500 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/WifiTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/WifiTile.java @@ -18,6 +18,7 @@ package com.android.systemui.qs.tiles; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.provider.Settings; import android.util.Log; @@ -112,7 +113,6 @@ public class WifiTile extends QSTile { @Override protected void handleUpdateState(SignalState state, Object arg) { - state.visible = true; if (DEBUG) Log.d(TAG, "handleUpdateState arg=" + arg); CallbackInfo cb = (CallbackInfo) arg; if (cb == null) { @@ -188,6 +188,10 @@ public class WifiTile extends QSTile { return string; } + public static boolean isSupported(Host host) { + return host.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI); + } + protected static final class CallbackInfo { boolean enabled; boolean connected; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java index 7605f3b89bf1..07915f8dc56e 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java @@ -22,14 +22,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.UserInfo; -import android.os.IUserManager; -import android.os.RemoteException; -import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; -import android.util.ArraySet; -import android.util.Log; - import com.android.internal.logging.MetricsLogger; import com.android.systemui.R; import com.android.systemui.qs.QSTile; @@ -110,8 +104,7 @@ public class WorkModeTile extends QSTile { @Override protected void handleUpdateState(BooleanState state, Object arg) { if (!hasActiveProfile()) { - state.visible = false; - state.value = false; + mHost.removeTile(getTileSpec()); return; } @@ -124,7 +117,6 @@ public class WorkModeTile extends QSTile { userInitialized = false; } - state.visible = true; final AnimationIcon icon; state.label = mContext.getString(R.string.quick_settings_work_mode_label); if (state.value) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index e51cf7ac218f..6dde157dd8bd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -2233,6 +2233,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mHandler.post(mAnimateCollapsePanels); } + public void postAnimateOpenPanels() { + mHandler.sendEmptyMessage(MSG_OPEN_SETTINGS_PANEL); + } + public void animateCollapsePanels(int flags) { animateCollapsePanels(flags, false /* force */, false /* delayed */, 1.0f /* speedUpFactor */); @@ -3282,6 +3286,16 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, return !isDeviceProvisioned() || (mDisabled1 & StatusBarManager.DISABLE_SEARCH) != 0; } + public void postQSRunnableDismissingKeyguard(final Runnable runnable) { + mHandler.post(new Runnable() { + @Override + public void run() { + mLeaveOpenOnKeyguardHide = true; + executeRunnableDismissingKeyguard(runnable, null, false, true); + } + }); + } + public void postStartActivityDismissingKeyguard(final PendingIntent intent) { mHandler.post(new Runnable() { @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java index 9427f227b08d..c740b082e990 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.phone; +import android.app.ActivityManager; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; @@ -27,10 +28,11 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.Process; import android.os.RemoteException; +import android.provider.Settings; import android.service.quicksettings.IQSService; import android.service.quicksettings.Tile; +import android.text.TextUtils; import android.util.Log; - import com.android.systemui.R; import com.android.systemui.qs.QSTile; import com.android.systemui.qs.tiles.AirplaneModeTile; @@ -160,6 +162,11 @@ public final class QSTileHost extends IQSService.Stub implements QSTile.Host, Tu } @Override + public void startRunnableDismissingKeyguard(Runnable runnable) { + mStatusBar.postQSRunnableDismissingKeyguard(runnable); + } + + @Override public void warn(String message, Throwable t) { // already logged } @@ -170,6 +177,11 @@ public final class QSTileHost extends IQSService.Stub implements QSTile.Host, Tu } @Override + public void openPanels() { + mStatusBar.postAnimateOpenPanels(); + } + + @Override public Looper getLooper() { return mLooper; } @@ -267,8 +279,10 @@ public final class QSTileHost extends IQSService.Stub implements QSTile.Host, Tu if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec); try { QSTile tile = createTile(tileSpec); - tile.setTileSpec(tileSpec); - newTiles.put(tileSpec, tile); + if (tile != null) { + tile.setTileSpec(tileSpec); + newTiles.put(tileSpec, tile); + } } catch (Throwable t) { Log.w(TAG, "Error creating tile for spec: " + tileSpec, t); } @@ -284,6 +298,14 @@ public final class QSTileHost extends IQSService.Stub implements QSTile.Host, Tu } @Override + public void removeTile(String tileSpec) { + ArrayList specs = new ArrayList<>(mTileSpecs); + specs.remove(tileSpec); + Settings.Secure.putStringForUser(mContext.getContentResolver(), TILES_SETTING, + TextUtils.join(",", specs), ActivityManager.getCurrentUser()); + } + + @Override public void updateQsTile(Tile tile) throws RemoteException { verifyCaller(tile.getComponentName().getPackageName()); CustomTile customTile = getTileForComponent(tile.getComponentName()); @@ -328,13 +350,17 @@ public final class QSTileHost extends IQSService.Stub implements QSTile.Host, Tu } public QSTile createTile(String tileSpec) { - if (tileSpec.equals("wifi")) return new WifiTile(this); - else if (tileSpec.equals("bt")) return new BluetoothTile(this); + if (tileSpec.equals("wifi")) return WifiTile.isSupported(this) + ? new WifiTile(this) : null; + else if (tileSpec.equals("bt")) return BluetoothTile.isSupported(this) + ? new BluetoothTile(this) : null; + else if (tileSpec.equals("cell")) return CellularTile.isSupported(this) + ? new CellularTile(this) : null; + else if (tileSpec.equals("dnd")) return DndTile.isSupported(this) + ? new DndTile(this) : null; else if (tileSpec.equals("inversion")) return new ColorInversionTile(this); - else if (tileSpec.equals("cell")) return new CellularTile(this); else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this); else if (tileSpec.equals("work")) return new WorkModeTile(this); - else if (tileSpec.equals("dnd")) return new DndTile(this); else if (tileSpec.equals("rotation")) return new RotationLockTile(this); else if (tileSpec.equals("flashlight")) return new FlashlightTile(this); else if (tileSpec.equals("location")) return new LocationTile(this); -- 2.11.0