StatusBarTest.java revision 3e8f5a2c1beb4b918856063880e05125946e4347
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 (FLAG_FULLSCREEN)") {
85            public void run() {
86                Window win = getWindow();
87                win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
88                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
89                Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
90            }
91        },
92        new Test("Show (~FLAG_FULLSCREEN)") {
93            public void run() {
94                Window win = getWindow();
95                win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
96                Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
97            }
98        },
99        new Test("Immersive: Enter") {
100            public void run() {
101                setImmersive(true);
102            }
103        },
104        new Test("Immersive: Exit") {
105            public void run() {
106                setImmersive(false);
107            }
108        },
109        new Test("Priority notification") {
110            public void run() {
111                Notification not = new Notification(StatusBarTest.this,
112                                R.drawable.stat_sys_phone,
113                                "Incoming call from: Imperious Leader",
114                                System.currentTimeMillis()-(1000*60*60*24),
115                                "Imperious Leader",
116                                "(888) 555-5038",
117                                null
118                                );
119                not.flags |= Notification.FLAG_HIGH_PRIORITY;
120                Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
121                int id = (int)System.currentTimeMillis(); // XXX HAX
122                fullScreenIntent.putExtra("id", id);
123                not.fullScreenIntent = PendingIntent.getActivity(
124                    StatusBarTest.this,
125                    0,
126                    fullScreenIntent,
127                    PendingIntent.FLAG_CANCEL_CURRENT);
128                // if you tap on it you should get the original alert box
129                not.contentIntent = not.fullScreenIntent;
130                mNotificationManager.notify(id, not);
131            }
132        },
133        new Test("Disable Alerts") {
134            public void run() {
135                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS);
136            }
137        },
138        new Test("Disable Ticker") {
139            public void run() {
140                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER);
141            }
142        },
143        new Test("Disable Expand in 3 sec.") {
144            public void run() {
145                mHandler.postDelayed(new Runnable() {
146                        public void run() {
147                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
148                        }
149                    }, 3000);
150            }
151        },
152        new Test("Disable Notifications in 3 sec.") {
153            public void run() {
154                mHandler.postDelayed(new Runnable() {
155                        public void run() {
156                            mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS);
157                        }
158                    }, 3000);
159            }
160        },
161        new Test("Disable Expand + Notifications in 3 sec.") {
162            public void run() {
163                mHandler.postDelayed(new Runnable() {
164                        public void run() {
165                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND
166                                    | StatusBarManager.DISABLE_NOTIFICATION_ICONS);
167                        }
168                    }, 3000);
169            }
170        },
171        new Test("Disable Navigation") {
172            public void run() {
173                mStatusBarManager.disable(StatusBarManager.DISABLE_NAVIGATION);
174            }
175        },
176        new Test("Disable Clock") {
177            public void run() {
178                mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK);
179            }
180        },
181        new Test("Disable everything in 3 sec") {
182            public void run() {
183                mHandler.postDelayed(new Runnable() {
184                        public void run() {
185                            mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE);
186                        }
187                    }, 3000);
188            }
189        },
190        new Test("Enable everything") {
191            public void run() {
192                mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
193            }
194        },
195        new Test("Enable everything in 3 sec.") {
196            public void run() {
197                mHandler.postDelayed(new Runnable() {
198                        public void run() {
199                            mStatusBarManager.disable(0);
200                        }
201                    }, 3000);
202            }
203        },
204        new Test("Notify in 3 sec.") {
205            public void run() {
206                mHandler.postDelayed(new Runnable() {
207                        public void run() {
208                            mNotificationManager.notify(1,
209                                    new Notification(StatusBarTest.this,
210                                            R.drawable.ic_statusbar_missedcall,
211                                            "tick tick tick",
212                                            System.currentTimeMillis()-(1000*60*60*24),
213                                            "(453) 123-2328",
214                                            "", null
215                                            ));
216                        }
217                    }, 3000);
218            }
219        },
220        new Test("Cancel Notification in 3 sec.") {
221            public void run() {
222                mHandler.postDelayed(new Runnable() {
223                        public void run() {
224                            mNotificationManager.cancel(1);
225                        }
226                    }, 3000);
227            }
228        },
229        new Test("Expand") {
230            public void run() {
231                mStatusBarManager.expand();
232            }
233        },
234        new Test("Expand in 3 sec.") {
235            public void run() {
236                mHandler.postDelayed(new Runnable() {
237                        public void run() {
238                            mStatusBarManager.expand();
239                        }
240                    }, 3000);
241            }
242        },
243        new Test("Collapse in 3 sec.") {
244            public void run() {
245                mHandler.postDelayed(new Runnable() {
246                        public void run() {
247                            mStatusBarManager.collapse();
248                        }
249                    }, 3000);
250            }
251        },
252        new Test("More icons") {
253            public void run() {
254                for (String slot: new String[] {
255                            "sync_failing",
256                            "gps",
257                            "bluetooth",
258                            "tty",
259                            "speakerphone",
260                            "mute",
261                            "wifi",
262                            "alarm_clock",
263                            "secure",
264                        }) {
265                    mStatusBarManager.setIconVisibility(slot, true);
266                }
267            }
268        },
269    };
270}
271