Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 048a8585 authored by Cyrus Boadway's avatar Cyrus Boadway Committed by Android (Google) Code Review
Browse files

Merge "Use nullable field and boolean rather than optional" into sc-dev

parents 9010e773 551b4297
Loading
Loading
Loading
Loading
+14 −7
Original line number Original line Diff line number Diff line
@@ -57,7 +57,6 @@ import com.android.launcher3.views.BaseDragLayer.TouchCompleteListener;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;


import java.util.List;
import java.util.List;
import java.util.Optional;


/**
/**
 * {@inheritDoc}
 * {@inheritDoc}
@@ -118,7 +117,8 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
    private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
    private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
    private long mDeferUpdatesUntilMillis = 0;
    private long mDeferUpdatesUntilMillis = 0;
    private RemoteViews mDeferredRemoteViews;
    private RemoteViews mDeferredRemoteViews;
    private Optional<SparseIntArray> mDeferredColorChange = Optional.empty();
    private boolean mHasDeferredColorChange = false;
    private @Nullable SparseIntArray mDeferredColorChange = null;
    private boolean mEnableColorExtraction = true;
    private boolean mEnableColorExtraction = true;


    public LauncherAppWidgetHostView(Context context) {
    public LauncherAppWidgetHostView(Context context) {
@@ -244,18 +244,23 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
     */
     */
    public void endDeferringUpdates() {
    public void endDeferringUpdates() {
        RemoteViews remoteViews;
        RemoteViews remoteViews;
        Optional<SparseIntArray> deferredColors;
        SparseIntArray deferredColors;
        boolean hasDeferredColors;
        synchronized (mUpdateLock) {
        synchronized (mUpdateLock) {
            mDeferUpdatesUntilMillis = 0;
            mDeferUpdatesUntilMillis = 0;
            remoteViews = mDeferredRemoteViews;
            remoteViews = mDeferredRemoteViews;
            mDeferredRemoteViews = null;
            mDeferredRemoteViews = null;
            deferredColors = mDeferredColorChange;
            deferredColors = mDeferredColorChange;
            mDeferredColorChange = Optional.empty();
            hasDeferredColors = mHasDeferredColorChange;
            mDeferredColorChange = null;
            mHasDeferredColorChange = false;
        }
        }
        if (remoteViews != null) {
        if (remoteViews != null) {
            updateAppWidget(remoteViews);
            updateAppWidget(remoteViews);
        }
        }
        deferredColors.ifPresent(colors -> onColorsChanged(null /* rectF */, colors));
        if (hasDeferredColors) {
            onColorsChanged(null /* rectF */, deferredColors);
        }
    }
    }


    public boolean onInterceptTouchEvent(MotionEvent ev) {
    public boolean onInterceptTouchEvent(MotionEvent ev) {
@@ -437,10 +442,12 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
    public void onColorsChanged(RectF rectF, SparseIntArray colors) {
    public void onColorsChanged(RectF rectF, SparseIntArray colors) {
        synchronized (mUpdateLock) {
        synchronized (mUpdateLock) {
            if (isDeferringUpdates()) {
            if (isDeferringUpdates()) {
                mDeferredColorChange = Optional.ofNullable(colors);
                mDeferredColorChange = colors;
                mHasDeferredColorChange = true;
                return;
                return;
            }
            }
            mDeferredColorChange = Optional.empty();
            mDeferredColorChange = null;
            mHasDeferredColorChange = false;
        }
        }


        // setColorResources will reapply the view, which must happen in the UI thread.
        // setColorResources will reapply the view, which must happen in the UI thread.