Updating fallback activity

> Wallpaper based theme support
> Light/dark system UI
> Swipe gestures to start and dismiss a task
> Fixing insets and task preview size

Bug: 75979063
Change-Id: Id402e6ac50551a7c0849742e3a0e77df3ead5aa2
This commit is contained in:
Sunny Goyal 2018-03-27 17:35:54 -07:00
parent 76e2775bb6
commit ab83773e21
14 changed files with 168 additions and 80 deletions

View File

@ -48,7 +48,16 @@
It is set to true so that the activity can be started from command line --> It is set to true so that the activity can be started from command line -->
<activity android:name="com.android.quickstep.RecentsActivity" <activity android:name="com.android.quickstep.RecentsActivity"
android:exported="true" android:exported="true"
android:excludeFromRecents="true" /> android:excludeFromRecents="true"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/LauncherTheme"
android:screenOrientation="unspecified"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout|smallestScreenSize"
android:resizeableActivity="true"
android:resumeWhilePausing="true"
android:taskAffinity="" />
<!-- Content provider to settings search --> <!-- Content provider to settings search -->
<provider <provider

View File

@ -13,13 +13,14 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<com.android.quickstep.RecentsRootView <com.android.quickstep.fallback.RecentsRootView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drag_layer" android:id="@+id/drag_layer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.android.quickstep.FallbackRecentsView <com.android.quickstep.fallback.FallbackRecentsView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overview_panel" android:id="@+id/overview_panel"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -28,4 +29,4 @@
android:clipToPadding="false" android:clipToPadding="false"
android:theme="@style/HomeScreenElementTheme" /> android:theme="@style/HomeScreenElementTheme" />
</com.android.quickstep.RecentsRootView> </com.android.quickstep.fallback.RecentsRootView>

View File

