diff options
4 files changed, 100 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index a48355b4fa12..1bc9a63ce75b 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -87,6 +87,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD private final static String TAG = "RecentsActivity"; private final static boolean DEBUG = false; + private final static String KEY_SAVED_STATE_HISTORY_VISIBLE = + "saved_instance_state_history_visible"; + public final static int EVENT_BUS_PRIORITY = Recents.EVENT_BUS_PRIORITY + 1; private RecentsPackageMonitor mPackageMonitor; @@ -500,6 +503,25 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD } @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(KEY_SAVED_STATE_HISTORY_VISIBLE, + (mHistoryView != null) && mHistoryView.isVisible()); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + if (savedInstanceState.getBoolean(KEY_SAVED_STATE_HISTORY_VISIBLE, false)) { + ReferenceCountedTrigger postHideStackAnimationTrigger = + new ReferenceCountedTrigger(this); + postHideStackAnimationTrigger.increment(); + EventBus.getDefault().send(new ShowHistoryEvent(postHideStackAnimationTrigger)); + postHideStackAnimationTrigger.decrement(); + } + } + + @Override public void onTrimMemory(int level) { RecentsTaskLoader loader = Recents.getTaskLoader(); if (loader != null) { diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java index 2eee1da10781..06265bd8c12b 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java @@ -110,7 +110,9 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd } } + private Context mContext; private LayoutInflater mLayoutInflater; + private final List<Task> mTasks = new ArrayList<>(); private final List<Row> mRows = new ArrayList<>(); public RecentsHistoryAdapter(Context context) { @@ -121,6 +123,10 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd * Updates this adapter with the given tasks. */ public void updateTasks(Context context, List<Task> tasks) { + mContext = context; + mTasks.clear(); + mTasks.addAll(tasks); + final Locale l = context.getResources().getConfiguration().locale; final String dateFormatStr = DateFormat.getBestDateTimePattern(l, "EEEEMMMMd"); final List<Task> tasksMostRecent = new ArrayList<>(tasks); @@ -144,6 +150,24 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd notifyDataSetChanged(); } + /** + * Removes historical tasks beloning to the specified package and user. + */ + public void removeTasks(String packageName, int userId) { + boolean packagesRemoved = false; + for (int i = mTasks.size() - 1; i >= 0; i--) { + Task task = mTasks.get(i); + String taskPackage = task.key.getComponent().getPackageName(); + if (task.key.userId == userId && taskPackage.equals(packageName)) { + mTasks.remove(i); + packagesRemoved = true; + } + } + if (packagesRemoved) { + updateTasks(mContext, new ArrayList<Task>(mTasks)); + } + } + @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java index e8e6dd7bd8d7..538ec93efeb6 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java @@ -16,6 +16,7 @@ package com.android.systemui.recents.history; +import android.content.ComponentName; import android.content.Context; import android.content.res.Resources; import android.graphics.Rect; @@ -29,9 +30,18 @@ import android.view.animation.Interpolator; import android.widget.LinearLayout; import com.android.systemui.R; import com.android.systemui.recents.Recents; +import com.android.systemui.recents.RecentsActivity; import com.android.systemui.recents.RecentsConfiguration; +import com.android.systemui.recents.events.EventBus; +import com.android.systemui.recents.events.activity.PackagesChangedEvent; import com.android.systemui.recents.misc.ReferenceCountedTrigger; +import com.android.systemui.recents.misc.SystemServicesProxy; +import com.android.systemui.recents.model.Task; import com.android.systemui.recents.model.TaskStack; +import com.android.systemui.recents.views.TaskView; + +import java.util.ArrayList; +import java.util.HashSet; /** * A list of the recent tasks that are not in the stack. @@ -169,8 +179,27 @@ public class RecentsHistoryView extends LinearLayout { } @Override + protected void onAttachedToWindow() { + SystemServicesProxy ssp = Recents.getSystemServices(); + EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); + super.onAttachedToWindow(); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + EventBus.getDefault().unregister(this); + } + + @Override public WindowInsets onApplyWindowInsets(WindowInsets insets) { setSystemInsets(insets.getSystemWindowInsets()); return insets; } + + /**** EventBus Events ****/ + + public final void onBusEvent(PackagesChangedEvent event) { + mAdapter.removeTasks(event.packageName, event.userId); + } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index 9e2107213839..9d7a927f4423 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -27,6 +27,7 @@ import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; +import android.os.Parcelable; import android.util.IntProperty; import android.util.Log; import android.util.Property; @@ -91,6 +92,12 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal private final static String TAG = "TaskStackView"; private final static boolean DEBUG = false; + private final static String KEY_SAVED_STATE_SUPER = "saved_instance_state_super"; + private final static String KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE = + "saved_instance_state_layout_focused_state"; + private final static String KEY_SAVED_STATE_LAYOUT_STACK_SCROLL = + "saved_instance_state_layout_stack_scroll"; + // The thresholds at which to show/hide the history button. private static final float SHOW_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f; private static final float HIDE_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f; @@ -828,6 +835,24 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal } @Override + protected Parcelable onSaveInstanceState() { + Bundle savedState = new Bundle(); + savedState.putParcelable(KEY_SAVED_STATE_SUPER, super.onSaveInstanceState()); + savedState.putFloat(KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE, mLayoutAlgorithm.getFocusState()); + savedState.putFloat(KEY_SAVED_STATE_LAYOUT_STACK_SCROLL, mStackScroller.getStackScroll()); + return super.onSaveInstanceState(); + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + Bundle savedState = (Bundle) state; + super.onRestoreInstanceState(savedState.getParcelable(KEY_SAVED_STATE_SUPER)); + + mLayoutAlgorithm.setFocusState(savedState.getFloat(KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE)); + mStackScroller.setStackScroll(savedState.getFloat(KEY_SAVED_STATE_LAYOUT_STACK_SCROLL)); + } + + @Override public CharSequence getAccessibilityClassName() { return TaskStackView.class.getName(); } |