Skip to content

Commit 50c69b5

Browse files
mikejurkaAndroid (Google) Code Review
authored andcommitted
Merge "Preload recents on phones with hard nav keys"
2 parents 6ef1eed + 7f2668c commit 50c69b5

File tree

9 files changed

+291
-197
lines changed

9 files changed

+291
-197
lines changed

core/java/com/android/internal/statusbar/IStatusBar.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ oneway interface IStatusBar
3535
void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
3636
void setHardKeyboardStatus(boolean available, boolean enabled);
3737
void toggleRecentApps();
38+
void preloadRecentApps();
39+
void cancelPreloadRecentApps();
3840
}
3941

core/java/com/android/internal/statusbar/IStatusBarService.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ interface IStatusBarService
4747
void setSystemUiVisibility(int vis);
4848
void setHardKeyboardEnabled(boolean enabled);
4949
void toggleRecentApps();
50+
void preloadRecentApps();
51+
void cancelPreloadRecentApps();
5052
}

packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ protected void onFinishInflate() {
456456

457457
mPreloadTasksRunnable = new Runnable() {
458458
public void run() {
459+
// If we set our visibility to INVISIBLE here, we avoid an extra call to
460+
// onLayout later when we become visible (because onLayout is always called
461+
// when going from GONE)
459462
if (!mShowing) {
460463
setVisibility(INVISIBLE);
461464
refreshRecentTasksList();
@@ -562,9 +565,6 @@ public boolean onTouch(View v, MotionEvent ev) {
562565
if (!mShowing) {
563566
int action = ev.getAction() & MotionEvent.ACTION_MASK;
564567
if (action == MotionEvent.ACTION_DOWN) {
565-
// If we set our visibility to INVISIBLE here, we avoid an extra call to
566-
// onLayout later when we become visible (because onLayout is always called
567-
// when going from GONE)
568568
post(mPreloadTasksRunnable);
569569
} else if (action == MotionEvent.ACTION_CANCEL) {
570570
setVisibility(GONE);
@@ -583,9 +583,15 @@ public boolean onTouch(View v, MotionEvent ev) {
583583
return false;
584584
}
585585

586+
public void preloadRecentTasksList() {
587+
if (!mShowing) {
588+
mPreloadTasksRunnable.run();
589+
}
590+
}
591+
586592
public void clearRecentTasksList() {
587593
// Clear memory used by screenshots
588-
if (mRecentTaskDescriptions != null) {
594+
if (!mShowing && mRecentTaskDescriptions != null) {
589595
mRecentTasksLoader.cancelLoadingThumbnailsAndIcons();
590596
mRecentTaskDescriptions.clear();
591597
mListAdapter.notifyDataSetInvalidated();

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,53 @@
1919
import java.util.ArrayList;
2020

2121
import android.content.Context;
22+
import android.os.Handler;
2223
import android.os.IBinder;
24+
import android.os.Message;
2325
import android.os.RemoteException;
2426
import android.os.ServiceManager;
2527
import android.util.Log;
2628
import android.util.Slog;
2729
import android.view.Display;
2830
import android.view.IWindowManager;
31+
import android.view.LayoutInflater;
32+
import android.view.MotionEvent;
2933
import android.view.View;
34+
import android.view.ViewGroup.LayoutParams;
3035
import android.view.WindowManager;
36+
import android.view.WindowManagerImpl;
37+
import android.widget.LinearLayout;
3138

3239
import com.android.internal.statusbar.IStatusBarService;
3340
import com.android.internal.statusbar.StatusBarIcon;
3441
import com.android.internal.statusbar.StatusBarIconList;
3542
import com.android.internal.statusbar.StatusBarNotification;
3643
import com.android.systemui.SystemUI;
44+
import com.android.systemui.recent.RecentsPanelView;
45+
import com.android.systemui.recent.RecentTasksLoader;
46+
import com.android.systemui.recent.TaskDescription;
3747
import com.android.systemui.statusbar.CommandQueue;
48+
import com.android.systemui.statusbar.tablet.StatusBarPanel;
3849

3950
import com.android.systemui.R;
4051

41-
public abstract class BaseStatusBar extends SystemUI implements CommandQueue.Callbacks {
52+
public abstract class BaseStatusBar extends SystemUI implements
53+
CommandQueue.Callbacks, RecentsPanelView.OnRecentsPanelVisibilityChangedListener {
4254
static final String TAG = "StatusBar";
4355
private static final boolean DEBUG = false;
4456

57+
protected static final int MSG_OPEN_RECENTS_PANEL = 1020;
58+
protected static final int MSG_CLOSE_RECENTS_PANEL = 1021;
59+
protected static final int MSG_PRELOAD_RECENT_APPS = 1022;
60+
protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023;
61+
4562
protected CommandQueue mCommandQueue;
4663
protected IStatusBarService mBarService;
64+
protected H mHandler = createHandler();
65+
66+
// Recent apps
67+
protected RecentsPanelView mRecentsPanel;
68+
protected RecentTasksLoader mRecentTasksLoader;
4769

4870
// UI-specific methods
4971

@@ -162,4 +184,121 @@ public void onClick(View v) {
162184
public void dismissIntruder() {
163185
// pass
164186
}
187+
188+
@Override
189+
public void toggleRecentApps() {
190+
int msg = (mRecentsPanel.getVisibility() == View.VISIBLE)
191+
? MSG_CLOSE_RECENTS_PANEL : MSG_OPEN_RECENTS_PANEL;
192+
mHandler.removeMessages(msg);
193+
mHandler.sendEmptyMessage(msg);
194+
}
195+
196+
@Override
197+
public void preloadRecentApps() {
198+
int msg = MSG_PRELOAD_RECENT_APPS;
199+
mHandler.removeMessages(msg);
200+
mHandler.sendEmptyMessage(msg);
201+
}
202+
203+
@Override
204+
public void cancelPreloadRecentApps() {
205+
int msg = MSG_CANCEL_PRELOAD_RECENT_APPS;
206+
mHandler.removeMessages(msg);
207+
mHandler.sendEmptyMessage(msg);
208+
}
209+
210+
@Override
211+
public void onRecentsPanelVisibilityChanged(boolean visible) {
212+
}
213+
214+
protected abstract WindowManager.LayoutParams getRecentsLayoutParams(
215+
LayoutParams layoutParams);
216+
217+
protected void updateRecentsPanel() {
218+
// Recents Panel
219+
boolean visible = false;
220+
ArrayList<TaskDescription> recentTasksList = null;
221+
boolean firstScreenful = false;
222+
if (mRecentsPanel != null) {
223+
visible = mRecentsPanel.isShowing();
224+
WindowManagerImpl.getDefault().removeView(mRecentsPanel);
225+
if (visible) {
226+
recentTasksList = mRecentsPanel.getRecentTasksList();
227+
firstScreenful = mRecentsPanel.getFirstScreenful();
228+
}
229+
}
230+
231+
// Provide RecentsPanelView with a temporary parent to allow layout params to work.
232+
LinearLayout tmpRoot = new LinearLayout(mContext);
233+
mRecentsPanel = (RecentsPanelView) LayoutInflater.from(mContext).inflate(
234+
R.layout.status_bar_recent_panel, tmpRoot, false);
235+
mRecentsPanel.setRecentTasksLoader(mRecentTasksLoader);
236+
mRecentTasksLoader.setRecentsPanel(mRecentsPanel);
237+
mRecentsPanel.setOnTouchListener(
238+
new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, mRecentsPanel));
239+
mRecentsPanel.setVisibility(View.GONE);
240+
241+
242+
WindowManager.LayoutParams lp = getRecentsLayoutParams(mRecentsPanel.getLayoutParams());
243+
244+
WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);
245+
mRecentsPanel.setBar(this);
246+
if (visible) {
247+
mRecentsPanel.show(true, false, recentTasksList, firstScreenful);
248+
}
249+
250+
}
251+
252+
H createHandler() {
253+
return new H();
254+
}
255+
256+
protected class H extends Handler {
257+
public void handleMessage(Message m) {
258+
switch (m.what) {
259+
case MSG_OPEN_RECENTS_PANEL:
260+
if (DEBUG) Slog.d(TAG, "opening recents panel");
261+
if (mRecentsPanel != null) {
262+
mRecentsPanel.show(true, true);
263+
}
264+
break;
265+
case MSG_CLOSE_RECENTS_PANEL:
266+
if (DEBUG) Slog.d(TAG, "closing recents panel");
267+
if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
268+
mRecentsPanel.show(false, true);
269+
}
270+
break;
271+
case MSG_PRELOAD_RECENT_APPS:
272+
if (DEBUG) Slog.d(TAG, "preloading recents");
273+
mRecentsPanel.preloadRecentTasksList();
274+
break;
275+
case MSG_CANCEL_PRELOAD_RECENT_APPS:
276+
if (DEBUG) Slog.d(TAG, "cancel preloading recents");
277+
mRecentsPanel.clearRecentTasksList();
278+
break;
279+
}
280+
}
281+
}
282+
283+
public class TouchOutsideListener implements View.OnTouchListener {
284+
private int mMsg;
285+
private StatusBarPanel mPanel;
286+
287+
public TouchOutsideListener(int msg, StatusBarPanel panel) {
288+
mMsg = msg;
289+
mPanel = panel;
290+
}
291+
292+
public boolean onTouch(View v, MotionEvent ev) {
293+
final int action = ev.getAction();
294+
if (action == MotionEvent.ACTION_OUTSIDE
295+
|| (action == MotionEvent.ACTION_DOWN
296+
&& !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
297+
mHandler.removeMessages(mMsg);
298+
mHandler.sendEmptyMessage(mMsg);
299+
return true;
300+
}
301+
return false;
302+
}
303+
}
165304
}

packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public class CommandQueue extends IStatusBar.Stub {
6161
private static final int MSG_SET_HARD_KEYBOARD_STATUS = 10 << MSG_SHIFT;
6262

6363
private static final int MSG_TOGGLE_RECENT_APPS = 11 << MSG_SHIFT;
64+
private static final int MSG_PRELOAD_RECENT_APPS = 12 << MSG_SHIFT;
65+
private static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 13 << MSG_SHIFT;
6466

65-
private static final int MSG_SET_NAVIGATION_ICON_HINTS = 13 << MSG_SHIFT;
67+
private static final int MSG_SET_NAVIGATION_ICON_HINTS = 14 << MSG_SHIFT;
6668

6769
private StatusBarIconList mList;
6870
private Callbacks mCallbacks;
@@ -92,6 +94,8 @@ public void updateIcon(String slot, int index, int viewIndex,
9294
public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
9395
public void setHardKeyboardStatus(boolean available, boolean enabled);
9496
public void toggleRecentApps();
97+
public void preloadRecentApps();
98+
public void cancelPreloadRecentApps();
9599
public void setNavigationIconHints(int hints);
96100
}
97101

@@ -199,6 +203,20 @@ public void toggleRecentApps() {
199203
}
200204
}
201205

206+
public void preloadRecentApps() {
207+
synchronized (mList) {
208+
mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
209+
mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
210+
}
211+
}
212+
213+
public void cancelPreloadRecentApps() {
214+
synchronized (mList) {
215+
mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
216+
mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
217+
}
218+
}
219+
202220
public void setNavigationIconHints(int hints) {
203221
synchronized (mList) {
204222
mHandler.removeMessages(MSG_SET_NAVIGATION_ICON_HINTS);
@@ -275,6 +293,12 @@ public void handleMessage(Message msg) {
275293
case MSG_TOGGLE_RECENT_APPS:
276294
mCallbacks.toggleRecentApps();
277295
break;
296+
case MSG_PRELOAD_RECENT_APPS:
297+
mCallbacks.preloadRecentApps();
298+
break;
299+
case MSG_CANCEL_PRELOAD_RECENT_APPS:
300+
mCallbacks.cancelPreloadRecentApps();
301+
break;
278302
case MSG_SET_NAVIGATION_ICON_HINTS:
279303
mCallbacks.setNavigationIconHints(msg.arg1);
280304
break;

0 commit comments

Comments
 (0)