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> {
@Nullable
private ArrowTipView mArrowTipView;
public GoOverviewActionsView(Context context) {

View File

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

View File

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

View File

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

View File

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

View File

@ -39,10 +39,13 @@ import java.util.function.Consumer;
*/
public class GroupedTaskView extends TaskView {
@Nullable
private Task mSecondaryTask;
private TaskThumbnailView mSnapshotView2;
private IconView mIconView2;
@Nullable
private CancellableTask<ThumbnailData> mThumbnailLoadRequest2;
@Nullable
private CancellableTask mIconLoadRequest2;
private final float[] mIcon2CenterCoords = new float[2];
private TransformingTouchDelegate mIcon2TouchDelegate;
@ -153,6 +156,7 @@ public class GroupedTaskView extends TaskView {
}
}
@Nullable
@Override
public RunnableList launchTaskAnimated() {
getRecentsView().getSplitPlaceholder().launchTasks(mTask, mSecondaryTask,
@ -167,7 +171,7 @@ public class GroupedTaskView extends TaskView {
}
@Override
void refreshThumbnails(HashMap<Integer, ThumbnailData> thumbnailDatas) {
void refreshThumbnails(@Nullable HashMap<Integer, ThumbnailData> thumbnailDatas) {
super.refreshThumbnails(thumbnailDatas);
if (mSecondaryTask != null && thumbnailDatas != null) {
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.View;
import androidx.annotation.Nullable;
import com.android.launcher3.Utilities;
/**
@ -31,6 +33,7 @@ import com.android.launcher3.Utilities;
*/
public class IconView extends View {
@Nullable
private Drawable mDrawable;
private int mDrawableWidth, mDrawableHeight;
@ -46,7 +49,10 @@ public class IconView extends View {
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) {
mDrawable.setCallback(null);
}
@ -76,6 +82,7 @@ public class IconView extends View {
mDrawable.setBounds(drawableRect);
}
@Nullable
public Drawable getDrawable() {
return mDrawable;
}

View File

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

View File

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

View File

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

View File

@ -78,6 +78,7 @@ public class TaskThumbnailView extends View {
};
private final BaseActivity mActivity;
@Nullable
private TaskOverlay mOverlay;
private final Paint mPaint = 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 TaskView.FullscreenDrawParams mFullscreenParams;
@Nullable
private Task mTask;
@Nullable
private ThumbnailData mThumbnailData;
@Nullable
protected BitmapShader mBitmapShader;
/** 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
* 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;
mThumbnailData =
(thumbnailData != null && thumbnailData.thumbnail != null) ? thumbnailData : null;
@ -151,7 +156,7 @@ public class TaskThumbnailView extends View {
}
/** 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 */);
}
@ -366,6 +371,10 @@ public class TaskThumbnailView extends View {
return Utilities.makeColorTintingColorFilter(mDimColor, dimAmount);
}
/**
* Returns current thumbnail or null if none is set.
*/
@Nullable
public Bitmap getThumbnail() {
if (mThumbnailData == null) {
return null;

View File

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