@ -15,7 +15,6 @@
*/ */
package com.android.launcher3.uioverrides; package com.android.launcher3.uioverrides;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity; import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import android.animation.Animator; import android.animation.Animator;
@ -26,15 +25,15 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher; import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.Utilities; import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.Interpolators; import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.touch.SwipeDetector; import com.android.launcher3.touch.SwipeDetector;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.util.TouchController; import com.android.launcher3.util.TouchController;
import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.PendingAnimation; import com.android.quickstep.PendingAnimation;
import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView; import com.android.quickstep.views.TaskView;
@ -42,8 +41,8 @@ import com.android.quickstep.views.TaskView;
/** /**
* Touch controller for handling task view card swipes * Touch controller for handling task view card swipes
*/ */
public class TaskViewTouchController extends AnimatorListenerAdapter public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
implements TouchController, SwipeDetector.Listener { extends AnimatorListenerAdapter implements TouchController, SwipeDetector.Listener {
private static final String TAG = "OverviewSwipeController"; private static final String TAG = "OverviewSwipeController";
@ -53,7 +52,7 @@ public class TaskViewTouchController extends AnimatorListenerAdapter
// Progress after which the transition is assumed to be a success in case user does not fling // Progress after which the transition is assumed to be a success in case user does not fling
private static final float SUCCESS_TRANSITION_PROGRESS = 0.5f; private static final float SUCCESS_TRANSITION_PROGRESS = 0.5f;
private final Launcher mLauncher; protected final T mActivity;
private final SwipeDetector mDetector; private final SwipeDetector mDetector;
private final RecentsView mRecentsView; private final RecentsView mRecentsView;
private final int[] mTempCords = new int[2]; private final int[] mTempCords = new int[2];
@ -70,10 +69,10 @@ public class TaskViewTouchController extends AnimatorListenerAdapter
private TaskView mTaskBeingDragged; private TaskView mTaskBeingDragged;
public TaskViewTouchController(Launcher launcher) { public TaskViewTouchController(T activity) {
mLauncher = launcher; mActivity = activity;
mRecentsView = launcher.getOverviewPanel(); mRecentsView = activity.getOverviewPanel();
mDetector = new SwipeDetector(launcher, this, SwipeDetector.VERTICAL); mDetector = new SwipeDetector(activity, this, SwipeDetector.VERTICAL);
} }
private boolean canInterceptTouch() { private boolean canInterceptTouch() {
@ -81,12 +80,14 @@ public class TaskViewTouchController extends AnimatorListenerAdapter
// If we are already animating from a previous state, we can intercept. // If we are already animating from a previous state, we can intercept.
return true; return true;
} }
if (AbstractFloatingView.getTopOpenView(mLauncher) != null) { if (AbstractFloatingView.getTopOpenView(mActivity) != null) {
return false; return false;
} }
return mLauncher.isInState(OVERVIEW); return isRecentsInteractive();
} }
protected abstract boolean isRecentsInteractive();
@Override @Override
public void onAnimationCancel(Animator animation) { public void onAnimationCancel(Animator animation) {
if (mCurrentAnimation != null && animation == mCurrentAnimation.getTarget()) { if (mCurrentAnimation != null && animation == mCurrentAnimation.getTarget()) {
@ -115,7 +116,7 @@ public class TaskViewTouchController extends AnimatorListenerAdapter
mTaskBeingDragged = null; mTaskBeingDragged = null;
View view = mRecentsView.getChildAt(mRecentsView.getCurrentPage()); View view = mRecentsView.getChildAt(mRecentsView.getCurrentPage());
if (view instanceof TaskView && mLauncher.getDragLayer().isEventOverView(view, ev)) { if (view instanceof TaskView && mActivity.getDragLayer().isEventOverView(view, ev)) {
// The tile can be dragged down to open the task. // The tile can be dragged down to open the task.
mTaskBeingDragged = (TaskView) view; mTaskBeingDragged = (TaskView) view;
directionsToDetectScroll = SwipeDetector.DIRECTION_BOTH; directionsToDetectScroll = SwipeDetector.DIRECTION_BOTH;
@ -156,9 +157,8 @@ public class TaskViewTouchController extends AnimatorListenerAdapter
} }
mCurrentAnimationIsGoingUp = goingUp; mCurrentAnimationIsGoingUp = goingUp;
float range = mLauncher.getAllAppsController().getShiftRange(); BaseDragLayer dl = mActivity.getDragLayer();
long maxDuration = (long) (2 * range); long maxDuration = (long) (2 * dl.getHeight());
DragLayer dl = mLauncher.getDragLayer();
if (goingUp) { if (goingUp) {
mPendingAnimation = mRecentsView.createTaskDismissAnimation(mTaskBeingDragged, mPendingAnimation = mRecentsView.createTaskDismissAnimation(mTaskBeingDragged,
@ -254,7 +254,7 @@ public class TaskViewTouchController extends AnimatorListenerAdapter
} }
if (wasSuccess) { if (wasSuccess) {
if (!mCurrentAnimationIsGoingUp) { if (!mCurrentAnimationIsGoingUp) {
mLauncher.getUserEventDispatcher().logTaskLaunch(logAction, mActivity.getUserEventDispatcher().logTaskLaunch(logAction,
Direction.DOWN, mTaskBeingDragged.getTask().getTopComponent()); Direction.DOWN, mTaskBeingDragged.getTask().getTopComponent());
} }
} }

View File

@ -16,6 +16,7 @@
package com.android.launcher3.uioverrides; package com.android.launcher3.uioverrides;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.Utilities.getPrefs; import static com.android.launcher3.Utilities.getPrefs;
import static com.android.quickstep.OverviewInteractionState.KEY_SWIPE_UP_ENABLED; import static com.android.quickstep.OverviewInteractionState.KEY_SWIPE_UP_ENABLED;
import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.ALL_APPS;
@ -41,19 +42,19 @@ public class UiFactory {
return new TouchController[] { return new TouchController[] {
launcher.getDragController(), launcher.getDragController(),
new LandscapeStatesTouchController(launcher), new LandscapeStatesTouchController(launcher),
new TaskViewTouchController(launcher)}; new LauncherTaskViewcontroller(launcher)};
} }
if (launcher.getDeviceProfile().isVerticalBarLayout()) { if (launcher.getDeviceProfile().isVerticalBarLayout()) {
return new TouchController[] { return new TouchController[] {
launcher.getDragController(), launcher.getDragController(),
new LandscapeStatesTouchController(launcher), new LandscapeStatesTouchController(launcher),
new LandscapeEdgeSwipeController(launcher), new LandscapeEdgeSwipeController(launcher),
new TaskViewTouchController(launcher)}; new LauncherTaskViewcontroller(launcher)};
} else { } else {
return new TouchController[] { return new TouchController[] {
launcher.getDragController(), launcher.getDragController(),
new PortraitStatesTouchController(launcher), new PortraitStatesTouchController(launcher),
new TaskViewTouchController(launcher)}; new LauncherTaskViewcontroller(launcher)};
} }
} }
@ -101,4 +102,16 @@ public class UiFactory {
model.onTrimMemory(level); model.onTrimMemory(level);
} }
} }
private static class LauncherTaskViewcontroller extends TaskViewTouchController<Launcher> {
public LauncherTaskViewcontroller(Launcher activity) {
super(activity);
}
@Override
protected boolean isRecentsInteractive() {
return mActivity.isInState(OVERVIEW);
}
}
} }

