sanders: KeyHandler: Add last app action

This commit is contained in:
Henrique Silva
2017-10-25 08:15:45 -03:00
committed by therootlord
parent 290dd03777
commit 18859c1826
5 changed files with 46 additions and 1 deletions

View File

@@ -54,6 +54,7 @@
<string name="action_wake">Acordar o dispositivo</string>
<string name="action_back">Voltar</string>
<string name="action_recents">Recentes</string>
<string name="action_last_app">Último app</string>
<string name="action_volume_up">Aumentar volume</string>
<string name="action_volume_down">Diminuir volume</string>
<string name="action_voice_assistant">Assistente de voz</string>

View File

@@ -21,6 +21,7 @@
<item>@string/action_power</item>
<item>@string/action_back</item>
<item>@string/action_recents</item>
<item>@string/action_last_app</item>
<item>@string/action_volume_up</item>
<item>@string/action_volume_down</item>
<item>@string/action_voice_assistant</item>
@@ -38,6 +39,7 @@
<item>101</item> <!-- power -->
<item>102</item> <!-- back -->
<item>103</item> <!-- recents -->
<item>121</item> <!-- last app -->
<item>104</item> <!-- volume up -->
<item>105</item> <!-- volume down -->
<item>106</item> <!-- voice assistant -->

View File

@@ -54,6 +54,7 @@
<string name="action_wake">Wake</string>
<string name="action_back">Back</string>
<string name="action_recents">Recents</string>
<string name="action_last_app">Last app</string>
<string name="action_volume_up">Volume up</string>
<string name="action_volume_down">Volume down</string>
<string name="action_voice_assistant">Voice assistant</string>

View File

@@ -217,6 +217,40 @@ public class KeyHandler implements DeviceKeyHandler {
}
}
private static void switchToLastApp(Context context) {
final ActivityManager am =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.RunningTaskInfo lastTask = getLastTask(context, am);
if (lastTask != null) {
am.moveTaskToFront(lastTask.id, ActivityManager.MOVE_TASK_NO_USER_ACTION);
}
}
private static ActivityManager.RunningTaskInfo getLastTask(Context context,
final ActivityManager am) {
final String defaultHomePackage = resolveCurrentLauncherPackage(context);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);
for (int i = 1; i < tasks.size(); i++) {
String packageName = tasks.get(i).topActivity.getPackageName();
if (!packageName.equals(defaultHomePackage)
&& !packageName.equals(context.getPackageName())
&& !packageName.equals("com.android.systemui")) {
return tasks.get(i);
}
}
return null;
}
private static String resolveCurrentLauncherPackage(Context context) {
final Intent launcherIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME);
final PackageManager pm = context.getPackageManager();
final ResolveInfo launcherInfo = pm.resolveActivity(launcherIntent, 0);
return launcherInfo.activityInfo.packageName;
}
private void setHapticFeedbackEnabledOnSystem(boolean enabled) {
Settings.System.putIntForUser(mContext.getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED, enabled ? 1 : 0, UserHandle.USER_CURRENT);
@@ -565,6 +599,11 @@ public class KeyHandler implements DeviceKeyHandler {
goToPipMode();
}
break;
case ACTION_LAST_APP:
if (!mKeyguardManager.inKeyguardRestrictedInputMode()) {
switchToLastApp(mContext);
}
break;
}
if (isHapticFeedbackEnabledOnFP && action != ACTION_VOICE_ASSISTANT && action != ACTION_CAMERA && action != ACTION_FLASHLIGHT && action != ACTION_POWER) { // prevent double vibration
doHapticFeedbackFP(false);

View File

@@ -64,6 +64,7 @@ public class Constants {
public static final int ACTION_EMAIL = 118;
public static final int ACTION_MESSAGES = 119;
public static final int ACTION_PIP = 120;
public static final int ACTION_LAST_APP = 121;
public static final int[] sFPSupportedActions = new int[]{
ACTION_HOME,
ACTION_POWER,
@@ -78,7 +79,8 @@ public class Constants {
ACTION_FLASHLIGHT,
ACTION_CAMERA,
ACTION_SCREENSHOT,
ACTION_PIP
ACTION_PIP,
ACTION_LAST_APP
};
public static final int[] sFPSupportedActionsScreenOff = new int[]{
ACTION_POWER,