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 import com.android.systemui.qs.customize.QSCustomizerController; 12 import com.android.systemui.qs.dagger.QSScope; 13 14 import java.util.Collection; 15 import java.util.Collections; 16 import java.util.Set; 17 18 import javax.inject.Inject; 19 20 /** */ 21 public class QSTileRevealController { 22 private static final long QS_REVEAL_TILES_DELAY = 500L; 23 24 private final Context mContext; 25 private final QSPanelController mQSPanelController; 26 private final PagedTileLayout mPagedTileLayout; 27 private final QSCustomizerController mQsCustomizerController; 28 private final ArraySet<String> mTilesToReveal = new ArraySet<>(); 29 private final Handler mHandler = new Handler(); 30 31 private final Runnable mRevealQsTiles = new Runnable() { 32 @Override 33 public void run() { 34 mPagedTileLayout.startTileReveal(mTilesToReveal, () -> { 35 if (mQSPanelController.isExpanded()) { 36 addTileSpecsToRevealed(mTilesToReveal); 37 mTilesToReveal.clear(); 38 } 39 }); 40 } 41 }; QSTileRevealController(Context context, QSPanelController qsPanelController, PagedTileLayout pagedTileLayout, QSCustomizerController qsCustomizerController)42 QSTileRevealController(Context context, QSPanelController qsPanelController, 43 PagedTileLayout pagedTileLayout, QSCustomizerController qsCustomizerController) { 44 mContext = context; 45 mQSPanelController = qsPanelController; 46 mPagedTileLayout = pagedTileLayout; 47 mQsCustomizerController = qsCustomizerController; 48 } 49 setExpansion(float expansion)50 public void setExpansion(float expansion) { 51 if (expansion == 1f) { 52 mHandler.postDelayed(mRevealQsTiles, QS_REVEAL_TILES_DELAY); 53 } else { 54 mHandler.removeCallbacks(mRevealQsTiles); 55 } 56 } 57 updateRevealedTiles(Collection<QSTile> tiles)58 public void updateRevealedTiles(Collection<QSTile> tiles) { 59 ArraySet<String> tileSpecs = new ArraySet<>(); 60 for (QSTile tile : tiles) { 61 tileSpecs.add(tile.getTileSpec()); 62 } 63 64 final Set<String> revealedTiles = Prefs.getStringSet( 65 mContext, QS_TILE_SPECS_REVEALED, Collections.EMPTY_SET); 66 if (revealedTiles.isEmpty() || mQsCustomizerController.isCustomizing()) { 67 // Do not reveal QS tiles the user has upon first load or those that they directly 68 // added through customization. 69 addTileSpecsToRevealed(tileSpecs); 70 } else { 71 // Animate all tiles that the user has not directly added themselves. 72 tileSpecs.removeAll(revealedTiles); 73 mTilesToReveal.addAll(tileSpecs); 74 } 75 } 76 addTileSpecsToRevealed(ArraySet<String> specs)77 private void addTileSpecsToRevealed(ArraySet<String> specs) { 78 final ArraySet<String> revealedTiles = new ArraySet<>( 79 Prefs.getStringSet(mContext, QS_TILE_SPECS_REVEALED, Collections.EMPTY_SET)); 80 revealedTiles.addAll(specs); 81 Prefs.putStringSet(mContext, QS_TILE_SPECS_REVEALED, revealedTiles); 82 } 83 84 /** TODO(b/168904199): Remove this once QSPanel has its rejection removed. */ 85 @QSScope 86 static class Factory { 87 private final Context mContext; 88 private final QSCustomizerController mQsCustomizerController; 89 90 @Inject Factory(Context context, QSCustomizerController qsCustomizerController)91 Factory(Context context, QSCustomizerController qsCustomizerController) { 92 mContext = context; 93 mQsCustomizerController = qsCustomizerController; 94 } 95 create(QSPanelController qsPanelController, PagedTileLayout pagedTileLayout)96 QSTileRevealController create(QSPanelController qsPanelController, 97 PagedTileLayout pagedTileLayout) { 98 return new QSTileRevealController(mContext, qsPanelController, pagedTileLayout, 99 mQsCustomizerController); 100 } 101 } 102 } 103