aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2016-04-06 14:38:41 -0400
committerChris Wren <cwren@android.com>2016-04-06 14:38:41 -0400
commit55c563b549ac8b0319e7ec82bfb6e0f533addffb (patch)
tree597ab7b7dd892029bd708cfab865df8a894767e1
parent8750051ab3bddc6e0481ab45e299504537653041 (diff)
downloadexperimental-55c563b549ac8b0319e7ec82bfb6e0f533addffb.tar.gz
port to NotificationManagerCompat to test APIs
Bug: 28021291 Change-Id: I20d9e0bd98590e68c8320ceb0b10aec5cc6d1e33
-rw-r--r--NotificationShowcase/res/layout/main.xml1
-rw-r--r--NotificationShowcase/res/values/strings.xml3
-rw-r--r--NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java5
-rw-r--r--NotificationShowcase/src/com/android/example/notificationshowcase/NotificationShowcaseActivity.java20
-rw-r--r--NotificationShowcase/src/com/android/example/notificationshowcase/ProgressService.java2
5 files changed, 27 insertions, 4 deletions
diff --git a/NotificationShowcase/res/layout/main.xml b/NotificationShowcase/res/layout/main.xml
index ddad922..d082544 100644
--- a/NotificationShowcase/res/layout/main.xml
+++ b/NotificationShowcase/res/layout/main.xml
@@ -8,5 +8,6 @@
<Button android:id="@+id/button1" android:text="@string/post_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doPost"></Button>
<Button android:id="@+id/button2" android:text="@string/remove_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doRemove"></Button>
<Button android:id="@+id/button3" android:text="@string/prefs_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doPrefs"></Button>
+ <Button android:id="@+id/disable" android:text="@string/no_button_label" android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="doDisable"></Button>
</LinearLayout>
</FrameLayout>
diff --git a/NotificationShowcase/res/values/strings.xml b/NotificationShowcase/res/values/strings.xml
index ca534c9..cd7239e 100644
--- a/NotificationShowcase/res/values/strings.xml
+++ b/NotificationShowcase/res/values/strings.xml
@@ -5,6 +5,9 @@
<string name="post_button_label">Post Notifications</string>
<string name="remove_button_label">Remove Notifications</string>
<string name="prefs_button_label">Preferences</string>
+ <string name="disable_button_label">Disable Notifications</string>
+ <string name="enable_button_label">Enable Notifications</string>
+ <string name="no_button_label">No Idea Dog</string>
<string name="answered">call answered</string>
<string name="ignored">call ignored</string>
<string name="full_screen_name">Full Screen Activity</string>
diff --git a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java
index 2c21a7e..5fb2a2b 100644
--- a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java
+++ b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java
@@ -19,7 +19,6 @@ package com.android.example.notificationshowcase;
import android.app.AlarmManager;
import android.app.IntentService;
import android.app.Notification;
-import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -36,6 +35,7 @@ import android.net.Uri;
import android.os.SystemClock;
import android.provider.ContactsContract;
import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.preference.PreferenceManager;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -185,8 +185,7 @@ public class NotificationService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
- NotificationManager noMa =
- (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ NotificationManagerCompat noMa = NotificationManagerCompat.from(this);
if (ACTION_DESTROY.equals(intent.getAction())) {
noMa.cancelAll();
return;
diff --git a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationShowcaseActivity.java b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationShowcaseActivity.java
index 8d1a2fc..2d0d09b 100644
--- a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationShowcaseActivity.java
+++ b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationShowcaseActivity.java
@@ -8,8 +8,11 @@ import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.net.Uri;
import android.os.Bundle;
+import android.support.v4.app.NotificationManagerCompat;
import android.view.View;
+import android.widget.Button;
public class NotificationShowcaseActivity extends Activity {
private static final String TAG = "NotificationShowcase";
@@ -19,6 +22,18 @@ public class NotificationShowcaseActivity extends Activity {
setContentView(R.layout.main);
}
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Button disableBtn = (Button) findViewById(R.id.disable);
+ NotificationManagerCompat noMa = NotificationManagerCompat.from(this);
+ if(noMa.areNotificationsEnabled()) {
+ disableBtn.setText(R.string.disable_button_label);
+ } else {
+ disableBtn.setText(R.string.enable_button_label);
+ }
+ }
+
public void doPost(View v) {
Intent intent = new Intent(NotificationService.ACTION_CREATE);
intent.setComponent(new ComponentName(this, NotificationService.class));
@@ -36,4 +51,9 @@ public class NotificationShowcaseActivity extends Activity {
intent.setComponent(new ComponentName(this, SettingsActivity.class));
startActivity(intent);
}
+
+ public void doDisable(View v) {
+ startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
+ Uri.parse("package:com.android.example.notificationshowcase")));
+ }
}
diff --git a/NotificationShowcase/src/com/android/example/notificationshowcase/ProgressService.java b/NotificationShowcase/src/com/android/example/notificationshowcase/ProgressService.java
index 799708d..cbc3476 100644
--- a/NotificationShowcase/src/com/android/example/notificationshowcase/ProgressService.java
+++ b/NotificationShowcase/src/com/android/example/notificationshowcase/ProgressService.java
@@ -59,7 +59,7 @@ public class ProgressService extends IntentService {
noMa.notify(NotificationService.NOTIFICATION_ID + mId,
NotificationService.makeUploadNotification(
ProgressService.this, mProgress, mWhen));
- mProgress += 10;
+ mProgress += 2;
if (mProgress <= 100) {
handler.postDelayed(this, 1000);
}