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