The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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.statusbartest; |
| 18 | |
| 19 | import android.app.ListActivity; |
| 20 | import android.app.Notification; |
| 21 | import android.app.NotificationManager; |
| 22 | import android.widget.ArrayAdapter; |
| 23 | import android.view.View; |
| 24 | import android.widget.ListView; |
| 25 | import android.content.Intent; |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 26 | import android.app.PendingIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.app.Notification; |
| 28 | import android.app.NotificationManager; |
| 29 | import android.app.StatusBarManager; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.Vibrator; |
| 33 | import android.os.Bundle; |
| 34 | import android.os.Handler; |
| 35 | import android.util.Log; |
| 36 | import android.net.Uri; |
| 37 | import android.os.SystemClock; |
| 38 | import android.widget.RemoteViews; |
| 39 | import android.widget.Toast; |
| 40 | import android.os.PowerManager; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 41 | import android.view.View; |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 42 | import android.view.Window; |
| 43 | import android.view.WindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | public class StatusBarTest extends TestActivity |
| 46 | { |
| 47 | private final static String TAG = "StatusBarTest"; |
| 48 | StatusBarManager mStatusBarManager; |
| 49 | NotificationManager mNotificationManager; |
| 50 | Handler mHandler = new Handler(); |
| 51 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 52 | View.OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener |
| 53 | = new View.OnSystemUiVisibilityChangeListener() { |
| 54 | public void onSystemUiVisibilityChange(int visibility) { |
| 55 | Log.d(TAG, "onSystemUiVisibilityChange visibility=" + visibility); |
| 56 | } |
| 57 | }; |
| 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | @Override |
| 60 | protected String tag() { |
| 61 | return TAG; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | protected Test[] tests() { |
| 66 | mStatusBarManager = (StatusBarManager)getSystemService(STATUS_BAR_SERVICE); |
| 67 | mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); |
| 68 | |
| 69 | return mTests; |
| 70 | } |
| 71 | |
| 72 | private Test[] mTests = new Test[] { |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 73 | new Test("DISABLE_NAVIGATION") { |
| 74 | public void run() { |
| 75 | View v = findViewById(android.R.id.list); |
| 76 | v.setSystemUiVisibility(View.STATUS_BAR_DISABLE_NAVIGATION); |
| 77 | } |
| 78 | }, |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 79 | new Test("STATUS_BAR_HIDDEN") { |
| 80 | public void run() { |
| 81 | View v = findViewById(android.R.id.list); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 82 | v.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 83 | v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN); |
| 84 | } |
| 85 | }, |
| 86 | new Test("STATUS_BAR_VISIBLE") { |
| 87 | public void run() { |
| 88 | View v = findViewById(android.R.id.list); |
| 89 | v.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener); |
| 90 | v.setSystemUiVisibility(View.STATUS_BAR_VISIBLE); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 91 | } |
| 92 | }, |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 93 | new Test("no setSystemUiVisibility") { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 94 | public void run() { |
| 95 | View v = findViewById(android.R.id.list); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 96 | v.setOnSystemUiVisibilityChangeListener(null); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 97 | v.setSystemUiVisibility(View.STATUS_BAR_VISIBLE); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 98 | } |
| 99 | }, |
Joe Onorato | 795f284 | 2010-09-27 11:34:46 -0700 | [diff] [blame] | 100 | new Test("Double Remove") { |
| 101 | public void run() { |
| 102 | Log.d(TAG, "set 0"); |
| 103 | mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0); |
| 104 | Log.d(TAG, "remove 1"); |
| 105 | mStatusBarManager.removeIcon("tty"); |
| 106 | |
| 107 | SystemClock.sleep(1000); |
| 108 | |
| 109 | Log.d(TAG, "set 1"); |
| 110 | mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0); |
| 111 | if (false) { |
| 112 | Log.d(TAG, "set 2"); |
| 113 | mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0); |
| 114 | } |
| 115 | Log.d(TAG, "remove 2"); |
| 116 | mStatusBarManager.removeIcon("tty"); |
| 117 | Log.d(TAG, "set 3"); |
| 118 | mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0); |
| 119 | } |
| 120 | }, |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 121 | new Test("Hide (FLAG_FULLSCREEN)") { |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 122 | public void run() { |
| 123 | Window win = getWindow(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 124 | win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| 125 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 126 | Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags)); |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 127 | } |
| 128 | }, |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 129 | new Test("Show (~FLAG_FULLSCREEN)") { |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 130 | public void run() { |
| 131 | Window win = getWindow(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 132 | win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 133 | Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags)); |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 134 | } |
| 135 | }, |
| 136 | new Test("Immersive: Enter") { |
| 137 | public void run() { |
| 138 | setImmersive(true); |
| 139 | } |
| 140 | }, |
| 141 | new Test("Immersive: Exit") { |
| 142 | public void run() { |
| 143 | setImmersive(false); |
| 144 | } |
| 145 | }, |
| 146 | new Test("Priority notification") { |
| 147 | public void run() { |
| 148 | Notification not = new Notification(StatusBarTest.this, |
Daniel Sandler | b59b944 | 2010-06-30 16:25:33 -0400 | [diff] [blame] | 149 | R.drawable.stat_sys_phone, |
| 150 | "Incoming call from: Imperious Leader", |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 151 | System.currentTimeMillis()-(1000*60*60*24), |
Daniel Sandler | b59b944 | 2010-06-30 16:25:33 -0400 | [diff] [blame] | 152 | "Imperious Leader", |
| 153 | "(888) 555-5038", |
| 154 | null |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 155 | ); |
| 156 | not.flags |= Notification.FLAG_HIGH_PRIORITY; |
| 157 | Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class); |
| 158 | int id = (int)System.currentTimeMillis(); // XXX HAX |
| 159 | fullScreenIntent.putExtra("id", id); |
| 160 | not.fullScreenIntent = PendingIntent.getActivity( |
| 161 | StatusBarTest.this, |
| 162 | 0, |
| 163 | fullScreenIntent, |
| 164 | PendingIntent.FLAG_CANCEL_CURRENT); |
Daniel Sandler | 27a8be4 | 2010-06-29 15:19:54 -0400 | [diff] [blame] | 165 | // if you tap on it you should get the original alert box |
| 166 | not.contentIntent = not.fullScreenIntent; |
Daniel Sandler | 8896783 | 2010-06-23 15:29:59 -0400 | [diff] [blame] | 167 | mNotificationManager.notify(id, not); |
| 168 | } |
| 169 | }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | new Test("Disable Alerts") { |
| 171 | public void run() { |
| 172 | mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); |
| 173 | } |
| 174 | }, |
Daniel Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 175 | new Test("Disable Ticker") { |
| 176 | public void run() { |
| 177 | mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER); |
| 178 | } |
| 179 | }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | new Test("Disable Expand in 3 sec.") { |
| 181 | public void run() { |
| 182 | mHandler.postDelayed(new Runnable() { |
| 183 | public void run() { |
| 184 | mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); |
| 185 | } |
| 186 | }, 3000); |
| 187 | } |
| 188 | }, |
| 189 | new Test("Disable Notifications in 3 sec.") { |
| 190 | public void run() { |
| 191 | mHandler.postDelayed(new Runnable() { |
| 192 | public void run() { |
| 193 | mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS); |
| 194 | } |
| 195 | }, 3000); |
| 196 | } |
| 197 | }, |
Daniel Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 198 | new Test("Disable Expand + Notifications in 3 sec.") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | public void run() { |
| 200 | mHandler.postDelayed(new Runnable() { |
| 201 | public void run() { |
| 202 | mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND |
| 203 | | StatusBarManager.DISABLE_NOTIFICATION_ICONS); |
| 204 | } |
| 205 | }, 3000); |
| 206 | } |
| 207 | }, |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 208 | new Test("Disable Navigation") { |
| 209 | public void run() { |
| 210 | mStatusBarManager.disable(StatusBarManager.DISABLE_NAVIGATION); |
| 211 | } |
| 212 | }, |
Daniel Sandler | 3e8f5a2 | 2010-12-03 14:52:10 -0500 | [diff] [blame] | 213 | new Test("Disable Clock") { |
| 214 | public void run() { |
| 215 | mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK); |
| 216 | } |
| 217 | }, |
Daniel Sandler | 6f6cf3c | 2010-12-16 12:54:03 -0500 | [diff] [blame] | 218 | new Test("Disable System Info") { |
| 219 | public void run() { |
| 220 | mStatusBarManager.disable(StatusBarManager.DISABLE_SYSTEM_INFO); |
| 221 | } |
| 222 | }, |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 223 | new Test("Disable everything in 3 sec") { |
| 224 | public void run() { |
| 225 | mHandler.postDelayed(new Runnable() { |
| 226 | public void run() { |
Daniel Sandler | 3e8f5a2 | 2010-12-03 14:52:10 -0500 | [diff] [blame] | 227 | mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 228 | } |
| 229 | }, 3000); |
| 230 | } |
| 231 | }, |
Daniel Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 232 | new Test("Enable everything") { |
| 233 | public void run() { |
Daniel Sandler | 3e8f5a2 | 2010-12-03 14:52:10 -0500 | [diff] [blame] | 234 | mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); |
Daniel Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 235 | } |
| 236 | }, |
| 237 | new Test("Enable everything in 3 sec.") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | public void run() { |
| 239 | mHandler.postDelayed(new Runnable() { |
| 240 | public void run() { |
| 241 | mStatusBarManager.disable(0); |
| 242 | } |
| 243 | }, 3000); |
| 244 | } |
| 245 | }, |
| 246 | new Test("Notify in 3 sec.") { |
| 247 | public void run() { |
| 248 | mHandler.postDelayed(new Runnable() { |
| 249 | public void run() { |
| 250 | mNotificationManager.notify(1, |
| 251 | new Notification(StatusBarTest.this, |
| 252 | R.drawable.ic_statusbar_missedcall, |
| 253 | "tick tick tick", |
| 254 | System.currentTimeMillis()-(1000*60*60*24), |
| 255 | "(453) 123-2328", |
| 256 | "", null |
| 257 | )); |
| 258 | } |
| 259 | }, 3000); |
| 260 | } |
| 261 | }, |
| 262 | new Test("Cancel Notification in 3 sec.") { |
| 263 | public void run() { |
| 264 | mHandler.postDelayed(new Runnable() { |
| 265 | public void run() { |
| 266 | mNotificationManager.cancel(1); |
| 267 | } |
| 268 | }, 3000); |
| 269 | } |
| 270 | }, |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 271 | new Test("Expand") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | public void run() { |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 273 | mStatusBarManager.expand(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | } |
| 275 | }, |
| 276 | new Test("Expand in 3 sec.") { |
| 277 | public void run() { |
| 278 | mHandler.postDelayed(new Runnable() { |
| 279 | public void run() { |
| 280 | mStatusBarManager.expand(); |
| 281 | } |
| 282 | }, 3000); |
| 283 | } |
| 284 | }, |
| 285 | new Test("Collapse in 3 sec.") { |
| 286 | public void run() { |
| 287 | mHandler.postDelayed(new Runnable() { |
| 288 | public void run() { |
| 289 | mStatusBarManager.collapse(); |
| 290 | } |
| 291 | }, 3000); |
| 292 | } |
| 293 | }, |
Joe Onorato | 0faeb07 | 2010-06-07 12:36:51 -0700 | [diff] [blame] | 294 | new Test("More icons") { |
| 295 | public void run() { |
| 296 | for (String slot: new String[] { |
| 297 | "sync_failing", |
| 298 | "gps", |
| 299 | "bluetooth", |
| 300 | "tty", |
| 301 | "speakerphone", |
| 302 | "mute", |
| 303 | "wifi", |
| 304 | "alarm_clock", |
| 305 | "secure", |
| 306 | }) { |
| 307 | mStatusBarManager.setIconVisibility(slot, true); |
| 308 | } |
| 309 | } |
| 310 | }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | }; |
| 312 | } |