StatusBarTest.java revision 664644d9e012aa2a28ac96f305b1ce6499ec8806
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
52    View.OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener
53            = new View.OnSystemUiVisibilityChangeListener() {
54        public void onSystemUiVisibilityChange(int visibility) {
55            Log.d(TAG, "onSystemUiVisibilityChange visibility=" + visibility);
56        }
57    };
58
59    @Override
60    protected String tag() {
61        return TAG;
62    }
63
64    @Override
65    protected Test[] tests() {
66        mStatusBarManager = (StatusBarManager)getSystemService(STATUS_BAR_SERVICE);
67        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
68
69        return mTests;
70    }
71
72    private Test[] mTests = new Test[] {
73        new Test("STATUS_BAR_HIDDEN") {
74            public void run() {
75                View v = findViewById(android.R.id.list);
76                v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
77                v.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
78            }
79        },
80        new Test("not STATUS_BAR_HIDDEN") {
81            public void run() {
82                View v = findViewById(android.R.id.list);
83                v.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
84                v.setOnSystemUiVisibilityChangeListener(null);
85            }
86        },
87        new Test("Double Remove") {
88            public void run() {
89                Log.d(TAG, "set 0");
90                mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0);
91                Log.d(TAG, "remove 1");
92                mStatusBarManager.removeIcon("tty");
93
94                SystemClock.sleep(1000);
95
96                Log.d(TAG, "set 1");
97                mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0);
98                if (false) {
99                    Log.d(TAG, "set 2");
100                    mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0);
101                }
102                Log.d(TAG, "remove 2");
103                mStatusBarManager.removeIcon("tty");
104                Log.d(TAG, "set 3");
105                mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0);
106            }
107        },
108        new Test("Hide (FLAG_FULLSCREEN)") {
109            public void run() {
110                Window win = getWindow();
111                win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
112                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
113                Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
114            }
115        },
116        new Test("Show (~FLAG_FULLSCREEN)") {
117            public void run() {
118                Window win = getWindow();
119                win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
120                Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
121            }
122        },
123        new Test("Immersive: Enter") {
124            public void run() {
125                setImmersive(true);
126            }
127        },
128        new Test("Immersive: Exit") {
129            public void run() {
130                setImmersive(false);
131            }
132        },
133        new Test("Priority notification") {
134            public void run() {
135                Notification not = new Notification(StatusBarTest.this,
136                                R.drawable.stat_sys_phone,
137                                "Incoming call from: Imperious Leader",
138                                System.currentTimeMillis()-(1000*60*60*24),
139                                "Imperious Leader",
140                                "(888) 555-5038",
141                                null
142                                );
143                not.flags |= Notification.FLAG_HIGH_PRIORITY;
144                Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
145                int id = (int)System.currentTimeMillis(); // XXX HAX
146                fullScreenIntent.putExtra("id", id);
147                not.fullScreenIntent = PendingIntent.getActivity(
148                    StatusBarTest.this,
149                    0,
150                    fullScreenIntent,
151                    PendingIntent.FLAG_CANCEL_CURRENT);
152                // if you tap on it you should get the original alert box
153                not.contentIntent = not.fullScreenIntent;
154                mNotificationManager.notify(id, not);
155            }
156        },
157        new Test("Disable Alerts") {
158            public void run() {
159                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS);
160            }
161        },
162        new Test("Disable Ticker") {
163            public void run() {
164                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER);
165            }
166        },
167        new Test("Disable Expand in 3 sec.") {
168            public void run() {
169                mHandler.postDelayed(new Runnable() {
170                        public void run() {
171                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
172                        }
173                    }, 3000);
174            }
175        },
176        new Test("Disable Notifications in 3 sec.") {
177            public void run() {
178                mHandler.postDelayed(new Runnable() {
179                        public void run() {
180                            mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS);
181                        }
182                    }, 3000);
183            }
184        },
185        new Test("Disable Expand + Notifications in 3 sec.") {
186            public void run() {
187                mHandler.postDelayed(new Runnable() {
188                        public void run() {
189                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND
190                                    | StatusBarManager.DISABLE_NOTIFICATION_ICONS);
191                        }
192                    }, 3000);
193            }
194        },
195        new Test("Disable Navigation") {
196            public void run() {
197                mStatusBarManager.disable(StatusBarManager.DISABLE_NAVIGATION);
198            }
199        },
200        new Test("Disable Clock") {
201            public void run() {
202                mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK);
203            }
204        },
205        new Test("Disable System Info") {
206            public void run() {
207                mStatusBarManager.disable(StatusBarManager.DISABLE_SYSTEM_INFO);
208            }
209        },
210        new Test("Disable everything in 3 sec") {
211            public void run() {
212                mHandler.postDelayed(new Runnable() {
213                        public void run() {
214                            mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE);
215                        }
216                    }, 3000);
217            }
218        },
219        new Test("Enable everything") {
220            public void run() {
221                mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
222            }
223        },
224        new Test("Enable everything in 3 sec.") {
225            public void run() {
226                mHandler.postDelayed(new Runnable() {
227                        public void run() {
228                            mStatusBarManager.disable(0);
229                        }
230                    }, 3000);
231            }
232        },
233        new Test("Notify in 3 sec.") {
234            public void run() {
235                mHandler.postDelayed(new Runnable() {
236                        public void run() {
237                            mNotificationManager.notify(1,
238                                    new Notification(StatusBarTest.this,
239                                            R.drawable.ic_statusbar_missedcall,
240                                            "tick tick tick",
241                                            System.currentTimeMillis()-(1000*60*60*24),
242                                            "(453) 123-2328",
243                                            "", null
244                                            ));
245                        }
246                    }, 3000);
247            }
248        },
249        new Test("Cancel Notification in 3 sec.") {
250            public void run() {
251                mHandler.postDelayed(new Runnable() {
252                        public void run() {
253                            mNotificationManager.cancel(1);
254                        }
255                    }, 3000);
256            }
257        },
258        new Test("Expand") {
259            public void run() {
260                mStatusBarManager.expand();
261            }
262        },
263        new Test("Expand in 3 sec.") {
264            public void run() {
265                mHandler.postDelayed(new Runnable() {
266                        public void run() {
267                            mStatusBarManager.expand();
268                        }
269                    }, 3000);
270            }
271        },
272        new Test("Collapse in 3 sec.") {
273            public void run() {
274                mHandler.postDelayed(new Runnable() {
275                        public void run() {
276                            mStatusBarManager.collapse();
277                        }
278                    }, 3000);
279            }
280        },
281        new Test("More icons") {
282            public void run() {
283                for (String slot: new String[] {
284                            "sync_failing",
285                            "gps",
286                            "bluetooth",
287                            "tty",
288                            "speakerphone",
289                            "mute",
290                            "wifi",
291                            "alarm_clock",
292                            "secure",
293                        }) {
294                    mStatusBarManager.setIconVisibility(slot, true);
295                }
296            }
297        },
298    };
299}
300