Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.recent; |
| 18 | |
| 19 | import android.app.Activity; |
Michael Jurka | e592363 | 2012-10-03 15:29:36 +0200 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Michael Jurka | 071316e | 2012-10-10 00:00:21 +0200 | [diff] [blame] | 21 | import android.app.WallpaperManager; |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
| 26 | import android.os.Bundle; |
| 27 | import android.os.UserHandle; |
| 28 | import android.view.MotionEvent; |
| 29 | import android.view.View; |
Michael Jurka | 071316e | 2012-10-10 00:00:21 +0200 | [diff] [blame] | 30 | import android.view.WindowManager; |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 31 | |
| 32 | import com.android.systemui.R; |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 33 | import com.android.systemui.statusbar.tablet.StatusBarPanel; |
| 34 | |
Michael Jurka | e592363 | 2012-10-03 15:29:36 +0200 | [diff] [blame] | 35 | import java.util.List; |
| 36 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 37 | public class RecentsActivity extends Activity { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 38 | 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 Jurka | cbe6920 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 45 | private static final String WAS_SHOWING = "was_showing"; |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 46 | |
| 47 | private RecentsPanelView mRecentsPanel; |
| 48 | private IntentFilter mIntentFilter; |
| 49 | private boolean mShowing; |
| 50 | private boolean mForeground; |
Michael Jurka | 071316e | 2012-10-10 00:00:21 +0200 | [diff] [blame] | 51 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 52 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 53 | @Override |
| 54 | public void onReceive(Context context, Intent intent) { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 55 | 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 Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 65 | } |
| 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 Jurka | 071316e | 2012-10-10 00:00:21 +0200 | [diff] [blame] | 91 | overridePendingTransition( |
| 92 | R.anim.recents_return_to_launcher_enter, |
| 93 | R.anim.recents_return_to_launcher_exit); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 94 | 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 Jurka | 071316e | 2012-10-10 00:00:21 +0200 | [diff] [blame] | 107 | 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 Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 116 | @Override |
| 117 | public void onStart() { |
Michael Jurka | 071316e | 2012-10-10 00:00:21 +0200 | [diff] [blame] | 118 | // Hide wallpaper if it's not a static image |
| 119 | if (WallpaperManager.getInstance(this).getWallpaperInfo() != null) { |
| 120 | updateWallpaperVisibility(false); |
| 121 | } else { |
| 122 | updateWallpaperVisibility(true); |
| 123 | } |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 124 | mShowing = true; |
Michael Jurka | 9bdaada | 2012-10-01 13:58:29 +0200 | [diff] [blame] | 125 | if (mRecentsPanel != null) { |
| 126 | mRecentsPanel.refreshViews(); |
| 127 | } |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 128 | super.onStart(); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public void onResume() { |
| 133 | mForeground = true; |
| 134 | super.onResume(); |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void onBackPressed() { |
| 139 | dismissAndGoBack(); |
| 140 | } |
| 141 | |
| 142 | public void dismissAndGoHome() { |
| 143 | if (mRecentsPanel != null) { |
| 144 | Intent homeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 145 | homeIntent.addCategory(Intent.CATEGORY_HOME); |
| 146 | homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 147 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 148 | startActivityAsUser(homeIntent, new UserHandle(UserHandle.USER_CURRENT)); |
| 149 | mRecentsPanel.show(false); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | public void dismissAndGoBack() { |
| 154 | if (mRecentsPanel != null) { |
Michael Jurka | e592363 | 2012-10-03 15:29:36 +0200 | [diff] [blame] | 155 | final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
| 156 | |
| 157 | final List<ActivityManager.RecentTaskInfo> recentTasks = |
| 158 | am.getRecentTasks(2, |
| 159 | ActivityManager.RECENT_WITH_EXCLUDED | |
| 160 | ActivityManager.RECENT_IGNORE_UNAVAILABLE); |
| 161 | if (recentTasks.size() > 1 && |
| 162 | mRecentsPanel.simulateClick(recentTasks.get(1).persistentId)) { |
| 163 | // recents panel will take care of calling show(false) through simulateClick |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 164 | return; |
| 165 | } |
| 166 | mRecentsPanel.show(false); |
| 167 | } |
| 168 | finish(); |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | protected void onCreate(Bundle savedInstanceState) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 173 | setContentView(R.layout.status_bar_recent_panel); |
| 174 | mRecentsPanel = (RecentsPanelView) findViewById(R.id.recents_root); |
| 175 | mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel)); |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 176 | |
| 177 | final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 178 | recentTasksLoader.setRecentsPanel(mRecentsPanel, mRecentsPanel); |
Michael Jurka | adf0b21 | 2012-09-04 05:15:26 -0700 | [diff] [blame] | 179 | mRecentsPanel.setMinSwipeAlpha( |
| 180 | getResources().getInteger(R.integer.config_recent_item_min_alpha) / 100f); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 181 | |
Michael Jurka | cbe6920 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 182 | if (savedInstanceState == null || |
| 183 | savedInstanceState.getBoolean(WAS_SHOWING)) { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 184 | handleIntent(getIntent(), (savedInstanceState == null)); |
Michael Jurka | cbe6920 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 185 | } |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 186 | mIntentFilter = new IntentFilter(); |
| 187 | mIntentFilter.addAction(CLOSE_RECENTS_INTENT); |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 188 | mIntentFilter.addAction(WINDOW_ANIMATION_START_INTENT); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 189 | registerReceiver(mIntentReceiver, mIntentFilter); |
| 190 | super.onCreate(savedInstanceState); |
| 191 | } |
| 192 | |
| 193 | @Override |
Michael Jurka | cbe6920 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 194 | protected void onSaveInstanceState(Bundle outState) { |
| 195 | outState.putBoolean(WAS_SHOWING, mRecentsPanel.isShowing()); |
| 196 | } |
| 197 | |
| 198 | @Override |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 199 | protected void onDestroy() { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 200 | RecentTasksLoader.getInstance(this).setRecentsPanel(null, mRecentsPanel); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 201 | unregisterReceiver(mIntentReceiver); |
| 202 | super.onDestroy(); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 207 | handleIntent(intent, true); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 210 | private void handleIntent(Intent intent, boolean checkWaitingForAnimationParam) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 211 | super.onNewIntent(intent); |
| 212 | |
| 213 | if (TOGGLE_RECENTS_INTENT.equals(intent.getAction())) { |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 214 | if (mRecentsPanel != null) { |
Michael Jurka | cbe6920 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 215 | if (mRecentsPanel.isShowing()) { |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 216 | dismissAndGoBack(); |
| 217 | } else { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 218 | final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this); |
| 219 | boolean waitingForWindowAnimation = checkWaitingForAnimationParam && |
| 220 | intent.getBooleanExtra(WAITING_FOR_WINDOW_ANIMATION_PARAM, false); |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 221 | mRecentsPanel.show(true, recentTasksLoader.getLoadedTasks(), |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame^] | 222 | recentTasksLoader.isFirstScreenful(), waitingForWindowAnimation); |
Michael Jurka | 482f159 | 2012-09-13 11:05:59 -0700 | [diff] [blame] | 223 | } |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
Craig Mautner | ca6da00 | 2012-09-20 14:54:37 -0700 | [diff] [blame] | 228 | boolean isForeground() { |
| 229 | return mForeground; |
| 230 | } |
Michael Jurka | 7ed267f | 2012-10-09 17:03:30 +0200 | [diff] [blame] | 231 | |
| 232 | boolean isActivityShowing() { |
| 233 | return mShowing; |
| 234 | } |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 235 | } |