Updated StatusBar test app for new notifications API.

New actions:
 - Toggle activity's immersive mode
 - Post a priority notification with fullScreenIntent
   that launches an alert-like activity

Change-Id: Ie38372209985577b6db856924c19914c000e1cec
This commit is contained in:
Daniel Sandler
2010-06-23 15:29:59 -04:00
parent 87160757e8
commit 8896783dc1
5 changed files with 148 additions and 0 deletions

View File

@@ -8,4 +8,6 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := StatusBarTest
LOCAL_CERTIFICATE := platform
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)

View File

@@ -35,5 +35,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="TestAlertActivity" android:theme="@android:style/Theme.Dialog">
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<TextView android:id="@+id/alertTitle"
style="?android:attr/textAppearanceLarge"
android:padding="5dip"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/ButtonBar">
<Button
android:id="@+id/snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:onClick="dismiss"
android:text="Snooze" />
<!-- blank stretchable view -->
<View
android:layout_width="2dip"
android:layout_height="2dip"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"/>
<Button
android:id="@+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:onClick="dismiss"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -23,6 +23,7 @@ import android.widget.ArrayAdapter;
import android.view.View;
import android.widget.ListView;
import android.content.Intent;
import android.app.PendingIntent;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.StatusBarManager;
@@ -35,6 +36,8 @@ import android.os.SystemClock;
import android.widget.RemoteViews;
import android.widget.Toast;
import android.os.PowerManager;
import android.view.Window;
import android.view.WindowManager;
public class StatusBarTest extends TestActivity
{
@@ -57,6 +60,53 @@ public class StatusBarTest extends TestActivity
}
private Test[] mTests = new Test[] {
new Test("Hide") {
public void run() {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
win.setAttributes(winParams);
}
},
new Test("Show") {
public void run() {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
win.setAttributes(winParams);
}
},
new Test("Immersive: Enter") {
public void run() {
setImmersive(true);
}
},
new Test("Immersive: Exit") {
public void run() {
setImmersive(false);
}
},
new Test("Priority notification") {
public void run() {
Notification not = new Notification(StatusBarTest.this,
R.drawable.ic_statusbar_missedcall,
"tick tick tick",
System.currentTimeMillis()-(1000*60*60*24),
"(453) 123-2328",
"", null
);
not.flags |= Notification.FLAG_HIGH_PRIORITY;
Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
int id = (int)System.currentTimeMillis(); // XXX HAX
fullScreenIntent.putExtra("id", id);
not.fullScreenIntent = PendingIntent.getActivity(
StatusBarTest.this,
0,
fullScreenIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
mNotificationManager.notify(id, not);
}
},
new Test("Disable Alerts") {
public void run() {
mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS);

View File

@@ -0,0 +1,37 @@
package com.android.statusbartest;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class TestAlertActivity extends Activity {
int mId;
@Override
public void onResume() {
super.onResume();
Log.d("StatusBarTest", "TestAlertActivity.onResume");
Intent intent = getIntent();
mId = intent.getIntExtra("id", -1);
Log.d("StatusBarTest", "Remembering notification id=" + mId);
setContentView(R.layout.test_alert);
}
@Override
public void onPause() {
super.onPause();
Log.d("StatusBarTest", "onPause: Canceling notification id=" + mId);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(mId);
finish();
}
@SuppressWarnings({"UnusedDeclaration"})
public void dismiss(View v) {
Log.d("StatusBarTest", "TestAlertActivity.dismiss");
finish();
}
}