Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 1 | /* |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 3 | * |
| 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 Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 17 | package com.android.systemui.recent; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 18 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 20 | import android.animation.LayoutTransition; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 22 | import android.app.ActivityManagerNative; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 23 | import android.app.ActivityOptions; |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 24 | import android.app.TaskStackBuilder; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 27 | import android.content.res.Resources; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 28 | import android.content.res.TypedArray; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 29 | import android.graphics.Bitmap; |
Jim Miller | fefef31 | 2010-11-09 14:08:39 -0800 | [diff] [blame] | 30 | import android.graphics.Matrix; |
Jim Miller | e5c16ab | 2010-12-03 19:18:38 -0800 | [diff] [blame] | 31 | import android.graphics.Shader.TileMode; |
| 32 | import android.graphics.drawable.BitmapDrawable; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 34 | import android.net.Uri; |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 36 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 38 | import android.provider.Settings; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 39 | import android.util.AttributeSet; |
| 40 | import android.util.Log; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 41 | import android.view.LayoutInflater; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 42 | import android.view.MenuItem; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 43 | import android.view.MotionEvent; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 44 | import android.view.View; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 45 | import android.view.ViewGroup; |
Jim Miller | 1737776 | 2011-10-11 15:33:34 -0700 | [diff] [blame] | 46 | import android.view.accessibility.AccessibilityEvent; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 47 | import android.view.animation.AnimationUtils; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 48 | import android.widget.AdapterView; |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 49 | import android.widget.AdapterView.OnItemClickListener; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 50 | import android.widget.BaseAdapter; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 51 | import android.widget.FrameLayout; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 52 | import android.widget.ImageView; |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 53 | import android.widget.ImageView.ScaleType; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 54 | import android.widget.PopupMenu; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 55 | import android.widget.TextView; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 56 | |
| 57 | import com.android.systemui.R; |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 58 | import com.android.systemui.statusbar.BaseStatusBar; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 60 | import com.android.systemui.statusbar.tablet.StatusBarPanel; |
| 61 | import com.android.systemui.statusbar.tablet.TabletStatusBar; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 62 | |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 63 | import java.util.ArrayList; |
| 64 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 65 | public class RecentsPanelView extends FrameLayout implements OnItemClickListener, RecentsCallback, |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 66 | StatusBarPanel, Animator.AnimatorListener { |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 67 | static final String TAG = "RecentsPanelView"; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 68 | static final boolean DEBUG = TabletStatusBar.DEBUG || PhoneStatusBar.DEBUG || false; |
Michael Jurka | cb46643 | 2012-04-03 05:22:45 -0700 | [diff] [blame] | 69 | private PopupMenu mPopup; |
Jim Miller | 85babff | 2011-01-11 14:26:03 -0800 | [diff] [blame] | 70 | private View mRecentsScrim; |
Michael Jurka | 6d66708 | 2011-09-16 17:04:40 -0700 | [diff] [blame] | 71 | private View mRecentsNoApps; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 72 | private ViewGroup mRecentsContainer; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 73 | private StatusBarTouchProxy mStatusBarTouchProxy; |
Peter Ng | 622a976 | 2011-08-29 10:56:53 -0700 | [diff] [blame] | 74 | |
Jim Miller | 85babff | 2011-01-11 14:26:03 -0800 | [diff] [blame] | 75 | private boolean mShowing; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 76 | private boolean mWaitingToShow; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 77 | private int mNumItemsWaitingForThumbnailsAndIcons; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 78 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 79 | private RecentTasksLoader mRecentTasksLoader; |
| 80 | private ArrayList<TaskDescription> mRecentTaskDescriptions; |
| 81 | private TaskDescriptionAdapter mListAdapter; |
| 82 | private int mThumbnailWidth; |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 83 | private boolean mFitThumbnailToXY; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 84 | private int mRecentItemLayoutId; |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 85 | private boolean mHighEndGfx; |
Dianne Hackborn | eeb1dca | 2011-09-08 13:30:11 -0700 | [diff] [blame] | 86 | |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 87 | public static interface RecentsScrollView { |
| 88 | public int numItemsInOneScreenful(); |
| 89 | public void setAdapter(TaskDescriptionAdapter adapter); |
| 90 | public void setCallback(RecentsCallback callback); |
| 91 | public void setMinSwipeAlpha(float minAlpha); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 92 | public View findViewForTask(TaskDescription task); |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 95 | private final class OnLongClickDelegate implements View.OnLongClickListener { |
| 96 | View mOtherView; |
| 97 | OnLongClickDelegate(View other) { |
| 98 | mOtherView = other; |
| 99 | } |
| 100 | public boolean onLongClick(View v) { |
| 101 | return mOtherView.performLongClick(); |
| 102 | } |
| 103 | } |
| 104 | |
Jim Miller | b5a2b29 | 2011-03-01 16:14:59 -0800 | [diff] [blame] | 105 | /* package */ final static class ViewHolder { |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 106 | View thumbnailView; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 107 | ImageView thumbnailViewImage; |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 108 | Bitmap thumbnailViewImageBitmap; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 109 | ImageView iconView; |
| 110 | TextView labelView; |
| 111 | TextView descriptionView; |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 112 | TaskDescription taskDescription; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 113 | boolean loadedThumbnailAndIcon; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 116 | /* package */ final class TaskDescriptionAdapter extends BaseAdapter { |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 117 | private LayoutInflater mInflater; |
| 118 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 119 | public TaskDescriptionAdapter(Context context) { |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 120 | mInflater = LayoutInflater.from(context); |
| 121 | } |
| 122 | |
| 123 | public int getCount() { |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 124 | return mRecentTaskDescriptions != null ? mRecentTaskDescriptions.size() : 0; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | public Object getItem(int position) { |
| 128 | return position; // we only need the index |
| 129 | } |
| 130 | |
| 131 | public long getItemId(int position) { |
| 132 | return position; // we just need something unique for this position |
| 133 | } |
| 134 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 135 | public View createView(ViewGroup parent) { |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 136 | View convertView = mInflater.inflate(mRecentItemLayoutId, parent, false); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 137 | ViewHolder holder = new ViewHolder(); |
| 138 | holder.thumbnailView = convertView.findViewById(R.id.app_thumbnail); |
| 139 | holder.thumbnailViewImage = |
| 140 | (ImageView) convertView.findViewById(R.id.app_thumbnail_image); |
| 141 | // If we set the default thumbnail now, we avoid an onLayout when we update |
| 142 | // the thumbnail later (if they both have the same dimensions) |
| 143 | if (mRecentTasksLoader != null) { |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 144 | updateThumbnail(holder, mRecentTasksLoader.getDefaultThumbnail(), false, false); |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 145 | } |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 146 | holder.iconView = (ImageView) convertView.findViewById(R.id.app_icon); |
| 147 | if (mRecentTasksLoader != null) { |
| 148 | holder.iconView.setImageBitmap(mRecentTasksLoader.getDefaultIcon()); |
| 149 | } |
| 150 | holder.labelView = (TextView) convertView.findViewById(R.id.app_label); |
| 151 | holder.descriptionView = (TextView) convertView.findViewById(R.id.app_description); |
| 152 | |
| 153 | convertView.setTag(holder); |
| 154 | return convertView; |
| 155 | } |
| 156 | |
| 157 | public View getView(int position, View convertView, ViewGroup parent) { |
| 158 | if (convertView == null) { |
| 159 | convertView = createView(parent); |
| 160 | } |
| 161 | ViewHolder holder = (ViewHolder) convertView.getTag(); |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 162 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 163 | // index is reverse since most recent appears at the bottom... |
| 164 | final int index = mRecentTaskDescriptions.size() - position - 1; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 165 | |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 166 | final TaskDescription td = mRecentTaskDescriptions.get(index); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 167 | |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 168 | holder.labelView.setText(td.getLabel()); |
| 169 | holder.thumbnailView.setContentDescription(td.getLabel()); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 170 | holder.loadedThumbnailAndIcon = td.isLoaded(); |
| 171 | if (td.isLoaded()) { |
| 172 | updateThumbnail(holder, td.getThumbnail(), true, false); |
| 173 | updateIcon(holder, td.getIcon(), true, false); |
| 174 | mNumItemsWaitingForThumbnailsAndIcons--; |
| 175 | } |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 176 | |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 177 | holder.thumbnailView.setTag(td); |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 178 | holder.thumbnailView.setOnLongClickListener(new OnLongClickDelegate(convertView)); |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 179 | holder.taskDescription = td; |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 180 | return convertView; |
| 181 | } |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 182 | |
| 183 | public void recycleView(View v) { |
| 184 | ViewHolder holder = (ViewHolder) v.getTag(); |
| 185 | updateThumbnail(holder, mRecentTasksLoader.getDefaultThumbnail(), false, false); |
| 186 | holder.iconView.setImageBitmap(mRecentTasksLoader.getDefaultIcon()); |
| 187 | holder.iconView.setVisibility(INVISIBLE); |
| 188 | holder.labelView.setText(null); |
| 189 | holder.thumbnailView.setContentDescription(null); |
| 190 | holder.thumbnailView.setTag(null); |
| 191 | holder.thumbnailView.setOnLongClickListener(null); |
| 192 | holder.thumbnailView.setVisibility(INVISIBLE); |
| 193 | holder.taskDescription = null; |
| 194 | holder.loadedThumbnailAndIcon = false; |
| 195 | } |
| 196 | } |
| 197 | |
Michael Jurka | 8b2e37e | 2012-05-08 20:06:13 -0700 | [diff] [blame] | 198 | public RecentsPanelView(Context context, AttributeSet attrs) { |
| 199 | this(context, attrs, 0); |
| 200 | } |
| 201 | |
| 202 | public RecentsPanelView(Context context, AttributeSet attrs, int defStyle) { |
| 203 | super(context, attrs, defStyle); |
Michael Jurka | 8b2e37e | 2012-05-08 20:06:13 -0700 | [diff] [blame] | 204 | updateValuesFromResources(); |
| 205 | |
| 206 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecentsPanelView, |
| 207 | defStyle, 0); |
| 208 | |
| 209 | mRecentItemLayoutId = a.getResourceId(R.styleable.RecentsPanelView_recentItemLayout, 0); |
| 210 | a.recycle(); |
| 211 | } |
| 212 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 213 | public int numItemsInOneScreenful() { |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 214 | if (mRecentsContainer instanceof RecentsScrollView){ |
| 215 | RecentsScrollView scrollView |
| 216 | = (RecentsScrollView) mRecentsContainer; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 217 | return scrollView.numItemsInOneScreenful(); |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 218 | } else { |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 219 | throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView"); |
| 220 | } |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 223 | private boolean pointInside(int x, int y, View v) { |
| 224 | final int l = v.getLeft(); |
| 225 | final int r = v.getRight(); |
| 226 | final int t = v.getTop(); |
| 227 | final int b = v.getBottom(); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 228 | return x >= l && x < r && y >= t && y < b; |
| 229 | } |
| 230 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 231 | public boolean isInContentArea(int x, int y) { |
Michael Jurka | b144bd7 | 2012-01-12 06:56:39 -0800 | [diff] [blame] | 232 | if (pointInside(x, y, mRecentsContainer)) { |
| 233 | return true; |
| 234 | } else if (mStatusBarTouchProxy != null && |
| 235 | pointInside(x, y, mStatusBarTouchProxy)) { |
| 236 | return true; |
| 237 | } else { |
| 238 | return false; |
| 239 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 240 | } |
| 241 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 242 | public void show(boolean show) { |
| 243 | show(show, null, false); |
| 244 | } |
| 245 | |
| 246 | public void show(boolean show, ArrayList<TaskDescription> recentTaskDescriptions, |
| 247 | boolean firstScreenful) { |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 248 | if (show) { |
| 249 | mWaitingToShow = true; |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 250 | refreshRecentTasksList(recentTaskDescriptions, firstScreenful); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 251 | showIfReady(); |
| 252 | } else { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 253 | showImpl(false); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | private void showIfReady() { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 258 | // mWaitingToShow => there was a touch up on the recents button |
| 259 | // mRecentTaskDescriptions != null => we've created views for the first screenful of items |
| 260 | if (mWaitingToShow && mRecentTaskDescriptions != null) { |
| 261 | showImpl(true); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 262 | } |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 265 | static void sendCloseSystemWindows(Context context, String reason) { |
| 266 | if (ActivityManagerNative.isSystemReady()) { |
| 267 | try { |
| 268 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 269 | } catch (RemoteException e) { |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 274 | private void showImpl(boolean show) { |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 275 | sendCloseSystemWindows(mContext, BaseStatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 276 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 277 | mShowing = show; |
| 278 | |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 279 | if (show) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 280 | // if there are no apps, bring up a "No recent apps" message |
| 281 | boolean noApps = mRecentTaskDescriptions != null |
| 282 | && (mRecentTaskDescriptions.size() == 0); |
| 283 | mRecentsNoApps.setAlpha(1f); |
| 284 | mRecentsNoApps.setVisibility(noApps ? View.VISIBLE : View.INVISIBLE); |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 285 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 286 | onAnimationEnd(null); |
Michael Jurka | e9166ed | 2011-07-27 18:23:18 -0700 | [diff] [blame] | 287 | setFocusable(true); |
| 288 | setFocusableInTouchMode(true); |
| 289 | requestFocus(); |
Michael Jurka | cb46643 | 2012-04-03 05:22:45 -0700 | [diff] [blame] | 290 | } else { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 291 | mWaitingToShow = false; |
| 292 | // call onAnimationEnd() and clearRecentTasksList() in onUiHidden() |
Michael Jurka | cb46643 | 2012-04-03 05:22:45 -0700 | [diff] [blame] | 293 | if (mPopup != null) { |
| 294 | mPopup.dismiss(); |
| 295 | } |
Michael Jurka | e9166ed | 2011-07-27 18:23:18 -0700 | [diff] [blame] | 296 | } |
Jim Miller | 85babff | 2011-01-11 14:26:03 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 299 | public void onUiHidden() { |
| 300 | if (!mShowing && mRecentTaskDescriptions != null) { |
| 301 | onAnimationEnd(null); |
| 302 | clearRecentTasksList(); |
| 303 | } |
Michael Jurka | c6461ca | 2011-09-02 12:12:15 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 306 | public void dismiss() { |
| 307 | ((RecentsActivity) mContext).dismissAndGoHome(); |
| 308 | } |
| 309 | |
| 310 | public void dismissAndGoBack() { |
| 311 | ((RecentsActivity) mContext).dismissAndGoBack(); |
Michael Jurka | 8b09866 | 2011-09-01 17:00:53 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 314 | public void onAnimationCancel(Animator animation) { |
| 315 | } |
| 316 | |
| 317 | public void onAnimationEnd(Animator animation) { |
| 318 | if (mShowing) { |
| 319 | final LayoutTransition transitioner = new LayoutTransition(); |
| 320 | ((ViewGroup)mRecentsContainer).setLayoutTransition(transitioner); |
| 321 | createCustomAnimations(transitioner); |
| 322 | } else { |
| 323 | ((ViewGroup)mRecentsContainer).setLayoutTransition(null); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | public void onAnimationRepeat(Animator animation) { |
| 328 | } |
| 329 | |
| 330 | public void onAnimationStart(Animator animation) { |
| 331 | } |
| 332 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 333 | @Override |
| 334 | public boolean dispatchHoverEvent(MotionEvent event) { |
| 335 | // Ignore hover events outside of this panel bounds since such events |
| 336 | // generate spurious accessibility events with the panel content when |
| 337 | // tapping outside of it, thus confusing the user. |
| 338 | final int x = (int) event.getX(); |
| 339 | final int y = (int) event.getY(); |
| 340 | if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) { |
| 341 | return super.dispatchHoverEvent(event); |
| 342 | } |
| 343 | return true; |
| 344 | } |
| 345 | |
Jim Miller | 85babff | 2011-01-11 14:26:03 -0800 | [diff] [blame] | 346 | /** |
| 347 | * Whether the panel is showing, or, if it's animating, whether it will be |
| 348 | * when the animation is done. |
| 349 | */ |
| 350 | public boolean isShowing() { |
| 351 | return mShowing; |
| 352 | } |
| 353 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 354 | public void setStatusBarView(View statusBarView) { |
| 355 | if (mStatusBarTouchProxy != null) { |
| 356 | mStatusBarTouchProxy.setStatusBar(statusBarView); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | public void setRecentTasksLoader(RecentTasksLoader loader) { |
| 361 | mRecentTasksLoader = loader; |
| 362 | } |
| 363 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 364 | public void updateValuesFromResources() { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 365 | final Resources res = mContext.getResources(); |
| 366 | mThumbnailWidth = Math.round(res.getDimension(R.dimen.status_bar_recents_thumbnail_width)); |
| 367 | mFitThumbnailToXY = res.getBoolean(R.bool.config_recents_thumbnail_image_fits_to_xy); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | @Override |
| 371 | protected void onFinishInflate() { |
| 372 | super.onFinishInflate(); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 373 | |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 374 | mRecentsContainer = (ViewGroup) findViewById(R.id.recents_container); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 375 | mStatusBarTouchProxy = (StatusBarTouchProxy) findViewById(R.id.status_bar_touch_proxy); |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 376 | mListAdapter = new TaskDescriptionAdapter(mContext); |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 377 | if (mRecentsContainer instanceof RecentsScrollView){ |
| 378 | RecentsScrollView scrollView |
| 379 | = (RecentsScrollView) mRecentsContainer; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 380 | scrollView.setAdapter(mListAdapter); |
| 381 | scrollView.setCallback(this); |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 382 | } else { |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 383 | throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView"); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 384 | } |
Jim Miller | 5fda69c | 2011-02-16 15:17:11 -0800 | [diff] [blame] | 385 | |
Michael Jurka | 6d66708 | 2011-09-16 17:04:40 -0700 | [diff] [blame] | 386 | mRecentsScrim = findViewById(R.id.recents_bg_protect); |
| 387 | mRecentsNoApps = findViewById(R.id.recents_no_apps); |
Jim Miller | e5c16ab | 2010-12-03 19:18:38 -0800 | [diff] [blame] | 388 | |
Michael Jurka | f16fc51 | 2012-02-27 15:02:23 -0800 | [diff] [blame] | 389 | if (mRecentsScrim != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 390 | mHighEndGfx = ActivityManager.isHighEndGfx(); |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 391 | if (!mHighEndGfx) { |
Michael Jurka | d5895a7 | 2012-05-12 13:24:58 -0700 | [diff] [blame] | 392 | mRecentsScrim.setBackground(null); |
Michael Jurka | f16fc51 | 2012-02-27 15:02:23 -0800 | [diff] [blame] | 393 | } else if (mRecentsScrim.getBackground() instanceof BitmapDrawable) { |
| 394 | // In order to save space, we make the background texture repeat in the Y direction |
| 395 | ((BitmapDrawable) mRecentsScrim.getBackground()).setTileModeY(TileMode.REPEAT); |
| 396 | } |
Jim Miller | e5c16ab | 2010-12-03 19:18:38 -0800 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 400 | public void setMinSwipeAlpha(float minAlpha) { |
| 401 | if (mRecentsContainer instanceof RecentsScrollView){ |
| 402 | RecentsScrollView scrollView |
| 403 | = (RecentsScrollView) mRecentsContainer; |
| 404 | scrollView.setMinSwipeAlpha(minAlpha); |
| 405 | } |
| 406 | } |
| 407 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 408 | private void createCustomAnimations(LayoutTransition transitioner) { |
Chet Haase | 212f625 | 2011-08-12 09:19:10 -0700 | [diff] [blame] | 409 | transitioner.setDuration(200); |
| 410 | transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0); |
| 411 | transitioner.setAnimator(LayoutTransition.DISAPPEARING, null); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 414 | private void updateIcon(ViewHolder h, Drawable icon, boolean show, boolean anim) { |
| 415 | if (icon != null) { |
| 416 | h.iconView.setImageDrawable(icon); |
| 417 | if (show && h.iconView.getVisibility() != View.VISIBLE) { |
| 418 | if (anim) { |
| 419 | h.iconView.setAnimation( |
| 420 | AnimationUtils.loadAnimation(mContext, R.anim.recent_appear)); |
| 421 | } |
| 422 | h.iconView.setVisibility(View.VISIBLE); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 427 | private void updateThumbnail(ViewHolder h, Bitmap thumbnail, boolean show, boolean anim) { |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 428 | if (thumbnail != null) { |
| 429 | // Should remove the default image in the frame |
| 430 | // that this now covers, to improve scrolling speed. |
| 431 | // That can't be done until the anim is complete though. |
| 432 | h.thumbnailViewImage.setImageBitmap(thumbnail); |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 433 | |
| 434 | // scale the image to fill the full width of the ImageView. do this only if |
| 435 | // we haven't set a bitmap before, or if the bitmap size has changed |
| 436 | if (h.thumbnailViewImageBitmap == null || |
| 437 | h.thumbnailViewImageBitmap.getWidth() != thumbnail.getWidth() || |
| 438 | h.thumbnailViewImageBitmap.getHeight() != thumbnail.getHeight()) { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 439 | if (mFitThumbnailToXY) { |
| 440 | h.thumbnailViewImage.setScaleType(ScaleType.FIT_XY); |
| 441 | } else { |
| 442 | Matrix scaleMatrix = new Matrix(); |
| 443 | float scale = mThumbnailWidth / (float) thumbnail.getWidth(); |
| 444 | scaleMatrix.setScale(scale, scale); |
| 445 | h.thumbnailViewImage.setScaleType(ScaleType.MATRIX); |
| 446 | h.thumbnailViewImage.setImageMatrix(scaleMatrix); |
| 447 | } |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 448 | } |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 449 | if (show && h.thumbnailView.getVisibility() != View.VISIBLE) { |
| 450 | if (anim) { |
| 451 | h.thumbnailView.setAnimation( |
| 452 | AnimationUtils.loadAnimation(mContext, R.anim.recent_appear)); |
| 453 | } |
| 454 | h.thumbnailView.setVisibility(View.VISIBLE); |
| 455 | } |
| 456 | h.thumbnailViewImageBitmap = thumbnail; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 457 | } |
Jim Miller | fefef31 | 2010-11-09 14:08:39 -0800 | [diff] [blame] | 458 | } |
| 459 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 460 | void onTaskThumbnailLoaded(TaskDescription td) { |
| 461 | synchronized (td) { |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 462 | if (mRecentsContainer != null) { |
| 463 | ViewGroup container = mRecentsContainer; |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 464 | if (container instanceof RecentsScrollView) { |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 465 | container = (ViewGroup) container.findViewById( |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 466 | R.id.recents_linear_layout); |
| 467 | } |
| 468 | // Look for a view showing this thumbnail, to update. |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 469 | for (int i=0; i < container.getChildCount(); i++) { |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 470 | View v = container.getChildAt(i); |
| 471 | if (v.getTag() instanceof ViewHolder) { |
| 472 | ViewHolder h = (ViewHolder)v.getTag(); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 473 | if (!h.loadedThumbnailAndIcon && h.taskDescription == td) { |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 474 | // only fade in the thumbnail if recents is already visible-- we |
| 475 | // show it immediately otherwise |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 476 | //boolean animateShow = mShowing && |
| 477 | // mRecentsContainer.getAlpha() > ViewConfiguration.ALPHA_THRESHOLD; |
| 478 | boolean animateShow = false; |
| 479 | updateIcon(h, td.getIcon(), true, animateShow); |
| 480 | updateThumbnail(h, td.getThumbnail(), true, animateShow); |
| 481 | h.loadedThumbnailAndIcon = true; |
| 482 | mNumItemsWaitingForThumbnailsAndIcons--; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | } |
| 486 | } |
Craig Mautner | ca6da00 | 2012-09-20 14:54:37 -0700 | [diff] [blame^] | 487 | } |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 488 | showIfReady(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 491 | public void clearRecentTasksList() { |
| 492 | // Clear memory used by screenshots |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 493 | if (mRecentTaskDescriptions != null) { |
| 494 | mRecentTasksLoader.cancelLoadingThumbnailsAndIcons(this); |
| 495 | onTaskLoadingCancelled(); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | public void onTaskLoadingCancelled() { |
| 500 | // Gets called by RecentTasksLoader when it's cancelled |
| 501 | if (mRecentTaskDescriptions != null) { |
| 502 | mRecentTaskDescriptions = null; |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 503 | mListAdapter.notifyDataSetInvalidated(); |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Craig Mautner | ca6da00 | 2012-09-20 14:54:37 -0700 | [diff] [blame^] | 507 | public void refreshViews() { |
| 508 | mListAdapter.notifyDataSetInvalidated(); |
| 509 | updateUiElements(); |
| 510 | showIfReady(); |
| 511 | } |
| 512 | |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 513 | public void refreshRecentTasksList() { |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 514 | refreshRecentTasksList(null, false); |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 517 | private void refreshRecentTasksList( |
| 518 | ArrayList<TaskDescription> recentTasksList, boolean firstScreenful) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 519 | if (mRecentTaskDescriptions == null && recentTasksList != null) { |
| 520 | onTasksLoaded(recentTasksList, firstScreenful); |
| 521 | } else { |
| 522 | mRecentTasksLoader.loadTasksInBackground(); |
Michael Jurka | 412cba8 | 2011-10-17 09:05:00 -0700 | [diff] [blame] | 523 | } |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 524 | } |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 525 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 526 | public void onTasksLoaded(ArrayList<TaskDescription> tasks, boolean firstScreenful) { |
| 527 | mNumItemsWaitingForThumbnailsAndIcons = firstScreenful |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 528 | ? tasks.size() : mRecentTaskDescriptions == null |
| 529 | ? 0 : mRecentTaskDescriptions.size(); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 530 | if (mRecentTaskDescriptions == null) { |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 531 | mRecentTaskDescriptions = new ArrayList<TaskDescription>(tasks); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 532 | } else { |
| 533 | mRecentTaskDescriptions.addAll(tasks); |
| 534 | } |
Craig Mautner | ca6da00 | 2012-09-20 14:54:37 -0700 | [diff] [blame^] | 535 | if (((RecentsActivity)mContext).isForeground()) { |
| 536 | refreshViews(); |
| 537 | } |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Craig Mautner | ca6da00 | 2012-09-20 14:54:37 -0700 | [diff] [blame^] | 540 | private void updateUiElements() { |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 541 | final int items = mRecentTaskDescriptions.size(); |
| 542 | |
| 543 | mRecentsContainer.setVisibility(items > 0 ? View.VISIBLE : View.GONE); |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 544 | |
| 545 | // Set description for accessibility |
| 546 | int numRecentApps = mRecentTaskDescriptions.size(); |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 547 | String recentAppsAccessibilityDescription; |
| 548 | if (numRecentApps == 0) { |
| 549 | recentAppsAccessibilityDescription = |
| 550 | getResources().getString(R.string.status_bar_no_recent_apps); |
| 551 | } else { |
| 552 | recentAppsAccessibilityDescription = getResources().getQuantityString( |
| 553 | R.plurals.status_bar_accessibility_recent_apps, numRecentApps, numRecentApps); |
| 554 | } |
| 555 | setContentDescription(recentAppsAccessibilityDescription); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 558 | public boolean simulateClick(TaskDescription task) { |
| 559 | if (mRecentsContainer instanceof RecentsScrollView){ |
| 560 | RecentsScrollView scrollView |
| 561 | = (RecentsScrollView) mRecentsContainer; |
| 562 | View v = scrollView.findViewForTask(task); |
| 563 | if (v != null) { |
| 564 | handleOnClick(v); |
| 565 | return true; |
| 566 | } |
| 567 | } |
| 568 | return false; |
| 569 | } |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 570 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 571 | public void handleOnClick(View view) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 572 | ViewHolder holder = (ViewHolder)view.getTag(); |
| 573 | TaskDescription ad = holder.taskDescription; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 574 | final Context context = view.getContext(); |
Jim Miller | e5c16ab | 2010-12-03 19:18:38 -0800 | [diff] [blame] | 575 | final ActivityManager am = (ActivityManager) |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 576 | context.getSystemService(Context.ACTIVITY_SERVICE); |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 577 | Bitmap bm = holder.thumbnailViewImageBitmap; |
| 578 | boolean usingDrawingCache; |
| 579 | if (bm.getWidth() == holder.thumbnailViewImage.getWidth() && |
| 580 | bm.getHeight() == holder.thumbnailViewImage.getHeight()) { |
| 581 | usingDrawingCache = false; |
| 582 | } else { |
| 583 | holder.thumbnailViewImage.setDrawingCacheEnabled(true); |
| 584 | bm = holder.thumbnailViewImage.getDrawingCache(); |
| 585 | usingDrawingCache = true; |
| 586 | } |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 587 | Bundle opts = (bm == null) ? |
| 588 | null : |
| 589 | ActivityOptions.makeThumbnailScaleUpAnimation( |
| 590 | holder.thumbnailViewImage, bm, 0, 0, null).toBundle(); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 591 | |
| 592 | show(false); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 593 | if (ad.taskId >= 0) { |
Dianne Hackborn | b677746 | 2010-11-12 12:43:22 -0800 | [diff] [blame] | 594 | // This is an active task; it should just go to the foreground. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 595 | am.moveTaskToFront(ad.taskId, ActivityManager.MOVE_TASK_WITH_HOME, |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 596 | opts); |
Dianne Hackborn | b677746 | 2010-11-12 12:43:22 -0800 | [diff] [blame] | 597 | } else { |
| 598 | Intent intent = ad.intent; |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 599 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 600 | | Intent.FLAG_ACTIVITY_TASK_ON_HOME |
| 601 | | Intent.FLAG_ACTIVITY_NEW_TASK); |
Dianne Hackborn | b677746 | 2010-11-12 12:43:22 -0800 | [diff] [blame] | 602 | if (DEBUG) Log.v(TAG, "Starting activity " + intent); |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 603 | context.startActivityAsUser(intent, opts, |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 604 | new UserHandle(UserHandle.USER_CURRENT)); |
Dianne Hackborn | b677746 | 2010-11-12 12:43:22 -0800 | [diff] [blame] | 605 | } |
Michael Jurka | b9a38c5 | 2012-06-14 11:57:50 -0700 | [diff] [blame] | 606 | if (usingDrawingCache) { |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 607 | holder.thumbnailViewImage.setDrawingCacheEnabled(false); |
| 608 | } |
Jim Miller | f1e22e5 | 2011-01-26 15:39:51 -0800 | [diff] [blame] | 609 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 610 | |
| 611 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 612 | handleOnClick(view); |
| 613 | } |
| 614 | |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 615 | public void handleSwipe(View view) { |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 616 | TaskDescription ad = ((ViewHolder) view.getTag()).taskDescription; |
Michael Jurka | a8eac1d | 2012-04-30 15:54:19 -0700 | [diff] [blame] | 617 | if (ad == null) { |
Michael Jurka | 9d69b44 | 2012-05-04 15:46:32 -0700 | [diff] [blame] | 618 | Log.v(TAG, "Not able to find activity description for swiped task; view=" + view + |
| 619 | " tag=" + view.getTag()); |
| 620 | return; |
Michael Jurka | a8eac1d | 2012-04-30 15:54:19 -0700 | [diff] [blame] | 621 | } |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 622 | if (DEBUG) Log.v(TAG, "Jettison " + ad.getLabel()); |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 623 | mRecentTaskDescriptions.remove(ad); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 624 | |
| 625 | // Handled by widget containers to enable LayoutTransitions properly |
| 626 | // mListAdapter.notifyDataSetChanged(); |
| 627 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 628 | if (mRecentTaskDescriptions.size() == 0) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 629 | dismissAndGoBack(); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | // Currently, either direction means the same thing, so ignore direction and remove |
| 633 | // the task. |
| 634 | final ActivityManager am = (ActivityManager) |
| 635 | mContext.getSystemService(Context.ACTIVITY_SERVICE); |
Michael Jurka | a8eac1d | 2012-04-30 15:54:19 -0700 | [diff] [blame] | 636 | if (am != null) { |
| 637 | am.removeTask(ad.persistentTaskId, ActivityManager.REMOVE_TASK_KILL_PROCESS); |
Jim Miller | 1737776 | 2011-10-11 15:33:34 -0700 | [diff] [blame] | 638 | |
Michael Jurka | a8eac1d | 2012-04-30 15:54:19 -0700 | [diff] [blame] | 639 | // Accessibility feedback |
| 640 | setContentDescription( |
| 641 | mContext.getString(R.string.accessibility_recents_item_dismissed, ad.getLabel())); |
| 642 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
| 643 | setContentDescription(null); |
| 644 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 647 | private void startApplicationDetailsActivity(String packageName) { |
| 648 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 649 | Uri.fromParts("package", packageName, null)); |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 650 | intent.setComponent(intent.resolveActivity(mContext.getPackageManager())); |
| 651 | TaskStackBuilder.create(getContext()) |
| 652 | .addNextIntentWithParentStack(intent).startActivities(); |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Michael Jurka | cb46643 | 2012-04-03 05:22:45 -0700 | [diff] [blame] | 655 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 656 | if (mPopup != null) { |
| 657 | return true; |
| 658 | } else { |
| 659 | return super.onInterceptTouchEvent(ev); |
| 660 | } |
| 661 | } |
| 662 | |
Michael Jurka | faa790c | 2011-09-02 17:35:02 -0700 | [diff] [blame] | 663 | public void handleLongPress( |
| 664 | final View selectedView, final View anchorView, final View thumbnailView) { |
| 665 | thumbnailView.setSelected(true); |
Michael Jurka | cb46643 | 2012-04-03 05:22:45 -0700 | [diff] [blame] | 666 | final PopupMenu popup = |
| 667 | new PopupMenu(mContext, anchorView == null ? selectedView : anchorView); |
| 668 | mPopup = popup; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 669 | popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu()); |
| 670 | popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
| 671 | public boolean onMenuItemClick(MenuItem item) { |
| 672 | if (item.getItemId() == R.id.recent_remove_item) { |
| 673 | mRecentsContainer.removeViewInLayout(selectedView); |
| 674 | } else if (item.getItemId() == R.id.recent_inspect_item) { |
| 675 | ViewHolder viewHolder = (ViewHolder) selectedView.getTag(); |
| 676 | if (viewHolder != null) { |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 677 | final TaskDescription ad = viewHolder.taskDescription; |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 678 | startApplicationDetailsActivity(ad.packageName); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 679 | show(false); |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 680 | } else { |
| 681 | throw new IllegalStateException("Oops, no tag on view " + selectedView); |
| 682 | } |
| 683 | } else { |
| 684 | return false; |
| 685 | } |
| 686 | return true; |
| 687 | } |
| 688 | }); |
Michael Jurka | faa790c | 2011-09-02 17:35:02 -0700 | [diff] [blame] | 689 | popup.setOnDismissListener(new PopupMenu.OnDismissListener() { |
| 690 | public void onDismiss(PopupMenu menu) { |
| 691 | thumbnailView.setSelected(false); |
Michael Jurka | cb46643 | 2012-04-03 05:22:45 -0700 | [diff] [blame] | 692 | mPopup = null; |
Michael Jurka | faa790c | 2011-09-02 17:35:02 -0700 | [diff] [blame] | 693 | } |
| 694 | }); |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 695 | popup.show(); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 696 | } |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 697 | } |