1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.qs; 16 17 import android.content.ComponentName; 18 import android.content.Context; 19 import android.content.res.Resources; 20 import android.os.Build; 21 import android.provider.Settings; 22 23 import com.android.systemui.R; 24 import com.android.systemui.plugins.qs.QSFactory; 25 import com.android.systemui.plugins.qs.QSTile; 26 import com.android.systemui.plugins.qs.QSTileView; 27 import com.android.systemui.util.leak.GarbageMonitor; 28 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.Collection; 32 import java.util.List; 33 34 public interface QSHost { 35 String TILES_SETTING = Settings.Secure.QS_TILES; 36 int POSITION_AT_END = -1; 37 38 /** 39 * Returns the default QS tiles for the context. 40 * @param res the resources to use to determine the default tiles 41 * @return a list of specs of the default tiles 42 */ getDefaultSpecs(Resources res)43 static List<String> getDefaultSpecs(Resources res) { 44 final ArrayList<String> tiles = new ArrayList(); 45 46 final String defaultTileList = res.getString(R.string.quick_settings_tiles_default); 47 48 tiles.addAll(Arrays.asList(defaultTileList.split(","))); 49 if (Build.IS_DEBUGGABLE 50 && GarbageMonitor.ADD_MEMORY_TILE_TO_DEFAULT_ON_DEBUGGABLE_BUILDS) { 51 tiles.add(GarbageMonitor.MemoryTile.TILE_SPEC); 52 } 53 return tiles; 54 } 55 getContext()56 Context getContext(); getUserContext()57 Context getUserContext(); getUserId()58 int getUserId(); getTiles()59 Collection<QSTile> getTiles(); addCallback(Callback callback)60 void addCallback(Callback callback); removeCallback(Callback callback)61 void removeCallback(Callback callback); removeTile(String tileSpec)62 void removeTile(String tileSpec); removeTiles(Collection<String> specs)63 void removeTiles(Collection<String> specs); 64 getSpecs()65 List<String> getSpecs(); 66 /** 67 * Create a view for a tile, iterating over all possible {@link QSFactory}. 68 * 69 * @see QSFactory#createTileView 70 */ createTileView(Context themedContext, QSTile tile, boolean collapsedView)71 QSTileView createTileView(Context themedContext, QSTile tile, boolean collapsedView); 72 /** Create a {@link QSTile} of a {@code tileSpec} type. 73 * 74 * This should only be called by classes that need to create one-off instances of tiles. 75 * Do not use to create {@code custom} tiles without explicitly taking care of its lifecycle. 76 */ createTile(String tileSpec)77 QSTile createTile(String tileSpec); 78 79 /** 80 * Add a tile to the end 81 * 82 * @param spec string matching a pre-defined tilespec 83 */ addTile(String spec)84 void addTile(String spec); 85 86 /** 87 * Add a tile into the requested spot, or at the end if the position is greater than the number 88 * of tiles. 89 * @param spec string matching a pre-defined tilespec 90 * @param requestPosition -1 for end, 0 for beginning, or X for insertion at position X 91 */ addTile(String spec, int requestPosition)92 void addTile(String spec, int requestPosition); addTile(ComponentName tile)93 void addTile(ComponentName tile); 94 95 /** 96 * Adds a custom tile to the set of current tiles. 97 * @param tile the component name of the {@link android.service.quicksettings.TileService} 98 * @param end if true, the tile will be added at the end. If false, at the beginning. 99 */ addTile(ComponentName tile, boolean end)100 void addTile(ComponentName tile, boolean end); removeTileByUser(ComponentName tile)101 void removeTileByUser(ComponentName tile); changeTilesByUser(List<String> previousTiles, List<String> newTiles)102 void changeTilesByUser(List<String> previousTiles, List<String> newTiles); 103 indexOf(String tileSpec)104 int indexOf(String tileSpec); 105 106 interface Callback { onTilesChanged()107 void onTilesChanged(); 108 } 109 } 110