View File

@ -41,6 +41,7 @@ import com.android.launcher3.LauncherState;
import com.android.launcher3.allapps.AllAppsTransitionController; import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.util.ViewOnDrawExecutor; import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.views.LauncherLayoutListener; import com.android.quickstep.views.LauncherLayoutListener;
import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView; import com.android.quickstep.views.TaskView;

View File

@ -16,13 +16,13 @@
package com.android.quickstep; package com.android.quickstep;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Log;
import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.RecentsAnimationControllerCompat; import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
import com.android.systemui.shared.system.RecentsAnimationListener; import com.android.systemui.shared.system.RecentsAnimationListener;
import com.android.systemui.shared.system.RemoteAnimationRunnerCompat; import com.android.systemui.shared.system.RemoteAnimationRunnerCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat; import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.TransactionCompat;
import com.android.systemui.shared.system.WindowManagerWrapper; import com.android.systemui.shared.system.WindowManagerWrapper;
/** /**
@ -39,6 +39,7 @@ public class FallbackActivityOptions implements RemoteAnimationRunnerCompat {
@Override @Override
public void onAnimationStart(RemoteAnimationTargetCompat[] targetCompats, public void onAnimationStart(RemoteAnimationTargetCompat[] targetCompats,
Runnable runnable) { Runnable runnable) {
showOpeningTarget(targetCompats);
DummyRecentsAnimationControllerCompat dummyRecentsAnim = DummyRecentsAnimationControllerCompat dummyRecentsAnim =
new DummyRecentsAnimationControllerCompat(runnable); new DummyRecentsAnimationControllerCompat(runnable);
@ -52,6 +53,18 @@ public class FallbackActivityOptions implements RemoteAnimationRunnerCompat {
mListener.onAnimationCanceled(); mListener.onAnimationCanceled();
} }
private void showOpeningTarget(RemoteAnimationTargetCompat[] targetCompats) {
for (RemoteAnimationTargetCompat target : targetCompats) {
TransactionCompat t = new TransactionCompat();
int layer = target.mode == RemoteAnimationTargetCompat.MODE_CLOSING
? Integer.MAX_VALUE
: target.prefixOrderIndex;
t.setLayer(target.leash, layer);
t.show(target.leash);
t.apply();
}
}
private static class DummyRecentsAnimationControllerCompat private static class DummyRecentsAnimationControllerCompat
extends RecentsAnimationControllerCompat { extends RecentsAnimationControllerCompat {

View File

@ -26,7 +26,11 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.badge.BadgeInfo; import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.fallback.RecentsRootView;
/** /**
* A simple activity to show the recently launched tasks * A simple activity to show the recently launched tasks
@ -51,6 +55,10 @@ public class RecentsActivity extends BaseDraggingActivity {
mRecentsRootView = findViewById(R.id.drag_layer); mRecentsRootView = findViewById(R.id.drag_layer);
mFallbackRecentsView = findViewById(R.id.overview_panel); mFallbackRecentsView = findViewById(R.id.overview_panel);
mRecentsRootView.setup();
getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
RecentsActivityTracker.onRecentsActivityCreate(this); RecentsActivityTracker.onRecentsActivityCreate(this);
} }

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.quickstep; package com.android.quickstep.fallback;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -23,6 +23,7 @@ import android.view.View;
import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable; import com.android.launcher3.Insettable;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsView;
public class FallbackRecentsView extends RecentsView<RecentsActivity> implements Insettable { public class FallbackRecentsView extends RecentsView<RecentsActivity> implements Insettable {
@ -73,12 +74,7 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity> implements
public static void getCenterPageRect(DeviceProfile grid, Context context, Rect outRect) { public static void getCenterPageRect(DeviceProfile grid, Context context, Rect outRect) {
Rect targetPadding = getPadding(grid, context); Rect targetPadding = getPadding(grid, context);
verticalCenter(targetPadding, grid); verticalCenter(targetPadding, grid);
Rect insets = grid.getInsets(); getPageRect(grid, context, outRect, targetPadding);
outRect.set(
targetPadding.left + insets.left,
targetPadding.top + insets.top,
grid.widthPx - targetPadding.right - insets.right,
grid.heightPx - targetPadding.bottom - insets.bottom);
} }
@Override @Override

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.quickstep; package com.android.quickstep.fallback;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
@ -25,15 +25,22 @@ import com.android.launcher3.R;
import com.android.launcher3.util.Themes; import com.android.launcher3.util.Themes;
import com.android.launcher3.util.TouchController; import com.android.launcher3.util.TouchController;
import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.RecentsActivity;
public class RecentsRootView extends BaseDragLayer<RecentsActivity> { public class RecentsRootView extends BaseDragLayer<RecentsActivity> {
private final BaseActivity mActivity; private final RecentsActivity mActivity;
public RecentsRootView(Context context, AttributeSet attrs) { public RecentsRootView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mActivity = BaseActivity.fromContext(context); mActivity = (RecentsActivity) BaseActivity.fromContext(context);
mControllers = new TouchController[0]; setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
public void setup() {
mControllers = new TouchController[] { new RecentsTaskController(mActivity) };
} }
@TargetApi(23) @TargetApi(23)

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep.fallback;
import com.android.launcher3.uioverrides.TaskViewTouchController;
import com.android.quickstep.RecentsActivity;
public class RecentsTaskController extends TaskViewTouchController<RecentsActivity> {
public RecentsTaskController(RecentsActivity activity) {
super(activity);
}
@Override
protected boolean isRecentsInteractive() {
return mActivity.hasWindowFocus();
}
}

View File

@ -405,7 +405,7 @@ public abstract class RecentsView<T extends BaseActivity>
getPageRect(grid, context, outRect, targetPadding); getPageRect(grid, context, outRect, targetPadding);
} }
private static void getPageRect(DeviceProfile grid, Context context, Rect outRect, protected static void getPageRect(DeviceProfile grid, Context context, Rect outRect,
Rect targetPadding) { Rect targetPadding) {
Rect insets = grid.getInsets(); Rect insets = grid.getInsets();
outRect.set( outRect.set(

View File

@ -34,13 +34,15 @@ import android.widget.Toast;
import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.badge.BadgeInfo; import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.dynamicui.WallpaperColorInfo;
import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.views.BaseDragLayer;
/** /**
* Extension of BaseActivity allowing support for drag-n-drop * Extension of BaseActivity allowing support for drag-n-drop
*/ */
public abstract class BaseDraggingActivity extends BaseActivity { public abstract class BaseDraggingActivity extends BaseActivity
implements WallpaperColorInfo.OnChangeListener {
private static final String TAG = "BaseDraggingActivity"; private static final String TAG = "BaseDraggingActivity";
@ -57,10 +59,38 @@ public abstract class BaseDraggingActivity extends BaseActivity {
private OnStartCallback mOnStartCallback; private OnStartCallback mOnStartCallback;
private int mThemeRes = R.style.LauncherTheme;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mIsSafeModeEnabled = getPackageManager().isSafeMode(); mIsSafeModeEnabled = getPackageManager().isSafeMode();
// Update theme
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
wallpaperColorInfo.addOnChangeListener(this);
int themeRes = getThemeRes(wallpaperColorInfo);
if (themeRes != mThemeRes) {
mThemeRes = themeRes;
setTheme(themeRes);
}
}
@Override
public void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo) {
if (mThemeRes != getThemeRes(wallpaperColorInfo)) {
recreate();
}
}
protected int getThemeRes(WallpaperColorInfo wallpaperColorInfo) {
if (wallpaperColorInfo.isDark()) {
return R.style.LauncherThemeDark;
} else if (wallpaperColorInfo.supportsDarkText()) {
return R.style.LauncherThemeDarkText;
} else {
return R.style.LauncherTheme;
}
} }
@Override @Override
@ -203,6 +233,12 @@ public abstract class BaseDraggingActivity extends BaseActivity {
} }
} }
@Override
protected void onDestroy() {
super.onDestroy();
WallpaperColorInfo.getInstance(this).removeOnChangeListener(this);
}
public <T extends BaseDraggingActivity> void setOnStartCallback(OnStartCallback<T> callback) { public <T extends BaseDraggingActivity> void setOnStartCallback(OnStartCallback<T> callback) {
mOnStartCallback = callback; mOnStartCallback = callback;
} }

