2018-03-14 12:30:11 -07:00
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
|
2021-04-20 16:51:10 -07:00
|
|
|
import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION;
|
2021-04-26 09:52:47 -07:00
|
|
|
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
2023-04-27 21:26:59 +00:00
|
|
|
import static com.android.launcher3.util.Executors.THREAD_POOL_EXECUTOR;
|
2020-02-03 14:22:09 -08:00
|
|
|
|
2021-04-26 09:52:47 -07:00
|
|
|
import android.app.WallpaperColors;
|
|
|
|
|
import android.app.WallpaperManager;
|
|
|
|
|
import android.app.WallpaperManager.OnColorsChangedListener;
|
2021-04-22 19:10:21 +01:00
|
|
|
import android.content.Context;
|
2018-08-11 15:53:40 -07:00
|
|
|
import android.content.res.Configuration;
|
2020-04-28 14:17:35 -07:00
|
|
|
import android.graphics.Point;
|
2018-03-14 12:30:11 -07:00
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.ActionMode;
|
2020-04-28 14:17:35 -07:00
|
|
|
import android.view.Display;
|
2018-03-14 12:30:11 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
|
2021-03-07 15:09:11 -08:00
|
|
|
import androidx.annotation.NonNull;
|
2019-09-06 11:46:19 -07:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
2020-01-07 13:07:55 -08:00
|
|
|
import com.android.launcher3.touch.ItemClickHandler;
|
2021-03-07 15:09:11 -08:00
|
|
|
import com.android.launcher3.util.ActivityOptionsWrapper;
|
2020-08-11 12:06:49 -07:00
|
|
|
import com.android.launcher3.util.DisplayController;
|
|
|
|
|
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
|
|
|
|
|
import com.android.launcher3.util.DisplayController.Info;
|
2021-03-07 15:09:11 -08:00
|
|
|
import com.android.launcher3.util.RunnableList;
|
2019-05-01 13:15:29 -07:00
|
|
|
import com.android.launcher3.util.Themes;
|
2019-10-14 14:06:38 -07:00
|
|
|
import com.android.launcher3.util.TraceHelper;
|
2020-05-27 17:52:03 -07:00
|
|
|
import com.android.launcher3.util.WindowBounds;
|
2018-03-14 12:30:11 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extension of BaseActivity allowing support for drag-n-drop
|
|
|
|
|
*/
|
2021-04-26 09:52:47 -07:00
|
|
|
@SuppressWarnings("NewApi")
|
2018-03-27 17:35:54 -07:00
|
|
|
public abstract class BaseDraggingActivity extends BaseActivity
|
2021-04-26 09:52:47 -07:00
|
|
|
implements OnColorsChangedListener, DisplayInfoChangeListener {
|
2018-03-14 12:30:11 -07:00
|
|
|
|
|
|
|
|
private static final String TAG = "BaseDraggingActivity";
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
protected boolean mIsSafeModeEnabled;
|
|
|
|
|
|
2019-10-14 16:30:38 -07:00
|
|
|
private Runnable mOnStartCallback;
|
2021-03-07 15:09:11 -08:00
|
|
|
private RunnableList mOnResumeCallbacks = new RunnableList();
|
2018-03-19 13:41:31 -07:00
|
|
|
|
2018-06-07 15:42:57 -07:00
|
|
|
private int mThemeRes = R.style.AppTheme;
|
2018-03-27 17:35:54 -07:00
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-10-14 14:06:38 -07:00
|
|
|
|
2020-07-09 12:21:40 -07:00
|
|
|
mIsSafeModeEnabled = TraceHelper.allowIpcs("isSafeMode",
|
2019-10-14 14:06:38 -07:00
|
|
|
() -> getPackageManager().isSafeMode());
|
2021-04-20 16:51:10 -07:00
|
|
|
DisplayController.INSTANCE.get(this).addChangeListener(this);
|
2018-03-27 17:35:54 -07:00
|
|
|
|
|
|
|
|
// Update theme
|
2021-04-26 09:52:47 -07:00
|
|
|
if (Utilities.ATLEAST_P) {
|
2023-04-27 21:26:59 +00:00
|
|
|
THREAD_POOL_EXECUTOR.execute(() -> getSystemService(WallpaperManager.class)
|
|
|
|
|
.addOnColorsChangedListener(this, MAIN_EXECUTOR.getHandler()));
|
2021-04-26 09:52:47 -07:00
|
|
|
}
|
2019-05-01 13:15:29 -07:00
|
|
|
int themeRes = Themes.getActivityThemeRes(this);
|
2018-03-27 17:35:54 -07:00
|
|
|
if (themeRes != mThemeRes) {
|
|
|
|
|
mThemeRes = themeRes;
|
|
|
|
|
setTheme(themeRes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-07 15:09:11 -08:00
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
mOnResumeCallbacks.executeAllAndClear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addOnResumeCallback(Runnable callback) {
|
|
|
|
|
mOnResumeCallbacks.add(callback);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 17:35:54 -07:00
|
|
|
@Override
|
2021-04-26 09:52:47 -07:00
|
|
|
public void onColorsChanged(WallpaperColors wallpaperColors, int which) {
|
2018-08-11 15:53:40 -07:00
|
|
|
updateTheme();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
updateTheme();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTheme() {
|
2019-05-01 13:15:29 -07:00
|
|
|
if (mThemeRes != Themes.getActivityThemeRes(this)) {
|
2020-10-28 00:13:03 -07:00
|
|
|
recreate();
|
2018-03-27 17:35:54 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:30:11 -07:00
|
|
|
@Override
|
|
|
|
|
public void onActionModeStarted(ActionMode mode) {
|
|
|
|
|
super.onActionModeStarted(mode);
|
|
|
|
|
mCurrentActionMode = mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onActionModeFinished(ActionMode mode) {
|
|
|
|
|
super.onActionModeFinished(mode);
|
|
|
|
|
mCurrentActionMode = null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 16:20:58 -08:00
|
|
|
protected boolean isInAutoCancelActionMode() {
|
|
|
|
|
return mCurrentActionMode != null && AUTO_CANCEL_ACTION_MODE == mCurrentActionMode.getTag();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 15:53:39 -07:00
|
|
|
@Override
|
2018-03-14 12:30:11 -07:00
|
|
|
public boolean finishAutoCancelActionMode() {
|
2023-01-12 16:20:58 -08:00
|
|
|
if (isInAutoCancelActionMode()) {
|
2018-03-14 12:30:11 -07:00
|
|
|
mCurrentActionMode.finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract <T extends View> T getOverviewPanel();
|
|
|
|
|
|
2018-03-19 13:41:31 -07:00
|
|
|
public abstract View getRootView();
|
|
|
|
|
|
2019-07-10 14:25:32 -07:00
|
|
|
public void returnToHomescreen() {
|
|
|
|
|
// no-op
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 13:35:06 -07:00
|
|
|
@Override
|
2021-03-07 15:09:11 -08:00
|
|
|
@NonNull
|
2021-04-09 14:00:25 -07:00
|
|
|
public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) {
|
2022-03-15 13:35:06 -07:00
|
|
|
ActivityOptionsWrapper wrapper = super.getActivityLaunchOptions(v, item);
|
|
|
|
|
addOnResumeCallback(wrapper.onEndCallback::executeAllAndDestroy);
|
|
|
|
|
return wrapper;
|
2018-03-14 12:30:11 -07:00
|
|
|
}
|
2018-03-19 13:41:31 -07:00
|
|
|
|
2023-05-12 12:08:53 -07:00
|
|
|
@Override
|
|
|
|
|
public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) {
|
|
|
|
|
ActivityOptionsWrapper wrapper = super.makeDefaultActivityOptions(splashScreenStyle);
|
|
|
|
|
addOnResumeCallback(wrapper.onEndCallback::executeAllAndDestroy);
|
|
|
|
|
return wrapper;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 13:41:31 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onStart() {
|
|
|
|
|
super.onStart();
|
|
|
|
|
|
|
|
|
|
if (mOnStartCallback != null) {
|
2019-10-14 16:30:38 -07:00
|
|
|
mOnStartCallback.run();
|
2018-03-19 13:41:31 -07:00
|
|
|
mOnStartCallback = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 17:35:54 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
2021-04-26 09:52:47 -07:00
|
|
|
if (Utilities.ATLEAST_P) {
|
|
|
|
|
getSystemService(WallpaperManager.class).removeOnColorsChangedListener(this);
|
|
|
|
|
}
|
2021-04-20 16:51:10 -07:00
|
|
|
DisplayController.INSTANCE.get(this).removeChangeListener(this);
|
2018-03-27 17:35:54 -07:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 16:30:38 -07:00
|
|
|
public void runOnceOnStart(Runnable action) {
|
|
|
|
|
mOnStartCallback = action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearRunOnceOnStartCallback() {
|
|
|
|
|
mOnStartCallback = null;
|
2018-03-19 13:41:31 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-07 17:31:40 -07:00
|
|
|
protected void onDeviceProfileInitiated() {
|
|
|
|
|
if (mDeviceProfile.isVerticalBarLayout()) {
|
2019-09-06 11:46:19 -07:00
|
|
|
mDeviceProfile.updateIsSeascape(this);
|
2018-05-07 17:31:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-03 14:22:09 -08:00
|
|
|
@Override
|
2021-04-22 19:10:21 +01:00
|
|
|
public void onDisplayInfoChanged(Context context, Info info, int flags) {
|
2020-02-03 14:22:09 -08:00
|
|
|
if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.updateIsSeascape(this)) {
|
2018-05-07 17:31:40 -07:00
|
|
|
reapplyUi();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 14:43:54 -07:00
|
|
|
@Override
|
|
|
|
|
public View.OnClickListener getItemOnClickListener() {
|
2020-01-07 13:07:55 -08:00
|
|
|
return ItemClickHandler.INSTANCE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 17:31:40 -07:00
|
|
|
protected abstract void reapplyUi();
|
2020-04-28 14:17:35 -07:00
|
|
|
|
2020-05-27 17:52:03 -07:00
|
|
|
protected WindowBounds getMultiWindowDisplaySize() {
|
2020-04-28 14:17:35 -07:00
|
|
|
if (Utilities.ATLEAST_R) {
|
2022-03-01 16:53:23 -08:00
|
|
|
return WindowBounds.fromWindowMetrics(getWindowManager().getCurrentWindowMetrics());
|
2020-04-28 14:17:35 -07:00
|
|
|
}
|
|
|
|
|
// Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return
|
|
|
|
|
// the app window size
|
|
|
|
|
Display display = getWindowManager().getDefaultDisplay();
|
|
|
|
|
Point mwSize = new Point();
|
|
|
|
|
display.getSize(mwSize);
|
2020-05-27 17:52:03 -07:00
|
|
|
return new WindowBounds(new Rect(0, 0, mwSize.x, mwSize.y), new Rect());
|
2020-04-28 14:17:35 -07:00
|
|
|
}
|
2021-01-12 12:59:39 -06:00
|
|
|
|
2022-03-15 13:35:06 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean isAppBlockedForSafeMode() {
|
|
|
|
|
return mIsSafeModeEnabled;
|
|
|
|
|
}
|
2018-03-14 12:30:11 -07:00
|
|
|
}
|