From 074f769adbe83c6cd1b9c8d23d9391f9c8f3d201 Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Tue, 20 Oct 2020 16:14:17 -0400 Subject: [PATCH] Use QSPanelController in QSAnimator. The animator doesn't want the view, but rather some of the views contained within. At times, it simply wants some of the functionality that the view provides that will be better encapsulated by its controller. Replaced Dependency.get(TunerService.class) with an injected instance. Injected an executor for the class to use rather than relying on QSPanels implicit handler. Bug: 168904199 Test: manual Change-Id: Id228a9dd921fbb11ed2d1d56c93d37d8ceda1cd3 --- .../com/android/systemui/qs/QSAnimator.java | 61 ++++++++++--------- .../systemui/qs/QSPanelController.java | 22 +++++-- .../systemui/qs/QSPanelControllerBase.java | 4 ++ .../android/systemui/util/ViewController.java | 20 ++++-- 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java index 4d41950632278..c52b8ca453af0 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java @@ -19,7 +19,7 @@ import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.View.OnLayoutChangeListener; -import com.android.systemui.Dependency; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.qs.QS; import com.android.systemui.plugins.qs.QSTile; import com.android.systemui.plugins.qs.QSTileView; @@ -34,6 +34,7 @@ import com.android.systemui.tuner.TunerService.Tunable; import java.util.ArrayList; import java.util.Collection; +import java.util.concurrent.Executor; import javax.inject.Inject; @@ -57,7 +58,6 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha */ private final ArrayList mQuickQsViews = new ArrayList<>(); private final QuickQSPanel mQuickQsPanel; - private final QSPanel mQsPanel; private final QSPanelController mQsPanelController; private final QuickQSPanelController mQuickQSPanelController; private final QSSecurityFooter mSecurityFooter; @@ -83,34 +83,36 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha private boolean mFullRows; private int mNumQuickTiles; private float mLastPosition; - private QSTileHost mHost; + private final QSTileHost mHost; + private final Executor mExecutor; + private final TunerService mTunerService; private boolean mShowCollapsedOnKeyguard; @Inject - public QSAnimator(QS qs, QuickQSPanel quickPanel, QSPanel panel, - QSPanelController qsPanelController, QuickQSPanelController quickQSPanelController, - QSTileHost qsTileHost, - QSSecurityFooter securityFooter) { + public QSAnimator(QS qs, QuickQSPanel quickPanel, QSPanelController qsPanelController, + QuickQSPanelController quickQSPanelController, QSTileHost qsTileHost, + QSSecurityFooter securityFooter, @Main Executor executor, TunerService tunerService) { mQs = qs; mQuickQsPanel = quickPanel; - mQsPanel = panel; mQsPanelController = qsPanelController; mQuickQSPanelController = quickQSPanelController; mSecurityFooter = securityFooter; mHost = qsTileHost; + mExecutor = executor; + mTunerService = tunerService; mHost.addCallback(this); - mQsPanel.addOnAttachStateChangeListener(this); + mQsPanelController.addOnAttachStateChangeListener(this); qs.getView().addOnLayoutChangeListener(this); - if (mQsPanel.isAttachedToWindow()) { + if (mQsPanelController.isAttachedToWindow()) { onViewAttachedToWindow(null); } - QSTileLayout tileLayout = mQsPanel.getTileLayout(); + QSTileLayout tileLayout = mQsPanelController.getTileLayout(); if (tileLayout instanceof PagedTileLayout) { mPagedLayout = ((PagedTileLayout) tileLayout); } else { Log.w(TAG, "QS Not using page layout"); } - panel.setPageListener(this); + mQsPanelController.setPageListener(this); } public void onRtlChanged() { @@ -153,14 +155,14 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha @Override public void onViewAttachedToWindow(View v) { - Dependency.get(TunerService.class).addTunable(this, ALLOW_FANCY_ANIMATION, + mTunerService.addTunable(this, ALLOW_FANCY_ANIMATION, MOVE_FULL_ROWS, QuickQSPanel.NUM_QUICK_TILES); } @Override public void onViewDetachedFromWindow(View v) { mHost.removeCallback(this); - Dependency.get(TunerService.class).removeTunable(this); + mTunerService.removeTunable(this); } @Override @@ -205,7 +207,7 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha mAllViews.clear(); mQuickQsViews.clear(); - QSTileLayout tileLayout = mQsPanel.getTileLayout(); + QSTileLayout tileLayout = mQsPanelController.getTileLayout(); mAllViews.add((View) tileLayout); int height = mQs.getView() != null ? mQs.getView().getMeasuredHeight() : 0; int width = mQs.getView() != null ? mQs.getView().getMeasuredWidth() : 0; @@ -223,7 +225,8 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha View view = mQs.getView(); // This case: less tiles to animate in small displays. - if (count < mQuickQsPanel.getTileLayout().getNumVisibleTiles() && mAllowFancy) { + if (count < mQuickQSPanelController.getTileLayout().getNumVisibleTiles() + && mAllowFancy) { // Quick tiles. QSTileView quickTileView = mQuickQSPanelController.getTileView(tile); if (quickTileView == null) continue; @@ -254,7 +257,8 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha translationYBuilder.addFloat(quickTileView, "translationY", 0, yDiff); // xDiff is negative here and this makes it "more" negative - final int translationX = mQsPanel.isLayoutRtl() ? xDiff - width : xDiff + width; + final int translationX = + mQsPanelController.isLayoutRtl() ? xDiff - width : xDiff + width; translationXBuilder.addFloat(quickTileView, "translationX", 0, translationX); } @@ -288,7 +292,7 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha if (mAllowFancy) { // Make brightness appear static position and alpha in through second half. - View brightness = mQsPanel.getBrightnessView(); + View brightness = mQsPanelController.getBrightnessView(); if (brightness != null) { firstPageBuilder.addFloat(brightness, "translationY", heightDiff, 0); mBrightnessAnimator = new TouchAnimator.Builder() @@ -311,13 +315,13 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha // Fade in the security footer and the divider as we reach the final position builder = new Builder().setStartDelay(EXPANDED_TILE_DELAY); builder.addFloat(mSecurityFooter.getView(), "alpha", 0, 1); - if (mQsPanel.getDivider() != null) { - builder.addFloat(mQsPanel.getDivider(), "alpha", 0, 1); + if (mQsPanelController.getDivider() != null) { + builder.addFloat(mQsPanelController.getDivider(), "alpha", 0, 1); } mAllPagesDelayedAnimator = builder.build(); mAllViews.add(mSecurityFooter.getView()); - if (mQsPanel.getDivider() != null) { - mAllViews.add(mQsPanel.getDivider()); + if (mQsPanelController.getDivider() != null) { + mAllViews.add(mQsPanelController.getDivider()); } float px = 0; @@ -447,14 +451,14 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - mQsPanel.post(mUpdateAnimators); + mExecutor.execute(mUpdateAnimators); } @Override public void onTilesChanged() { // Give the QS panels a moment to generate their new tiles, then create all new animators // hooked up to the new views. - mQsPanel.post(mUpdateAnimators); + mExecutor.execute(mUpdateAnimators); } private final TouchAnimator.Listener mNonFirstPageListener = @@ -470,11 +474,8 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha } }; - private Runnable mUpdateAnimators = new Runnable() { - @Override - public void run() { - updateAnimators(); - setCurrentPosition(); - } + private final Runnable mUpdateAnimators = () -> { + updateAnimators(); + setCurrentPosition(); }; } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java index e9670a959ceed..4f87825a49186 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java @@ -119,10 +119,6 @@ public class QSPanelController extends QSPanelControllerBase { mView.setHeaderContainer(headerContainer); } - public QSPanel.QSTileLayout getTileLayout() { - return mView.getTileLayout(); - } - /** */ public void setVisibility(int visibility) { mView.setVisibility(visibility); @@ -209,4 +205,22 @@ public class QSPanelController extends QSPanelControllerBase { public void setGridContentVisibility(boolean visible) { mView.setGridContentVisibility(visible); } + + public boolean isLayoutRtl() { + return mView.isLayoutRtl(); + } + + public View getBrightnessView() { + return mView.getBrightnessView(); + } + + public View getDivider() { + return mView.getDivider(); + } + + /** */ + public void setPageListener(PagedTileLayout.PageListener listener) { + mView.setPageListener(listener); + } } + diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java index 0a4151b382101..bab141bc4dfd6 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java @@ -263,6 +263,10 @@ public abstract class QSPanelControllerBase extends ViewContr } } + public QSPanel.QSTileLayout getTileLayout() { + return mView.getTileLayout(); + } + /** */ public static final class TileRecord extends QSPanel.Record { public QSTile tile; diff --git a/packages/SystemUI/src/com/android/systemui/util/ViewController.java b/packages/SystemUI/src/com/android/systemui/util/ViewController.java index 880d09abeb607..0dd5788105b71 100644 --- a/packages/SystemUI/src/com/android/systemui/util/ViewController.java +++ b/packages/SystemUI/src/com/android/systemui/util/ViewController.java @@ -76,12 +76,10 @@ public abstract class ViewController { onInit(); mInited = true; - if (mView != null) { - if (mView.isAttachedToWindow()) { - mOnAttachStateListener.onViewAttachedToWindow(mView); - } - mView.addOnAttachStateChangeListener(mOnAttachStateListener); + if (isAttachedToWindow()) { + mOnAttachStateListener.onViewAttachedToWindow(mView); } + addOnAttachStateChangeListener(mOnAttachStateListener); } /** @@ -100,6 +98,17 @@ public abstract class ViewController { return mView.getResources(); } + public boolean isAttachedToWindow() { + return mView != null && mView.isAttachedToWindow(); + } + + /** Add an OnAttachStateListener to the view. Does nothing if the view is null. */ + public void addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) { + if (mView != null) { + mView.addOnAttachStateChangeListener(listener); + } + } + /** * Called when the view is attached and a call to {@link #init()} has been made in either order. */ @@ -109,4 +118,5 @@ public abstract class ViewController { * Called when the view is detached. */ protected abstract void onViewDetached(); + }