OSDN Git Service

Remove visibility from tiles, make them always visible
authorJason Monk <jmonk@google.com>
Tue, 8 Dec 2015 14:04:23 +0000 (09:04 -0500)
committerJason Monk <jmonk@google.com>
Tue, 8 Dec 2015 15:52:10 +0000 (10:52 -0500)
Some tiles are statically not available on boot, etc.
based on hardware availability or settings, but most
are just always visible.

Change-Id: Ib1a45ef5b029fe710f9957cb997496dcb14f5875

29 files changed:
packages/SystemUI/AndroidManifest.xml
packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
packages/SystemUI/src/com/android/systemui/qs/QSTile.java
packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
packages/SystemUI/src/com/android/systemui/qs/TileLayout.java
packages/SystemUI/src/com/android/systemui/qs/UsageTracker.java [deleted file]
packages/SystemUI/src/com/android/systemui/qs/customize/BlankCustomTile.java
packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java
packages/SystemUI/src/com/android/systemui/qs/customize/NonPagedTileLayout.java
packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/BatteryTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/IntentTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/UserTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/WifiTile.java
packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java

index 2f79adf..2e65656 100644 (file)
             </intent-filter>
         </receiver>
 
-        <receiver android:name=".qs.tiles.HotspotTile$APChangedReceiver"
-                androidprv:systemUserOnly="true">
-            <intent-filter>
-                <action android:name="android.net.wifi.WIFI_AP_STATE_CHANGED" />
-            </intent-filter>
-        </receiver>
-
         <activity android:name=".tuner.TunerActivity"
                   android:enabled="false"
                   android:icon="@drawable/tuner"
index 61b1b8e..ca4a03a 100644 (file)
@@ -73,11 +73,6 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
     }
 
     @Override
-    public void setTileVisibility(TileRecord tile, int visibility) {
-        tile.tileView.setVisibility(visibility);
-    }
-
-    @Override
     public void addTile(TileRecord tile) {
         mTiles.add(tile);
         distributeTiles();
index cf1ffe3..5d3fbe2 100644 (file)
@@ -302,15 +302,6 @@ public class QSPanel extends FrameLayout implements Tunable {
         mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget();
     }
 
-    private void setTileVisibility(TileRecord record, int visibility) {
-        mHandler.obtainMessage(H.SET_TILE_VISIBILITY, visibility, 0, record).sendToTarget();
-    }
-
-    private void handleSetTileVisibility(TileRecord tile, int visibility) {
-        if (visibility == tile.tileView.getVisibility()) return;
-        mTileLayout.setTileVisibility(tile, visibility);
-    }
-
     public void setTiles(Collection<QSTile<?>> 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();
     }
index 7f74a12..39f0c55 100644 (file)
@@ -320,8 +320,10 @@ public abstract class QSTile<TState extends State> 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<QSTile<?>> getTiles();
@@ -338,6 +340,7 @@ public abstract class QSTile<TState extends State> 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<TState extends State> 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<TState extends State> 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<TState extends State> 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);
index a5c8d91..fe8ce9b 100644 (file)
@@ -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;
         }
index e82396e..ff11177 100644 (file)
@@ -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 (file)
index e64f6a0..0000000
+++ /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();
-            }
-        }
-    };
-}
index a4ff685..95ff611 100644 (file)
@@ -72,12 +72,10 @@ public class BlankCustomTile extends QSTile<QSTile.State> {
         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;
         }
     }
 
