NotificationBuilderTest.java revision 8595a3dd9a6feff70f8ddbad924d79b591d611e4
1/*
2 * Copyright (C) 2010 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.Notification;
20import android.app.NotificationManager;
21import android.app.PendingIntent;
22import android.content.Context;
23import android.content.ContentResolver;
24import android.content.Intent;
25import android.graphics.Bitmap;
26import android.graphics.drawable.BitmapDrawable;
27import android.net.Uri;
28import android.os.Environment;
29import android.os.Vibrator;
30import android.os.Handler;
31import android.util.Log;
32import android.net.Uri;
33import android.os.SystemClock;
34import android.widget.RemoteViews;
35import android.os.PowerManager;
36
37public class NotificationBuilderTest extends TestActivity
38{
39    private final static String TAG = "NotificationTestList";
40
41    NotificationManager mNM;
42
43    @Override
44    protected String tag() {
45        return TAG;
46    }
47
48    @Override
49    protected Test[] tests() {
50        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
51
52        return mTests;
53    }
54
55    private Test[] mTests = new Test[] {
56        new Test("Cancel (1)") {
57            public void run() {
58                mNM.cancel(1);
59            }
60        },
61
62        new Test("Basic Content (1)") {
63            public void run() {
64                int id = 1;
65
66                Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this);
67
68                b.setWhen(System.currentTimeMillis());
69                b.setSmallIcon(R.drawable.ic_statusbar_chat);
70                b.setContentTitle("Title");
71                b.setContentText("text\nline2");
72                b.setContentIntent(makeContentIntent(id));
73                b.setDeleteIntent(makeDeleteIntent(id));
74
75                mNM.notify(id, b.getNotification());
76            }
77        },
78
79        new Test("Basic Content w/ Number (1)") {
80            public void run() {
81                int id = 1;
82
83                Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this);
84
85                b.setWhen(System.currentTimeMillis());
86                b.setSmallIcon(R.drawable.ic_statusbar_chat);
87                b.setContentTitle("Title");
88                b.setContentText("text\nline2");
89                b.setContentIntent(makeContentIntent(id));
90                b.setDeleteIntent(makeDeleteIntent(id));
91                b.setNumber(12345);
92
93                mNM.notify(id, b.getNotification());
94            }
95        },
96
97    };
98
99    private PendingIntent makeContentIntent(int id) {
100        Intent intent = new Intent(this, ConfirmationActivity.class);
101        intent.setData(Uri.fromParts("content", "//status_bar_test/content/" + id, null));
102        intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Content intent");
103        intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id);
104        return PendingIntent.getActivity(this, 0, intent, 0);
105    }
106
107    private PendingIntent makeDeleteIntent(int id) {
108        Intent intent = new Intent(this, ConfirmationActivity.class);
109        intent.setData(Uri.fromParts("content", "//status_bar_test/delete/" + id, null));
110        intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Delete intent");
111        intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id);
112        return PendingIntent.getActivity(this, 0, intent, 0);
113    }
114}
115
116