1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.recent;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.UserHandle;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import com.android.systemui.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.statusbar.tablet.StatusBarPanel;
import java.util.List;
public class RecentsActivity extends Activity {
public static final String TOGGLE_RECENTS_INTENT = "com.android.systemui.TOGGLE_RECENTS";
public static final String CLOSE_RECENTS_INTENT = "com.android.systemui.CLOSE_RECENTS";
private static final String WAS_SHOWING = "was_showing";
private RecentsPanelView mRecentsPanel;
private IntentFilter mIntentFilter;
private boolean mShowing;
private boolean mForeground;
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
if (mShowing && !mForeground) {
// Captures the case right before we transition to another activity
mRecentsPanel.show(false);
}
}
}
};
public static interface WindowAnimationStartListener {
void onWindowAnimationStart();
}
public class TouchOutsideListener implements View.OnTouchListener {
private StatusBarPanel mPanel;
public TouchOutsideListener(StatusBarPanel panel) {
mPanel = panel;
}
public boolean onTouch(View v, MotionEvent ev) {
final int action = ev.getAction();
if (action == MotionEvent.ACTION_OUTSIDE
|| (action == MotionEvent.ACTION_DOWN
&& !mPanel.isInContentArea((int) ev.getX(), (int) ev.getY()))) {
dismissAndGoHome();
return true;
}
return false;
}
}
@Override
public void onPause() {
overridePendingTransition(
R.anim.recents_return_to_launcher_enter,
R.anim.recents_return_to_launcher_exit);
mForeground = false;
super.onPause();
}
@Override
public void onStop() {
mShowing = false;
if (mRecentsPanel != null) {
mRecentsPanel.onUiHidden();
}
super.onStop();
}
private void updateWallpaperVisibility(boolean visible) {
int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
int curflags = getWindow().getAttributes().flags
& WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
if (wpflags != curflags) {
getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
}
}
@Override
public void onStart() {
// Hide wallpaper if it's not a static image
if (WallpaperManager.getInstance(this).getWallpaperInfo() != null) {
updateWallpaperVisibility(false);
} else {
updateWallpaperVisibility(true);
}
mShowing = true;
if (mRecentsPanel != null) {
mRecentsPanel.refreshViews();
}
super.onStart();
}
@Override
public void onResume() {
mForeground = true;
super.onResume();
}
@Override
public void onBackPressed() {
dismissAndGoBack();
}
public void dismissAndGoHome() {
if (mRecentsPanel != null) {
Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivityAsUser(homeIntent, new UserHandle(UserHandle.USER_CURRENT));
mRecentsPanel.show(false);
}
}
public void dismissAndGoBack() {
if (mRecentsPanel != null) {
final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(2,
ActivityManager.RECENT_WITH_EXCLUDED |
ActivityManager.RECENT_IGNORE_UNAVAILABLE);
if (recentTasks.size() > 1 &&
mRecentsPanel.simulateClick(recentTasks.get(1).persistentId)) {
// recents panel will take care of calling show(false) through simulateClick
return;
}
mRecentsPanel.show(false);
}
finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
final SystemUIApplication app = (SystemUIApplication) getApplication();
final RecentTasksLoader recentTasksLoader = app.getRecentTasksLoader();
setContentView(R.layout.status_bar_recent_panel);
mRecentsPanel = (RecentsPanelView) findViewById(R.id.recents_root);
mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel));
mRecentsPanel.setRecentTasksLoader(recentTasksLoader);
recentTasksLoader.setRecentsPanel(mRecentsPanel, mRecentsPanel);
mRecentsPanel.setMinSwipeAlpha(
getResources().getInteger(R.integer.config_recent_item_min_alpha) / 100f);
if (savedInstanceState == null ||
savedInstanceState.getBoolean(WAS_SHOWING)) {
handleIntent(getIntent());
}
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(CLOSE_RECENTS_INTENT);
registerReceiver(mIntentReceiver, mIntentFilter);
app.setWindowAnimationStartListener(mRecentsPanel);
super.onCreate(savedInstanceState);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean(WAS_SHOWING, mRecentsPanel.isShowing());
}
@Override
protected void onDestroy() {
final SystemUIApplication app = (SystemUIApplication) getApplication();
final RecentTasksLoader recentTasksLoader = app.getRecentTasksLoader();
recentTasksLoader.setRecentsPanel(null, mRecentsPanel);
unregisterReceiver(mIntentReceiver);
app.setWindowAnimationStartListener(null);
super.onDestroy();
}
@Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
super.onNewIntent(intent);
if (TOGGLE_RECENTS_INTENT.equals(intent.getAction())) {
if (mRecentsPanel != null) {
if (mRecentsPanel.isShowing()) {
dismissAndGoBack();
} else {
final SystemUIApplication app = (SystemUIApplication) getApplication();
final RecentTasksLoader recentTasksLoader = app.getRecentTasksLoader();
mRecentsPanel.show(true, recentTasksLoader.getLoadedTasks(),
recentTasksLoader.isFirstScreenful());
}
}
}
}
boolean isForeground() {
return mForeground;
}
boolean isActivityShowing() {
return mShowing;
}
}
|