blob: ada30acc68cf27960c7c96b74e3f64053793582f [file] [log] [blame]
Jim Miller44c66fe2010-10-20 18:32:52 -07001/*
Jim Miller9f0f0e02011-05-17 20:06:29 -07002 * Copyright (C) 2011 The Android Open Source Project
Jim Miller44c66fe2010-10-20 18:32:52 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jim Miller9f0f0e02011-05-17 20:06:29 -070017package com.android.systemui.recent;
Jim Miller44c66fe2010-10-20 18:32:52 -070018
Michael Jurka3b1fc472011-06-13 10:54:40 -070019import android.animation.Animator;
Jim Miller9f0f0e02011-05-17 20:06:29 -070020import android.animation.LayoutTransition;
Michael Jurka9bdaada2012-10-01 13:58:29 +020021import android.animation.TimeInterpolator;
Jim Miller44c66fe2010-10-20 18:32:52 -070022import android.app.ActivityManager;
Michael Jurka56a57832012-05-14 13:24:43 -070023import android.app.ActivityManagerNative;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070024import android.app.ActivityOptions;
Adam Powell0fc5b2b2012-07-18 18:20:29 -070025import android.app.TaskStackBuilder;
Jim Miller44c66fe2010-10-20 18:32:52 -070026import android.content.Context;
27import android.content.Intent;
Michael Jurka9bdaada2012-10-01 13:58:29 +020028import android.content.res.Configuration;
Michael Jurkabfd24ac2011-11-13 13:50:38 -080029import android.content.res.Resources;
Daniel Sandler4a066c52012-04-20 14:49:13 -040030import android.content.res.TypedArray;
Jim Miller44c66fe2010-10-20 18:32:52 -070031import android.graphics.Bitmap;
Jim Millerfefef312010-11-09 14:08:39 -080032import android.graphics.Matrix;
Jim Millere5c16ab2010-12-03 19:18:38 -080033import android.graphics.Shader.TileMode;
34import android.graphics.drawable.BitmapDrawable;
Michael Jurka99a96552012-01-27 17:23:38 -080035import android.graphics.drawable.Drawable;
Jim Millerc0d27312011-07-14 18:54:01 -070036import android.net.Uri;
Michael Jurka482f1592012-09-13 11:05:59 -070037import android.os.Bundle;
Michael Jurka56a57832012-05-14 13:24:43 -070038import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070039import android.os.UserHandle;
Jim Millerc0d27312011-07-14 18:54:01 -070040import android.provider.Settings;
Jim Miller44c66fe2010-10-20 18:32:52 -070041import android.util.AttributeSet;
42import android.util.Log;
Jim Miller5fda69c2011-02-16 15:17:11 -080043import android.view.LayoutInflater;
Jim Millerc0d27312011-07-14 18:54:01 -070044import android.view.MenuItem;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070045import android.view.MotionEvent;
Jim Miller44c66fe2010-10-20 18:32:52 -070046import android.view.View;
Jim Miller5fda69c2011-02-16 15:17:11 -080047import android.view.ViewGroup;
Michael Jurkae0523f72013-04-08 15:44:00 -070048import android.view.ViewPropertyAnimator;
Michael Jurkaf42d90102013-05-08 18:00:04 +020049import android.view.ViewRootImpl;
Jim Miller17377762011-10-11 15:33:34 -070050import android.view.accessibility.AccessibilityEvent;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070051import android.view.animation.AnimationUtils;
Michael Jurka9bdaada2012-10-01 13:58:29 +020052import android.view.animation.DecelerateInterpolator;
Jim Miller5fda69c2011-02-16 15:17:11 -080053import android.widget.AdapterView;
Michael Jurkabfd24ac2011-11-13 13:50:38 -080054import android.widget.AdapterView.OnItemClickListener;
Jim Miller5fda69c2011-02-16 15:17:11 -080055import android.widget.BaseAdapter;
Michael Jurka99a96552012-01-27 17:23:38 -080056import android.widget.FrameLayout;
Jim Miller44c66fe2010-10-20 18:32:52 -070057import android.widget.ImageView;
Michael Jurkabfd24ac2011-11-13 13:50:38 -080058import android.widget.ImageView.ScaleType;
Jim Millerc0d27312011-07-14 18:54:01 -070059import android.widget.PopupMenu;
Jim Miller44c66fe2010-10-20 18:32:52 -070060import android.widget.TextView;
Jim Miller44c66fe2010-10-20 18:32:52 -070061
62import com.android.systemui.R;
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -050063import com.android.systemui.statusbar.BaseStatusBar;
John Spurlockb0e49fc2013-06-12 15:50:50 -040064import com.android.systemui.statusbar.StatusBarPanel;
Michael Jurka3b1fc472011-06-13 10:54:40 -070065import com.android.systemui.statusbar.phone.PhoneStatusBar;
Jim Miller44c66fe2010-10-20 18:32:52 -070066
Michael Jurkabfd24ac2011-11-13 13:50:38 -080067import java.util.ArrayList;
68
Michael Jurka99a96552012-01-27 17:23:38 -080069public class RecentsPanelView extends FrameLayout implements OnItemClickListener, RecentsCallback,
Michael Jurka80343f62012-10-18 13:13:46 +020070 StatusBarPanel, Animator.AnimatorListener {
Michael Jurka3cd0a592011-08-16 12:40:30 -070071 static final String TAG = "RecentsPanelView";
John Spurlockb0e49fc2013-06-12 15:50:50 -040072 static final boolean DEBUG = PhoneStatusBar.DEBUG || false;
Michael Jurkacb466432012-04-03 05:22:45 -070073 private PopupMenu mPopup;
Jim Miller85babff2011-01-11 14:26:03 -080074 private View mRecentsScrim;
Michael Jurka6d667082011-09-16 17:04:40 -070075 private View mRecentsNoApps;
Jim Millerc0d27312011-07-14 18:54:01 -070076 private ViewGroup mRecentsContainer;
Peter Ng622a9762011-08-29 10:56:53 -070077
Jim Miller85babff2011-01-11 14:26:03 -080078 private boolean mShowing;
Michael Jurka99a96552012-01-27 17:23:38 -080079 private boolean mWaitingToShow;
Michael Jurka9bdaada2012-10-01 13:58:29 +020080 private ViewHolder mItemToAnimateInWhenWindowAnimationIsFinished;
Michael Jurkad894c8c2012-11-20 16:46:09 -080081 private boolean mAnimateIconOfFirstTask;
Michael Jurka80343f62012-10-18 13:13:46 +020082 private boolean mWaitingForWindowAnimation;
Michael Jurkad894c8c2012-11-20 16:46:09 -080083 private long mWindowAnimationStartTime;
Michael Jurka0e7757b2013-03-04 16:18:51 +010084 private boolean mCallUiHiddenBeforeNextReload;
Michael Jurka21385cd2012-05-03 10:57:31 -070085
Michael Jurkaab48b682011-09-12 15:39:45 -070086 private RecentTasksLoader mRecentTasksLoader;
87 private ArrayList<TaskDescription> mRecentTaskDescriptions;
88 private TaskDescriptionAdapter mListAdapter;
89 private int mThumbnailWidth;
Michael Jurkabfd24ac2011-11-13 13:50:38 -080090 private boolean mFitThumbnailToXY;
Daniel Sandler4a066c52012-04-20 14:49:13 -040091 private int mRecentItemLayoutId;
Michael Jurkac016aaa2012-06-05 17:22:24 -070092 private boolean mHighEndGfx;
Dianne Hackborneeb1dca2011-09-08 13:30:11 -070093
Michael Jurka4eaa9832012-02-29 15:51:49 -080094 public static interface RecentsScrollView {
95 public int numItemsInOneScreenful();
96 public void setAdapter(TaskDescriptionAdapter adapter);
97 public void setCallback(RecentsCallback callback);
98 public void setMinSwipeAlpha(float minAlpha);
Michael Jurkae5923632012-10-03 15:29:36 +020099 public View findViewForTask(int persistentTaskId);
Michael Jurka4eaa9832012-02-29 15:51:49 -0800100 }
101
Jim Millerc0d27312011-07-14 18:54:01 -0700102 private final class OnLongClickDelegate implements View.OnLongClickListener {
103 View mOtherView;
104 OnLongClickDelegate(View other) {
105 mOtherView = other;
106 }
107 public boolean onLongClick(View v) {
108 return mOtherView.performLongClick();
109 }
110 }
111
Jim Millerb5a2b292011-03-01 16:14:59 -0800112 /* package */ final static class ViewHolder {
Jim Millerc0d27312011-07-14 18:54:01 -0700113 View thumbnailView;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700114 ImageView thumbnailViewImage;
Michael Jurka412cba82011-10-17 09:05:00 -0700115 Bitmap thumbnailViewImageBitmap;
Jim Miller9f0f0e02011-05-17 20:06:29 -0700116 ImageView iconView;
117 TextView labelView;
118 TextView descriptionView;
Michael Jurka9bdaada2012-10-01 13:58:29 +0200119 View calloutLine;
Michael Jurkaab48b682011-09-12 15:39:45 -0700120 TaskDescription taskDescription;
Michael Jurka99a96552012-01-27 17:23:38 -0800121 boolean loadedThumbnailAndIcon;
Jim Miller5fda69c2011-02-16 15:17:11 -0800122 }
123
Michael Jurkaab48b682011-09-12 15:39:45 -0700124 /* package */ final class TaskDescriptionAdapter extends BaseAdapter {
Jim Miller5fda69c2011-02-16 15:17:11 -0800125 private LayoutInflater mInflater;
126
Michael Jurkaab48b682011-09-12 15:39:45 -0700127 public TaskDescriptionAdapter(Context context) {
Jim Miller5fda69c2011-02-16 15:17:11 -0800128 mInflater = LayoutInflater.from(context);
129 }
130
131 public int getCount() {
Michael Jurkaab48b682011-09-12 15:39:45 -0700132 return mRecentTaskDescriptions != null ? mRecentTaskDescriptions.size() : 0;
Jim Miller5fda69c2011-02-16 15:17:11 -0800133 }
134
135 public Object getItem(int position) {
136 return position; // we only need the index
137 }
138
139 public long getItemId(int position) {
140 return position; // we just need something unique for this position
141 }
142
Michael Jurka99a96552012-01-27 17:23:38 -0800143 public View createView(ViewGroup parent) {
Daniel Sandler4a066c52012-04-20 14:49:13 -0400144 View convertView = mInflater.inflate(mRecentItemLayoutId, parent, false);
Michael Jurka99a96552012-01-27 17:23:38 -0800145 ViewHolder holder = new ViewHolder();
146 holder.thumbnailView = convertView.findViewById(R.id.app_thumbnail);
147 holder.thumbnailViewImage =
148 (ImageView) convertView.findViewById(R.id.app_thumbnail_image);
149 // If we set the default thumbnail now, we avoid an onLayout when we update
150 // the thumbnail later (if they both have the same dimensions)
Michael Jurka80343f62012-10-18 13:13:46 +0200151 updateThumbnail(holder, mRecentTasksLoader.getDefaultThumbnail(), false, false);
Michael Jurka99a96552012-01-27 17:23:38 -0800152 holder.iconView = (ImageView) convertView.findViewById(R.id.app_icon);
Michael Jurka80343f62012-10-18 13:13:46 +0200153 holder.iconView.setImageBitmap(mRecentTasksLoader.getDefaultIcon());
Michael Jurka99a96552012-01-27 17:23:38 -0800154 holder.labelView = (TextView) convertView.findViewById(R.id.app_label);
Michael Jurka9bdaada2012-10-01 13:58:29 +0200155 holder.calloutLine = convertView.findViewById(R.id.recents_callout_line);
Michael Jurka99a96552012-01-27 17:23:38 -0800156 holder.descriptionView = (TextView) convertView.findViewById(R.id.app_description);
157
158 convertView.setTag(holder);
159 return convertView;
160 }
161
162 public View getView(int position, View convertView, ViewGroup parent) {
163 if (convertView == null) {
164 convertView = createView(parent);
165 }
Michael Jurka12cdec92013-02-07 17:51:09 +0100166 final ViewHolder holder = (ViewHolder) convertView.getTag();
Jim Miller5fda69c2011-02-16 15:17:11 -0800167
Michael Jurkaab48b682011-09-12 15:39:45 -0700168 // index is reverse since most recent appears at the bottom...
169 final int index = mRecentTaskDescriptions.size() - position - 1;
Jim Miller5fda69c2011-02-16 15:17:11 -0800170
Michael Jurka412cba82011-10-17 09:05:00 -0700171 final TaskDescription td = mRecentTaskDescriptions.get(index);
Michael Jurka99a96552012-01-27 17:23:38 -0800172
Michael Jurka412cba82011-10-17 09:05:00 -0700173 holder.labelView.setText(td.getLabel());
174 holder.thumbnailView.setContentDescription(td.getLabel());
Michael Jurka99a96552012-01-27 17:23:38 -0800175 holder.loadedThumbnailAndIcon = td.isLoaded();
176 if (td.isLoaded()) {
177 updateThumbnail(holder, td.getThumbnail(), true, false);
178 updateIcon(holder, td.getIcon(), true, false);
Michael Jurka99a96552012-01-27 17:23:38 -0800179 }
Michael Jurka9bdaada2012-10-01 13:58:29 +0200180 if (index == 0) {
Michael Jurkad894c8c2012-11-20 16:46:09 -0800181 if (mAnimateIconOfFirstTask) {
Michael Jurka0e7757b2013-03-04 16:18:51 +0100182 ViewHolder oldHolder = mItemToAnimateInWhenWindowAnimationIsFinished;
183 if (oldHolder != null) {
184 oldHolder.iconView.setAlpha(1f);
185 oldHolder.iconView.setTranslationX(0f);
186 oldHolder.iconView.setTranslationY(0f);
187 oldHolder.labelView.setAlpha(1f);
188 oldHolder.labelView.setTranslationX(0f);
189 oldHolder.labelView.setTranslationY(0f);
190 if (oldHolder.calloutLine != null) {
191 oldHolder.calloutLine.setAlpha(1f);
192 oldHolder.calloutLine.setTranslationX(0f);
193 oldHolder.calloutLine.setTranslationY(0f);
Michael Jurkaa9240762012-10-17 13:02:55 +0200194 }
195 }
Michael Jurkae0523f72013-04-08 15:44:00 -0700196 mItemToAnimateInWhenWindowAnimationIsFinished = holder;
197 int translation = -getResources().getDimensionPixelSize(
198 R.dimen.status_bar_recents_app_icon_translate_distance);
199 final Configuration config = getResources().getConfiguration();
200 if (config.orientation == Configuration.ORIENTATION_PORTRAIT) {
201 if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
202 translation = -translation;
Michael Jurka12cdec92013-02-07 17:51:09 +0100203 }
Michael Jurkae0523f72013-04-08 15:44:00 -0700204 holder.iconView.setAlpha(0f);
205 holder.iconView.setTranslationX(translation);
206 holder.labelView.setAlpha(0f);
207 holder.labelView.setTranslationX(translation);
208 holder.calloutLine.setAlpha(0f);
209 holder.calloutLine.setTranslationX(translation);
210 } else {
211 holder.iconView.setAlpha(0f);
212 holder.iconView.setTranslationY(translation);
213 }
214 if (!mWaitingForWindowAnimation) {
215 animateInIconOfFirstTask();
216 }
Michael Jurka9bdaada2012-10-01 13:58:29 +0200217 }
218 }
Michael Jurkaab48b682011-09-12 15:39:45 -0700219
Michael Jurka412cba82011-10-17 09:05:00 -0700220 holder.thumbnailView.setTag(td);
Jim Millerc0d27312011-07-14 18:54:01 -0700221 holder.thumbnailView.setOnLongClickListener(new OnLongClickDelegate(convertView));
Michael Jurka412cba82011-10-17 09:05:00 -0700222 holder.taskDescription = td;
Jim Miller5fda69c2011-02-16 15:17:11 -0800223 return convertView;
224 }
Michael Jurka99a96552012-01-27 17:23:38 -0800225
226 public void recycleView(View v) {
227 ViewHolder holder = (ViewHolder) v.getTag();
228 updateThumbnail(holder, mRecentTasksLoader.getDefaultThumbnail(), false, false);
229 holder.iconView.setImageBitmap(mRecentTasksLoader.getDefaultIcon());
230 holder.iconView.setVisibility(INVISIBLE);
Michael Jurkad894c8c2012-11-20 16:46:09 -0800231 holder.iconView.animate().cancel();
Michael Jurka99a96552012-01-27 17:23:38 -0800232 holder.labelView.setText(null);
Michael Jurkad894c8c2012-11-20 16:46:09 -0800233 holder.labelView.animate().cancel();
Michael Jurka99a96552012-01-27 17:23:38 -0800234 holder.thumbnailView.setContentDescription(null);
235 holder.thumbnailView.setTag(null);
236 holder.thumbnailView.setOnLongClickListener(null);
237 holder.thumbnailView.setVisibility(INVISIBLE);
Michael Jurkafe09ad82012-10-22 13:58:38 -0700238 holder.iconView.setAlpha(1f);
239 holder.iconView.setTranslationX(0f);
240 holder.iconView.setTranslationY(0f);
241 holder.labelView.setAlpha(1f);
242 holder.labelView.setTranslationX(0f);
243 holder.labelView.setTranslationY(0f);
244 if (holder.calloutLine != null) {
245 holder.calloutLine.setAlpha(1f);
246 holder.calloutLine.setTranslationX(0f);
247 holder.calloutLine.setTranslationY(0f);
Michael Jurkad894c8c2012-11-20 16:46:09 -0800248 holder.calloutLine.animate().cancel();
Michael Jurkafe09ad82012-10-22 13:58:38 -0700249 }
Michael Jurka99a96552012-01-27 17:23:38 -0800250 holder.taskDescription = null;
251 holder.loadedThumbnailAndIcon = false;
252 }
253 }
254
Michael Jurka8b2e37e2012-05-08 20:06:13 -0700255 public RecentsPanelView(Context context, AttributeSet attrs) {
256 this(context, attrs, 0);
257 }
258
259 public RecentsPanelView(Context context, AttributeSet attrs, int defStyle) {
260 super(context, attrs, defStyle);
Michael Jurka8b2e37e2012-05-08 20:06:13 -0700261 updateValuesFromResources();
262
263 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecentsPanelView,
264 defStyle, 0);
265
266 mRecentItemLayoutId = a.getResourceId(R.styleable.RecentsPanelView_recentItemLayout, 0);
Michael Jurka80343f62012-10-18 13:13:46 +0200267 mRecentTasksLoader = RecentTasksLoader.getInstance(context);
Michael Jurka8b2e37e2012-05-08 20:06:13 -0700268 a.recycle();
269 }
270
Michael Jurka99a96552012-01-27 17:23:38 -0800271 public int numItemsInOneScreenful() {
Michael Jurka4eaa9832012-02-29 15:51:49 -0800272 if (mRecentsContainer instanceof RecentsScrollView){
273 RecentsScrollView scrollView
274 = (RecentsScrollView) mRecentsContainer;
Michael Jurka99a96552012-01-27 17:23:38 -0800275 return scrollView.numItemsInOneScreenful();
Michael Jurka4eaa9832012-02-29 15:51:49 -0800276 } else {
Michael Jurka99a96552012-01-27 17:23:38 -0800277 throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
278 }
Jim Miller5fda69c2011-02-16 15:17:11 -0800279 }
280
Daniel Sandler328310c2011-09-23 15:56:52 -0400281 private boolean pointInside(int x, int y, View v) {
282 final int l = v.getLeft();
283 final int r = v.getRight();
284 final int t = v.getTop();
285 final int b = v.getBottom();
Jim Miller44c66fe2010-10-20 18:32:52 -0700286 return x >= l && x < r && y >= t && y < b;
287 }
288
Daniel Sandler328310c2011-09-23 15:56:52 -0400289 public boolean isInContentArea(int x, int y) {
John Spurlockb0e49fc2013-06-12 15:50:50 -0400290 return pointInside(x, y, mRecentsContainer);
Daniel Sandler328310c2011-09-23 15:56:52 -0400291 }
292
Michael Jurkacb2522c2012-04-13 09:32:47 -0700293 public void show(boolean show) {
Michael Jurka80343f62012-10-18 13:13:46 +0200294 show(show, null, false, false);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700295 }
296
297 public void show(boolean show, ArrayList<TaskDescription> recentTaskDescriptions,
Michael Jurkad894c8c2012-11-20 16:46:09 -0800298 boolean firstScreenful, boolean animateIconOfFirstTask) {
Michael Jurka0e7757b2013-03-04 16:18:51 +0100299 if (show && mCallUiHiddenBeforeNextReload) {
300 onUiHidden();
301 recentTaskDescriptions = null;
302 mAnimateIconOfFirstTask = false;
303 mWaitingForWindowAnimation = false;
304 } else {
305 mAnimateIconOfFirstTask = animateIconOfFirstTask;
306 mWaitingForWindowAnimation = animateIconOfFirstTask;
307 }
Michael Jurka99a96552012-01-27 17:23:38 -0800308 if (show) {
309 mWaitingToShow = true;
Michael Jurkacb2522c2012-04-13 09:32:47 -0700310 refreshRecentTasksList(recentTaskDescriptions, firstScreenful);
Michael Jurka99a96552012-01-27 17:23:38 -0800311 showIfReady();
312 } else {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700313 showImpl(false);
Michael Jurka99a96552012-01-27 17:23:38 -0800314 }
315 }
316
317 private void showIfReady() {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700318 // mWaitingToShow => there was a touch up on the recents button
319 // mRecentTaskDescriptions != null => we've created views for the first screenful of items
320 if (mWaitingToShow && mRecentTaskDescriptions != null) {
321 showImpl(true);
Michael Jurka99a96552012-01-27 17:23:38 -0800322 }
Michael Jurkaab48b682011-09-12 15:39:45 -0700323 }
324
Michael Jurka56a57832012-05-14 13:24:43 -0700325 static void sendCloseSystemWindows(Context context, String reason) {
326 if (ActivityManagerNative.isSystemReady()) {
327 try {
328 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
329 } catch (RemoteException e) {
330 }
331 }
332 }
333
Michael Jurkacb2522c2012-04-13 09:32:47 -0700334 private void showImpl(boolean show) {
Michael Jurka56a57832012-05-14 13:24:43 -0700335 sendCloseSystemWindows(mContext, BaseStatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS);
336
Michael Jurkacb2522c2012-04-13 09:32:47 -0700337 mShowing = show;
338
Michael Jurka7daf95d2011-09-30 11:07:30 -0700339 if (show) {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700340 // if there are no apps, bring up a "No recent apps" message
341 boolean noApps = mRecentTaskDescriptions != null
342 && (mRecentTaskDescriptions.size() == 0);
343 mRecentsNoApps.setAlpha(1f);
344 mRecentsNoApps.setVisibility(noApps ? View.VISIBLE : View.INVISIBLE);
Michael Jurka7daf95d2011-09-30 11:07:30 -0700345
Michael Jurkaab48b682011-09-12 15:39:45 -0700346 onAnimationEnd(null);
Michael Jurkae9166ed2011-07-27 18:23:18 -0700347 setFocusable(true);
348 setFocusableInTouchMode(true);
349 requestFocus();
Michael Jurkacb466432012-04-03 05:22:45 -0700350 } else {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700351 mWaitingToShow = false;
352 // call onAnimationEnd() and clearRecentTasksList() in onUiHidden()
Michael Jurka0e7757b2013-03-04 16:18:51 +0100353 mCallUiHiddenBeforeNextReload = true;
Michael Jurkacb466432012-04-03 05:22:45 -0700354 if (mPopup != null) {
355 mPopup.dismiss();
356 }
Michael Jurkae9166ed2011-07-27 18:23:18 -0700357 }
Jim Miller85babff2011-01-11 14:26:03 -0800358 }
359
Michael Jurkaf42d90102013-05-08 18:00:04 +0200360 protected void onAttachedToWindow () {
361 super.onAttachedToWindow();
362 final ViewRootImpl root = getViewRootImpl();
363 if (root != null) {
364 root.setDrawDuringWindowsAnimating(true);
365 }
366 }
367
Michael Jurkacb2522c2012-04-13 09:32:47 -0700368 public void onUiHidden() {
Michael Jurka0e7757b2013-03-04 16:18:51 +0100369 mCallUiHiddenBeforeNextReload = false;
Michael Jurkacb2522c2012-04-13 09:32:47 -0700370 if (!mShowing && mRecentTaskDescriptions != null) {
371 onAnimationEnd(null);
372 clearRecentTasksList();
373 }
Michael Jurkac6461ca2011-09-02 12:12:15 -0700374 }
375
Michael Jurkacb2522c2012-04-13 09:32:47 -0700376 public void dismiss() {
377 ((RecentsActivity) mContext).dismissAndGoHome();
378 }
379
380 public void dismissAndGoBack() {
381 ((RecentsActivity) mContext).dismissAndGoBack();
Michael Jurka8b098662011-09-01 17:00:53 -0700382 }
383
Michael Jurka3b1fc472011-06-13 10:54:40 -0700384 public void onAnimationCancel(Animator animation) {
385 }
386
387 public void onAnimationEnd(Animator animation) {
388 if (mShowing) {
389 final LayoutTransition transitioner = new LayoutTransition();
390 ((ViewGroup)mRecentsContainer).setLayoutTransition(transitioner);
391 createCustomAnimations(transitioner);
392 } else {
393 ((ViewGroup)mRecentsContainer).setLayoutTransition(null);
394 }
395 }
396
397 public void onAnimationRepeat(Animator animation) {
398 }
399
400 public void onAnimationStart(Animator animation) {
401 }
402
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700403 @Override
404 public boolean dispatchHoverEvent(MotionEvent event) {
405 // Ignore hover events outside of this panel bounds since such events
406 // generate spurious accessibility events with the panel content when
407 // tapping outside of it, thus confusing the user.
408 final int x = (int) event.getX();
409 final int y = (int) event.getY();
410 if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
411 return super.dispatchHoverEvent(event);
412 }
413 return true;
414 }
415
Jim Miller85babff2011-01-11 14:26:03 -0800416 /**
417 * Whether the panel is showing, or, if it's animating, whether it will be
418 * when the animation is done.
419 */
420 public boolean isShowing() {
421 return mShowing;
422 }
423
Daniel Sandler328310c2011-09-23 15:56:52 -0400424 public void setRecentTasksLoader(RecentTasksLoader loader) {
425 mRecentTasksLoader = loader;
426 }
427
Michael Jurkaab48b682011-09-12 15:39:45 -0700428 public void updateValuesFromResources() {
Michael Jurkabfd24ac2011-11-13 13:50:38 -0800429 final Resources res = mContext.getResources();
430 mThumbnailWidth = Math.round(res.getDimension(R.dimen.status_bar_recents_thumbnail_width));
431 mFitThumbnailToXY = res.getBoolean(R.bool.config_recents_thumbnail_image_fits_to_xy);
Jim Miller44c66fe2010-10-20 18:32:52 -0700432 }
433
434 @Override
435 protected void onFinishInflate() {
436 super.onFinishInflate();
Daniel Sandler4a066c52012-04-20 14:49:13 -0400437
Jim Millerc0d27312011-07-14 18:54:01 -0700438 mRecentsContainer = (ViewGroup) findViewById(R.id.recents_container);
Michael Jurkaab48b682011-09-12 15:39:45 -0700439 mListAdapter = new TaskDescriptionAdapter(mContext);
Michael Jurka4eaa9832012-02-29 15:51:49 -0800440 if (mRecentsContainer instanceof RecentsScrollView){
441 RecentsScrollView scrollView
442 = (RecentsScrollView) mRecentsContainer;
Jim Miller9f0f0e02011-05-17 20:06:29 -0700443 scrollView.setAdapter(mListAdapter);
444 scrollView.setCallback(this);
Michael Jurka4eaa9832012-02-29 15:51:49 -0800445 } else {
Michael Jurka3cd0a592011-08-16 12:40:30 -0700446 throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
Jim Miller9f0f0e02011-05-17 20:06:29 -0700447 }
Jim Miller5fda69c2011-02-16 15:17:11 -0800448
Michael Jurka6d667082011-09-16 17:04:40 -0700449 mRecentsScrim = findViewById(R.id.recents_bg_protect);
450 mRecentsNoApps = findViewById(R.id.recents_no_apps);
Jim Millere5c16ab2010-12-03 19:18:38 -0800451
Michael Jurkaf16fc512012-02-27 15:02:23 -0800452 if (mRecentsScrim != null) {
Jeff Brown98365d72012-08-19 20:30:52 -0700453 mHighEndGfx = ActivityManager.isHighEndGfx();
Michael Jurkac016aaa2012-06-05 17:22:24 -0700454 if (!mHighEndGfx) {
Michael Jurkad5895a72012-05-12 13:24:58 -0700455 mRecentsScrim.setBackground(null);
Michael Jurkaf16fc512012-02-27 15:02:23 -0800456 } else if (mRecentsScrim.getBackground() instanceof BitmapDrawable) {
457 // In order to save space, we make the background texture repeat in the Y direction
458 ((BitmapDrawable) mRecentsScrim.getBackground()).setTileModeY(TileMode.REPEAT);
459 }
Jim Millere5c16ab2010-12-03 19:18:38 -0800460 }
461 }
462
Michael Jurka4eaa9832012-02-29 15:51:49 -0800463 public void setMinSwipeAlpha(float minAlpha) {
464 if (mRecentsContainer instanceof RecentsScrollView){
465 RecentsScrollView scrollView
466 = (RecentsScrollView) mRecentsContainer;
467 scrollView.setMinSwipeAlpha(minAlpha);
468 }
469 }
470
Jim Miller9f0f0e02011-05-17 20:06:29 -0700471 private void createCustomAnimations(LayoutTransition transitioner) {
Chet Haase212f6252011-08-12 09:19:10 -0700472 transitioner.setDuration(200);
473 transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
474 transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
Jim Miller9f0f0e02011-05-17 20:06:29 -0700475 }
476
Michael Jurka99a96552012-01-27 17:23:38 -0800477 private void updateIcon(ViewHolder h, Drawable icon, boolean show, boolean anim) {
478 if (icon != null) {
479 h.iconView.setImageDrawable(icon);
480 if (show && h.iconView.getVisibility() != View.VISIBLE) {
481 if (anim) {
482 h.iconView.setAnimation(
483 AnimationUtils.loadAnimation(mContext, R.anim.recent_appear));
484 }
485 h.iconView.setVisibility(View.VISIBLE);
486 }
487 }
488 }
489
Michael Jurka412cba82011-10-17 09:05:00 -0700490 private void updateThumbnail(ViewHolder h, Bitmap thumbnail, boolean show, boolean anim) {
Michael Jurkaab48b682011-09-12 15:39:45 -0700491 if (thumbnail != null) {
492 // Should remove the default image in the frame
493 // that this now covers, to improve scrolling speed.
494 // That can't be done until the anim is complete though.
495 h.thumbnailViewImage.setImageBitmap(thumbnail);
Michael Jurka412cba82011-10-17 09:05:00 -0700496
497 // scale the image to fill the full width of the ImageView. do this only if
498 // we haven't set a bitmap before, or if the bitmap size has changed
499 if (h.thumbnailViewImageBitmap == null ||
500 h.thumbnailViewImageBitmap.getWidth() != thumbnail.getWidth() ||
501 h.thumbnailViewImageBitmap.getHeight() != thumbnail.getHeight()) {
Michael Jurkabfd24ac2011-11-13 13:50:38 -0800502 if (mFitThumbnailToXY) {
503 h.thumbnailViewImage.setScaleType(ScaleType.FIT_XY);
504 } else {
505 Matrix scaleMatrix = new Matrix();
506 float scale = mThumbnailWidth / (float) thumbnail.getWidth();
507 scaleMatrix.setScale(scale, scale);
508 h.thumbnailViewImage.setScaleType(ScaleType.MATRIX);
509 h.thumbnailViewImage.setImageMatrix(scaleMatrix);
510 }
Jim Miller44c66fe2010-10-20 18:32:52 -0700511 }
Michael Jurka412cba82011-10-17 09:05:00 -0700512 if (show && h.thumbnailView.getVisibility() != View.VISIBLE) {
513 if (anim) {
514 h.thumbnailView.setAnimation(
515 AnimationUtils.loadAnimation(mContext, R.anim.recent_appear));
516 }
517 h.thumbnailView.setVisibility(View.VISIBLE);
518 }
519 h.thumbnailViewImageBitmap = thumbnail;
Jim Miller44c66fe2010-10-20 18:32:52 -0700520 }
Jim Millerfefef312010-11-09 14:08:39 -0800521 }
522
Michael Jurka99a96552012-01-27 17:23:38 -0800523 void onTaskThumbnailLoaded(TaskDescription td) {
524 synchronized (td) {
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700525 if (mRecentsContainer != null) {
526 ViewGroup container = mRecentsContainer;
Michael Jurka4eaa9832012-02-29 15:51:49 -0800527 if (container instanceof RecentsScrollView) {
Michael Jurka99a96552012-01-27 17:23:38 -0800528 container = (ViewGroup) container.findViewById(
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700529 R.id.recents_linear_layout);
530 }
531 // Look for a view showing this thumbnail, to update.
Michael Jurka99a96552012-01-27 17:23:38 -0800532 for (int i=0; i < container.getChildCount(); i++) {
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700533 View v = container.getChildAt(i);
534 if (v.getTag() instanceof ViewHolder) {
535 ViewHolder h = (ViewHolder)v.getTag();
Michael Jurka99a96552012-01-27 17:23:38 -0800536 if (!h.loadedThumbnailAndIcon && h.taskDescription == td) {
Michael Jurka412cba82011-10-17 09:05:00 -0700537 // only fade in the thumbnail if recents is already visible-- we
538 // show it immediately otherwise
Michael Jurka99a96552012-01-27 17:23:38 -0800539 //boolean animateShow = mShowing &&
540 // mRecentsContainer.getAlpha() > ViewConfiguration.ALPHA_THRESHOLD;
541 boolean animateShow = false;
542 updateIcon(h, td.getIcon(), true, animateShow);
543 updateThumbnail(h, td.getThumbnail(), true, animateShow);
544 h.loadedThumbnailAndIcon = true;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700545 }
546 }
547 }
548 }
Craig Mautnerca6da002012-09-20 14:54:37 -0700549 }
Michael Jurka99a96552012-01-27 17:23:38 -0800550 showIfReady();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700551 }
552
Michael Jurkad894c8c2012-11-20 16:46:09 -0800553 private void animateInIconOfFirstTask() {
554 if (mItemToAnimateInWhenWindowAnimationIsFinished != null &&
555 !mRecentTasksLoader.isFirstScreenful()) {
556 int timeSinceWindowAnimation =
557 (int) (System.currentTimeMillis() - mWindowAnimationStartTime);
Michael Jurkaf42d90102013-05-08 18:00:04 +0200558 final int minStartDelay = 150;
Michael Jurkad894c8c2012-11-20 16:46:09 -0800559 final int startDelay = Math.max(0, Math.min(
560 minStartDelay - timeSinceWindowAnimation, minStartDelay));
Michael Jurka9bdaada2012-10-01 13:58:29 +0200561 final int duration = 250;
562 final ViewHolder holder = mItemToAnimateInWhenWindowAnimationIsFinished;
563 final TimeInterpolator cubic = new DecelerateInterpolator(1.5f);
Michael Jurkae0523f72013-04-08 15:44:00 -0700564 FirstFrameAnimatorHelper.initializeDrawListener(holder.iconView);
Michael Jurka9bdaada2012-10-01 13:58:29 +0200565 for (View v :
566 new View[] { holder.iconView, holder.labelView, holder.calloutLine }) {
567 if (v != null) {
Michael Jurkae0523f72013-04-08 15:44:00 -0700568 ViewPropertyAnimator vpa = v.animate().translationX(0).translationY(0)
569 .alpha(1f).setStartDelay(startDelay)
Michael Jurka9bdaada2012-10-01 13:58:29 +0200570 .setDuration(duration).setInterpolator(cubic);
Michael Jurkae0523f72013-04-08 15:44:00 -0700571 FirstFrameAnimatorHelper h = new FirstFrameAnimatorHelper(vpa, v);
Michael Jurka9bdaada2012-10-01 13:58:29 +0200572 }
573 }
574 mItemToAnimateInWhenWindowAnimationIsFinished = null;
Michael Jurkad894c8c2012-11-20 16:46:09 -0800575 mAnimateIconOfFirstTask = false;
Michael Jurka9bdaada2012-10-01 13:58:29 +0200576 }
577 }
578
Michael Jurkad894c8c2012-11-20 16:46:09 -0800579 public void onWindowAnimationStart() {
580 mWaitingForWindowAnimation = false;
581 mWindowAnimationStartTime = System.currentTimeMillis();
582 animateInIconOfFirstTask();
583 }
584
Michael Jurka412cba82011-10-17 09:05:00 -0700585 public void clearRecentTasksList() {
586 // Clear memory used by screenshots
Michael Jurkacb2522c2012-04-13 09:32:47 -0700587 if (mRecentTaskDescriptions != null) {
588 mRecentTasksLoader.cancelLoadingThumbnailsAndIcons(this);
589 onTaskLoadingCancelled();
590 }
591 }
592
593 public void onTaskLoadingCancelled() {
594 // Gets called by RecentTasksLoader when it's cancelled
595 if (mRecentTaskDescriptions != null) {
596 mRecentTaskDescriptions = null;
Michael Jurka412cba82011-10-17 09:05:00 -0700597 mListAdapter.notifyDataSetInvalidated();
Michael Jurka412cba82011-10-17 09:05:00 -0700598 }
599 }
600
Craig Mautnerca6da002012-09-20 14:54:37 -0700601 public void refreshViews() {
602 mListAdapter.notifyDataSetInvalidated();
603 updateUiElements();
604 showIfReady();
605 }
606
Michael Jurka412cba82011-10-17 09:05:00 -0700607 public void refreshRecentTasksList() {
Michael Jurka99a96552012-01-27 17:23:38 -0800608 refreshRecentTasksList(null, false);
Michael Jurka412cba82011-10-17 09:05:00 -0700609 }
610
Michael Jurka99a96552012-01-27 17:23:38 -0800611 private void refreshRecentTasksList(
612 ArrayList<TaskDescription> recentTasksList, boolean firstScreenful) {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700613 if (mRecentTaskDescriptions == null && recentTasksList != null) {
614 onTasksLoaded(recentTasksList, firstScreenful);
615 } else {
616 mRecentTasksLoader.loadTasksInBackground();
Michael Jurka412cba82011-10-17 09:05:00 -0700617 }
Michael Jurkaab48b682011-09-12 15:39:45 -0700618 }
Michael Jurka7daf95d2011-09-30 11:07:30 -0700619
Michael Jurkacb2522c2012-04-13 09:32:47 -0700620 public void onTasksLoaded(ArrayList<TaskDescription> tasks, boolean firstScreenful) {
Michael Jurka99a96552012-01-27 17:23:38 -0800621 if (mRecentTaskDescriptions == null) {
Craig Mautnerbb1449b2012-03-23 16:11:14 -0700622 mRecentTaskDescriptions = new ArrayList<TaskDescription>(tasks);
Michael Jurka99a96552012-01-27 17:23:38 -0800623 } else {
624 mRecentTaskDescriptions.addAll(tasks);
625 }
Michael Jurka7ed267f2012-10-09 17:03:30 +0200626 if (((RecentsActivity) mContext).isActivityShowing()) {
Craig Mautnerca6da002012-09-20 14:54:37 -0700627 refreshViews();
628 }
Michael Jurka99a96552012-01-27 17:23:38 -0800629 }
630
Craig Mautnerca6da002012-09-20 14:54:37 -0700631 private void updateUiElements() {
Dianne Hackborn8da429e2012-09-23 12:52:19 -0700632 final int items = mRecentTaskDescriptions != null
633 ? mRecentTaskDescriptions.size() : 0;
Michael Jurkaab48b682011-09-12 15:39:45 -0700634
635 mRecentsContainer.setVisibility(items > 0 ? View.VISIBLE : View.GONE);
Michael Jurkaab48b682011-09-12 15:39:45 -0700636
637 // Set description for accessibility
Dianne Hackborn8da429e2012-09-23 12:52:19 -0700638 int numRecentApps = mRecentTaskDescriptions != null
639 ? mRecentTaskDescriptions.size() : 0;
Michael Jurka7daf95d2011-09-30 11:07:30 -0700640 String recentAppsAccessibilityDescription;
641 if (numRecentApps == 0) {
642 recentAppsAccessibilityDescription =
643 getResources().getString(R.string.status_bar_no_recent_apps);
644 } else {
645 recentAppsAccessibilityDescription = getResources().getQuantityString(
646 R.plurals.status_bar_accessibility_recent_apps, numRecentApps, numRecentApps);
647 }
648 setContentDescription(recentAppsAccessibilityDescription);
Jim Miller44c66fe2010-10-20 18:32:52 -0700649 }
650
Michael Jurkae5923632012-10-03 15:29:36 +0200651 public boolean simulateClick(int persistentTaskId) {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700652 if (mRecentsContainer instanceof RecentsScrollView){
653 RecentsScrollView scrollView
654 = (RecentsScrollView) mRecentsContainer;
Michael Jurkae5923632012-10-03 15:29:36 +0200655 View v = scrollView.findViewForTask(persistentTaskId);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700656 if (v != null) {
657 handleOnClick(v);
658 return true;
659 }
660 }
661 return false;
662 }
Michael Jurkac016aaa2012-06-05 17:22:24 -0700663
Jim Miller9f0f0e02011-05-17 20:06:29 -0700664 public void handleOnClick(View view) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700665 ViewHolder holder = (ViewHolder)view.getTag();
666 TaskDescription ad = holder.taskDescription;
Jim Miller9f0f0e02011-05-17 20:06:29 -0700667 final Context context = view.getContext();
Jim Millere5c16ab2010-12-03 19:18:38 -0800668 final ActivityManager am = (ActivityManager)
Jim Miller9f0f0e02011-05-17 20:06:29 -0700669 context.getSystemService(Context.ACTIVITY_SERVICE);
Michael Jurkac016aaa2012-06-05 17:22:24 -0700670 Bitmap bm = holder.thumbnailViewImageBitmap;
671 boolean usingDrawingCache;
672 if (bm.getWidth() == holder.thumbnailViewImage.getWidth() &&
673 bm.getHeight() == holder.thumbnailViewImage.getHeight()) {
674 usingDrawingCache = false;
675 } else {
676 holder.thumbnailViewImage.setDrawingCacheEnabled(true);
677 bm = holder.thumbnailViewImage.getDrawingCache();
678 usingDrawingCache = true;
679 }
Michael Jurka482f1592012-09-13 11:05:59 -0700680 Bundle opts = (bm == null) ?
681 null :
682 ActivityOptions.makeThumbnailScaleUpAnimation(
683 holder.thumbnailViewImage, bm, 0, 0, null).toBundle();
Michael Jurkacb2522c2012-04-13 09:32:47 -0700684
685 show(false);
Jim Miller9f0f0e02011-05-17 20:06:29 -0700686 if (ad.taskId >= 0) {
Dianne Hackbornb6777462010-11-12 12:43:22 -0800687 // This is an active task; it should just go to the foreground.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700688 am.moveTaskToFront(ad.taskId, ActivityManager.MOVE_TASK_WITH_HOME,
Michael Jurka482f1592012-09-13 11:05:59 -0700689 opts);
Dianne Hackbornb6777462010-11-12 12:43:22 -0800690 } else {
691 Intent intent = ad.intent;
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800692 intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700693 | Intent.FLAG_ACTIVITY_TASK_ON_HOME
694 | Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackbornb6777462010-11-12 12:43:22 -0800695 if (DEBUG) Log.v(TAG, "Starting activity " + intent);
Michael Jurkaa2bdffe2013-02-08 15:41:56 +0100696 try {
697 context.startActivityAsUser(intent, opts,
698 new UserHandle(UserHandle.USER_CURRENT));
699 } catch (SecurityException e) {
700 Log.e(TAG, "Recents does not have the permission to launch " + intent, e);
701 }
Dianne Hackbornb6777462010-11-12 12:43:22 -0800702 }
Michael Jurkab9a38c52012-06-14 11:57:50 -0700703 if (usingDrawingCache) {
Michael Jurkac016aaa2012-06-05 17:22:24 -0700704 holder.thumbnailViewImage.setDrawingCacheEnabled(false);
705 }
Jim Millerf1e22e52011-01-26 15:39:51 -0800706 }
Jim Miller9f0f0e02011-05-17 20:06:29 -0700707
708 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
709 handleOnClick(view);
710 }
711
Michael Jurka07d40462011-07-19 10:54:38 -0700712 public void handleSwipe(View view) {
Michael Jurkaab48b682011-09-12 15:39:45 -0700713 TaskDescription ad = ((ViewHolder) view.getTag()).taskDescription;
Michael Jurkaa8eac1d2012-04-30 15:54:19 -0700714 if (ad == null) {
Michael Jurka9d69b442012-05-04 15:46:32 -0700715 Log.v(TAG, "Not able to find activity description for swiped task; view=" + view +
716 " tag=" + view.getTag());
717 return;
Michael Jurkaa8eac1d2012-04-30 15:54:19 -0700718 }
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700719 if (DEBUG) Log.v(TAG, "Jettison " + ad.getLabel());
Michael Jurkaab48b682011-09-12 15:39:45 -0700720 mRecentTaskDescriptions.remove(ad);
Michael Jurkae57922c2012-11-26 16:05:12 -0800721 mRecentTasksLoader.remove(ad);
Jim Miller9f0f0e02011-05-17 20:06:29 -0700722
723 // Handled by widget containers to enable LayoutTransitions properly
724 // mListAdapter.notifyDataSetChanged();
725
Michael Jurkaab48b682011-09-12 15:39:45 -0700726 if (mRecentTaskDescriptions.size() == 0) {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700727 dismissAndGoBack();
Jim Miller9f0f0e02011-05-17 20:06:29 -0700728 }
729
730 // Currently, either direction means the same thing, so ignore direction and remove
731 // the task.
732 final ActivityManager am = (ActivityManager)
733 mContext.getSystemService(Context.ACTIVITY_SERVICE);
Michael Jurkaa8eac1d2012-04-30 15:54:19 -0700734 if (am != null) {
735 am.removeTask(ad.persistentTaskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
Jim Miller17377762011-10-11 15:33:34 -0700736
Michael Jurkaa8eac1d2012-04-30 15:54:19 -0700737 // Accessibility feedback
738 setContentDescription(
739 mContext.getString(R.string.accessibility_recents_item_dismissed, ad.getLabel()));
740 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
741 setContentDescription(null);
742 }
Jim Miller9f0f0e02011-05-17 20:06:29 -0700743 }
744
Jim Millerc0d27312011-07-14 18:54:01 -0700745 private void startApplicationDetailsActivity(String packageName) {
746 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
747 Uri.fromParts("package", packageName, null));
Adam Powell0fc5b2b2012-07-18 18:20:29 -0700748 intent.setComponent(intent.resolveActivity(mContext.getPackageManager()));
749 TaskStackBuilder.create(getContext())
750 .addNextIntentWithParentStack(intent).startActivities();
Jim Millerc0d27312011-07-14 18:54:01 -0700751 }
752
Michael Jurkacb466432012-04-03 05:22:45 -0700753 public boolean onInterceptTouchEvent(MotionEvent ev) {
754 if (mPopup != null) {
755 return true;
756 } else {
757 return super.onInterceptTouchEvent(ev);
758 }
759 }
760
Michael Jurkafaa790c2011-09-02 17:35:02 -0700761 public void handleLongPress(
762 final View selectedView, final View anchorView, final View thumbnailView) {
763 thumbnailView.setSelected(true);
Michael Jurkacb466432012-04-03 05:22:45 -0700764 final PopupMenu popup =
765 new PopupMenu(mContext, anchorView == null ? selectedView : anchorView);
766 mPopup = popup;
Jim Millerc0d27312011-07-14 18:54:01 -0700767 popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu());
768 popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
769 public boolean onMenuItemClick(MenuItem item) {
770 if (item.getItemId() == R.id.recent_remove_item) {
771 mRecentsContainer.removeViewInLayout(selectedView);
772 } else if (item.getItemId() == R.id.recent_inspect_item) {
773 ViewHolder viewHolder = (ViewHolder) selectedView.getTag();
774 if (viewHolder != null) {
Michael Jurkaab48b682011-09-12 15:39:45 -0700775 final TaskDescription ad = viewHolder.taskDescription;
Jim Millerc0d27312011-07-14 18:54:01 -0700776 startApplicationDetailsActivity(ad.packageName);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700777 show(false);
Jim Millerc0d27312011-07-14 18:54:01 -0700778 } else {
779 throw new IllegalStateException("Oops, no tag on view " + selectedView);
780 }
781 } else {
782 return false;
783 }
784 return true;
785 }
786 });
Michael Jurkafaa790c2011-09-02 17:35:02 -0700787 popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
788 public void onDismiss(PopupMenu menu) {
789 thumbnailView.setSelected(false);
Michael Jurkacb466432012-04-03 05:22:45 -0700790 mPopup = null;
Michael Jurkafaa790c2011-09-02 17:35:02 -0700791 }
792 });
Jim Millerc0d27312011-07-14 18:54:01 -0700793 popup.show();
Jim Miller9f0f0e02011-05-17 20:06:29 -0700794 }
Jim Miller44c66fe2010-10-20 18:32:52 -0700795}