diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java index c5d7c95e0b..d39dfda930 100644 --- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java @@ -36,6 +36,7 @@ import android.os.CancellationSignal; import com.android.launcher3.LauncherState.ScaleAndTranslation; import com.android.launcher3.LauncherStateManager.StateHandler; +import com.android.launcher3.accessibility.SystemActions; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.WellbeingModel; import com.android.launcher3.popup.SystemShortcut; @@ -62,6 +63,8 @@ import java.util.stream.Stream; public abstract class BaseQuickstepLauncher extends Launcher implements NavigationModeChangeListener { + protected SystemActions mSystemActions; + /** * Reusable command for applying the back button alpha on the background thread. */ @@ -74,6 +77,7 @@ public abstract class BaseQuickstepLauncher extends Launcher @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mSystemActions = new SystemActions(this); SysUINavigationMode.Mode mode = SysUINavigationMode.INSTANCE.get(this) .addModeChangeListener(this); @@ -131,6 +135,12 @@ public abstract class BaseQuickstepLauncher extends Launcher getRotationHelper().setRotationHadDifferentUI(newMode != Mode.NO_BUTTON); } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + mSystemActions.onActivityResult(requestCode); + } + @Override public void onEnterAnimationComplete() { super.onEnterAnimationComplete(); @@ -188,6 +198,15 @@ public abstract class BaseQuickstepLauncher extends Launcher // removes the task itself. startActivity(ProxyActivityStarter.getLaunchIntent(this, null)); } + + // Register all system actions once they are available + mSystemActions.register(); + } + + @Override + protected void onPause() { + super.onPause(); + mSystemActions.unregister(); } @Override diff --git a/quickstep/src/com/android/launcher3/accessibility/SystemActions.java b/quickstep/src/com/android/launcher3/accessibility/SystemActions.java new file mode 100644 index 0000000000..669877f5b3 --- /dev/null +++ b/quickstep/src/com/android/launcher3/accessibility/SystemActions.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2020 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.accessibility; + +import static com.android.launcher3.LauncherState.ALL_APPS; +import static com.android.launcher3.LauncherState.NORMAL; + +import android.app.PendingIntent; +import android.app.RemoteAction; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.graphics.drawable.Icon; +import android.view.accessibility.AccessibilityManager; +import com.android.launcher3.Launcher; +import com.android.launcher3.LauncherState; +import com.android.launcher3.LauncherStateManager; +import com.android.launcher3.R; + +/** + * Manages the launcher system actions presented to accessibility services. + */ +public class SystemActions { + + /** + * System Action ID to show all apps. This ID should follow the ones in + * com.android.systemui.accessibility.SystemActions. + */ + private static final int SYSTEM_ACTION_ID_ALL_APPS = 100; + + private Launcher mLauncher; + private AccessibilityManager mAccessibilityManager; + private RemoteAction mAllAppsAction; + private boolean mRegistered; + + public SystemActions(Launcher launcher) { + mLauncher = launcher; + mAccessibilityManager = (AccessibilityManager) launcher.getSystemService( + Context.ACCESSIBILITY_SERVICE); + mAllAppsAction = new RemoteAction( + Icon.createWithResource(launcher, R.drawable.ic_apps), + launcher.getString(R.string.all_apps_label), + launcher.getString(R.string.all_apps_label), + launcher.createPendingResult(SYSTEM_ACTION_ID_ALL_APPS, new Intent(), + 0 /* flags */)); + } + + public void register() { + if (mRegistered) { + return; + } + mAccessibilityManager.registerSystemAction(mAllAppsAction, SYSTEM_ACTION_ID_ALL_APPS); + mRegistered = true; + } + + public void unregister() { + if (!mRegistered) { + return; + } + mAccessibilityManager.unregisterSystemAction(SYSTEM_ACTION_ID_ALL_APPS); + mRegistered = false; + } + + public void onActivityResult(int requestCode) { + if (requestCode == SYSTEM_ACTION_ID_ALL_APPS) { + showAllApps(); + } + } + + private void showAllApps() { + LauncherStateManager stateManager = mLauncher.getStateManager(); + stateManager.goToState(NORMAL); + stateManager.goToState(ALL_APPS); + } +} diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 7c85bb7396..3e1032319a 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -833,6 +833,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); } } + mDragLayer.clearAnimatedView(); }