blob: 818c2980f33bd05f4c1ede6a064de4f1b7732514 [file] [log] [blame]
Michael Jurkacb2522c2012-04-13 09:32:47 -07001/*
2 * Copyright (C) 2012 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
17package com.android.systemui.recent;
18
19import android.app.Activity;
Michael Jurkae5923632012-10-03 15:29:36 +020020import android.app.ActivityManager;
Michael Jurka071316e2012-10-10 00:00:21 +020021import android.app.WallpaperManager;
Michael Jurkacb2522c2012-04-13 09:32:47 -070022import android.content.BroadcastReceiver;
23import android.content.Context;
24import android.content.Intent;
25import android.content.IntentFilter;
26import android.os.Bundle;
27import android.os.UserHandle;
28import android.view.MotionEvent;
29import android.view.View;
Michael Jurka071316e2012-10-10 00:00:21 +020030import android.view.WindowManager;
Michael Jurkacb2522c2012-04-13 09:32:47 -070031
32import com.android.systemui.R;
John Spurlockb0e49fc2013-06-12 15:50:50 -040033import com.android.systemui.statusbar.StatusBarPanel;
Michael Jurkacb2522c2012-04-13 09:32:47 -070034
Michael Jurkae5923632012-10-03 15:29:36 +020035import java.util.List;
36
Michael Jurkacb2522c2012-04-13 09:32:47 -070037public class RecentsActivity extends Activity {
Michael Jurka80343f62012-10-18 13:13:46 +020038 public static final String TOGGLE_RECENTS_INTENT = "com.android.systemui.recent.action.TOGGLE_RECENTS";
39 public static final String PRELOAD_INTENT = "com.android.systemui.recent.action.PRELOAD";
40 public static final String CANCEL_PRELOAD_INTENT = "com.android.systemui.recent.CANCEL_PRELOAD";
41 public static final String CLOSE_RECENTS_INTENT = "com.android.systemui.recent.action.CLOSE";
42 public static final String WINDOW_ANIMATION_START_INTENT = "com.android.systemui.recent.action.WINDOW_ANIMATION_START";
43 public static final String PRELOAD_PERMISSION = "com.android.systemui.recent.permission.PRELOAD";
44 public static final String WAITING_FOR_WINDOW_ANIMATION_PARAM = "com.android.systemui.recent.WAITING_FOR_WINDOW_ANIMATION";
Michael Jurkacbe69202012-09-13 11:05:59 -070045 private static final String WAS_SHOWING = "was_showing";
Michael Jurkacb2522c2012-04-13 09:32:47 -070046
47 private RecentsPanelView mRecentsPanel;
48 private IntentFilter mIntentFilter;
49 private boolean mShowing;
50 private boolean mForeground;
Michael Jurka071316e2012-10-10 00:00:21 +020051
Michael Jurkacb2522c2012-04-13 09:32:47 -070052 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
53 @Override
54 public void onReceive(Context context, Intent intent) {
Michael Jurka80343f62012-10-18 13:13:46 +020055 if (CLOSE_RECENTS_INTENT.equals(intent.getAction())) {
56 if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
57 if (mShowing && !mForeground) {
58 // Captures the case right before we transition to another activity
59 mRecentsPanel.show(false);
60 }
61 }
62 } else if (WINDOW_ANIMATION_START_INTENT.equals(intent.getAction())) {
63 if (mRecentsPanel != null) {
64 mRecentsPanel.onWindowAnimationStart();
Michael Jurkacb2522c2012-04-13 09:32:47 -070065 }
66 }
67 }
68 };
69
70 public class TouchOutsideListener implements View.OnTouchListener {
71 private StatusBarPanel mPanel;
72
73 public TouchOutsideListener(StatusBarPanel panel) {
74 mPanel = panel;
75 }
76
77 public boolean onTouch(View v, MotionEvent ev) {
78 final int action = ev.getAction();
79 if (action == MotionEvent.ACTION_OUTSIDE
80 || (action == MotionEvent.ACTION_DOWN
81 && !mPanel.isInContentArea((int) ev.getX(), (int) ev.getY()))) {
82 dismissAndGoHome();
83 return true;
84 }
85 return false;
86 }
87 }
88
89 @Override
90 public void onPause() {
Michael Jurka071316e2012-10-10 00:00:21 +020091 overridePendingTransition(
92 R.anim.recents_return_to_launcher_enter,
93 R.anim.recents_return_to_launcher_exit);
Michael Jurkacb2522c2012-04-13 09:32:47 -070094 mForeground = false;
95 super.onPause();
96 }
97
98 @Override
99 public void onStop() {
100 mShowing = false;
101 if (mRecentsPanel != null) {
102 mRecentsPanel.onUiHidden();
103 }
104 super.onStop();
105 }
106
Michael Jurka071316e2012-10-10 00:00:21 +0200107 private void updateWallpaperVisibility(boolean visible) {
108 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
109 int curflags = getWindow().getAttributes().flags
110 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
111 if (wpflags != curflags) {
112 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
113 }
114 }
115
Michael Jurka833808d2012-10-19 19:12:29 +0200116 public static boolean forceOpaqueBackground(Context context) {
117 return WallpaperManager.getInstance(context).getWallpaperInfo() != null;
118 }
119
Michael Jurkacb2522c2012-04-13 09:32:47 -0700120 @Override
121 public void onStart() {
Michael Jurka071316e2012-10-10 00:00:21 +0200122 // Hide wallpaper if it's not a static image
Michael Jurka833808d2012-10-19 19:12:29 +0200123 if (forceOpaqueBackground(this)) {
Michael Jurka071316e2012-10-10 00:00:21 +0200124 updateWallpaperVisibility(false);
125 } else {
126 updateWallpaperVisibility(true);
127 }
Michael Jurkacb2522c2012-04-13 09:32:47 -0700128 mShowing = true;
Michael Jurka9bdaada2012-10-01 13:58:29 +0200129 if (mRecentsPanel != null) {
Michael Jurka45eed3c2013-05-02 14:49:45 +0200130 // Call and refresh the recent tasks list in case we didn't preload tasks
131 // or in case we don't get an onNewIntent
132 mRecentsPanel.refreshRecentTasksList();
Michael Jurka9bdaada2012-10-01 13:58:29 +0200133 mRecentsPanel.refreshViews();
134 }
Michael Jurkacb2522c2012-04-13 09:32:47 -0700135 super.onStart();
136 }
137
138 @Override
139 public void onResume() {
140 mForeground = true;
141 super.onResume();
142 }
143
144 @Override
145 public void onBackPressed() {
146 dismissAndGoBack();
147 }
148
149 public void dismissAndGoHome() {
150 if (mRecentsPanel != null) {
151 Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);
152 homeIntent.addCategory(Intent.CATEGORY_HOME);
153 homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
154 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
155 startActivityAsUser(homeIntent, new UserHandle(UserHandle.USER_CURRENT));
156 mRecentsPanel.show(false);
157 }
158 }
159
160 public void dismissAndGoBack() {
161 if (mRecentsPanel != null) {
Michael Jurkae5923632012-10-03 15:29:36 +0200162 final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
163
164 final List<ActivityManager.RecentTaskInfo> recentTasks =
165 am.getRecentTasks(2,
166 ActivityManager.RECENT_WITH_EXCLUDED |
167 ActivityManager.RECENT_IGNORE_UNAVAILABLE);
168 if (recentTasks.size() > 1 &&
169 mRecentsPanel.simulateClick(recentTasks.get(1).persistentId)) {
170 // recents panel will take care of calling show(false) through simulateClick
Michael Jurkacb2522c2012-04-13 09:32:47 -0700171 return;
172 }
173 mRecentsPanel.show(false);
174 }
175 finish();
176 }
177
178 @Override
179 protected void onCreate(Bundle savedInstanceState) {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700180 setContentView(R.layout.status_bar_recent_panel);
181 mRecentsPanel = (RecentsPanelView) findViewById(R.id.recents_root);
182 mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel));
Michael Jurka31a6fb32013-03-20 16:44:13 +0100183 mRecentsPanel.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Michael Jurka80343f62012-10-18 13:13:46 +0200184
185 final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700186 recentTasksLoader.setRecentsPanel(mRecentsPanel, mRecentsPanel);
Michael Jurkaadf0b212012-09-04 05:15:26 -0700187 mRecentsPanel.setMinSwipeAlpha(
188 getResources().getInteger(R.integer.config_recent_item_min_alpha) / 100f);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700189
Michael Jurkacbe69202012-09-13 11:05:59 -0700190 if (savedInstanceState == null ||
191 savedInstanceState.getBoolean(WAS_SHOWING)) {
Michael Jurka80343f62012-10-18 13:13:46 +0200192 handleIntent(getIntent(), (savedInstanceState == null));
Michael Jurkacbe69202012-09-13 11:05:59 -0700193 }
Michael Jurkacb2522c2012-04-13 09:32:47 -0700194 mIntentFilter = new IntentFilter();
195 mIntentFilter.addAction(CLOSE_RECENTS_INTENT);
Michael Jurka80343f62012-10-18 13:13:46 +0200196 mIntentFilter.addAction(WINDOW_ANIMATION_START_INTENT);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700197 registerReceiver(mIntentReceiver, mIntentFilter);
198 super.onCreate(savedInstanceState);
199 }
200
201 @Override
Michael Jurkacbe69202012-09-13 11:05:59 -0700202 protected void onSaveInstanceState(Bundle outState) {
203 outState.putBoolean(WAS_SHOWING, mRecentsPanel.isShowing());
204 }
205
206 @Override
Michael Jurkacb2522c2012-04-13 09:32:47 -0700207 protected void onDestroy() {
Michael Jurka80343f62012-10-18 13:13:46 +0200208 RecentTasksLoader.getInstance(this).setRecentsPanel(null, mRecentsPanel);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700209 unregisterReceiver(mIntentReceiver);
210 super.onDestroy();
211 }
212
213 @Override
214 protected void onNewIntent(Intent intent) {
Michael Jurka80343f62012-10-18 13:13:46 +0200215 handleIntent(intent, true);
Michael Jurkacb2522c2012-04-13 09:32:47 -0700216 }
217
Michael Jurka80343f62012-10-18 13:13:46 +0200218 private void handleIntent(Intent intent, boolean checkWaitingForAnimationParam) {
Michael Jurkacb2522c2012-04-13 09:32:47 -0700219 super.onNewIntent(intent);
220
221 if (TOGGLE_RECENTS_INTENT.equals(intent.getAction())) {
Michael Jurka482f1592012-09-13 11:05:59 -0700222 if (mRecentsPanel != null) {
Michael Jurkacbe69202012-09-13 11:05:59 -0700223 if (mRecentsPanel.isShowing()) {
Michael Jurka482f1592012-09-13 11:05:59 -0700224 dismissAndGoBack();
225 } else {
Michael Jurka80343f62012-10-18 13:13:46 +0200226 final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this);
227 boolean waitingForWindowAnimation = checkWaitingForAnimationParam &&
228 intent.getBooleanExtra(WAITING_FOR_WINDOW_ANIMATION_PARAM, false);
Michael Jurka482f1592012-09-13 11:05:59 -0700229 mRecentsPanel.show(true, recentTasksLoader.getLoadedTasks(),
Michael Jurka80343f62012-10-18 13:13:46 +0200230 recentTasksLoader.isFirstScreenful(), waitingForWindowAnimation);
Michael Jurka482f1592012-09-13 11:05:59 -0700231 }
Michael Jurkacb2522c2012-04-13 09:32:47 -0700232 }
233 }
234 }
235
Craig Mautnerca6da002012-09-20 14:54:37 -0700236 boolean isForeground() {
237 return mForeground;
238 }
Michael Jurka7ed267f2012-10-09 17:03:30 +0200239
240 boolean isActivityShowing() {
241 return mShowing;
242 }
Michael Jurkacb2522c2012-04-13 09:32:47 -0700243}