StatusBarTest.java revision 091e1b8a86d34d2d51d2a5f7ae3cd903925fa5bf
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.os.Vibrator; 31import android.os.Bundle; 32import android.os.Handler; 33import android.util.Log; 34import android.net.Uri; 35import android.os.SystemClock; 36import android.widget.RemoteViews; 37import android.widget.Toast; 38import android.os.PowerManager; 39import android.view.Window; 40import android.view.WindowManager; 41 42public class StatusBarTest extends TestActivity 43{ 44 private final static String TAG = "StatusBarTest"; 45 StatusBarManager mStatusBarManager; 46 NotificationManager mNotificationManager; 47 Handler mHandler = new Handler(); 48 49 @Override 50 protected String tag() { 51 return TAG; 52 } 53 54 @Override 55 protected Test[] tests() { 56 mStatusBarManager = (StatusBarManager)getSystemService(STATUS_BAR_SERVICE); 57 mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 58 59 return mTests; 60 } 61 62 private Test[] mTests = new Test[] { 63 new Test("Hide (FLAG_FULLSCREEN)") { 64 public void run() { 65 Window win = getWindow(); 66 win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 67 WindowManager.LayoutParams.FLAG_FULLSCREEN); 68 Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags)); 69 } 70 }, 71 new Test("Show (~FLAG_FULLSCREEN)") { 72 public void run() { 73 Window win = getWindow(); 74 win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN); 75 Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags)); 76 } 77 }, 78 new Test("Immersive: Enter") { 79 public void run() { 80 setImmersive(true); 81 } 82 }, 83 new Test("Immersive: Exit") { 84 public void run() { 85 setImmersive(false); 86 } 87 }, 88 new Test("Priority notification") { 89 public void run() { 90 Notification not = new Notification(StatusBarTest.this, 91 R.drawable.stat_sys_phone, 92 "Incoming call from: Imperious Leader", 93 System.currentTimeMillis()-(1000*60*60*24), 94 "Imperious Leader", 95 "(888) 555-5038", 96 null 97 ); 98 not.flags |= Notification.FLAG_HIGH_PRIORITY; 99 Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class); 100 int id = (int)System.currentTimeMillis(); // XXX HAX 101 fullScreenIntent.putExtra("id", id); 102 not.fullScreenIntent = PendingIntent.getActivity( 103 StatusBarTest.this, 104 0, 105 fullScreenIntent, 106 PendingIntent.FLAG_CANCEL_CURRENT); 107 // if you tap on it you should get the original alert box 108 not.contentIntent = not.fullScreenIntent; 109 mNotificationManager.notify(id, not); 110 } 111 }, 112 new Test("Disable Alerts") { 113 public void run() { 114 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); 115 } 116 }, 117 new Test("Disable Ticker") { 118 public void run() { 119 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER); 120 } 121 }, 122 new Test("Disable Expand in 3 sec.") { 123 public void run() { 124 mHandler.postDelayed(new Runnable() { 125 public void run() { 126 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); 127 } 128 }, 3000); 129 } 130 }, 131 new Test("Disable Notifications in 3 sec.") { 132 public void run() { 133 mHandler.postDelayed(new Runnable() { 134 public void run() { 135 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS); 136 } 137 }, 3000); 138 } 139 }, 140 new Test("Disable Expand + Notifications in 3 sec.") { 141 public void run() { 142 mHandler.postDelayed(new Runnable() { 143 public void run() { 144 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND 145 | StatusBarManager.DISABLE_NOTIFICATION_ICONS); 146 } 147 }, 3000); 148 } 149 }, 150 new Test("Disable Navigation") { 151 public void run() { 152 mStatusBarManager.disable(StatusBarManager.DISABLE_NAVIGATION); 153 } 154 }, 155 new Test("Disable everything in 3 sec") { 156 public void run() { 157 mHandler.postDelayed(new Runnable() { 158 public void run() { 159 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND 160 | StatusBarManager.DISABLE_NOTIFICATION_ICONS 161 | StatusBarManager.DISABLE_NOTIFICATION_ALERTS 162 | StatusBarManager.DISABLE_SYSTEM_INFO 163 | StatusBarManager.DISABLE_NAVIGATION); 164 } 165 }, 3000); 166 } 167 }, 168 new Test("Enable everything") { 169 public void run() { 170 mStatusBarManager.disable(0); 171 } 172 }, 173 new Test("Enable everything in 3 sec.") { 174 public void run() { 175 mHandler.postDelayed(new Runnable() { 176 public void run() { 177 mStatusBarManager.disable(0); 178 } 179 }, 3000); 180 } 181 }, 182 new Test("Notify in 3 sec.") { 183 public void run() { 184 mHandler.postDelayed(new Runnable() { 185 public void run() { 186 mNotificationManager.notify(1, 187 new Notification(StatusBarTest.this, 188 R.drawable.ic_statusbar_missedcall, 189 "tick tick tick", 190 System.currentTimeMillis()-(1000*60*60*24), 191 "(453) 123-2328", 192 "", null 193 )); 194 } 195 }, 3000); 196 } 197 }, 198 new Test("Cancel Notification in 3 sec.") { 199 public void run() { 200 mHandler.postDelayed(new Runnable() { 201 public void run() { 202 mNotificationManager.cancel(1); 203 } 204 }, 3000); 205 } 206 }, 207 new Test("Expand") { 208 public void run() { 209 mStatusBarManager.expand(); 210 } 211 }, 212 new Test("Expand in 3 sec.") { 213 public void run() { 214 mHandler.postDelayed(new Runnable() { 215 public void run() { 216 mStatusBarManager.expand(); 217 } 218 }, 3000); 219 } 220 }, 221 new Test("Collapse in 3 sec.") { 222 public void run() { 223 mHandler.postDelayed(new Runnable() { 224 public void run() { 225 mStatusBarManager.collapse(); 226 } 227 }, 3000); 228 } 229 }, 230 new Test("More icons") { 231 public void run() { 232 for (String slot: new String[] { 233 "sync_failing", 234 "gps", 235 "bluetooth", 236 "tty", 237 "speakerphone", 238 "mute", 239 "wifi", 240 "alarm_clock", 241 "secure", 242 }) { 243 mStatusBarManager.setIconVisibility(slot, true); 244 } 245 } 246 }, 247 }; 248} 249