|
19 | 19 | import java.util.ArrayList; |
20 | 20 |
|
21 | 21 | import android.content.Context; |
| 22 | +import android.os.Handler; |
22 | 23 | import android.os.IBinder; |
| 24 | +import android.os.Message; |
23 | 25 | import android.os.RemoteException; |
24 | 26 | import android.os.ServiceManager; |
25 | 27 | import android.util.Log; |
26 | 28 | import android.util.Slog; |
27 | 29 | import android.view.Display; |
28 | 30 | import android.view.IWindowManager; |
| 31 | +import android.view.LayoutInflater; |
| 32 | +import android.view.MotionEvent; |
29 | 33 | import android.view.View; |
| 34 | +import android.view.ViewGroup.LayoutParams; |
30 | 35 | import android.view.WindowManager; |
| 36 | +import android.view.WindowManagerImpl; |
| 37 | +import android.widget.LinearLayout; |
31 | 38 |
|
32 | 39 | import com.android.internal.statusbar.IStatusBarService; |
33 | 40 | import com.android.internal.statusbar.StatusBarIcon; |
34 | 41 | import com.android.internal.statusbar.StatusBarIconList; |
35 | 42 | import com.android.internal.statusbar.StatusBarNotification; |
36 | 43 | 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; |
37 | 47 | import com.android.systemui.statusbar.CommandQueue; |
| 48 | +import com.android.systemui.statusbar.tablet.StatusBarPanel; |
38 | 49 |
|
39 | 50 | import com.android.systemui.R; |
40 | 51 |
|
41 | | -public abstract class BaseStatusBar extends SystemUI implements CommandQueue.Callbacks { |
| 52 | +public abstract class BaseStatusBar extends SystemUI implements |
| 53 | + CommandQueue.Callbacks, RecentsPanelView.OnRecentsPanelVisibilityChangedListener { |
42 | 54 | static final String TAG = "StatusBar"; |
43 | 55 | private static final boolean DEBUG = false; |
44 | 56 |
|
| 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 | + |
45 | 62 | protected CommandQueue mCommandQueue; |
46 | 63 | protected IStatusBarService mBarService; |
| 64 | + protected H mHandler = createHandler(); |
| 65 | + |
| 66 | + // Recent apps |
| 67 | + protected RecentsPanelView mRecentsPanel; |
| 68 | + protected RecentTasksLoader mRecentTasksLoader; |
47 | 69 |
|
48 | 70 | // UI-specific methods |
49 | 71 |
|
@@ -162,4 +184,121 @@ public void onClick(View v) { |
162 | 184 | public void dismissIntruder() { |
163 | 185 | // pass |
164 | 186 | } |
| 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 | + } |
165 | 304 | } |
0 commit comments