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("Double Remove") { 64 public void run() { 65 Log.d(TAG, "set 0"); 66 mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0); 67 Log.d(TAG, "remove 1"); 68 mStatusBarManager.removeIcon("tty"); 69 70 SystemClock.sleep(1000); 71 72 Log.d(TAG, "set 1"); 73 mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0); 74 if (false) { 75 Log.d(TAG, "set 2"); 76 mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0); 77 } 78 Log.d(TAG, "remove 2"); 79 mStatusBarManager.removeIcon("tty"); 80 Log.d(TAG, "set 3"); 81 mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0); 82 } 83 }, 84 new Test("Hide") { 85 public void run() { 86 Window win = getWindow(); 87 WindowManager.LayoutParams winParams = win.getAttributes(); 88 winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; 89 win.setAttributes(winParams); 90 } 91 }, 92 new Test("Show") { 93 public void run() { 94 Window win = getWindow(); 95 WindowManager.LayoutParams winParams = win.getAttributes(); 96 winParams.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; 97 win.setAttributes(winParams); 98 } 99 }, 100 new Test("fullScreenIntent") { 101 public void run() { 102 Notification not = new Notification(StatusBarTest.this, 103 R.drawable.stat_sys_phone, 104 "Incoming call from: Imperious Leader", 105 System.currentTimeMillis()-(1000*60*60*24), 106 "Imperious Leader", 107 "(888) 555-5038", 108 null 109 ); 110 Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class); 111 int id = (int)System.currentTimeMillis(); 112 fullScreenIntent.putExtra("id", id); 113 not.fullScreenIntent = PendingIntent.getActivity( 114 StatusBarTest.this, 115 0, 116 fullScreenIntent, 117 PendingIntent.FLAG_CANCEL_CURRENT); 118 // if you tap on it you should get the original alert box 119 not.contentIntent = not.fullScreenIntent; 120 mNotificationManager.notify(id, not); 121 } 122 }, 123 new Test("Disable Alerts") { 124 public void run() { 125 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); 126 } 127 }, 128 new Test("Disable Ticker") { 129 public void run() { 130 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER); 131 } 132 }, 133 new Test("Disable Expand in 3 sec.") { 134 public void run() { 135 mHandler.postDelayed(new Runnable() { 136 public void run() { 137 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); 138 } 139 }, 3000); 140 } 141 }, 142 new Test("Disable Notifications in 3 sec.") { 143 public void run() { 144 mHandler.postDelayed(new Runnable() { 145 public void run() { 146 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS); 147 } 148 }, 3000); 149 } 150 }, 151 new Test("Disable Expand + Notifications in 3 sec.") { 152 public void run() { 153 mHandler.postDelayed(new Runnable() { 154 public void run() { 155 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND 156 | StatusBarManager.DISABLE_NOTIFICATION_ICONS); 157 } 158 }, 3000); 159 } 160 }, 161 new Test("Enable everything") { 162 public void run() { 163 mStatusBarManager.disable(0); 164 } 165 }, 166 new Test("Enable everything in 3 sec.") { 167 public void run() { 168 mHandler.postDelayed(new Runnable() { 169 public void run() { 170 mStatusBarManager.disable(0); 171 } 172 }, 3000); 173 } 174 }, 175 new Test("Notify in 3 sec.") { 176 public void run() { 177 mHandler.postDelayed(new Runnable() { 178 public void run() { 179 mNotificationManager.notify(1, 180 new Notification(StatusBarTest.this, 181 R.drawable.ic_statusbar_missedcall, 182 "tick tick tick", 183 System.currentTimeMillis()-(1000*60*60*24), 184 "(453) 123-2328", 185 "", null 186 )); 187 } 188 }, 3000); 189 } 190 }, 191 new Test("Cancel Notification in 3 sec.") { 192 public void run() { 193 mHandler.postDelayed(new Runnable() { 194 public void run() { 195 mNotificationManager.cancel(1); 196 } 197 }, 3000); 198 } 199 }, 200 new Test("Expand") { 201 public void run() { 202 mStatusBarManager.expand(); 203 } 204 }, 205 new Test("Expand in 3 sec.") { 206 public void run() { 207 mHandler.postDelayed(new Runnable() { 208 public void run() { 209 mStatusBarManager.expand(); 210 } 211 }, 3000); 212 } 213 }, 214 new Test("Collapse in 3 sec.") { 215 public void run() { 216 mHandler.postDelayed(new Runnable() { 217 public void run() { 218 mStatusBarManager.collapse(); 219 } 220 }, 3000); 221 } 222 }, 223 new Test("More icons") { 224 public void run() { 225 for (String slot: new String[] { 226 "sync_failing", 227 "gps", 228 "bluetooth", 229 "tty", 230 "speakerphone", 231 "mute", 232 "wifi", 233 "alarm_clock", 234 "secure", 235 }) { 236 mStatusBarManager.setIconVisibility(slot, true); 237 } 238 } 239 }, 240 }; 241} 242