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