index 422ae4d..8dda9ba 100644 (file)
@@ -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();
index f2b5d1c..3acbed8 100644 (file)
@@ -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;
index 144b202..6706c7a 100644 (file)
@@ -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();
index 49f8d1c..fc802dd 100644 (file)
@@ -73,7 +73,6 @@ public class AirplaneModeTile extends QSTile<QSTile.BooleanState> {
         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;
index 8f9655d..84eac65 100644 (file)
@@ -73,7 +73,6 @@ public class BatteryTile extends QSTile<QSTile.State> 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) {
index ae10051..cfc09a0 100644 (file)
@@ -85,11 +85,9 @@ public class BluetoothTile extends QSTile<QSTile.BooleanState>  {
 
     @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<QSTile.BooleanState>  {
         }
     }
 
+    public static boolean isSupported(Host host) {
+        return host.getBluetoothController().isBluetoothSupported();
+    }
+
     private final BluetoothController.Callback mCallback = new BluetoothController.Callback() {
         @Override
         public void onBluetoothStateChange(boolean enabled) {
index 48b74a4..a8e139c 100644 (file)
@@ -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<QSTile.BooleanState> {
 
     @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;
index 959ccf0..5fb76c8 100644 (file)
@@ -87,8 +87,6 @@ public class CellularTile extends QSTile<QSTile.SignalState> {
 
     @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<QSTile.SignalState> {
         return string;
     }
 
+    public static boolean isSupported(Host host) {
+        return host.getNetworkController().hasMobileDataFeature();
+    }
+
     private static final class CallbackInfo {
         boolean enabled;
         boolean wifiEnabled;
index 2f9a496..f73ee35 100644 (file)
 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<QSTile.BooleanState> {
@@ -34,7 +30,6 @@ public class ColorInversionTile extends QSTile<QSTile.BooleanState> {
     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<QSTile.BooleanState> {
                 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<QSTile.BooleanState> {
 
     @Override
     public void setListening(boolean listening) {
-        mListening = listening;
+        mSetting.setListening(listening);
     }
 
     @Override
@@ -95,23 +76,9 @@ public class ColorInversionTile extends QSTile<QSTile.BooleanState> {
     }
 
     @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;
index b63cdec..bb74f34 100644 (file)
@@ -174,7 +174,6 @@ public class CustomTile extends QSTile<QSTile.State> {
 
     @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);
index 781ab1c..d96f735 100644 (file)
@@ -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<QSTile.BooleanState> {
         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<QSTile.BooleanState> {
         }
     };
 
+    public static boolean isSupported(Host host) {
+        return isVisible(host.getContext());
+    }
+
     private final class DndDetailAdapter implements DetailAdapter, OnAttachStateChangeListener {
 
         @Override
index 21cbef2..12c1298 100644 (file)
@@ -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<QSTile.BooleanState> 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;
index 79084ae..250d567 100644 (file)
 
 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<QSTile.BooleanState> {
             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<QSTile.BooleanState> {
     }
 
     @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<QSTile.BooleanState> {
         } 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<QSTile.BooleanState> {
         }
     }
 
-    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();
-        }
-    }
 }
index c7f2284..0883445 100644 (file)
@@ -124,7 +124,6 @@ public class IntentTile extends QSTile<QSTile.State> {
         }
         // 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;
index 0e2672c..08540f6 100644 (file)
@@ -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<QSTile.BooleanState> {
 
     @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<QSTile.BooleanState> {
         // 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;
index 1a26a4d..d85cf60 100644 (file)
@@ -72,7 +72,8 @@ public class RotationLockTile extends QSTile<QSTile.BooleanState> {
         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;
index 3c5ab8d..d29cae4 100644 (file)
@@ -67,17 +67,19 @@ public class UserTile extends QSTile<QSTile.State> implements UserInfoController
     @Override
     protected void handleUpdateState(State state, Object arg) {
         final Pair<String, Drawable> p = arg != null ? (Pair<String, Drawable>) 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
index 5228081..48b4096 100644 (file)
@@ -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<QSTile.SignalState> {
 
     @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<QSTile.SignalState> {
         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;
index 7605f3b..07915f8 100644 (file)
@@ -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<QSTile.BooleanState> {
     @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<QSTile.BooleanState> {
             userInitialized = false;
         }
 
-        state.visible = true;
         final AnimationIcon icon;
         state.label = mContext.getString(R.string.quick_settings_work_mode_label);
         if (state.value) {
index e51cf7a..6dde157 100644 (file)
@@ -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
index 9427f22..c740b08 100644 (file)
@@ -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<String> 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);