From cedd60e78dcc196a5c4fc86accb9b3f0faeb7a8e Mon Sep 17 00:00:00 2001 From: Shawn Lee Date: Tue, 13 Sep 2022 15:15:19 -0700 Subject: [PATCH] Resolved minor warnings in a few notification and accessibility classes Bug: 246975184 Test: existing tests Change-Id: I7732ffb788ce380d3c71206718b24bd30ad827e0 --- .../SimpleMirrorWindowControl.java | 7 +- .../WindowMagnificationController.java | 12 +- .../stack/NotificationSection.java | 13 +- .../stack/NotificationStackScrollLayout.java | 111 +++++++----------- 4 files changed, 55 insertions(+), 88 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/SimpleMirrorWindowControl.java b/packages/SystemUI/src/com/android/systemui/accessibility/SimpleMirrorWindowControl.java index 2ba2bb6edc18c..ed6fbecd19fe2 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/SimpleMirrorWindowControl.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/SimpleMirrorWindowControl.java @@ -45,7 +45,7 @@ class SimpleMirrorWindowControl extends MirrorWindowControl implements View.OnCl private boolean mShouldSetTouchStart; @Nullable private MoveWindowTask mMoveWindowTask; - private PointF mLastDrag = new PointF(); + private final PointF mLastDrag = new PointF(); private final Handler mHandler; SimpleMirrorWindowControl(Context context, Handler handler) { @@ -92,8 +92,7 @@ class SimpleMirrorWindowControl extends MirrorWindowControl implements View.OnCl } private Point findOffset(View v, int moveFrameAmount) { - final Point offset = mTmpPoint; - offset.set(0, 0); + mTmpPoint.set(0, 0); if (v.getId() == R.id.left_control) { mTmpPoint.x = -moveFrameAmount; } else if (v.getId() == R.id.up_control) { @@ -184,7 +183,7 @@ class SimpleMirrorWindowControl extends MirrorWindowControl implements View.OnCl private final int mYOffset; private final Handler mHandler; /** Time in milliseconds between successive task executions.*/ - private long mPeriod; + private final long mPeriod; private boolean mCancel; MoveWindowTask(@NonNull MirrorWindowDelegate windowDelegate, Handler handler, int xOffset, diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index e3c04a379fe44..a6e767ca27ee9 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java @@ -104,7 +104,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private final Context mContext; private final Resources mResources; private final Handler mHandler; - private Rect mWindowBounds; + private final Rect mWindowBounds; private final int mDisplayId; @Surface.Rotation @VisibleForTesting @@ -193,11 +193,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider; private final MagnificationGestureDetector mGestureDetector; private final int mBounceEffectDuration; - private Choreographer.FrameCallback mMirrorViewGeometryVsyncCallback; + private final Choreographer.FrameCallback mMirrorViewGeometryVsyncCallback; private Locale mLocale; private NumberFormat mPercentFormat; private float mBounceEffectAnimationScale; - private SysUiState mSysUiState; + private final SysUiState mSysUiState; // Set it to true when the view is overlapped with the gesture insets at the bottom. private boolean mOverlapWithGestureInsets; private boolean mIsDragging; @@ -215,7 +215,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private boolean mEditSizeEnable = false; @Nullable - private MirrorWindowControl mMirrorWindowControl; + private final MirrorWindowControl mMirrorWindowControl; WindowMagnificationController( @UiContext Context context, @@ -562,9 +562,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold /** Returns the rotation degree change of two {@link Surface.Rotation} */ private int getDegreeFromRotation(@Surface.Rotation int newRotation, @Surface.Rotation int oldRotation) { - final int rotationDiff = oldRotation - newRotation; - final int degree = (rotationDiff + 4) % 4 * 90; - return degree; + return (oldRotation - newRotation + 4) % 4 * 90; } private void createMirrorWindow() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSection.java index bc172ce537f36..0b435fe9dcc66 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSection.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSection.java @@ -35,12 +35,12 @@ import com.android.systemui.statusbar.notification.row.ExpandableView; * bounds change. */ public class NotificationSection { - private @PriorityBucket int mBucket; - private View mOwningView; - private Rect mBounds = new Rect(); - private Rect mCurrentBounds = new Rect(-1, -1, -1, -1); - private Rect mStartAnimationRect = new Rect(); - private Rect mEndAnimationRect = new Rect(); + private @PriorityBucket final int mBucket; + private final View mOwningView; + private final Rect mBounds = new Rect(); + private final Rect mCurrentBounds = new Rect(-1, -1, -1, -1); + private final Rect mStartAnimationRect = new Rect(); + private final Rect mEndAnimationRect = new Rect(); private ObjectAnimator mTopAnimator = null; private ObjectAnimator mBottomAnimator = null; private ExpandableView mFirstVisibleChild; @@ -277,7 +277,6 @@ public class NotificationSection { } } } - top = Math.max(minTopPosition, top); ExpandableView lastView = getLastVisibleChild(); if (lastView != null) { float finalTranslationY = ViewState.getFinalTranslationY(lastView); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index 5fbaa515d5d74..e377501943680 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -135,7 +135,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private static final boolean SPEW = Log.isLoggable(TAG, Log.VERBOSE); // Delay in milli-seconds before shade closes for clear all. - private final int DELAY_BEFORE_SHADE_CLOSE = 200; + private static final int DELAY_BEFORE_SHADE_CLOSE = 200; private boolean mShadeNeedsToClose = false; private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; @@ -152,7 +152,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1; private boolean mKeyguardBypassEnabled; - private ExpandHelper mExpandHelper; + private final ExpandHelper mExpandHelper; private NotificationSwipeHelper mSwipeHelper; private int mCurrentStackHeight = Integer.MAX_VALUE; private final Paint mBackgroundPaint = new Paint(); @@ -165,12 +165,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private VelocityTracker mVelocityTracker; private OverScroller mScroller; - /** Last Y position reported by {@link #mScroller}, used to calculate scroll delta. */ - private int mLastScrollerY; - /** - * True if the max position was set to a known position on the last call to {@link #mScroller}. - */ - private boolean mIsScrollerBoundSet; + private Runnable mFinishScrollingCallback; private int mTouchSlop; private float mSlopMultiplier; @@ -194,7 +189,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private int mContentHeight; private float mIntrinsicContentHeight; - private int mCollapsedSize; private int mPaddingBetweenElements; private int mMaxTopPadding; private int mTopPadding; @@ -210,15 +204,15 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private final StackScrollAlgorithm mStackScrollAlgorithm; private final AmbientState mAmbientState; - private GroupMembershipManager mGroupMembershipManager; - private GroupExpansionManager mGroupExpansionManager; - private HashSet mChildrenToAddAnimated = new HashSet<>(); - private ArrayList mAddedHeadsUpChildren = new ArrayList<>(); - private ArrayList mChildrenToRemoveAnimated = new ArrayList<>(); - private ArrayList mChildrenChangingPositions = new ArrayList<>(); - private HashSet mFromMoreCardAdditions = new HashSet<>(); - private ArrayList mAnimationEvents = new ArrayList<>(); - private ArrayList mSwipedOutViews = new ArrayList<>(); + private final GroupMembershipManager mGroupMembershipManager; + private final GroupExpansionManager mGroupExpansionManager; + private final HashSet mChildrenToAddAnimated = new HashSet<>(); + private final ArrayList mAddedHeadsUpChildren = new ArrayList<>(); + private final ArrayList mChildrenToRemoveAnimated = new ArrayList<>(); + private final ArrayList mChildrenChangingPositions = new ArrayList<>(); + private final HashSet mFromMoreCardAdditions = new HashSet<>(); + private final ArrayList mAnimationEvents = new ArrayList<>(); + private final ArrayList mSwipedOutViews = new ArrayList<>(); private NotificationStackSizeCalculator mNotificationStackSizeCalculator; private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); private boolean mAnimationsEnabled; @@ -296,7 +290,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private boolean mDisallowDismissInThisMotion; private boolean mDisallowScrollingInThisMotion; private long mGoToFullShadeDelay; - private ViewTreeObserver.OnPreDrawListener mChildrenUpdater + private final ViewTreeObserver.OnPreDrawListener mChildrenUpdater = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { @@ -309,17 +303,16 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable }; private NotificationStackScrollLogger mLogger; private CentralSurfaces mCentralSurfaces; - private int[] mTempInt2 = new int[2]; + private final int[] mTempInt2 = new int[2]; private boolean mGenerateChildOrderChangedEvent; - private HashSet mAnimationFinishedRunnables = new HashSet<>(); - private HashSet mClearTransientViewsWhenFinished = new HashSet<>(); - private HashSet> mHeadsUpChangeAnimations + private final HashSet mAnimationFinishedRunnables = new HashSet<>(); + private final HashSet mClearTransientViewsWhenFinished = new HashSet<>(); + private final HashSet> mHeadsUpChangeAnimations = new HashSet<>(); - private boolean mTrackingHeadsUp; private boolean mForceNoOverlappingRendering; private final ArrayList> mTmpList = new ArrayList<>(); private boolean mAnimationRunning; - private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater + private final ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { @@ -327,21 +320,21 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable return true; } }; - private NotificationSection[] mSections; + private final NotificationSection[] mSections; private boolean mAnimateNextBackgroundTop; private boolean mAnimateNextBackgroundBottom; private boolean mAnimateNextSectionBoundsChange; private int mBgColor; private float mDimAmount; private ValueAnimator mDimAnimator; - private ArrayList mTmpSortedChildren = new ArrayList<>(); + private final ArrayList mTmpSortedChildren = new ArrayList<>(); private final Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDimAnimator = null; } }; - private ValueAnimator.AnimatorUpdateListener mDimUpdateListener + private final ValueAnimator.AnimatorUpdateListener mDimUpdateListener = new ValueAnimator.AnimatorUpdateListener() { @Override @@ -351,29 +344,23 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable }; protected ViewGroup mQsHeader; // Rect of QsHeader. Kept as a field just to avoid creating a new one each time. - private Rect mQsHeaderBound = new Rect(); + private final Rect mQsHeaderBound = new Rect(); private boolean mContinuousShadowUpdate; private boolean mContinuousBackgroundUpdate; - private ViewTreeObserver.OnPreDrawListener mShadowUpdater + private final ViewTreeObserver.OnPreDrawListener mShadowUpdater = () -> { updateViewShadows(); return true; }; - private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { + private final ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> { updateBackground(); return true; }; - private Comparator mViewPositionComparator = (view, otherView) -> { + private final Comparator mViewPositionComparator = (view, otherView) -> { float endY = view.getTranslationY() + view.getActualHeight(); float otherEndY = otherView.getTranslationY() + otherView.getActualHeight(); - if (endY < otherEndY) { - return -1; - } else if (endY > otherEndY) { - return 1; - } else { - // The two notifications end at the same location - return 0; - } + // Return zero when the two notifications end at the same location + return Float.compare(endY, otherEndY); }; private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { @Override @@ -435,16 +422,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private int mUpcomingStatusBarState; private int mCachedBackgroundColor; private boolean mHeadsUpGoingAwayAnimationsAllowed = true; - private Runnable mReflingAndAnimateScroll = () -> { - animateScroll(); - }; + private final Runnable mReflingAndAnimateScroll = this::animateScroll; private int mCornerRadius; private int mMinimumPaddings; private int mQsTilePadding; private boolean mSkinnyNotifsInLandscape; private int mSidePaddings; private final Rect mBackgroundAnimationRect = new Rect(); - private ArrayList> mExpandedHeightListeners = new ArrayList<>(); + private final ArrayList> mExpandedHeightListeners = new ArrayList<>(); private int mHeadsUpInset; /** @@ -479,8 +464,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private int mWaterfallTopInset; private NotificationStackScrollLayoutController mController; - private boolean mKeyguardMediaControllorVisible; - /** * The clip path used to clip the view in a rounded way. */ @@ -501,7 +484,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private int mRoundedRectClippingTop; private int mRoundedRectClippingBottom; private int mRoundedRectClippingRight; - private float[] mBgCornerRadii = new float[8]; + private final float[] mBgCornerRadii = new float[8]; /** * Whether stackY should be animated in case the view is getting shorter than the scroll @@ -527,7 +510,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable /** * Corner radii of the launched notification if it's clipped */ - private float[] mLaunchedNotificationRadii = new float[8]; + private final float[] mLaunchedNotificationRadii = new float[8]; /** * The notification that is being launched currently. @@ -779,7 +762,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable y = getLayoutHeight(); drawDebugInfo(canvas, y, Color.YELLOW, /* label= */ "getLayoutHeight() = " + y); - y = (int) mMaxLayoutHeight; + y = mMaxLayoutHeight; drawDebugInfo(canvas, y, Color.MAGENTA, /* label= */ "mMaxLayoutHeight = " + y); // The space between mTopPadding and mKeyguardBottomPadding determines the available space @@ -997,7 +980,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable mOverflingDistance = configuration.getScaledOverflingDistance(); Resources res = context.getResources(); - mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height); mStackScrollAlgorithm.initView(context); mAmbientState.reload(context); @@ -1256,12 +1238,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private void clampScrollPosition() { int scrollRange = getScrollRange(); if (scrollRange < mOwnScrollY && !mAmbientState.isClearAllInProgress()) { - boolean animateStackY = false; - if (scrollRange < getScrollAmountToScrollBoundary() - && mAnimateStackYForContentHeightChange) { - // if the scroll boundary updates the position of the stack, - animateStackY = true; - } + // if the scroll boundary updates the position of the stack, + boolean animateStackY = scrollRange < getScrollAmountToScrollBoundary() + && mAnimateStackYForContentHeightChange; setOwnScrollY(scrollRange, animateStackY); } } @@ -1504,7 +1483,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable } if (mAmbientState.isHiddenAtAll()) { - clipToOutline = false; invalidateOutline(); if (isFullyHidden()) { setClipBounds(null); @@ -1782,7 +1760,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable } @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) - private Runnable mReclamp = new Runnable() { + private final Runnable mReclamp = new Runnable() { @Override public void run() { int range = getScrollRange(); @@ -3084,11 +3062,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable int currentIndex = indexOfChild(child); if (currentIndex == -1) { - boolean isTransient = false; - if (child instanceof ExpandableNotificationRow - && child.getTransientContainer() != null) { - isTransient = true; - } + boolean isTransient = child instanceof ExpandableNotificationRow + && child.getTransientContainer() != null; Log.e(TAG, "Attempting to re-position " + (isTransient ? "transient" : "") + " view {" @@ -3149,7 +3124,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable private void generateHeadsUpAnimationEvents() { for (Pair eventPair : mHeadsUpChangeAnimations) { ExpandableNotificationRow row = eventPair.first; - String key = row.getEntry().getKey(); boolean isHeadsUp = eventPair.second; if (isHeadsUp != row.isHeadsUp()) { // For cases where we have a heads up showing and appearing again we shouldn't @@ -3212,10 +3186,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable @ShadeViewRefactor(RefactorComponent.COORDINATOR) private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) { - if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { - return false; - } - return true; + return viewState.yTranslation + viewState.height + >= mAmbientState.getMaxHeadsUpTranslation(); } @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER) @@ -4790,7 +4762,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) public void setTrackingHeadsUp(ExpandableNotificationRow row) { mAmbientState.setTrackedHeadsUpRow(row); - mTrackingHeadsUp = row != null; } @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) @@ -6176,7 +6147,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable } @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) - private ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { + private final ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() { @Override public ExpandableView getChildAtPosition(float touchX, float touchY) { return NotificationStackScrollLayout.this.getChildAtPosition(touchX, touchY);