Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 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 | |
| 17 | package com.android.systemui.recents.views; |
| 18 | |
| 19 | import android.app.ActivityOptions; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 20 | import android.app.TaskStackBuilder; |
Winson Chung | c620baf | 2014-03-19 17:15:29 -0700 | [diff] [blame] | 21 | import android.content.ActivityNotFoundException; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.Canvas; |
| 26 | import android.graphics.Rect; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 28 | import android.os.UserHandle; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 29 | import android.provider.Settings; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 30 | import android.view.Gravity; |
| 31 | import android.view.LayoutInflater; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 32 | import android.view.View; |
| 33 | import android.widget.FrameLayout; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 34 | import android.widget.TextView; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 35 | import com.android.systemui.recents.Console; |
| 36 | import com.android.systemui.recents.Constants; |
| 37 | import com.android.systemui.recents.RecentsConfiguration; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 38 | import com.android.systemui.recents.RecentsTaskLoader; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 39 | import com.android.systemui.recents.model.SpaceNode; |
| 40 | import com.android.systemui.recents.model.Task; |
| 41 | import com.android.systemui.recents.model.TaskStack; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 42 | import com.android.systemui.R; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 43 | |
| 44 | import java.util.ArrayList; |
| 45 | |
| 46 | |
| 47 | /** |
| 48 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 49 | * to their SpaceNode bounds. |
| 50 | */ |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 51 | public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 52 | |
| 53 | /** The RecentsView callbacks */ |
| 54 | public interface RecentsViewCallbacks { |
| 55 | public void onTaskLaunching(); |
| 56 | } |
| 57 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 58 | // The space partitioning root of this container |
| 59 | SpaceNode mBSP; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 60 | // Search bar view |
| 61 | View mSearchBar; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 62 | // Recents view callbacks |
| 63 | RecentsViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 64 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 65 | LayoutInflater mInflater; |
| 66 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 67 | public RecentsView(Context context) { |
| 68 | super(context); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 69 | mInflater = LayoutInflater.from(context); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 70 | setWillNotDraw(false); |
| 71 | } |
| 72 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 73 | /** Sets the callbacks */ |
| 74 | public void setCallbacks(RecentsViewCallbacks cb) { |
| 75 | mCb = cb; |
| 76 | } |
| 77 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 78 | /** Set/get the bsp root node */ |
| 79 | public void setBSP(SpaceNode n) { |
| 80 | mBSP = n; |
| 81 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 82 | // Create and add all the stacks for this partition of space. |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 83 | boolean hasTasks = false; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 84 | removeAllViews(); |
| 85 | ArrayList<TaskStack> stacks = mBSP.getStacks(); |
| 86 | for (TaskStack stack : stacks) { |
| 87 | TaskStackView stackView = new TaskStackView(getContext(), stack); |
| 88 | stackView.setCallbacks(this); |
| 89 | addView(stackView); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 90 | hasTasks |= (stack.getTaskCount() > 0); |
| 91 | } |
| 92 | |
| 93 | // Create the search bar (and hide it if we have no recent tasks) |
| 94 | if (Constants.DebugFlags.App.EnableSearchButton) { |
| 95 | createSearchBar(); |
| 96 | if (!hasTasks) { |
| 97 | mSearchBar.setVisibility(View.GONE); |
| 98 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | /** Launches the first task from the first stack if possible */ |
| 103 | public boolean launchFirstTask() { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 104 | // Get the first stack view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 105 | int childCount = getChildCount(); |
| 106 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 107 | View child = getChildAt(i); |
| 108 | if (child instanceof TaskStackView) { |
| 109 | TaskStackView stackView = (TaskStackView) child; |
| 110 | TaskStack stack = stackView.mStack; |
| 111 | ArrayList<Task> tasks = stack.getTasks(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 112 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 113 | // Get the first task in the stack |
| 114 | if (!tasks.isEmpty()) { |
| 115 | Task task = tasks.get(tasks.size() - 1); |
| 116 | TaskView tv = null; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 117 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 118 | // Try and use the first child task view as the source of the launch animation |
| 119 | if (stackView.getChildCount() > 0) { |
| 120 | TaskView stv = (TaskView) stackView.getChildAt(stackView.getChildCount() - 1); |
| 121 | if (stv.getTask() == task) { |
| 122 | tv = stv; |
| 123 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 124 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 125 | onTaskLaunched(stackView, tv, stack, task); |
| 126 | return true; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 127 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 133 | /** Creates and adds the search bar */ |
| 134 | void createSearchBar() { |
| 135 | // Create a temporary search bar |
| 136 | mSearchBar = mInflater.inflate(R.layout.recents_search_bar, this, false); |
| 137 | mSearchBar.setOnClickListener(new OnClickListener() { |
| 138 | @Override |
| 139 | public void onClick(View v) { |
| 140 | onSearchTriggered(); |
| 141 | } |
| 142 | }); |
| 143 | addView(mSearchBar); |
| 144 | } |
| 145 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 146 | @Override |
| 147 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 148 | int width = MeasureSpec.getSize(widthMeasureSpec); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 149 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 150 | int height = MeasureSpec.getSize(heightMeasureSpec); |
| 151 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 152 | |
Winson Chung | 7124390 | 2014-03-14 17:52:47 -0700 | [diff] [blame] | 153 | Console.log(Constants.DebugFlags.UI.MeasureAndLayout, "[RecentsView|measure]", |
| 154 | "width: " + width + " height: " + height, Console.AnsiGreen); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 155 | Console.logTraceTime(Constants.DebugFlags.App.TimeRecentsStartup, |
| 156 | Constants.DebugFlags.App.TimeRecentsStartupKey, "RecentsView.onMeasure"); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 157 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 158 | // Get the search bar bounds so that we can account for its height in the children |
| 159 | Rect searchBarSpaceBounds = new Rect(); |
| 160 | Rect searchBarBounds = new Rect(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 161 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 162 | config.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 163 | searchBarSpaceBounds, searchBarBounds); |
| 164 | if (mSearchBar != null) { |
| 165 | mSearchBar.measure(MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), widthMode), |
| 166 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), heightMode)); |
| 167 | } |
| 168 | |
| 169 | // We measure our stack views sans the status bar. It will handle the nav bar itself. |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 170 | int childWidth = width - config.systemInsets.right; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 171 | int childHeight = height - config.systemInsets.top - searchBarSpaceBounds.height(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 172 | |
| 173 | // Measure each child |
| 174 | int childCount = getChildCount(); |
| 175 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 176 | View child = getChildAt(i); |
| 177 | if (child instanceof TaskStackView && child.getVisibility() != GONE) { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 178 | child.measure(MeasureSpec.makeMeasureSpec(childWidth, widthMode), |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 179 | MeasureSpec.makeMeasureSpec(childHeight, heightMode)); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | setMeasuredDimension(width, height); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson Chung | 7124390 | 2014-03-14 17:52:47 -0700 | [diff] [blame] | 188 | Console.log(Constants.DebugFlags.UI.MeasureAndLayout, "[RecentsView|layout]", |
| 189 | new Rect(left, top, right, bottom) + " changed: " + changed, Console.AnsiGreen); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 190 | Console.logTraceTime(Constants.DebugFlags.App.TimeRecentsStartup, |
| 191 | Constants.DebugFlags.App.TimeRecentsStartupKey, "RecentsView.onLayout"); |
| 192 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 193 | // Get the search bar bounds so that we can account for its height in the children |
| 194 | Rect searchBarSpaceBounds = new Rect(); |
| 195 | Rect searchBarBounds = new Rect(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 196 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 197 | config.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 198 | searchBarSpaceBounds, searchBarBounds); |
| 199 | if (mSearchBar != null) { |
| 200 | mSearchBar.layout(config.systemInsets.left + searchBarSpaceBounds.left, |
| 201 | config.systemInsets.top + searchBarSpaceBounds.top, |
| 202 | config.systemInsets.left + mSearchBar.getMeasuredWidth(), |
| 203 | config.systemInsets.top + mSearchBar.getMeasuredHeight()); |
| 204 | } |
| 205 | |
| 206 | // We offset our stack views by the status bar height. It will handle the nav bar itself. |
| 207 | top += config.systemInsets.top + searchBarSpaceBounds.height(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 208 | |
| 209 | // Layout each child |
| 210 | // XXX: Based on the space node for that task view |
| 211 | int childCount = getChildCount(); |
| 212 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 213 | View child = getChildAt(i); |
| 214 | if (child instanceof TaskStackView && child.getVisibility() != GONE) { |
| 215 | int width = child.getMeasuredWidth(); |
| 216 | int height = child.getMeasuredHeight(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 217 | child.layout(left, top, left + width, top + height); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | @Override |
| 223 | protected void dispatchDraw(Canvas canvas) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 224 | Console.log(Constants.DebugFlags.UI.Draw, "[RecentsView|dispatchDraw]", "", |
| 225 | Console.AnsiPurple); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 226 | super.dispatchDraw(canvas); |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | protected boolean fitSystemWindows(Rect insets) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 231 | Console.log(Constants.DebugFlags.UI.MeasureAndLayout, |
| 232 | "[RecentsView|fitSystemWindows]", "insets: " + insets, Console.AnsiGreen); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 233 | |
| 234 | // Update the configuration with the latest system insets and trigger a relayout |
| 235 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 236 | config.updateSystemInsets(insets); |
| 237 | requestLayout(); |
| 238 | |
| 239 | return true; |
| 240 | } |
| 241 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 242 | /** Closes any open info panes */ |
| 243 | public boolean closeOpenInfoPanes() { |
| 244 | if (mBSP != null) { |
| 245 | // Get the first stack view |
| 246 | int childCount = getChildCount(); |
| 247 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 248 | View child = getChildAt(i); |
| 249 | if (child instanceof TaskStackView) { |
| 250 | TaskStackView stackView = (TaskStackView) child; |
| 251 | if (stackView.closeOpenInfoPanes()) { |
| 252 | return true; |
| 253 | } |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | } |
| 257 | return false; |
| 258 | } |
| 259 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 260 | /** Unfilters any filtered stacks */ |
| 261 | public boolean unfilterFilteredStacks() { |
| 262 | if (mBSP != null) { |
| 263 | // Check if there are any filtered stacks and unfilter them before we back out of Recents |
| 264 | boolean stacksUnfiltered = false; |
| 265 | ArrayList<TaskStack> stacks = mBSP.getStacks(); |
| 266 | for (TaskStack stack : stacks) { |
| 267 | if (stack.hasFilteredTasks()) { |
| 268 | stack.unfilterTasks(); |
| 269 | stacksUnfiltered = true; |
| 270 | } |
| 271 | } |
| 272 | return stacksUnfiltered; |
| 273 | } |
| 274 | return false; |
| 275 | } |
| 276 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 277 | /**** TaskStackView.TaskStackCallbacks Implementation ****/ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 278 | |
| 279 | @Override |
| 280 | public void onTaskLaunched(final TaskStackView stackView, final TaskView tv, |
| 281 | final TaskStack stack, final Task task) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 282 | // Notify any callbacks of the launching of a new task |
| 283 | if (mCb != null) { |
| 284 | mCb.onTaskLaunching(); |
| 285 | } |
| 286 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 287 | // Close any open info panes |
| 288 | closeOpenInfoPanes(); |
| 289 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 290 | final Runnable launchRunnable = new Runnable() { |
| 291 | @Override |
| 292 | public void run() { |
| 293 | TaskViewTransform transform; |
| 294 | View sourceView = tv; |
| 295 | int offsetX = 0; |
| 296 | int offsetY = 0; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 297 | int stackScroll = stackView.getStackScroll(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 298 | if (tv == null) { |
Winson Chung | c620baf | 2014-03-19 17:15:29 -0700 | [diff] [blame] | 299 | // If there is no actual task view, then use the stack view as the source view |
| 300 | // and then offset to the expected transform rect, but bound this to just |
| 301 | // outside the display rect (to ensure we don't animate from too far away) |
| 302 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 303 | sourceView = stackView; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 304 | transform = stackView.getStackTransform(stack.indexOfTask(task), stackScroll); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 305 | offsetX = transform.rect.left; |
Winson Chung | c620baf | 2014-03-19 17:15:29 -0700 | [diff] [blame] | 306 | offsetY = Math.min(transform.rect.top, config.displayRect.height()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 307 | } else { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 308 | transform = stackView.getStackTransform(stack.indexOfTask(task), stackScroll); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | // Compute the thumbnail to scale up from |
| 312 | ActivityOptions opts = null; |
| 313 | int thumbnailWidth = transform.rect.width(); |
| 314 | int thumbnailHeight = transform.rect.height(); |
| 315 | if (task.thumbnail != null && thumbnailWidth > 0 && thumbnailHeight > 0 && |
| 316 | task.thumbnail.getWidth() > 0 && task.thumbnail.getHeight() > 0) { |
| 317 | // Resize the thumbnail to the size of the view that we are animating from |
| 318 | Bitmap b = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, |
| 319 | Bitmap.Config.ARGB_8888); |
| 320 | Canvas c = new Canvas(b); |
| 321 | c.drawBitmap(task.thumbnail, |
| 322 | new Rect(0, 0, task.thumbnail.getWidth(), task.thumbnail.getHeight()), |
| 323 | new Rect(0, 0, thumbnailWidth, thumbnailHeight), null); |
| 324 | c.setBitmap(null); |
| 325 | opts = ActivityOptions.makeThumbnailScaleUpAnimation(sourceView, |
| 326 | b, offsetX, offsetY); |
| 327 | } |
| 328 | |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 329 | |
| 330 | if (task.isActive) { |
| 331 | // Bring an active task to the foreground |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 332 | RecentsTaskLoader.getInstance().getSystemServicesProxy() |
| 333 | .moveTaskToFront(task.key.id, opts); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 334 | } else { |
| 335 | // Launch the activity with the desired animation |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 336 | Intent i = new Intent(task.key.baseIntent); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 337 | i.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY |
| 338 | | Intent.FLAG_ACTIVITY_TASK_ON_HOME |
| 339 | | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 340 | try { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 341 | UserHandle taskUser = new UserHandle(task.userId); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 342 | if (opts != null) { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 343 | getContext().startActivityAsUser(i, opts.toBundle(), taskUser); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 344 | } else { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 345 | getContext().startActivityAsUser(i, taskUser); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 346 | } |
| 347 | } catch (ActivityNotFoundException anfe) { |
| 348 | Console.logError(getContext(), "Could not start Activity"); |
| 349 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 350 | } |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 351 | |
| 352 | Console.logTraceTime(Constants.DebugFlags.App.TimeRecentsLaunchTask, |
| 353 | Constants.DebugFlags.App.TimeRecentsLaunchKey, "startActivity"); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 354 | } |
| 355 | }; |
| 356 | |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 357 | Console.logTraceTime(Constants.DebugFlags.App.TimeRecentsLaunchTask, |
| 358 | Constants.DebugFlags.App.TimeRecentsLaunchKey, "onTaskLaunched"); |
| 359 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 360 | // Launch the app right away if there is no task view, otherwise, animate the icon out first |
Winson Chung | b44c24f | 2014-04-09 15:17:43 -0700 | [diff] [blame] | 361 | if (tv == null || !Constants.Values.TaskView.AnimateFrontTaskBarOnLeavingRecents) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 362 | post(launchRunnable); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 363 | } else { |
| 364 | tv.animateOnLeavingRecents(launchRunnable); |
| 365 | } |
| 366 | } |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 367 | |
| 368 | @Override |
| 369 | public void onTaskAppInfoLaunched(Task t) { |
| 370 | // Create a new task stack with the application info details activity |
| 371 | Intent baseIntent = t.key.baseIntent; |
| 372 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 373 | Uri.fromParts("package", baseIntent.getComponent().getPackageName(), null)); |
| 374 | intent.setComponent(intent.resolveActivity(getContext().getPackageManager())); |
| 375 | TaskStackBuilder.create(getContext()) |
| 376 | .addNextIntentWithParentStack(intent).startActivities(); |
| 377 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame^] | 378 | |
| 379 | public void onSearchTriggered() { |
| 380 | // Get the search bar source bounds |
| 381 | Rect searchBarSpaceBounds = new Rect(); |
| 382 | Rect searchBarBounds = new Rect(); |
| 383 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 384 | config.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 385 | searchBarSpaceBounds, searchBarBounds); |
| 386 | |
| 387 | // Get the search intent and start it |
| 388 | Intent searchIntent = RecentsTaskLoader.getInstance().getSystemServicesProxy() |
| 389 | .getGlobalSearchIntent(searchBarBounds); |
| 390 | if (searchIntent != null) { |
| 391 | try { |
| 392 | getContext().startActivity(searchIntent); |
| 393 | } catch (ActivityNotFoundException anfe) { |
| 394 | Console.logError(getContext(), "Could not start Search activity"); |
| 395 | } |
| 396 | } |
| 397 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 398 | } |