StatusBarTest.java revision 60ee25643e0a7b8841063a4e97b0f18c51807e91
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 R.drawable.stat_sys_phone, 172 "Incoming call from: Imperious Leader", 173 System.currentTimeMillis()-(1000*60*60*24) 174 ); 175 not.flags |= Notification.FLAG_HIGH_PRIORITY; 176 Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class); 177 int id = (int)System.currentTimeMillis(); // XXX HAX 178 fullScreenIntent.putExtra("id", id); 179 not.fullScreenIntent = PendingIntent.getActivity( 180 StatusBarTest.this, 181 0, 182 fullScreenIntent, 183 PendingIntent.FLAG_CANCEL_CURRENT); 184 // if you tap on it you should get the original alert box 185 not.contentIntent = not.fullScreenIntent; 186 mNotificationManager.notify(id, not); 187 } 188 }, 189 new Test("Disable Alerts") { 190 public void run() { 191 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); 192 } 193 }, 194 new Test("Disable Ticker") { 195 public void run() { 196 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER); 197 } 198 }, 199 new Test("Disable Expand in 3 sec.") { 200 public void run() { 201 mHandler.postDelayed(new Runnable() { 202 public void run() { 203 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); 204 } 205 }, 3000); 206 } 207 }, 208 new Test("Disable Notifications in 3 sec.") { 209 public void run() { 210 mHandler.postDelayed(new Runnable() { 211 public void run() { 212 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS); 213 } 214 }, 3000); 215 } 216 }, 217 new Test("Disable Expand + Notifications in 3 sec.") { 218 public void run() { 219 mHandler.postDelayed(new Runnable() { 220 public void run() { 221 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND 222 | StatusBarManager.DISABLE_NOTIFICATION_ICONS); 223 } 224 }, 3000); 225 } 226 }, 227 new Test("Disable Navigation") { 228 public void run() { 229 mStatusBarManager.disable(StatusBarManager.DISABLE_NAVIGATION); 230 } 231 }, 232 new Test("Disable Clock") { 233 public void run() { 234 mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK); 235 } 236 }, 237 new Test("Disable System Info") { 238 public void run() { 239 mStatusBarManager.disable(StatusBarManager.DISABLE_SYSTEM_INFO); 240 } 241 }, 242 new Test("Disable everything in 3 sec") { 243 public void run() { 244 mHandler.postDelayed(new Runnable() { 245 public void run() { 246 mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE); 247 } 248 }, 3000); 249 } 250 }, 251 new Test("Enable everything") { 252 public void run() { 253 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); 254 } 255 }, 256 new Test("Enable everything in 3 sec.") { 257 public void run() { 258 mHandler.postDelayed(new Runnable() { 259 public void run() { 260 mStatusBarManager.disable(0); 261 } 262 }, 3000); 263 } 264 }, 265 new Test("Notify in 3 sec.") { 266 public void run() { 267 mHandler.postDelayed(new Runnable() { 268 public void run() { 269 mNotificationManager.notify(1, 270 new Notification( 271 R.drawable.ic_statusbar_missedcall, 272 "tick tick tick", 273 System.currentTimeMillis()-(1000*60*60*24) 274 )); 275 } 276 }, 3000); 277 } 278 }, 279 new Test("Cancel Notification in 3 sec.") { 280 public void run() { 281 mHandler.postDelayed(new Runnable() { 282 public void run() { 283 mNotificationManager.cancel(1); 284 } 285 }, 3000); 286 } 287 }, 288 new Test("Expand") { 289 public void run() { 290 mStatusBarManager.expand(); 291 } 292 }, 293 new Test("Expand in 3 sec.") { 294 public void run() { 295 mHandler.postDelayed(new Runnable() { 296 public void run() { 297 mStatusBarManager.expand(); 298 } 299 }, 3000); 300 } 301 }, 302 new Test("Collapse in 3 sec.") { 303 public void run() { 304 mHandler.postDelayed(new Runnable() { 305 public void run() { 306 mStatusBarManager.collapse(); 307 } 308 }, 3000); 309 } 310 }, 311 new Test("More icons") { 312 public void run() { 313 for (String slot: new String[] { 314 "sync_failing", 315 "gps", 316 "bluetooth", 317 "tty", 318 "speakerphone", 319 "mute", 320 "wifi", 321 "alarm_clock", 322 "secure", 323 }) { 324 mStatusBarManager.setIconVisibility(slot, true); 325 } 326 } 327 }, 328 }; 329} 330