Merge "Use nullable field and boolean rather than optional" into sc-dev am: 048a858575 am: 2c0058d280

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15171711

Change-Id: I8102fdf54c026e8ff723e34ef74e728c8a31e0fd
This commit is contained in:
Cyrus Boadway
2021-07-01 17:27:56 +00:00
committed by Automerger Merge Worker
@@ -52,7 +52,6 @@ import com.android.launcher3.views.BaseDragLayer.TouchCompleteListener;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
import java.util.List;
import java.util.Optional;
/**
* {@inheritDoc}
@@ -99,7 +98,8 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
private long mDeferUpdatesUntilMillis = 0;
private RemoteViews mDeferredRemoteViews;
private Optional<SparseIntArray> mDeferredColorChange = Optional.empty();
private boolean mHasDeferredColorChange = false;
private @Nullable SparseIntArray mDeferredColorChange = null;
private boolean mEnableColorExtraction = true;
public LauncherAppWidgetHostView(Context context) {
@@ -217,18 +217,23 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
*/
public void endDeferringUpdates() {
RemoteViews remoteViews;
Optional<SparseIntArray> deferredColors;
SparseIntArray deferredColors;
boolean hasDeferredColors;
synchronized (mUpdateLock) {
mDeferUpdatesUntilMillis = 0;
remoteViews = mDeferredRemoteViews;
mDeferredRemoteViews = null;
deferredColors = mDeferredColorChange;
mDeferredColorChange = Optional.empty();
hasDeferredColors = mHasDeferredColorChange;
mDeferredColorChange = null;
mHasDeferredColorChange = false;
}
if (remoteViews != null) {
updateAppWidget(remoteViews);
}
deferredColors.ifPresent(colors -> onColorsChanged(null /* rectF */, colors));
if (hasDeferredColors) {
onColorsChanged(null /* rectF */, deferredColors);
}
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
@@ -394,10 +399,12 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
public void onColorsChanged(RectF rectF, SparseIntArray colors) {
synchronized (mUpdateLock) {
if (isDeferringUpdates()) {
mDeferredColorChange = Optional.ofNullable(colors);
mDeferredColorChange = colors;
mHasDeferredColorChange = true;
return;
}
mDeferredColorChange = Optional.empty();
mDeferredColorChange = null;
mHasDeferredColorChange = false;
}
// setColorResources will reapply the view, which must happen in the UI thread.