View File

@ -135,8 +135,8 @@ import java.util.Set;
/** /**
* Default launcher application. * Default launcher application.
*/ */
public class Launcher extends BaseDraggingActivity implements LauncherExterns, LauncherModel.Callbacks, public class Launcher extends BaseDraggingActivity
LauncherProviderChangeListener, WallpaperColorInfo.OnThemeChangeListener { implements LauncherExterns, LauncherModel.Callbacks, LauncherProviderChangeListener {
public static final String TAG = "Launcher"; public static final String TAG = "Launcher";
static final boolean LOGD = false; static final boolean LOGD = false;
@ -266,10 +266,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, L
} }
TraceHelper.beginSection("Launcher-onCreate"); TraceHelper.beginSection("Launcher-onCreate");
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
wallpaperColorInfo.setOnThemeChangeListener(this);
overrideTheme(wallpaperColorInfo.isDark(), wallpaperColorInfo.supportsDarkText());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
TraceHelper.partitionSection("Launcher-onCreate", "super call"); TraceHelper.partitionSection("Launcher-onCreate", "super call");
@ -402,23 +398,10 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, L
return mRotationHelper; return mRotationHelper;
} }
@Override
public void onThemeChanged() {
recreate();
}
public LauncherStateManager getStateManager() { public LauncherStateManager getStateManager() {
return mStateManager; return mStateManager;
} }
protected void overrideTheme(boolean isDark, boolean supportsDarkText) {
if (isDark) {
setTheme(R.style.LauncherThemeDark);
} else if (supportsDarkText) {
setTheme(R.style.LauncherThemeDarkText);
}
}
@Override @Override
public <T extends View> T findViewById(int id) { public <T extends View> T findViewById(int id) {
return mLauncherView.findViewById(id); return mLauncherView.findViewById(id);
@ -1367,7 +1350,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, L
} }
TextKeyListener.getInstance().release(); TextKeyListener.getInstance().release();
WallpaperColorInfo.getInstance(this).setOnThemeChangeListener(null);
LauncherAnimUtils.onDestroyActivity(); LauncherAnimUtils.onDestroyActivity();

