FileDocCategorySizeDatePackage
QSTileHost.javaAPI DocAndroid 5.1 API11200Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.phone

QSTileHost

public class QSTileHost extends Object implements QSTile.Host
Platform implementation of the quick settings tile host

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final String
TILES_SETTING
private final android.content.Context
mContext
private final PhoneStatusBar
mStatusBar
private final LinkedHashMap
mTiles
private final Observer
mObserver
private final com.android.systemui.statusbar.policy.BluetoothController
mBluetooth
private final com.android.systemui.statusbar.policy.LocationController
mLocation
private final com.android.systemui.statusbar.policy.RotationLockController
mRotation
private final com.android.systemui.statusbar.policy.NetworkController
mNetwork
private final com.android.systemui.statusbar.policy.ZenModeController
mZen
private final com.android.systemui.statusbar.policy.HotspotController
mHotspot
private final com.android.systemui.statusbar.policy.CastController
mCast
private final android.os.Looper
mLooper
private final com.android.systemui.settings.CurrentUserTracker
mUserTracker
private final com.android.systemui.statusbar.policy.FlashlightController
mFlashlight
private final com.android.systemui.statusbar.policy.UserSwitcherController
mUserSwitcherController
private final com.android.systemui.statusbar.policy.KeyguardMonitor
mKeyguard
private final com.android.systemui.statusbar.policy.SecurityController
mSecurity
private Callback
mCallback
Constructors Summary
public QSTileHost(android.content.Context context, PhoneStatusBar statusBar, com.android.systemui.statusbar.policy.BluetoothController bluetooth, com.android.systemui.statusbar.policy.LocationController location, com.android.systemui.statusbar.policy.RotationLockController rotation, com.android.systemui.statusbar.policy.NetworkController network, com.android.systemui.statusbar.policy.ZenModeController zen, com.android.systemui.statusbar.policy.HotspotController hotspot, com.android.systemui.statusbar.policy.CastController cast, com.android.systemui.statusbar.policy.FlashlightController flashlight, com.android.systemui.statusbar.policy.UserSwitcherController userSwitcher, com.android.systemui.statusbar.policy.KeyguardMonitor keyguard, com.android.systemui.statusbar.policy.SecurityController security)


        
               
               
               
               
               
              
        mContext = context;
        mStatusBar = statusBar;
        mBluetooth = bluetooth;
        mLocation = location;
        mRotation = rotation;
        mNetwork = network;
        mZen = zen;
        mHotspot = hotspot;
        mCast = cast;
        mFlashlight = flashlight;
        mUserSwitcherController = userSwitcher;
        mKeyguard = keyguard;
        mSecurity = security;

        final HandlerThread ht = new HandlerThread(QSTileHost.class.getSimpleName(),
                Process.THREAD_PRIORITY_BACKGROUND);
        ht.start();
        mLooper = ht.getLooper();

        mUserTracker = new CurrentUserTracker(mContext) {
            @Override
            public void onUserSwitched(int newUserId) {
                recreateTiles();
                for (QSTile<?> tile : mTiles.values()) {
                    tile.userSwitch(newUserId);
                }
                mSecurity.onUserSwitched(newUserId);
                mNetwork.onUserSwitched(newUserId);
                mObserver.register();
            }
        };
        recreateTiles();

        mUserTracker.startTracking();
        mObserver.register();
    
Methods Summary
public voidcollapsePanels()

        mStatusBar.postAnimateCollapsePanels();
    
private com.android.systemui.qs.QSTilecreateTile(java.lang.String tileSpec)

        if (tileSpec.equals("wifi")) return new WifiTile(this);
        else if (tileSpec.equals("bt")) return new BluetoothTile(this);
        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("rotation")) return new RotationLockTile(this);
        else if (tileSpec.equals("flashlight")) return new FlashlightTile(this);
        else if (tileSpec.equals("location")) return new LocationTile(this);
        else if (tileSpec.equals("cast")) return new CastTile(this);
        else if (tileSpec.equals("hotspot")) return new HotspotTile(this);
        else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
        else throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
    
