Change recents UIs to do task switches.
When switching to a recent task that is currently active, do a task switch instead of a start activity, so the activity is brought back in its exact same state. Also fix problem in phone recents where the icon would disappear after you touch it. Change-Id: Id5c8478f8c33c90f52fbb4d969037d2bf5af9fff
This commit is contained in:
@@ -29,6 +29,8 @@ import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.IThumbnailReceiver;
|
||||
import android.app.ActivityManager.RunningTaskInfo;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@@ -189,8 +191,15 @@ public class RecentApplicationsActivity extends Activity {
|
||||
public void onCardSelected(int n) {
|
||||
if (n < mActivityDescriptions.size()) {
|
||||
ActivityDescription item = mActivityDescriptions.get(n);
|
||||
// prepare a launch intent and send it
|
||||
if (item.intent != null) {
|
||||
if (item.id >= 0) {
|
||||
// This is an active task; it should just go to the foreground.
|
||||
IActivityManager am = ActivityManagerNative.getDefault();
|
||||
try {
|
||||
am.moveTaskToFront(item.id);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
} else if (item.intent != null) {
|
||||
// prepare a launch intent and send it
|
||||
item.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
|
||||
try {
|
||||
if (DBG) Log.v(TAG, "Starting intent " + item.intent);
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.IThumbnailReceiver;
|
||||
import android.app.ActivityManager.RunningTaskInfo;
|
||||
import android.content.Context;
|
||||
@@ -236,7 +238,7 @@ public class RecentAppsPanel extends LinearLayout implements StatusBarPanel, OnC
|
||||
appIcon.setImageDrawable(activityDescription.icon);
|
||||
appDescription.setText(activityDescription.label);
|
||||
view.setOnClickListener(this);
|
||||
view.setTag(activityDescription.intent);
|
||||
view.setTag(activityDescription);
|
||||
Log.v(TAG, "Adding task: " + activityDescription.label);
|
||||
mRecentsContainer.addView(view);
|
||||
}
|
||||
@@ -247,9 +249,19 @@ public class RecentAppsPanel extends LinearLayout implements StatusBarPanel, OnC
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
Intent intent = (Intent) v.getTag();
|
||||
if (DEBUG) Log.v(TAG, "Starting activity " + intent);
|
||||
getContext().startActivity(intent);
|
||||
ActivityDescription ad = (ActivityDescription)v.getTag();
|
||||
if (ad.id >= 0) {
|
||||
// This is an active task; it should just go to the foreground.
|
||||
IActivityManager am = ActivityManagerNative.getDefault();
|
||||
try {
|
||||
am.moveTaskToFront(ad.id);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
} else {
|
||||
Intent intent = ad.intent;
|
||||
if (DEBUG) Log.v(TAG, "Starting activity " + intent);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
mBar.animateCollapse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.android.internal.policy.impl;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.Dialog;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.StatusBarManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -30,6 +32,8 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@@ -53,6 +57,22 @@ public class RecentApplicationsDialog extends Dialog implements OnClickListener
|
||||
View mNoAppsText;
|
||||
IntentFilter mBroadcastIntentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
|
||||
class RecentTag {
|
||||
ActivityManager.RecentTaskInfo info;
|
||||
Intent intent;
|
||||
}
|
||||
|
||||
Handler mHandler = new Handler();
|
||||
Runnable mCleanup = new Runnable() {
|
||||
public void run() {
|
||||
// dump extra memory we're hanging on to
|
||||
for (TextView icon: mIcons) {
|
||||
icon.setCompoundDrawables(null, null, null, null);
|
||||
icon.setTag(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private int mIconSize;
|
||||
|
||||
public RecentApplicationsDialog(Context context) {
|
||||
@@ -115,12 +135,18 @@ public class RecentApplicationsDialog extends Dialog implements OnClickListener
|
||||
|
||||
for (TextView b: mIcons) {
|
||||
if (b == v) {
|
||||
// prepare a launch intent and send it
|
||||
Intent intent = (Intent)b.getTag();
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
|
||||
RecentTag tag = (RecentTag)b.getTag();
|
||||
if (tag.info.id >= 0) {
|
||||
// This is an active task; it should just go to the foreground.
|
||||
IActivityManager am = ActivityManagerNative.getDefault();
|
||||
try {
|
||||
getContext().startActivity(intent);
|
||||
am.moveTaskToFront(tag.info.id);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
} else if (tag.intent != null) {
|
||||
tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
|
||||
try {
|
||||
getContext().startActivity(tag.intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w("Recent", "Unable to launch recent task", e);
|
||||
}
|
||||
@@ -144,6 +170,8 @@ public class RecentApplicationsDialog extends Dialog implements OnClickListener
|
||||
|
||||
// receive broadcasts
|
||||
getContext().registerReceiver(mBroadcastReceiver, mBroadcastIntentFilter);
|
||||
|
||||
mHandler.removeCallbacks(mCleanup);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,18 +181,14 @@ public class RecentApplicationsDialog extends Dialog implements OnClickListener
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
// dump extra memory we're hanging on to
|
||||
for (TextView icon: mIcons) {
|
||||
icon.setCompoundDrawables(null, null, null, null);
|
||||
icon.setTag(null);
|
||||
}
|
||||
|
||||
if (sStatusBar != null) {
|
||||
sStatusBar.disable(StatusBarManager.DISABLE_NONE);
|
||||
}
|
||||
|
||||
// stop receiving broadcasts
|
||||
getContext().unregisterReceiver(mBroadcastReceiver);
|
||||
|
||||
mHandler.postDelayed(mCleanup, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +248,10 @@ public class RecentApplicationsDialog extends Dialog implements OnClickListener
|
||||
tv.setText(title);
|
||||
icon = iconUtilities.createIconDrawable(icon);
|
||||
tv.setCompoundDrawables(null, icon, null, null);
|
||||
tv.setTag(intent);
|
||||
RecentTag tag = new RecentTag();
|
||||
tag.info = info;
|
||||
tag.intent = intent;
|
||||
tv.setTag(tag);
|
||||
tv.setVisibility(View.VISIBLE);
|
||||
tv.setPressed(false);
|
||||
tv.clearFocus();
|
||||
|
||||
Reference in New Issue
Block a user