NotificationBuilderTest.java revision 8595a3dd9a6feff70f8ddbad924d79b591d611e4
146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato/* 246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * Copyright (C) 2010 The Android Open Source Project 346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * 446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * Licensed under the Apache License, Version 2.0 (the "License"); 546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * you may not use this file except in compliance with the License. 646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * You may obtain a copy of the License at 746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * 846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * http://www.apache.org/licenses/LICENSE-2.0 946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * 1046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * Unless required by applicable law or agreed to in writing, software 1146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * distributed under the License is distributed on an "AS IS" BASIS, 1246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * See the License for the specific language governing permissions and 1446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato * limitations under the License. 1546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato */ 1646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 1746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratopackage com.android.statusbartest; 1846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 1946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.app.Notification; 2046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.app.NotificationManager; 2146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.app.PendingIntent; 2246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.content.Context; 2346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.content.ContentResolver; 2446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.content.Intent; 2546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.graphics.Bitmap; 2646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.graphics.drawable.BitmapDrawable; 2746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.net.Uri; 2846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.os.Environment; 2946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.os.Vibrator; 3046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.os.Handler; 3146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.util.Log; 3246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.net.Uri; 3346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.os.SystemClock; 3446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.widget.RemoteViews; 3546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratoimport android.os.PowerManager; 3646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 3746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onoratopublic class NotificationBuilderTest extends TestActivity 3846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato{ 3946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato private final static String TAG = "NotificationTestList"; 4046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 4146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato NotificationManager mNM; 4246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 4346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato @Override 4446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato protected String tag() { 4546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato return TAG; 4646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato } 4746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 4846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato @Override 4946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato protected Test[] tests() { 5046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 5146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 5246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato return mTests; 5346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato } 5446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 5546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato private Test[] mTests = new Test[] { 5646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato new Test("Cancel (1)") { 5746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato public void run() { 5846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato mNM.cancel(1); 5946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato } 6046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato }, 6146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 6246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato new Test("Basic Content (1)") { 6346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato public void run() { 6446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato int id = 1; 6546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 6646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this); 6746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 6846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato b.setWhen(System.currentTimeMillis()); 6946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato b.setSmallIcon(R.drawable.ic_statusbar_chat); 7046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato b.setContentTitle("Title"); 7146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato b.setContentText("text\nline2"); 7246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato b.setContentIntent(makeContentIntent(id)); 7346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato b.setDeleteIntent(makeDeleteIntent(id)); 7446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 7546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato mNM.notify(id, b.getNotification()); 7646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato } 7746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato }, 788595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato 798595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato new Test("Basic Content w/ Number (1)") { 808595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato public void run() { 818595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato int id = 1; 828595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato 838595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this); 848595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato 858595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setWhen(System.currentTimeMillis()); 868595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setSmallIcon(R.drawable.ic_statusbar_chat); 878595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setContentTitle("Title"); 888595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setContentText("text\nline2"); 898595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setContentIntent(makeContentIntent(id)); 908595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setDeleteIntent(makeDeleteIntent(id)); 918595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato b.setNumber(12345); 928595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato 938595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato mNM.notify(id, b.getNotification()); 948595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato } 958595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato }, 968595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato 9746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato }; 9846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 9946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato private PendingIntent makeContentIntent(int id) { 10046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato Intent intent = new Intent(this, ConfirmationActivity.class); 10146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato intent.setData(Uri.fromParts("content", "//status_bar_test/content/" + id, null)); 10246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Content intent"); 10346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id); 10446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato return PendingIntent.getActivity(this, 0, intent, 0); 10546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato } 10646439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 10746439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato private PendingIntent makeDeleteIntent(int id) { 10846439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato Intent intent = new Intent(this, ConfirmationActivity.class); 10946439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato intent.setData(Uri.fromParts("content", "//status_bar_test/delete/" + id, null)); 11046439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Delete intent"); 11146439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id); 11246439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato return PendingIntent.getActivity(this, 0, intent, 0); 11346439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato } 11446439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato} 11546439cec0eb0da4d0f853f2d8712d0c00c98475bJoe Onorato 116