1 package com.android.systemui.qs;
2 
3 import static com.android.systemui.Prefs.Key.QS_TILE_SPECS_REVEALED;
4 
5 import android.content.Context;
6 import android.os.Handler;
7 import android.util.ArraySet;
8 
9 import com.android.systemui.Prefs;
10 import com.android.systemui.plugins.qs.QSTile;
11 
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.Set;
15 
16 public class QSTileRevealController {
17     private static final long QS_REVEAL_TILES_DELAY = 500L;
18 
19     private final Context mContext;
20     private final QSPanel mQSPanel;
21     private final PagedTileLayout mPagedTileLayout;
22     private final ArraySet<String> mTilesToReveal = new ArraySet<>();
23     private final Handler mHandler = new Handler();
24 
25     private final Runnable mRevealQsTiles = new Runnable() {
26         @Override
27         public void run() {
28             mPagedTileLayout.startTileReveal(mTilesToReveal, () -> {
29                 if (mQSPanel.isExpanded()) {
30                     addTileSpecsToRevealed(mTilesToReveal);
31                     mTilesToReveal.clear();
32                 }
33             });
34         }
35     };
36 
QSTileRevealController(Context context, QSPanel qsPanel, PagedTileLayout pagedTileLayout)37     QSTileRevealController(Context context, QSPanel qsPanel, PagedTileLayout pagedTileLayout) {
38         mContext = context;
39         mQSPanel = qsPanel;
40         mPagedTileLayout = pagedTileLayout;
41     }
42 
setExpansion(float expansion)43     public void setExpansion(float expansion) {
44         if (expansion == 1f) {
45             mHandler.postDelayed(mRevealQsTiles, QS_REVEAL_TILES_DELAY);
46         } else {
47             mHandler.removeCallbacks(mRevealQsTiles);
48         }
49     }
50 
updateRevealedTiles(Collection<QSTile> tiles)51     public void updateRevealedTiles(Collection<QSTile> tiles) {
52         ArraySet<String> tileSpecs = new ArraySet<>();
53         for (QSTile tile : tiles) {
54             tileSpecs.add(tile.getTileSpec());
55         }
56 
57         final Set<String> revealedTiles = Prefs.getStringSet(
58                 mContext, QS_TILE_SPECS_REVEALED, Collections.EMPTY_SET);
59         if (revealedTiles.isEmpty() || mQSPanel.isShowingCustomize()) {
60             // Do not reveal QS tiles the user has upon first load or those that they directly
61             // added through customization.
62             addTileSpecsToRevealed(tileSpecs);
63         } else {
64             // Animate all tiles that the user has not directly added themselves.
65             tileSpecs.removeAll(revealedTiles);
66             mTilesToReveal.addAll(tileSpecs);
67         }
68     }
69 
addTileSpecsToRevealed(ArraySet<String> specs)70     private void addTileSpecsToRevealed(ArraySet<String> specs) {
71         final ArraySet<String> revealedTiles = new ArraySet<>(
72                 Prefs.getStringSet(mContext, QS_TILE_SPECS_REVEALED, Collections.EMPTY_SET));
73         revealedTiles.addAll(specs);
74         Prefs.putStringSet(mContext, QS_TILE_SPECS_REVEALED, revealedTiles);
75     }
76 }
77