StatusBarTest.java revision 8896783dc1d31c5274b277c364da0ffe7cc27cca
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") { 64 public void run() { 65 Window win = getWindow(); 66 WindowManager.LayoutParams winParams = win.getAttributes(); 67 winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; 68 win.setAttributes(winParams); 69 } 70 }, 71 new Test("Show") { 72 public void run() { 73 Window win = getWindow(); 74 WindowManager.LayoutParams winParams = win.getAttributes(); 75 winParams.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; 76 win.setAttributes(winParams); 77 } 78 }, 79 new Test("Immersive: Enter") { 80 public void run() { 81 setImmersive(true); 82 } 83 }, 84 new Test("Immersive: Exit") { 85 public void run() { 86 setImmersive(false); 87 } 88 }, 89 new Test("Priority notification") { 90 public void run() { 91 Notification not = new Notification(StatusBarTest.this, 92 R.drawable.ic_statusbar_missedcall, 93 "tick tick tick", 94 System.currentTimeMillis()-(1000*60*60*24), 95 "(453) 123-2328", 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 mNotificationManager.notify(id, not); 108 } 109 }, 110 new Test("Disable Alerts") { 111 public void run() { 112 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); 113 } 114 }, 115 new Test("Disable Ticker") { 116 public void run() { 117 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER); 118 } 119 }, 120 new Test("Disable Expand in 3 sec.") { 121 public void run() { 122 mHandler.postDelayed(new Runnable() { 123 public void run() { 124 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); 125 } 126 }, 3000); 127 } 128 }, 129 new Test("Disable Notifications in 3 sec.") { 130 public void run() { 131 mHandler.postDelayed(new Runnable() { 132 public void run() { 133 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS); 134 } 135 }, 3000); 136 } 137 }, 138 new Test("Disable Expand + Notifications in 3 sec.") { 139 public void run() { 140 mHandler.postDelayed(new Runnable() { 141 public void run() { 142 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND 143 | StatusBarManager.DISABLE_NOTIFICATION_ICONS); 144 } 145 }, 3000); 146 } 147 }, 148 new Test("Enable everything") { 149 public void run() { 150 mStatusBarManager.disable(0); 151 } 152 }, 153 new Test("Enable everything in 3 sec.") { 154 public void run() { 155 mHandler.postDelayed(new Runnable() { 156 public void run() { 157 mStatusBarManager.disable(0); 158 } 159 }, 3000); 160 } 161 }, 162 new Test("Notify in 3 sec.") { 163 public void run() { 164 mHandler.postDelayed(new Runnable() { 165 public void run() { 166 mNotificationManager.notify(1, 167 new Notification(StatusBarTest.this, 168 R.drawable.ic_statusbar_missedcall, 169 "tick tick tick", 170 System.currentTimeMillis()-(1000*60*60*24), 171 "(453) 123-2328", 172 "", null 173 )); 174 } 175 }, 3000); 176 } 177 }, 178 new Test("Cancel Notification in 3 sec.") { 179 public void run() { 180 mHandler.postDelayed(new Runnable() { 181 public void run() { 182 mNotificationManager.cancel(1); 183 } 184 }, 3000); 185 } 186 }, 187 new Test("Expand") { 188 public void run() { 189 mStatusBarManager.expand(); 190 } 191 }, 192 new Test("Expand in 3 sec.") { 193 public void run() { 194 mHandler.postDelayed(new Runnable() { 195 public void run() { 196 mStatusBarManager.expand(); 197 } 198 }, 3000); 199 } 200 }, 201 new Test("Collapse in 3 sec.") { 202 public void run() { 203 mHandler.postDelayed(new Runnable() { 204 public void run() { 205 mStatusBarManager.collapse(); 206 } 207 }, 3000); 208 } 209 }, 210 new Test("More icons") { 211 public void run() { 212 for (String slot: new String[] { 213 "sync_failing", 214 "gps", 215 "bluetooth", 216 "tty", 217 "speakerphone", 218 "mute", 219 "wifi", 220 "alarm_clock", 221 "secure", 222 }) { 223 mStatusBarManager.setIconVisibility(slot, true); 224 } 225 } 226 }, 227 }; 228} 229