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.provider.Settings;
21 
22 import com.android.systemui.plugins.qs.QSTile;
23 import com.android.systemui.res.R;
24 
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.List;
29 
30 public interface QSHost {
31     String TILES_SETTING = Settings.Secure.QS_TILES;
32     int POSITION_AT_END = -1;
33 
34     /**
35      * Returns the default QS tiles for the context.
36      * @param res the resources to use to determine the default tiles
37      * @return a list of specs of the default tiles
38      */
getDefaultSpecs(Resources res)39     static List<String> getDefaultSpecs(Resources res) {
40         final ArrayList<String> tiles = new ArrayList();
41 
42         final String defaultTileList = res.getString(R.string.quick_settings_tiles_default);
43 
44         tiles.addAll(Arrays.asList(defaultTileList.split(",")));
45         return tiles;
46     }
47 
getContext()48     Context getContext();
getUserContext()49     Context getUserContext();
getUserId()50     int getUserId();
getTiles()51     Collection<QSTile> getTiles();
addCallback(Callback callback)52     void addCallback(Callback callback);
removeCallback(Callback callback)53     void removeCallback(Callback callback);
removeTile(String tileSpec)54     void removeTile(String tileSpec);
removeTiles(Collection<String> specs)55     void removeTiles(Collection<String> specs);
56 
getSpecs()57     List<String> getSpecs();
58 
59     /** Create a {@link QSTile} of a {@code tileSpec} type.
60      *
61      * This should only be called by classes that need to create one-off instances of tiles.
62      * Do not use to create {@code custom} tiles without explicitly taking care of its lifecycle.
63      */
createTile(String tileSpec)64     QSTile createTile(String tileSpec);
65 
66     /**
67      * Add a tile to the end
68      *
69      * @param spec string matching a pre-defined tilespec
70      */
addTile(String spec)71     void addTile(String spec);
72 
73     /**
74      * Add a tile into the requested spot, or at the end if the position is greater than the number
75      * of tiles.
76      * @param spec string matching a pre-defined tilespec
77      * @param requestPosition -1 for end, 0 for beginning, or X for insertion at position X
78      */
addTile(String spec, int requestPosition)79     void addTile(String spec, int requestPosition);
addTile(ComponentName tile)80     void addTile(ComponentName tile);
81 
82     /**
83      * Adds a custom tile to the set of current tiles.
84      * @param tile the component name of the {@link android.service.quicksettings.TileService}
85      * @param end if true, the tile will be added at the end. If false, at the beginning.
86      */
addTile(ComponentName tile, boolean end)87     void addTile(ComponentName tile, boolean end);
removeTileByUser(ComponentName tile)88     void removeTileByUser(ComponentName tile);
changeTilesByUser(List<String> previousTiles, List<String> newTiles)89     void changeTilesByUser(List<String> previousTiles, List<String> newTiles);
90 
indexOf(String tileSpec)91     int indexOf(String tileSpec);
92 
93     interface Callback {
onTilesChanged()94         void onTilesChanged();
95     }
96 }
97