diff --git a/quickstep/src/com/android/launcher3/uioverrides/BackButtonAlphaHandler.java b/quickstep/src/com/android/launcher3/uioverrides/BackButtonAlphaHandler.java index 722f51ba76..693ae60f22 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/BackButtonAlphaHandler.java +++ b/quickstep/src/com/android/launcher3/uioverrides/BackButtonAlphaHandler.java @@ -35,7 +35,7 @@ public class BackButtonAlphaHandler implements LauncherStateManager.StateHandler public BackButtonAlphaHandler(Launcher launcher) { mLauncher = launcher; - mOverviewInteractionState = OverviewInteractionState.getInstance(mLauncher); + mOverviewInteractionState = OverviewInteractionState.INSTANCE.get(mLauncher); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/LandscapeEdgeSwipeController.java b/quickstep/src/com/android/launcher3/uioverrides/LandscapeEdgeSwipeController.java index 6d1061990b..fd4bf9b8fc 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/LandscapeEdgeSwipeController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/LandscapeEdgeSwipeController.java @@ -73,7 +73,7 @@ public class LandscapeEdgeSwipeController extends AbstractStateChangeTouchContro protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) { super.onSwipeInteractionCompleted(targetState, logAction); if (mStartState == NORMAL && targetState == OVERVIEW) { - RecentsModel.getInstance(mLauncher).onOverviewShown(true, TAG); + RecentsModel.INSTANCE.get(mLauncher).onOverviewShown(true, TAG); } } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java index 7f956f8a29..543336e970 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java @@ -77,7 +77,7 @@ public class OverviewState extends LauncherState { public void onStateDisabled(Launcher launcher) { RecentsView rv = launcher.getOverviewPanel(); rv.setOverviewStateEnabled(false); - RecentsModel.getInstance(launcher).resetAssistCache(); + RecentsModel.INSTANCE.get(launcher).resetAssistCache(); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java index 1d1b7dac96..a1ae99eae9 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java @@ -256,7 +256,7 @@ public class PortraitStatesTouchController extends AbstractStateChangeTouchContr protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) { super.onSwipeInteractionCompleted(targetState, logAction); if (mStartState == NORMAL && targetState == OVERVIEW) { - RecentsModel.getInstance(mLauncher).onOverviewShown(true, TAG); + RecentsModel.INSTANCE.get(mLauncher).onOverviewShown(true, TAG); } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/TaskViewTouchController.java index 9a920c843e..88f2315757 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/TaskViewTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/TaskViewTouchController.java @@ -121,7 +121,7 @@ public abstract class TaskViewTouchController if (mRecentsView.isTaskViewVisible(view) && mActivity.getDragLayer() .isEventOverView(view, ev)) { mTaskBeingDragged = view; - if (!OverviewInteractionState.getInstance(mActivity) + if (!OverviewInteractionState.INSTANCE.get(mActivity) .isSwipeUpGestureEnabled()) { // Don't allow swipe down to open if we don't support swipe up // to enter overview. diff --git a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java index 2d0946b890..b42e118a90 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java +++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java @@ -57,7 +57,7 @@ import java.util.zip.Deflater; public class UiFactory { public static TouchController[] createTouchControllers(Launcher launcher) { - boolean swipeUpEnabled = OverviewInteractionState.getInstance(launcher) + boolean swipeUpEnabled = OverviewInteractionState.INSTANCE.get(launcher) .isSwipeUpGestureEnabled(); if (!swipeUpEnabled) { return new TouchController[] { @@ -80,7 +80,7 @@ public class UiFactory { } public static void setOnTouchControllersChangedListener(Context context, Runnable listener) { - OverviewInteractionState.getInstance(context).setOnSwipeUpSettingChangedListener(listener); + OverviewInteractionState.INSTANCE.get(context).setOnSwipeUpSettingChangedListener(listener); } public static StateHandler[] getStateHandler(Launcher launcher) { @@ -100,7 +100,7 @@ public class UiFactory { shouldBackButtonBeHidden = AbstractFloatingView.getTopOpenViewWithType(launcher, TYPE_ALL & ~TYPE_HIDE_BACK_BUTTON) == null; } - OverviewInteractionState.getInstance(launcher) + OverviewInteractionState.INSTANCE.get(launcher) .setBackButtonAlpha(shouldBackButtonBeHidden ? 0 : 1, true /* animate */); } @@ -122,7 +122,7 @@ public class UiFactory { @Override public void onStateTransitionComplete(LauncherState finalState) { - boolean swipeUpEnabled = OverviewInteractionState.getInstance(launcher) + boolean swipeUpEnabled = OverviewInteractionState.INSTANCE.get(launcher) .isSwipeUpGestureEnabled(); LauncherState prevState = launcher.getStateManager().getLastState(); @@ -159,7 +159,7 @@ public class UiFactory { } public static void onStart(Context context) { - RecentsModel model = RecentsModel.getInstance(context); + RecentsModel model = RecentsModel.INSTANCE.get(context); if (model != null) { model.onStart(); } @@ -169,7 +169,7 @@ public class UiFactory { // After the transition to home, enable the high-res thumbnail loader if it wasn't enabled // as a part of quickstep/scrub, so that high-res thumbnails can load the next time we // enter overview - RecentsModel.getInstance(context).getRecentsTaskLoader() + RecentsModel.INSTANCE.get(context).getRecentsTaskLoader() .getHighResThumbnailLoader().setVisible(true); } @@ -187,7 +187,7 @@ public class UiFactory { } public static void onTrimMemory(Context context, int level) { - RecentsModel model = RecentsModel.getInstance(context); + RecentsModel model = RecentsModel.INSTANCE.get(context); if (model != null) { model.onTrimMemory(level); } diff --git a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java index 7c6eb32591..3d54b82d18 100644 --- a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java +++ b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java @@ -111,7 +111,7 @@ public class OverviewCommandHelper { mContext = context; mAM = ActivityManagerWrapper.getInstance(); mMainThreadExecutor = new MainThreadExecutor(); - mRecentsModel = RecentsModel.getInstance(mContext); + mRecentsModel = RecentsModel.INSTANCE.get(mContext); Intent myHomeIntent = new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_HOME) diff --git a/quickstep/src/com/android/quickstep/OverviewInteractionState.java b/quickstep/src/com/android/quickstep/OverviewInteractionState.java index 922a7ff295..ed4e2cc859 100644 --- a/quickstep/src/com/android/quickstep/OverviewInteractionState.java +++ b/quickstep/src/com/android/quickstep/OverviewInteractionState.java @@ -25,21 +25,18 @@ import android.content.Context; import android.content.res.Resources; import android.database.ContentObserver; import android.os.Handler; -import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.provider.Settings; import android.support.annotation.WorkerThread; import android.util.Log; -import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.DiscoveryBounce; +import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.UiThreadHelper; import com.android.systemui.shared.recents.ISystemUiProxy; -import java.util.concurrent.ExecutionException; - /** * Sets overview interaction flags, such as: * @@ -60,23 +57,8 @@ public class OverviewInteractionState { "config_swipe_up_gesture_default"; // We do not need any synchronization for this variable as its only written on UI thread. - private static OverviewInteractionState INSTANCE; - - public static OverviewInteractionState getInstance(final Context context) { - if (INSTANCE == null) { - if (Looper.myLooper() == Looper.getMainLooper()) { - INSTANCE = new OverviewInteractionState(context.getApplicationContext()); - } else { - try { - return new MainThreadExecutor().submit( - () -> OverviewInteractionState.getInstance(context)).get(); - } catch (InterruptedException|ExecutionException e) { - throw new RuntimeException(e); - } - } - } - return INSTANCE; - } + public static final MainThreadInitializedObject INSTANCE = + new MainThreadInitializedObject<>((c) -> new OverviewInteractionState(c)); private static final int MSG_SET_PROXY = 200; private static final int MSG_SET_BACK_BUTTON_ALPHA = 201; diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java index 0b97f0119f..fa4e016db4 100644 --- a/quickstep/src/com/android/quickstep/RecentsModel.java +++ b/quickstep/src/com/android/quickstep/RecentsModel.java @@ -27,7 +27,6 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.os.Looper; import android.os.RemoteException; import android.os.UserHandle; import android.support.annotation.WorkerThread; @@ -38,6 +37,7 @@ import android.view.accessibility.AccessibilityManager; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.R; +import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.Preconditions; import com.android.systemui.shared.recents.ISystemUiProxy; import com.android.systemui.shared.recents.model.IconLoader; @@ -50,7 +50,6 @@ import com.android.systemui.shared.system.BackgroundExecutor; import com.android.systemui.shared.system.TaskStackChangeListener; import java.util.ArrayList; -import java.util.concurrent.ExecutionException; import java.util.function.Consumer; /** @@ -59,23 +58,8 @@ import java.util.function.Consumer; @TargetApi(Build.VERSION_CODES.O) public class RecentsModel extends TaskStackChangeListener { // We do not need any synchronization for this variable as its only written on UI thread. - private static RecentsModel INSTANCE; - - public static RecentsModel getInstance(final Context context) { - if (INSTANCE == null) { - if (Looper.myLooper() == Looper.getMainLooper()) { - INSTANCE = new RecentsModel(context.getApplicationContext()); - } else { - try { - return new MainThreadExecutor().submit( - () -> RecentsModel.getInstance(context)).get(); - } catch (InterruptedException|ExecutionException e) { - throw new RuntimeException(e); - } - } - } - return INSTANCE; - } + public static final MainThreadInitializedObject INSTANCE = + new MainThreadInitializedObject<>(c -> new RecentsModel(c)); private final SparseArray mCachedAssistData = new SparseArray<>(1); private final ArrayList mAssistDataListeners = new ArrayList<>(); diff --git a/quickstep/src/com/android/quickstep/TaskSystemShortcut.java b/quickstep/src/com/android/quickstep/TaskSystemShortcut.java index 24e199b977..e64d04afd8 100644 --- a/quickstep/src/com/android/quickstep/TaskSystemShortcut.java +++ b/quickstep/src/com/android/quickstep/TaskSystemShortcut.java @@ -160,7 +160,7 @@ public class TaskSystemShortcut extends SystemShortcut boolean dockTopOrLeft = navBarPosition != WindowManagerWrapper.NAV_BAR_POS_LEFT; if (ActivityManagerWrapper.getInstance().startActivityFromRecents(taskId, ActivityOptionsCompat.makeSplitScreenOptions(dockTopOrLeft))) { - ISystemUiProxy sysUiProxy = RecentsModel.getInstance(activity).getSystemUiProxy(); + ISystemUiProxy sysUiProxy = RecentsModel.INSTANCE.get(activity).getSystemUiProxy(); try { sysUiProxy.onSplitScreenInvoked(); } catch (RemoteException e) { @@ -225,7 +225,7 @@ public class TaskSystemShortcut extends SystemShortcut @Override public View.OnClickListener getOnClickListener( BaseDraggingActivity activity, TaskView taskView) { - ISystemUiProxy sysUiProxy = RecentsModel.getInstance(activity).getSystemUiProxy(); + ISystemUiProxy sysUiProxy = RecentsModel.INSTANCE.get(activity).getSystemUiProxy(); if (sysUiProxy == null) { return null; } diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 5a1f523391..9fe6f8b4b8 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -179,13 +179,13 @@ public class TouchInteractionService extends Service { public void onCreate() { super.onCreate(); mAM = ActivityManagerWrapper.getInstance(); - mRecentsModel = RecentsModel.getInstance(this); + mRecentsModel = RecentsModel.INSTANCE.get(this); mRecentsModel.setPreloadTasksInBackground(true); mMainThreadExecutor = new MainThreadExecutor(); mOverviewCommandHelper = new OverviewCommandHelper(this); mMainThreadChoreographer = Choreographer.getInstance(); mEventQueue = new MotionEventQueue(mMainThreadChoreographer, TouchConsumer.NO_OP); - mOverviewInteractionState = OverviewInteractionState.getInstance(this); + mOverviewInteractionState = OverviewInteractionState.INSTANCE.get(this); mOverviewCallbacks = OverviewCallbacks.get(this); mTaskOverlayFactory = TaskOverlayFactory.get(this); diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index 95dcf48e48..a04fe61646 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -490,7 +490,7 @@ public class WindowTransformSwipeHandler { // This method is only called when STATE_GESTURE_STARTED_QUICKSTEP/ // STATE_GESTURE_STARTED_QUICKSCRUB is set, so we can enable the high-res thumbnail loader // here once we are sure that we will end up in an overview state - RecentsModel.getInstance(mContext).getRecentsTaskLoader() + RecentsModel.INSTANCE.get(mContext).getRecentsTaskLoader() .getHighResThumbnailLoader().setVisible(true); } @@ -949,7 +949,7 @@ public class WindowTransformSwipeHandler { mRecentsView.animateUpRunningTaskIconScale(); mRecentsView.setSwipeDownShouldLaunchApp(true); - RecentsModel.getInstance(mContext).onOverviewShown(false, TAG); + RecentsModel.INSTANCE.get(mContext).onOverviewShown(false, TAG); doLogGesture(true /* toLauncher */); reset(); @@ -979,7 +979,7 @@ public class WindowTransformSwipeHandler { mQuickScrubController.onFinishedTransitionToQuickScrub(); mRecentsView.animateUpRunningTaskIconScale(); - RecentsModel.getInstance(mContext).onOverviewShown(false, TAG); + RecentsModel.INSTANCE.get(mContext).onOverviewShown(false, TAG); } public void onQuickScrubProgress(float progress) { @@ -1113,7 +1113,7 @@ public class WindowTransformSwipeHandler { } private void preloadAssistData() { - RecentsModel.getInstance(mContext).preloadAssistData(mRunningTaskId, mAssistData); + RecentsModel.INSTANCE.get(mContext).preloadAssistData(mRunningTaskId, mAssistData); } public static float getHiddenTargetAlpha(RemoteAnimationTargetCompat app, Float expectedAlpha) { diff --git a/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java b/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java index df70a8a394..0597a2ebdf 100644 --- a/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java +++ b/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java @@ -30,7 +30,6 @@ import android.graphics.RectF; import android.os.Build; import android.os.RemoteException; import android.support.annotation.Nullable; -import android.view.Surface; import android.view.animation.Interpolator; import com.android.launcher3.BaseDraggingActivity; @@ -50,7 +49,6 @@ import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplier.Surfac import com.android.systemui.shared.system.TransactionCompat; import com.android.systemui.shared.system.WindowManagerWrapper; -import java.util.function.BiConsumer; import java.util.function.BiFunction; /** @@ -260,7 +258,7 @@ public class ClipAnimationHelper { } private void updateStackBoundsToMultiWindowTaskSize(BaseDraggingActivity activity) { - ISystemUiProxy sysUiProxy = RecentsModel.getInstance(activity).getSystemUiProxy(); + ISystemUiProxy sysUiProxy = RecentsModel.INSTANCE.get(activity).getSystemUiProxy(); if (sysUiProxy != null) { try { mSourceStackBounds.set(sysUiProxy.getNonMinimizedSplitScreenSecondaryBounds()); diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java index 7c5828b440..697bb4f1ca 100644 --- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java +++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java @@ -124,7 +124,7 @@ public class LauncherRecentsView extends RecentsView { ClipAnimationHelper helper) { AnimatorSet anim = super.createAdjacentPageAnimForTaskLaunch(tv, helper); - if (!OverviewInteractionState.getInstance(mActivity).isSwipeUpGestureEnabled()) { + if (!OverviewInteractionState.INSTANCE.get(mActivity).isSwipeUpGestureEnabled()) { // Hotseat doesn't move when opening recents with the button, // so don't animate it here either. return anim; diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 72ab26156a..fc0975a709 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -277,7 +277,7 @@ public abstract class RecentsView extends PagedView impl .getDimensionPixelSize(R.dimen.recents_fast_fling_velocity); mActivity = (T) BaseActivity.fromContext(context); mQuickScrubController = new QuickScrubController(mActivity, this); - mModel = RecentsModel.getInstance(context); + mModel = RecentsModel.INSTANCE.get(context); mClearAllButton = (ClearAllButton) LayoutInflater.from(context) .inflate(R.layout.overview_clear_all_button, this, false);