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.Notification; 20 import android.app.NotificationManager; 21 import android.view.View; 22 import android.content.Intent; 23 import android.app.PendingIntent; 24 import android.app.StatusBarManager; 25 import android.os.Handler; 26 import android.util.Log; 27 import android.os.SystemClock; 28 import android.view.Window; 29 import android.view.WindowManager; 30 31 public class StatusBarTest extends TestActivity 32 { 33 private final static String TAG = "StatusBarTest"; 34 StatusBarManager mStatusBarManager; 35 NotificationManager mNotificationManager; 36 Handler mHandler = new Handler(); 37 int mUiVisibility = 0; 38 View mListView; 39 40 View.OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener 41 = new View.OnSystemUiVisibilityChangeListener() { 42 public void onSystemUiVisibilityChange(int visibility) { 43 Log.d(TAG, "onSystemUiVisibilityChange visibility=" + visibility); 44 } 45 }; 46 47 @Override 48 protected String tag() { 49 return TAG; 50 } 51 52 @Override 53 protected Test[] tests() { 54 mStatusBarManager = (StatusBarManager)getSystemService(STATUS_BAR_SERVICE); 55 mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 56 57 return mTests; 58 } 59 60 @Override 61 public void onResume() { 62 super.onResume(); 63 64 mListView = findViewById(android.R.id.list); 65 mListView.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener); 66 } 67 68 private Test[] mTests = new Test[] { 69 new Test("toggle LOW_PROFILE (lights out)") { 70 public void run() { 71 if (0 != (mUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE)) { 72 mUiVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE; 73 } else { 74 mUiVisibility |= View.SYSTEM_UI_FLAG_LOW_PROFILE; 75 } 76 mListView.setSystemUiVisibility(mUiVisibility); 77 } 78 }, 79 new Test("toggle HIDE_NAVIGATION") { 80 public void run() { 81 if (0 != (mUiVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)) { 82 mUiVisibility &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 83 } else { 84 mUiVisibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 85 } 86 mListView.setSystemUiVisibility(mUiVisibility); 87 88 } 89 }, 90 new Test("clear SYSTEM_UI_FLAGs") { 91 public void run() { 92 mUiVisibility = 0; 93 mListView.setSystemUiVisibility(mUiVisibility); 94 } 95 }, 96 // new Test("no setSystemUiVisibility") { 97 // public void run() { 98 // View v = findViewById(android.R.id.list); 99 // v.setOnSystemUiVisibilityChangeListener(null); 100 // v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 101 // } 102 // }, 103 new Test("systemUiVisibility: STATUS_BAR_DISABLE_HOME") { 104 public void run() { 105 mListView.setSystemUiVisibility(View.STATUS_BAR_DISABLE_HOME); 106 } 107 }, 108 new Test("Double Remove") { 109 public void run() { 110 Log.d(TAG, "set 0"); 111 mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null); 112 Log.d(TAG, "remove 1"); 113 mStatusBarManager.removeIcon("tty"); 114 115 SystemClock.sleep(1000); 116 117 Log.d(TAG, "set 1"); 118 mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null); 119 if (false) { 120 Log.d(TAG, "set 2"); 121 mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null); 122 } 123 Log.d(TAG, "remove 2"); 124 mStatusBarManager.removeIcon("tty"); 125 Log.d(TAG, "set 3"); 126 mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null); 127 } 128 }, 129 new Test("Hide (FLAG_FULLSCREEN)") { 130 public void run() { 131 Window win = getWindow(); 132 win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 133 WindowManager.LayoutParams.FLAG_FULLSCREEN); 134 Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags)); 135 } 136 }, 137 new Test("Show (~FLAG_FULLSCREEN)") { 138 public void run() { 139 Window win = getWindow(); 140 win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN); 141 Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags)); 142 } 143 }, 144 new Test("Immersive: Enter") { 145 public void run() { 146 setImmersive(true); 147 } 148 }, 149 new Test("Immersive: Exit") { 150 public void run() { 151 setImmersive(false); 152 } 153 }, 154 new Test("Priority notification") { 155 public void run() { 156 Notification not = new Notification(); 157 not.icon = R.drawable.stat_sys_phone; 158 not.when = System.currentTimeMillis()-(1000*60*60*24); 159 not.setLatestEventInfo(StatusBarTest.this, 160 "Incoming call", 161 "from: Imperious Leader", 162 null 163 ); 164 not.flags |= Notification.FLAG_HIGH_PRIORITY; 165 Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class); 166 int id = (int)System.currentTimeMillis(); // XXX HAX 167 fullScreenIntent.putExtra("id", id); 168 not.fullScreenIntent = PendingIntent.getActivity( 169 StatusBarTest.this, 170 0, 171 fullScreenIntent, 172 PendingIntent.FLAG_CANCEL_CURRENT); 173 // if you tap on it you should get the original alert box 174 not.contentIntent = not.fullScreenIntent; 175 mNotificationManager.notify(id, not); 176 } 177 }, 178 new Test("Disable Alerts") { 179 public void run() { 180 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); 181 } 182 }, 183 new Test("Disable Ticker") { 184 public void run() { 185 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER); 186 } 187 }, 188 new Test("Disable Expand in 3 sec.") { 189 public void run() { 190 mHandler.postDelayed(new Runnable() { 191 public void run() { 192 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); 193 } 194 }, 3000); 195 } 196 }, 197 new Test("Disable Notifications in 3 sec.") { 198 public void run() { 199 mHandler.postDelayed(new Runnable() { 200 public void run() { 201 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS); 202 } 203 }, 3000); 204 } 205 }, 206 new Test("Disable Expand + Notifications in 3 sec.") { 207 public void run() { 208 mHandler.postDelayed(new Runnable() { 209 public void run() { 210 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND 211 | StatusBarManager.DISABLE_NOTIFICATION_ICONS); 212 } 213 }, 3000); 214 } 215 }, 216 new Test("Disable Home (StatusBarManager)") { 217 public void run() { 218 mStatusBarManager.disable(StatusBarManager.DISABLE_HOME); 219 } 220 }, 221 new Test("Disable Back (StatusBarManager)") { 222 public void run() { 223 mStatusBarManager.disable(StatusBarManager.DISABLE_BACK); 224 } 225 }, 226 new Test("Disable Recent (StatusBarManager)") { 227 public void run() { 228 mStatusBarManager.disable(StatusBarManager.DISABLE_RECENT); 229 } 230 }, 231 new Test("Disable Clock") { 232 public void run() { 233 mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK); 234 } 235 }, 236 new Test("Disable System Info") { 237 public void run() { 238 mStatusBarManager.disable(StatusBarManager.DISABLE_SYSTEM_INFO); 239 } 240 }, 241 new Test("Disable everything in 3 sec") { 242 public void run() { 243 mHandler.postDelayed(new Runnable() { 244 public void run() { 245 mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE); 246 } 247 }, 3000); 248 } 249 }, 250 new Test("Enable everything") { 251 public void run() { 252 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); 253 } 254 }, 255 new Test("Enable everything in 3 sec.") { 256 public void run() { 257 mHandler.postDelayed(new Runnable() { 258 public void run() { 259 mStatusBarManager.disable(0); 260 } 261 }, 3000); 262 } 263 }, 264 new Test("Notify in 3 sec.") { 265 public void run() { 266 mHandler.postDelayed(new Runnable() { 267 public void run() { 268 mNotificationManager.notify(1, 269 new Notification( 270 R.drawable.ic_statusbar_missedcall, 271 "tick tick tick", 272 System.currentTimeMillis()-(1000*60*60*24) 273 )); 274 } 275 }, 3000); 276 } 277 }, 278 new Test("Cancel Notification in 3 sec.") { 279 public void run() { 280 mHandler.postDelayed(new Runnable() { 281 public void run() { 282 mNotificationManager.cancel(1); 283 } 284 }, 3000); 285 } 286 }, 287 new Test("Expand notifications") { 288 public void run() { 289 mStatusBarManager.expandNotificationsPanel(); 290 } 291 }, 292 new Test(" ... in 3 sec.") { 293 public void run() { 294 mHandler.postDelayed(new Runnable() { 295 public void run() { 296 mStatusBarManager.expandNotificationsPanel(); 297 } 298 }, 3000); 299 } 300 }, 301 new Test("Expand settings") { 302 public void run() { 303 mStatusBarManager.expandSettingsPanel(); 304 } 305 }, 306 new Test(" ... in 3 sec.") { 307 public void run() { 308 mHandler.postDelayed(new Runnable() { 309 public void run() { 310 mStatusBarManager.expandSettingsPanel(); 311 } 312 }, 3000); 313 } 314 }, 315 new Test("Collapse panels in 3 sec.") { 316 public void run() { 317 mHandler.postDelayed(new Runnable() { 318 public void run() { 319 mStatusBarManager.collapsePanels(); 320 } 321 }, 3000); 322 } 323 }, 324 new Test("More icons") { 325 public void run() { 326 for (String slot: new String[] { 327 "sync_failing", 328 "gps", 329 "bluetooth", 330 "tty", 331 "speakerphone", 332 "mute", 333 "wifi", 334 "alarm_clock", 335 "secure", 336 }) { 337 mStatusBarManager.setIconVisibility(slot, true); 338 } 339 } 340 }, 341 }; 342 } 343