View File

@ -33,7 +33,8 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
private int mSecondaryColor; private int mSecondaryColor;
private boolean mIsDark; private boolean mIsDark;
private boolean mSupportsDarkText; private boolean mSupportsDarkText;
private OnThemeChangeListener mOnThemeChangeListener;
private OnChangeListener[] mTempListeners;
private WallpaperColorInfo(Context context) { private WallpaperColorInfo(Context context) {
mWallpaperManager = WallpaperManagerCompat.getInstance(context); mWallpaperManager = WallpaperManagerCompat.getInstance(context);
@ -61,10 +62,8 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
@Override @Override
public void onColorsChanged(WallpaperColorsCompat colors, int which) { public void onColorsChanged(WallpaperColorsCompat colors, int which) {
if ((which & FLAG_SYSTEM) != 0) { if ((which & FLAG_SYSTEM) != 0) {
boolean wasDarkTheme = mIsDark;
boolean didSupportDarkText = mSupportsDarkText;
update(colors); update(colors);
notifyChange(wasDarkTheme != mIsDark || didSupportDarkText != mSupportsDarkText); notifyChange();
} }
} }
@ -85,10 +84,6 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
& WallpaperColorsCompat.HINT_SUPPORTS_DARK_THEME) > 0 : false; & WallpaperColorsCompat.HINT_SUPPORTS_DARK_THEME) > 0 : false;
} }
public void setOnThemeChangeListener(OnThemeChangeListener onThemeChangeListener) {
this.mOnThemeChangeListener = onThemeChangeListener;
}
public void addOnChangeListener(OnChangeListener listener) { public void addOnChangeListener(OnChangeListener listener) {
mListeners.add(listener); mListeners.add(listener);
} }
@ -97,23 +92,19 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
mListeners.remove(listener); mListeners.remove(listener);
} }
public void notifyChange(boolean themeChanged) { private void notifyChange() {
if (themeChanged) { OnChangeListener[] copy =
if (mOnThemeChangeListener != null) { mTempListeners != null && mTempListeners.length == mListeners.size() ?
mOnThemeChangeListener.onThemeChanged(); mTempListeners : new OnChangeListener[mListeners.size()];
}
} else { // Create a new array to avoid concurrent modification when the activity destroys itself.
for (OnChangeListener listener : mListeners) { mTempListeners = mListeners.toArray(copy);
listener.onExtractedColorsChanged(this); for (OnChangeListener listener : mTempListeners) {
} listener.onExtractedColorsChanged(this);
} }
} }
public interface OnChangeListener { public interface OnChangeListener {
void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo); void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo);
} }
public interface OnThemeChangeListener {
void onThemeChanged();
}
} }