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.internal.logging.InstanceId; 24 import com.android.internal.logging.UiEventLogger; 25 import com.android.systemui.R; 26 import com.android.systemui.plugins.qs.QSFactory; 27 import com.android.systemui.plugins.qs.QSTile; 28 import com.android.systemui.plugins.qs.QSTileView; 29 import com.android.systemui.util.leak.GarbageMonitor; 30 31 import java.util.ArrayList; 32 import java.util.Arrays; 33 import java.util.Collection; 34 import java.util.List; 35 36 public interface QSHost { 37 String TILES_SETTING = Settings.Secure.QS_TILES; 38 int POSITION_AT_END = -1; 39 40 /** 41 * Returns the default QS tiles for the context. 42 * @param context the context to obtain the resources from 43 * @return a list of specs of the default tiles 44 */ getDefaultSpecs(Context context)45 static List<String> getDefaultSpecs(Context context) { 46 final ArrayList<String> tiles = new ArrayList(); 47 48 final Resources res = context.getResources(); 49 final String defaultTileList = res.getString(R.string.quick_settings_tiles_default); 50 51 tiles.addAll(Arrays.asList(defaultTileList.split(","))); 52 if (Build.IS_DEBUGGABLE 53 && GarbageMonitor.ADD_MEMORY_TILE_TO_DEFAULT_ON_DEBUGGABLE_BUILDS) { 54 tiles.add(GarbageMonitor.MemoryTile.TILE_SPEC); 55 } 56 return tiles; 57 } 58 warn(String message, Throwable t)59 void warn(String message, Throwable t); collapsePanels()60 void collapsePanels(); forceCollapsePanels()61 void forceCollapsePanels(); openPanels()62 void openPanels(); getContext()63 Context getContext(); getUserContext()64 Context getUserContext(); getUserId()65 int getUserId(); getUiEventLogger()66 UiEventLogger getUiEventLogger(); getTiles()67 Collection<QSTile> getTiles(); addCallback(Callback callback)68 void addCallback(Callback callback); removeCallback(Callback callback)69 void removeCallback(Callback callback); removeTile(String tileSpec)70 void removeTile(String tileSpec); removeTiles(Collection<String> specs)71 void removeTiles(Collection<String> specs); 72 getSpecs()73 List<String> getSpecs(); 74 /** 75 * Create a view for a tile, iterating over all possible {@link QSFactory}. 76 * 77 * @see QSFactory#createTileView 78 */ createTileView(Context themedContext, QSTile tile, boolean collapsedView)79 QSTileView createTileView(Context themedContext, QSTile tile, boolean collapsedView); 80 /** Create a {@link QSTile} of a {@code tileSpec} type. */ createTile(String tileSpec)81 QSTile createTile(String tileSpec); 82 83 /** 84 * Add a tile to the end 85 * 86 * @param spec string matching a pre-defined tilespec 87 */ addTile(String spec)88 void addTile(String spec); 89 90 /** 91 * Add a tile into the requested spot, or at the end if the position is greater than the number 92 * of tiles. 93 * @param spec string matching a pre-defined tilespec 94 * @param requestPosition -1 for end, 0 for beginning, or X for insertion at position X 95 */ addTile(String spec, int requestPosition)96 void addTile(String spec, int requestPosition); addTile(ComponentName tile)97 void addTile(ComponentName tile); 98 99 /** 100 * Adds a custom tile to the set of current tiles. 101 * @param tile the component name of the {@link android.service.quicksettings.TileService} 102 * @param end if true, the tile will be added at the end. If false, at the beginning. 103 */ addTile(ComponentName tile, boolean end)104 void addTile(ComponentName tile, boolean end); removeTileByUser(ComponentName tile)105 void removeTileByUser(ComponentName tile); changeTilesByUser(List<String> previousTiles, List<String> newTiles)106 void changeTilesByUser(List<String> previousTiles, List<String> newTiles); 107 isTileAdded(ComponentName componentName, int userId)108 boolean isTileAdded(ComponentName componentName, int userId); setTileAdded(ComponentName componentName, int userId, boolean added)109 void setTileAdded(ComponentName componentName, int userId, boolean added); 110 indexOf(String tileSpec)111 int indexOf(String tileSpec); 112 getNewInstanceId()113 InstanceId getNewInstanceId(); 114 115 interface Callback { onTilesChanged()116 void onTilesChanged(); 117 } 118 } 119