StatusBarTest.java revision b59b94456b3a8fdfdf524a81274839f657fbb65b
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.stat_sys_phone,
93                                "Incoming call from: Imperious Leader",
94                                System.currentTimeMillis()-(1000*60*60*24),
95                                "Imperious Leader",
96                                "(888) 555-5038",
97                                null
98                                );
99                not.flags |= Notification.FLAG_HIGH_PRIORITY;
100                Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
101                int id = (int)System.currentTimeMillis(); // XXX HAX
102                fullScreenIntent.putExtra("id", id);
103                not.fullScreenIntent = PendingIntent.getActivity(
104                    StatusBarTest.this,
105                    0,
106                    fullScreenIntent,
107                    PendingIntent.FLAG_CANCEL_CURRENT);
108                // if you tap on it you should get the original alert box
109                not.contentIntent = not.fullScreenIntent;
110                mNotificationManager.notify(id, not);
111            }
112        },
113        new Test("Disable Alerts") {
114            public void run() {
115                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS);
116            }
117        },
118        new Test("Disable Ticker") {
119            public void run() {
120                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER);
121            }
122        },
123        new Test("Disable Expand in 3 sec.") {
124            public void run() {
125                mHandler.postDelayed(new Runnable() {
126                        public void run() {
127                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
128                        }
129                    }, 3000);
130            }
131        },
132        new Test("Disable Notifications in 3 sec.") {
133            public void run() {
134                mHandler.postDelayed(new Runnable() {
135                        public void run() {
136                            mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS);
137                        }
138                    }, 3000);
139            }
140        },
141        new Test("Disable Expand + Notifications in 3 sec.") {
142            public void run() {
143                mHandler.postDelayed(new Runnable() {
144                        public void run() {
145                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND
146                                    | StatusBarManager.DISABLE_NOTIFICATION_ICONS);
147                        }
148                    }, 3000);
149            }
150        },
151        new Test("Enable everything") {
152            public void run() {
153                mStatusBarManager.disable(0);
154            }
155        },
156        new Test("Enable everything in 3 sec.") {
157            public void run() {
158                mHandler.postDelayed(new Runnable() {
159                        public void run() {
160                            mStatusBarManager.disable(0);
161                        }
162                    }, 3000);
163            }
164        },
165        new Test("Notify in 3 sec.") {
166            public void run() {
167                mHandler.postDelayed(new Runnable() {
168                        public void run() {
169                            mNotificationManager.notify(1,
170                                    new Notification(StatusBarTest.this,
171                                            R.drawable.ic_statusbar_missedcall,
172                                            "tick tick tick",
173                                            System.currentTimeMillis()-(1000*60*60*24),
174                                            "(453) 123-2328",
175                                            "", null
176                                            ));
177                        }
178                    }, 3000);
179            }
180        },
181        new Test("Cancel Notification in 3 sec.") {
182            public void run() {
183                mHandler.postDelayed(new Runnable() {
184                        public void run() {
185                            mNotificationManager.cancel(1);
186                        }
187                    }, 3000);
188            }
189        },
190        new Test("Expand") {
191            public void run() {
192                mStatusBarManager.expand();
193            }
194        },
195        new Test("Expand in 3 sec.") {
196            public void run() {
197                mHandler.postDelayed(new Runnable() {
198                        public void run() {
199                            mStatusBarManager.expand();
200                        }
201                    }, 3000);
202            }
203        },
204        new Test("Collapse in 3 sec.") {
205            public void run() {
206                mHandler.postDelayed(new Runnable() {
207                        public void run() {
208                            mStatusBarManager.collapse();
209                        }
210                    }, 3000);
211            }
212        },
213        new Test("More icons") {
214            public void run() {
215                for (String slot: new String[] {
216                            "sync_failing",
217                            "gps",
218                            "bluetooth",
219                            "tty",
220                            "speakerphone",
221                            "mute",
222                            "wifi",
223                            "alarm_clock",
224                            "secure",
225                        }) {
226                    mStatusBarManager.setIconVisibility(slot, true);
227                }
228            }
229        },
230    };
231}
232