Files
lawnchair/src/com/android/launcher3/BaseDraggingActivity.java
Alex Chau 007abe80e4 Reland "Handle uiMode changes in QuickstepLauncher"
- Added uiMode in handled configChanges for QuickstepLauncher, NexusLauncherActivity
- RecentsActivity will be handled separately in b/382072029
- This avoids Launcher from being recreated when swithching from an app in driving mode (e.g. Maps), which causes massive jank
- Launcher layout is unaffected when driving mode changes, so a recreation is unnecessary
- When Light/dark mode changes, BaseActivity.updateTheme will still causes activity to be recreated. Launcher will mark a boolean in saved staete so next recreate will restore previous state even if state has FLAG_DISABLE_RESTORE (e.g. Overview), similar to the existing check that force restore when UI_MODE changes

Relanded changes: /q/submissionid:27627108-b/339747262

Fix: 339747262
Test: Swtich from driving mode app to another or home in 1p and 3p laucnher
Test: Switch light/dark mode and Launcher is updated correctly and stay in previous state
Flag: EXEMPT bugfix
Change-Id: I5a62b1bcd19eed9d232f30db94aa0e032f4541bd
2024-12-03 18:20:56 +00:00

172 lines
5.3 KiB
Java

/*
* 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.launcher3;
import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.View;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.OnColorHintListener;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.WallpaperColorHints;
import com.android.launcher3.util.WindowBounds;
/**
* Extension of BaseActivity allowing support for drag-n-drop
*/
@SuppressWarnings("NewApi")
public abstract class BaseDraggingActivity extends BaseActivity
implements OnColorHintListener, DisplayInfoChangeListener {
// When starting an action mode, setting this tag will cause the action mode to be cancelled
// automatically when user interacts with the launcher.
public static final Object AUTO_CANCEL_ACTION_MODE = new Object();
private ActionMode mCurrentActionMode;
private int mThemeRes = R.style.AppTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DisplayController.INSTANCE.get(this).addChangeListener(this);
// Update theme
WallpaperColorHints.get(this).registerOnColorHintsChangedListener(this);
int themeRes = Themes.getActivityThemeRes(this);
if (themeRes != mThemeRes) {
mThemeRes = themeRes;
setTheme(themeRes);
}
}
@MainThread
@Override
public void onColorHintsChanged(int colorHints) {
updateTheme();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateTheme();
}
private void updateTheme() {
if (mThemeRes != Themes.getActivityThemeRes(this)) {
recreateToUpdateTheme();
}
}
protected void recreateToUpdateTheme() {
recreate();
}
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
mCurrentActionMode = mode;
}
@Override
public void onActionModeFinished(ActionMode mode) {
super.onActionModeFinished(mode);
mCurrentActionMode = null;
}
protected boolean isInAutoCancelActionMode() {
return mCurrentActionMode != null && AUTO_CANCEL_ACTION_MODE == mCurrentActionMode.getTag();
}
@Override
public boolean finishAutoCancelActionMode() {
if (isInAutoCancelActionMode()) {
mCurrentActionMode.finish();
return true;
}
return false;
}
public abstract View getRootView();
public void returnToHomescreen() {
// no-op
}
@Override
@NonNull
public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) {
ActivityOptionsWrapper wrapper = super.getActivityLaunchOptions(v, item);
addEventCallback(EVENT_RESUMED, wrapper.onEndCallback::executeAllAndDestroy);
return wrapper;
}
@Override
public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) {
ActivityOptionsWrapper wrapper = super.makeDefaultActivityOptions(splashScreenStyle);
addEventCallback(EVENT_RESUMED, wrapper.onEndCallback::executeAllAndDestroy);
return wrapper;
}
@Override
protected void onDestroy() {
super.onDestroy();
DisplayController.INSTANCE.get(this).removeChangeListener(this);
WallpaperColorHints.get(this).unregisterOnColorsChangedListener(this);
}
protected void onDeviceProfileInitiated() {
}
@Override
public void onDisplayInfoChanged(Context context, Info info, int flags) {
if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.isVerticalBarLayout()) {
reapplyUi();
}
}
@Override
public View.OnClickListener getItemOnClickListener() {
return ItemClickHandler.INSTANCE;
}
protected abstract void reapplyUi();
protected WindowBounds getMultiWindowDisplaySize() {
return WindowBounds.fromWindowMetrics(getWindowManager().getCurrentWindowMetrics());
}
@Override
public boolean isAppBlockedForSafeMode() {
return LauncherAppState.getInstance(this).isSafeModeEnabled();
}
}