Merge "Implement fallback recents activity for Go" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot
2019-02-19 23:26:53 +00:00
committed by Android (Google) Code Review
10 changed files with 328 additions and 121 deletions
@@ -0,0 +1,162 @@
/*
* Copyright (C) 2019 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;
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import java.io.FileDescriptor;
import java.io.PrintWriter;
/**
* A base fallback recents activity that provides support for device profile changes, activity
* lifecycle tracking, and basic input handling from recents.
*
* This class is only used as a fallback in case the default launcher does not have a recents
* implementation.
*/
public abstract class BaseRecentsActivity extends BaseDraggingActivity {
private Configuration mOldConfig;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mOldConfig = new Configuration(getResources().getConfiguration());
initDeviceProfile();
initViews();
getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
RecentsActivityTracker.onRecentsActivityCreate(this);
}
/**
* Init drag layer and overview panel views.
*/
abstract protected void initViews();
@Override
public void onConfigurationChanged(Configuration newConfig) {
int diff = newConfig.diff(mOldConfig);
if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
onHandleConfigChanged();
}
mOldConfig.setTo(newConfig);
super.onConfigurationChanged(newConfig);
}
/**
* Logic for when device configuration changes (rotation, screen size change, multi-window,
* etc.)
*/
protected void onHandleConfigChanged() {
mUserEventDispatcher = null;
initDeviceProfile();
AbstractFloatingView.closeOpenViews(this, true,
AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
dispatchDeviceProfileChanged();
reapplyUi();
}
/**
* Initialize/update the device profile.
*/
private void initDeviceProfile() {
mDeviceProfile = createDeviceProfile();
onDeviceProfileInitiated();
}
/**
* Generate the device profile to use in this activity.
* @return device profile
*/
protected DeviceProfile createDeviceProfile() {
DeviceProfile dp = InvariantDeviceProfile.INSTANCE.get(this).getDeviceProfile(this);
// In case we are reusing IDP, create a copy so that we don't conflict with Launcher
// activity.
return dp.copy(this);
}
@Override
protected void onStop() {
super.onStop();
// Workaround for b/78520668, explicitly trim memory once UI is hidden
onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
}
@Override
public void onEnterAnimationComplete() {
super.onEnterAnimationComplete();
UiFactory.onEnterAnimationComplete(this);
}
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
UiFactory.onTrimMemory(this, level);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
RecentsActivityTracker.onRecentsActivityNewIntent(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
RecentsActivityTracker.onRecentsActivityDestroy(this);
}
@Override
public void onBackPressed() {
// TODO: Launch the task we came from
startHome();
}
public void startHome() {
startActivity(new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
@Override
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
super.dump(prefix, fd, writer, args);
writer.println(prefix + "Misc:");
dumpMisc(writer);
}
}
@@ -1,265 +0,0 @@
/*
* Copyright (C) 2017 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;
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
import static com.android.launcher3.QuickstepAppTransitionManagerImpl.RECENTS_LAUNCH_DURATION;
import static com.android.launcher3.QuickstepAppTransitionManagerImpl.STATUS_BAR_TRANSITION_DURATION;
import static com.android.launcher3.QuickstepAppTransitionManagerImpl.STATUS_BAR_TRANSITION_PRE_DELAY;
import static com.android.quickstep.TaskUtils.getRecentsWindowAnimator;
import static com.android.quickstep.TaskUtils.taskIsATargetWithMode;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.app.ActivityOptions;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAnimationRunner;
import com.android.launcher3.R;
import com.android.launcher3.anim.Interpolators;
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.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.fallback.RecentsRootView;
import com.android.quickstep.util.ClipAnimationHelper;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.system.ActivityOptionsCompat;
import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;
import com.android.systemui.shared.system.RemoteAnimationRunnerCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import java.io.FileDescriptor;
import java.io.PrintWriter;
/**
* A simple activity to show the recently launched tasks
*/
public class RecentsActivity extends BaseDraggingActivity {
private Handler mUiHandler = new Handler(Looper.getMainLooper());
private RecentsRootView mRecentsRootView;
private FallbackRecentsView mFallbackRecentsView;
private Configuration mOldConfig;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mOldConfig = new Configuration(getResources().getConfiguration());
initDeviceProfile();
setContentView(R.layout.fallback_recents_activity);
mRecentsRootView = findViewById(R.id.drag_layer);
mFallbackRecentsView = findViewById(R.id.overview_panel);
mRecentsRootView.setup();
getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
RecentsActivityTracker.onRecentsActivityCreate(this);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
int diff = newConfig.diff(mOldConfig);
if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
onHandleConfigChanged();
}
mOldConfig.setTo(newConfig);
super.onConfigurationChanged(newConfig);
}
@Override
public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
onHandleConfigChanged();
super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig);
}
public void onRootViewSizeChanged() {
if (isInMultiWindowMode()) {
onHandleConfigChanged();
}
}
private void onHandleConfigChanged() {
mUserEventDispatcher = null;
initDeviceProfile();
AbstractFloatingView.closeOpenViews(this, true,
AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
dispatchDeviceProfileChanged();
mRecentsRootView.setup();
reapplyUi();
}
@Override
protected void reapplyUi() {
mRecentsRootView.dispatchInsets();
}
private void initDeviceProfile() {
DeviceProfile dp = InvariantDeviceProfile.INSTANCE.get(this).getDeviceProfile(this);
// In case we are reusing IDP, create a copy so that we don't conflict with Launcher
// activity.
mDeviceProfile = (mRecentsRootView != null) && isInMultiWindowMode()
? dp.getMultiWindowProfile(this, mRecentsRootView.getLastKnownSize())
: dp.copy(this);
onDeviceProfileInitiated();
}
@Override
public BaseDragLayer getDragLayer() {
return mRecentsRootView;
}
@Override
public View getRootView() {
return mRecentsRootView;
}
@Override
public <T extends View> T getOverviewPanel() {
return (T) mFallbackRecentsView;
}
@Override
public ActivityOptions getActivityLaunchOptions(final View v) {
if (!(v instanceof TaskView)) {
return null;
}
final TaskView taskView = (TaskView) v;
RemoteAnimationRunnerCompat runner = new LauncherAnimationRunner(mUiHandler,
true /* startAtFrontOfQueue */) {
@Override
public void onCreateAnimation(RemoteAnimationTargetCompat[] targetCompats,
AnimationResult result) {
result.setAnimation(composeRecentsLaunchAnimator(taskView, targetCompats));
}
};
return ActivityOptionsCompat.makeRemoteAnimation(new RemoteAnimationAdapterCompat(
runner, RECENTS_LAUNCH_DURATION,
RECENTS_LAUNCH_DURATION - STATUS_BAR_TRANSITION_DURATION
- STATUS_BAR_TRANSITION_PRE_DELAY));
}
/**
* Composes the animations for a launch from the recents list if possible.
*/
private AnimatorSet composeRecentsLaunchAnimator(TaskView taskView,
RemoteAnimationTargetCompat[] targets) {
AnimatorSet target = new AnimatorSet();
boolean activityClosing = taskIsATargetWithMode(targets, getTaskId(), MODE_CLOSING);
ClipAnimationHelper helper = new ClipAnimationHelper(this);
target.play(getRecentsWindowAnimator(taskView, !activityClosing, targets, helper)
.setDuration(RECENTS_LAUNCH_DURATION));
// Found a visible recents task that matches the opening app, lets launch the app from there
if (activityClosing) {
Animator adjacentAnimation = mFallbackRecentsView
.createAdjacentPageAnimForTaskLaunch(taskView, helper);
adjacentAnimation.setInterpolator(Interpolators.TOUCH_RESPONSE_INTERPOLATOR);
adjacentAnimation.setDuration(RECENTS_LAUNCH_DURATION);
adjacentAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mFallbackRecentsView.resetTaskVisuals();
}
});
target.play(adjacentAnimation);
}
return target;
}
@Override
protected void onStart() {
// Set the alpha to 1 before calling super, as it may get set back to 0 due to
// onActivityStart callback.
mFallbackRecentsView.setContentAlpha(1);
super.onStart();
mFallbackRecentsView.resetTaskVisuals();
}
@Override
protected void onStop() {
super.onStop();
// Workaround for b/78520668, explicitly trim memory once UI is hidden
onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
}
@Override
public void onEnterAnimationComplete() {
super.onEnterAnimationComplete();
UiFactory.onEnterAnimationComplete(this);
}
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
UiFactory.onTrimMemory(this, level);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
RecentsActivityTracker.onRecentsActivityNewIntent(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
RecentsActivityTracker.onRecentsActivityDestroy(this);
}
@Override
public void onBackPressed() {
// TODO: Launch the task we came from
startHome();
}
public void startHome() {
startActivity(new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
@Override
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
super.dump(prefix, fd, writer, args);
writer.println(prefix + "Misc:");
dumpMisc(writer);
}
}
@@ -30,17 +30,18 @@ import java.lang.ref.WeakReference;
import java.util.function.BiPredicate;
/**
* Utility class to track create/destroy for RecentsActivity
* Utility class to track create/destroy for some {@link BaseRecentsActivity}.
*/
@TargetApi(Build.VERSION_CODES.P)
public class RecentsActivityTracker implements ActivityInitListener {
public class RecentsActivityTracker<T extends BaseRecentsActivity> implements ActivityInitListener {
private static WeakReference<RecentsActivity> sCurrentActivity = new WeakReference<>(null);
private static WeakReference<BaseRecentsActivity> sCurrentActivity =
new WeakReference<>(null);
private static final Scheduler sScheduler = new Scheduler();
private final BiPredicate<RecentsActivity, Boolean> mOnInitListener;
private final BiPredicate<T, Boolean> mOnInitListener;
public RecentsActivityTracker(BiPredicate<RecentsActivity, Boolean> onInitListener) {
public RecentsActivityTracker(BiPredicate<T, Boolean> onInitListener) {
mOnInitListener = onInitListener;
}
@@ -54,12 +55,12 @@ public class RecentsActivityTracker implements ActivityInitListener {
sScheduler.clearReference(this);
}
private boolean init(RecentsActivity activity, boolean visible) {
private boolean init(T activity, boolean visible) {
return mOnInitListener.test(activity, visible);
}
public static RecentsActivity getCurrentActivity() {
return sCurrentActivity.get();
public static <T extends BaseRecentsActivity> T getCurrentActivity() {
return (T) sCurrentActivity.get();
}
@Override
@@ -71,17 +72,17 @@ public class RecentsActivityTracker implements ActivityInitListener {
context.startActivity(intent, options);
}
public static void onRecentsActivityCreate(RecentsActivity activity) {
public static void onRecentsActivityCreate(BaseRecentsActivity activity) {
sCurrentActivity = new WeakReference<>(activity);
sScheduler.initIfPending(activity, false);
}
public static void onRecentsActivityNewIntent(RecentsActivity activity) {
public static void onRecentsActivityNewIntent(BaseRecentsActivity activity) {
sScheduler.initIfPending(activity, activity.isStarted());
}
public static void onRecentsActivityDestroy(RecentsActivity activity) {
public static void onRecentsActivityDestroy(BaseRecentsActivity activity) {
if (sCurrentActivity.get() == activity) {
sCurrentActivity.clear();
}
@@ -103,13 +104,14 @@ public class RecentsActivityTracker implements ActivityInitListener {
@Override
public void run() {
RecentsActivity activity = sCurrentActivity.get();
BaseRecentsActivity activity = sCurrentActivity.get();
if (activity != null) {
initIfPending(activity, activity.isStarted());
}
}
public synchronized boolean initIfPending(RecentsActivity activity, boolean alreadyOnHome) {
public synchronized boolean initIfPending(BaseRecentsActivity activity,
boolean alreadyOnHome) {
RecentsActivityTracker tracker = mPendingTracker.get();
if (tracker != null) {
if (!tracker.init(activity, alreadyOnHome)) {
@@ -1,73 +0,0 @@
/*
* 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 android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import com.android.launcher3.DeviceProfile;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.util.LayoutUtils;
import com.android.quickstep.views.RecentsView;
public class FallbackRecentsView extends RecentsView<RecentsActivity> {
public FallbackRecentsView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public FallbackRecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOverviewStateEnabled(true);
}
@Override
public void startHome() {
mActivity.startHome();
}
@Override
public void onViewAdded(View child) {
super.onViewAdded(child);
updateEmptyMessage();
}
@Override
public void onViewRemoved(View child) {
super.onViewRemoved(child);
updateEmptyMessage();
}
@Override
public void draw(Canvas canvas) {
maybeDrawEmptyMessage(canvas);
super.draw(canvas);
}
@Override
protected void getTaskSize(DeviceProfile dp, Rect outRect) {
LayoutUtils.calculateFallbackTaskSize(getContext(), dp, outRect);
}
@Override
public boolean shouldUseMultiWindowTaskSizeStrategy() {
// Just use the activity task size for multi-window as well.
return false;
}
}
@@ -1,90 +0,0 @@
/*
* 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 android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.R;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.RecentsActivity;
public class RecentsRootView extends BaseDragLayer<RecentsActivity> {
private final RecentsActivity mActivity;
private final Point mLastKnownSize = new Point(10, 10);
public RecentsRootView(Context context, AttributeSet attrs) {
super(context, attrs, 1 /* alphaChannelCount */);
mActivity = (RecentsActivity) BaseActivity.fromContext(context);
setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
public Point getLastKnownSize() {
return mLastKnownSize;
}
public void setup() {
mControllers = new TouchController[] { new RecentsTaskController(mActivity) };
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Check size changes before the actual measure, to avoid multiple measure calls.
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (mLastKnownSize.x != width || mLastKnownSize.y != height) {
mLastKnownSize.set(width, height);
mActivity.onRootViewSizeChanged();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@TargetApi(23)
@Override
protected boolean fitSystemWindows(Rect insets) {
// Update device profile before notifying the children.
mActivity.getDeviceProfile().updateInsets(insets);
setInsets(insets);
return true; // I'll take it from here
}
@Override
public void setInsets(Rect insets) {
// If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by
// modifying child layout params.
if (!insets.equals(mInsets)) {
super.setInsets(insets);
}
setBackground(insets.top == 0 ? null
: Themes.getAttrDrawable(getContext(), R.attr.workspaceStatusBarScrim));
}
public void dispatchInsets() {
mActivity.getDeviceProfile().updateInsets(mInsets);
super.setInsets(mInsets);
}
}
@@ -1,31 +0,0 @@
/*
* 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();
}
}