Add @Nullable annotations for simple cases

Add @Nullable annotations for the fields that are expected
to be null at arbitrary lifecycle time and are their usage
is protected by null checks.

Bug: 205828770
Test: m LauncherGoResLib
Change-Id: I9c31e1dc0d01cdd68dfff0a005ba1f40c257f8ea
(cherry picked from commit 920dc2f28f81ce2aec07477dfb6f4efd8f91e4ad)
This commit is contained in:
Fedor Kudasov 2021-11-11 14:01:44 +00:00
parent 6c7c91fe86
commit 2ca545c387
12 changed files with 55 additions and 8 deletions

View File

@ -35,6 +35,7 @@ import com.android.quickstep.util.RecentsOrientedState;
*/ */
public class GoOverviewActionsView extends OverviewActionsView<OverlayUICallbacksGo> { public class GoOverviewActionsView extends OverviewActionsView<OverlayUICallbacksGo> {
@Nullable
private ArrowTipView mArrowTipView; private ArrowTipView mArrowTipView;
public GoOverviewActionsView(Context context) { public GoOverviewActionsView(Context context) {

View File

@ -35,6 +35,7 @@ import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
@ -58,6 +59,7 @@ public class AllAppsEduView extends AbstractFloatingView {
private Launcher mLauncher; private Launcher mLauncher;
private AllAppsEduTouchController mTouchController; private AllAppsEduTouchController mTouchController;
@Nullable
private AnimatorSet mAnimation; private AnimatorSet mAnimation;
private GradientDrawable mCircle; private GradientDrawable mCircle;

View File

@ -44,6 +44,7 @@ import android.view.ViewOutlineProvider;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import com.android.launcher3.BaseActivity; import com.android.launcher3.BaseActivity;
@ -69,6 +70,7 @@ public final class DigitalWellBeingToast {
private Task mTask; private Task mTask;
private boolean mHasLimit; private boolean mHasLimit;
private long mAppRemainingTimeMs; private long mAppRemainingTimeMs;
@Nullable
private View mBanner; private View mBanner;
private ViewOutlineProvider mOldBannerOutlineProvider; private ViewOutlineProvider mOldBannerOutlineProvider;
private float mBannerOffsetPercentage; private float mBannerOffsetPercentage;
@ -234,7 +236,7 @@ public final class DigitalWellBeingToast {
task.titleDescription; task.titleDescription;
} }
private void replaceBanner(View view) { private void replaceBanner(@Nullable View view) {
resetOldBanner(); resetOldBanner();
setBanner(view); setBanner(view);
} }
@ -248,7 +250,7 @@ public final class DigitalWellBeingToast {
} }
} }
private void setBanner(View view) { private void setBanner(@Nullable View view) {
mBanner = view; mBanner = view;
if (view != null) { if (view != null) {
setupAndAddBanner(); setupAndAddBanner();

View File

@ -27,6 +27,8 @@ import android.view.View;
import android.view.ViewOutlineProvider; import android.view.ViewOutlineProvider;
import android.widget.RemoteViews.RemoteViewOutlineProvider; import android.widget.RemoteViews.RemoteViewOutlineProvider;
import androidx.annotation.Nullable;
import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.RoundedCornerEnforcement; import com.android.launcher3.widget.RoundedCornerEnforcement;
@ -42,7 +44,9 @@ final class FloatingWidgetBackgroundView extends View {
private final DrawableProperties mForegroundProperties = new DrawableProperties(); private final DrawableProperties mForegroundProperties = new DrawableProperties();
private final DrawableProperties mBackgroundProperties = new DrawableProperties(); private final DrawableProperties mBackgroundProperties = new DrawableProperties();
@Nullable
private Drawable mOriginalForeground; private Drawable mOriginalForeground;
@Nullable
private Drawable mOriginalBackground; private Drawable mOriginalBackground;
private float mFinalRadius; private float mFinalRadius;
private float mInitialOutlineRadius; private float mInitialOutlineRadius;
@ -50,7 +54,7 @@ final class FloatingWidgetBackgroundView extends View {
private boolean mIsUsingFallback; private boolean mIsUsingFallback;
private View mSourceView; private View mSourceView;
FloatingWidgetBackgroundView(Context context, AttributeSet attrs, int defStyleAttr) { FloatingWidgetBackgroundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
setOutlineProvider(new ViewOutlineProvider() { setOutlineProvider(new ViewOutlineProvider() {
@Override @Override
@ -161,8 +165,10 @@ final class FloatingWidgetBackgroundView extends View {
/** Stores and modifies a drawable's properties through an animation. */ /** Stores and modifies a drawable's properties through an animation. */
private static class DrawableProperties { private static class DrawableProperties {
@Nullable
private Drawable mDrawable; private Drawable mDrawable;
private float mOriginalRadius; private float mOriginalRadius;
@Nullable
private float[] mOriginalRadii; private float[] mOriginalRadii;
private final float[] mTmpRadii = new float[8]; private final float[] mTmpRadii = new float[8];

View File

@ -57,10 +57,14 @@ public class FloatingWidgetView extends FrameLayout implements AnimatorListener,
private LauncherAppWidgetHostView mAppWidgetView; private LauncherAppWidgetHostView mAppWidgetView;
private View mAppWidgetBackgroundView; private View mAppWidgetBackgroundView;
private RectF mBackgroundPosition; private RectF mBackgroundPosition;
@Nullable
private GhostView mForegroundOverlayView; private GhostView mForegroundOverlayView;
@Nullable
private Runnable mEndRunnable; private Runnable mEndRunnable;
@Nullable
private Runnable mFastFinishRunnable; private Runnable mFastFinishRunnable;
@Nullable
private Runnable mOnTargetChangeRunnable; private Runnable mOnTargetChangeRunnable;
private boolean mAppTargetIsTranslucent; private boolean mAppTargetIsTranslucent;

View File

@ -39,10 +39,13 @@ import java.util.function.Consumer;
*/ */
public class GroupedTaskView extends TaskView { public class GroupedTaskView extends TaskView {
@Nullable
private Task mSecondaryTask; private Task mSecondaryTask;
private TaskThumbnailView mSnapshotView2; private TaskThumbnailView mSnapshotView2;
private IconView mIconView2; private IconView mIconView2;
@Nullable
private CancellableTask<ThumbnailData> mThumbnailLoadRequest2; private CancellableTask<ThumbnailData> mThumbnailLoadRequest2;
@Nullable
private CancellableTask mIconLoadRequest2; private CancellableTask mIconLoadRequest2;
private final float[] mIcon2CenterCoords = new float[2]; private final float[] mIcon2CenterCoords = new float[2];
private TransformingTouchDelegate mIcon2TouchDelegate; private TransformingTouchDelegate mIcon2TouchDelegate;
@ -153,6 +156,7 @@ public class GroupedTaskView extends TaskView {
} }
} }
@Nullable
@Override @Override
public RunnableList launchTaskAnimated() { public RunnableList launchTaskAnimated() {
getRecentsView().getSplitPlaceholder().launchTasks(mTask, mSecondaryTask, getRecentsView().getSplitPlaceholder().launchTasks(mTask, mSecondaryTask,
@ -167,7 +171,7 @@ public class GroupedTaskView extends TaskView {
} }
@Override @Override
void refreshThumbnails(HashMap<Integer, ThumbnailData> thumbnailDatas) { void refreshThumbnails(@Nullable HashMap<Integer, ThumbnailData> thumbnailDatas) {
super.refreshThumbnails(thumbnailDatas); super.refreshThumbnails(thumbnailDatas);
if (mSecondaryTask != null && thumbnailDatas != null) { if (mSecondaryTask != null && thumbnailDatas != null) {
final ThumbnailData thumbnailData = thumbnailDatas.get(mSecondaryTask.key.id); final ThumbnailData thumbnailData = thumbnailDatas.get(mSecondaryTask.key.id);

View File

@ -23,6 +23,8 @@ import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import androidx.annotation.Nullable;
import com.android.launcher3.Utilities; import com.android.launcher3.Utilities;
/** /**
@ -31,6 +33,7 @@ import com.android.launcher3.Utilities;
*/ */
public class IconView extends View { public class IconView extends View {
@Nullable
private Drawable mDrawable; private Drawable mDrawable;
private int mDrawableWidth, mDrawableHeight; private int mDrawableWidth, mDrawableHeight;
@ -46,7 +49,10 @@ public class IconView extends View {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
} }
public void setDrawable(Drawable d) { /**
* Sets a {@link Drawable} to be displayed.
*/
public void setDrawable(@Nullable Drawable d) {
if (mDrawable != null) { if (mDrawable != null) {
mDrawable.setCallback(null); mDrawable.setCallback(null);
} }
@ -76,6 +82,7 @@ public class IconView extends View {
mDrawable.setBounds(drawableRect); mDrawable.setBounds(drawableRect);
} }
@Nullable
public Drawable getDrawable() { public Drawable getDrawable() {
return mDrawable; return mDrawable;
} }

View File

@ -90,8 +90,10 @@ public class OverviewActionsView<T extends OverlayUICallbacks> extends FrameLayo
@ActionsDisabledFlags @ActionsDisabledFlags
protected int mDisabledFlags; protected int mDisabledFlags;
@Nullable
protected T mCallbacks; protected T mCallbacks;
@Nullable
protected DeviceProfile mDp; protected DeviceProfile mDp;
public OverviewActionsView(Context context) { public OverviewActionsView(Context context) {

View File

@ -40,6 +40,7 @@ public class SplitPlaceholderView extends FrameLayout {
} }
}; };
@Nullable
private IconView mIconView; private IconView mIconView;
public SplitPlaceholderView(Context context, AttributeSet attrs) { public SplitPlaceholderView(Context context, AttributeSet attrs) {

View File

@ -39,6 +39,8 @@ import android.view.ViewTreeObserver.OnScrollChangedListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile;
@ -67,6 +69,7 @@ public class TaskMenuView extends AbstractFloatingView implements OnScrollChange
private BaseDraggingActivity mActivity; private BaseDraggingActivity mActivity;
private TextView mTaskName; private TextView mTaskName;
@Nullable
private AnimatorSet mOpenCloseAnimator; private AnimatorSet mOpenCloseAnimator;
private TaskView mTaskView; private TaskView mTaskView;
private TaskIdAttributeContainer mTaskContainer; private TaskIdAttributeContainer mTaskContainer;

View File

@ -78,6 +78,7 @@ public class TaskThumbnailView extends View {
}; };
private final BaseActivity mActivity; private final BaseActivity mActivity;
@Nullable
private TaskOverlay mOverlay; private TaskOverlay mOverlay;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
@ -90,8 +91,11 @@ public class TaskThumbnailView extends View {
private final PreviewPositionHelper mPreviewPositionHelper = new PreviewPositionHelper(); private final PreviewPositionHelper mPreviewPositionHelper = new PreviewPositionHelper();
private TaskView.FullscreenDrawParams mFullscreenParams; private TaskView.FullscreenDrawParams mFullscreenParams;
@Nullable
private Task mTask; private Task mTask;
@Nullable
private ThumbnailData mThumbnailData; private ThumbnailData mThumbnailData;
@Nullable
protected BitmapShader mBitmapShader; protected BitmapShader mBitmapShader;
/** How much this thumbnail is dimmed, 0 not dimmed at all, 1 totally dimmed. */ /** How much this thumbnail is dimmed, 0 not dimmed at all, 1 totally dimmed. */
@ -141,7 +145,8 @@ public class TaskThumbnailView extends View {
* upon swipe up so that a usable screenshot is accessible immediately when * upon swipe up so that a usable screenshot is accessible immediately when
* recents animation needs to be finished / cancelled. * recents animation needs to be finished / cancelled.
*/ */
public void setThumbnail(Task task, ThumbnailData thumbnailData, boolean refreshNow) { public void setThumbnail(@Nullable Task task, @Nullable ThumbnailData thumbnailData,
boolean refreshNow) {
mTask = task; mTask = task;
mThumbnailData = mThumbnailData =
(thumbnailData != null && thumbnailData.thumbnail != null) ? thumbnailData : null; (thumbnailData != null && thumbnailData.thumbnail != null) ? thumbnailData : null;
@ -151,7 +156,7 @@ public class TaskThumbnailView extends View {
} }
/** See {@link #setThumbnail(Task, ThumbnailData, boolean)} */ /** See {@link #setThumbnail(Task, ThumbnailData, boolean)} */
public void setThumbnail(Task task, ThumbnailData thumbnailData) { public void setThumbnail(@Nullable Task task, @Nullable ThumbnailData thumbnailData) {
setThumbnail(task, thumbnailData, true /* refreshNow */); setThumbnail(task, thumbnailData, true /* refreshNow */);
} }
@ -366,6 +371,10 @@ public class TaskThumbnailView extends View {
return Utilities.makeColorTintingColorFilter(mDimColor, dimAmount); return Utilities.makeColorTintingColorFilter(mDimColor, dimAmount);
} }
/**
* Returns current thumbnail or null if none is set.
*/
@Nullable
public Bitmap getThumbnail() { public Bitmap getThumbnail() {
if (mThumbnailData == null) { if (mThumbnailData == null) {
return null; return null;

View File

@ -360,6 +360,7 @@ public class TaskView extends FrameLayout implements Reusable {
private final TaskOutlineProvider mOutlineProvider; private final TaskOutlineProvider mOutlineProvider;
@Nullable
protected Task mTask; protected Task mTask;
protected TaskThumbnailView mSnapshotView; protected TaskThumbnailView mSnapshotView;
protected IconView mIconView; protected IconView mIconView;
@ -394,6 +395,7 @@ public class TaskView extends FrameLayout implements Reusable {
private float mSplitSelectTranslationX; private float mSplitSelectTranslationX;
private float mSplitSelectScrollOffsetPrimary; private float mSplitSelectScrollOffsetPrimary;
@Nullable
private ObjectAnimator mIconAndDimAnimator; private ObjectAnimator mIconAndDimAnimator;
private float mIconScaleAnimStartProgress = 0; private float mIconScaleAnimStartProgress = 0;
private float mFocusTransitionProgress = 1; private float mFocusTransitionProgress = 1;
@ -411,7 +413,9 @@ public class TaskView extends FrameLayout implements Reusable {
private boolean mShowScreenshot; private boolean mShowScreenshot;
// The current background requests to load the task thumbnail and icon // The current background requests to load the task thumbnail and icon
@Nullable
private CancellableTask mThumbnailLoadRequest; private CancellableTask mThumbnailLoadRequest;
@Nullable
private CancellableTask mIconLoadRequest; private CancellableTask mIconLoadRequest;
private boolean mEndQuickswitchCuj; private boolean mEndQuickswitchCuj;
@ -544,6 +548,7 @@ public class TaskView extends FrameLayout implements Reusable {
return mTaskIdAttributeContainer; return mTaskIdAttributeContainer;
} }
@Nullable
public Task getTask() { public Task getTask() {
return mTask; return mTask;
} }
@ -686,6 +691,7 @@ public class TaskView extends FrameLayout implements Reusable {
* Starts the task associated with this view and animates the startup. * Starts the task associated with this view and animates the startup.
* @return CompletionStage to indicate the animation completion or null if the launch failed. * @return CompletionStage to indicate the animation completion or null if the launch failed.
*/ */
@Nullable
public RunnableList launchTaskAnimated() { public RunnableList launchTaskAnimated() {
if (mTask != null) { if (mTask != null) {
TestLogging.recordEvent( TestLogging.recordEvent(
@ -843,7 +849,7 @@ public class TaskView extends FrameLayout implements Reusable {
} }
} }
protected void setIcon(IconView iconView, Drawable icon) { protected void setIcon(IconView iconView, @Nullable Drawable icon) {
if (icon != null) { if (icon != null) {
iconView.setDrawable(icon); iconView.setDrawable(icon);
iconView.setOnClickListener(v -> { iconView.setOnClickListener(v -> {