public com.android.systemui.statusbar.policy.BluetoothControllergetBluetoothController()

        return mBluetooth;
    
public com.android.systemui.statusbar.policy.CastControllergetCastController()

        return mCast;
    
public android.content.ContextgetContext()

        return mContext;
    
public com.android.systemui.statusbar.policy.FlashlightControllergetFlashlightController()

        return mFlashlight;
    
public com.android.systemui.statusbar.policy.HotspotControllergetHotspotController()

        return mHotspot;
    
public com.android.systemui.statusbar.policy.KeyguardMonitorgetKeyguardMonitor()

        return mKeyguard;
    
public com.android.systemui.statusbar.policy.LocationControllergetLocationController()

        return mLocation;
    
public android.os.LoopergetLooper()

        return mLooper;
    
public com.android.systemui.statusbar.policy.NetworkControllergetNetworkController()

        return mNetwork;
    
public com.android.systemui.statusbar.policy.RotationLockControllergetRotationLockController()

        return mRotation;
    
public com.android.systemui.statusbar.policy.SecurityControllergetSecurityController()

        return mSecurity;
    
public java.util.CollectiongetTiles()

        return mTiles.values();
    
public com.android.systemui.statusbar.policy.UserSwitcherControllergetUserSwitcherController()

        return mUserSwitcherController;
    
public com.android.systemui.statusbar.policy.ZenModeControllergetZenModeController()

        return mZen;
    
private java.util.ListloadTileSpecs()

        final Resources res = mContext.getResources();
        final String defaultTileList = res.getString(R.string.quick_settings_tiles_default);
        String tileList = Secure.getStringForUser(mContext.getContentResolver(), TILES_SETTING,
                mUserTracker.getCurrentUserId());
        if (tileList == null) {
            tileList = res.getString(R.string.quick_settings_tiles);
            if (DEBUG) Log.d(TAG, "Loaded tile specs from config: " + tileList);
        } else {
            if (DEBUG) Log.d(TAG, "Loaded tile specs from setting: " + tileList);
        }
        final ArrayList<String> tiles = new ArrayList<String>();
        boolean addedDefault = false;
        for (String tile : tileList.split(",")) {
            tile = tile.trim();
            if (tile.isEmpty()) continue;
            if (tile.equals("default")) {
                if (!addedDefault) {
                    tiles.addAll(Arrays.asList(defaultTileList.split(",")));
                    addedDefault = true;
                }
            } else {
                tiles.add(tile);
            }
        }
        return tiles;
    
private voidrecreateTiles()

        if (DEBUG) Log.d(TAG, "Recreating tiles");
        final List<String> tileSpecs = loadTileSpecs();
        for (Map.Entry<String, QSTile<?>> tile : mTiles.entrySet()) {
            if (!tileSpecs.contains(tile.getKey())) {
                if (DEBUG) Log.d(TAG, "Destroying tile: " + tile.getKey());
                tile.getValue().destroy();
            }
        }
        final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>();
        for (String tileSpec : tileSpecs) {
            if (mTiles.containsKey(tileSpec)) {
                newTiles.put(tileSpec, mTiles.get(tileSpec));
            } else {
                if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec);
                try {
                    newTiles.put(tileSpec, createTile(tileSpec));
                } catch (Throwable t) {
                    Log.w(TAG, "Error creating tile for spec: " + tileSpec, t);
                }
            }
        }
        if (mTiles.equals(newTiles)) return;
        mTiles.clear();
        mTiles.putAll(newTiles);
        if (mCallback != null) {
            mCallback.onTilesChanged();
        }
    
public voidsetCallback(Callback callback)

        mCallback = callback;
    
public voidstartSettingsActivity(android.content.Intent intent)

        mStatusBar.postStartSettingsActivity(intent, 0);
    
public voidwarn(java.lang.String message, java.lang.Throwable t)

        // already logged