aboutsummaryrefslogtreecommitdiffstats
path: root/templates/other
diff options
context:
space:
mode:
authorRoman Nurik <romannurik@google.com>2012-12-19 10:46:55 -0800
committerRoman Nurik <romannurik@google.com>2012-12-20 09:02:15 -0800
commitd6f8dd0e3202af39a0fc80ed79a934027516ef8b (patch)
tree267cc056333935cb05128a4d15aca92c1a7aa359 /templates/other
parent17e7b9b0c77fe08193e31d7880eee1114ba21d44 (diff)
downloadsdk-d6f8dd0e3202af39a0fc80ed79a934027516ef8b.zip
sdk-d6f8dd0e3202af39a0fc80ed79a934027516ef8b.tar.gz
sdk-d6f8dd0e3202af39a0fc80ed79a934027516ef8b.tar.bz2
New "Notification" ADT template.
This change adds a new Notification template in the 'other' category, that creates a helper class to show and hide a notification with optional expanded styles for Android 4.1+ devices. The template also includes example resources relevant to notifications and leads the user through the notification icon wizard. Change-Id: I9765021ea66844f6f8887e1f1f27d6d262ee89a1
Diffstat (limited to 'templates/other')
-rw-r--r--templates/other/Notification/globals.xml.ftl9
-rw-r--r--templates/other/Notification/recipe.xml.ftl25
-rw-r--r--templates/other/Notification/root/AndroidManifest.xml.ftl5
-rw-r--r--templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_reply.pngbin0 -> 1480 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_share.pngbin0 -> 1606 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_reply.pngbin0 -> 1314 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_share.pngbin0 -> 1341 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-nodpi/example_picture_large.pngbin0 -> 5834 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-nodpi/example_picture_small.pngbin0 -> 1885 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_reply.pngbin0 -> 1692 bytes
-rw-r--r--templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_share.pngbin0 -> 1780 bytes
-rw-r--r--templates/other/Notification/root/res/values/strings.xml.ftl13
-rw-r--r--templates/other/Notification/root/src/app_package/NotificationHelper.java.ftl205
-rw-r--r--templates/other/Notification/template.xml58
-rw-r--r--templates/other/Notification/template_notification_list.pngbin0 -> 7306 bytes
-rw-r--r--templates/other/Notification/template_notification_list_actions.pngbin0 -> 7850 bytes
-rw-r--r--templates/other/Notification/template_notification_none.pngbin0 -> 4146 bytes
-rw-r--r--templates/other/Notification/template_notification_none_actions.pngbin0 -> 5904 bytes
-rw-r--r--templates/other/Notification/template_notification_picture.pngbin0 -> 6308 bytes
-rw-r--r--templates/other/Notification/template_notification_picture_actions.pngbin0 -> 6749 bytes
-rw-r--r--templates/other/Notification/template_notification_text.pngbin0 -> 6695 bytes
-rw-r--r--templates/other/Notification/template_notification_text_actions.pngbin0 -> 7073 bytes
22 files changed, 315 insertions, 0 deletions
diff --git a/templates/other/Notification/globals.xml.ftl b/templates/other/Notification/globals.xml.ftl
new file mode 100644
index 0000000..b302aa9
--- /dev/null
+++ b/templates/other/Notification/globals.xml.ftl
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<globals>
+ <global id="srcOut" value="src/${slashedPackageName(packageName)}" />
+ <global id="notificationName" value="${className?replace('notification','','i')}" />
+ <global id="notification_name" value="${camelCaseToUnderscore(className?replace('notification','','i'))}" />
+ <global id="display_title" value="${camelCaseToUnderscore(className?replace('notification','','i'))?replace('_',' ')?cap_first}" />
+
+ <global id="icon_resource" value="ic_stat_${camelCaseToUnderscore(className?replace('notification','','i'))}" />
+</globals>
diff --git a/templates/other/Notification/recipe.xml.ftl b/templates/other/Notification/recipe.xml.ftl
new file mode 100644
index 0000000..bd1c265
--- /dev/null
+++ b/templates/other/Notification/recipe.xml.ftl
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<recipe>
+
+ <merge from="AndroidManifest.xml.ftl" />
+
+ <#if expandedStyle == "picture">
+ <copy from="res/drawable-nodpi/example_picture_large.png"
+ to="res/drawable-nodpi/example_picture.png" />
+ <#else>
+ <copy from="res/drawable-nodpi/example_picture_small.png"
+ to="res/drawable-nodpi/example_picture.png" />
+ </#if>
+
+ <#if moreActions>
+ <copy from="res/drawable-hdpi" />
+ <copy from="res/drawable-mdpi" />
+ <copy from="res/drawable-xhdpi" />
+ </#if>
+
+ <merge from="res/values/strings.xml.ftl" />
+
+ <instantiate from="src/app_package/NotificationHelper.java.ftl"
+ to="${srcOut}/${className}.java" />
+ <open file="${srcOut}/${className}.java" />
+</recipe>
diff --git a/templates/other/Notification/root/AndroidManifest.xml.ftl b/templates/other/Notification/root/AndroidManifest.xml.ftl
new file mode 100644
index 0000000..fb564cc
--- /dev/null
+++ b/templates/other/Notification/root/AndroidManifest.xml.ftl
@@ -0,0 +1,5 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <uses-permission android:name="android.permission.VIBRATE" />
+
+</manifest>
diff --git a/templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_reply.png b/templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_reply.png
new file mode 100644
index 0000000..835d96f
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_reply.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_share.png b/templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_share.png
new file mode 100644
index 0000000..c329f58
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-hdpi/ic_action_stat_share.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_reply.png b/templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_reply.png
new file mode 100644
index 0000000..9e34465
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_reply.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_share.png b/templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_share.png
new file mode 100644
index 0000000..056deb5
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-mdpi/ic_action_stat_share.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-nodpi/example_picture_large.png b/templates/other/Notification/root/res/drawable-nodpi/example_picture_large.png
new file mode 100644
index 0000000..1e69424
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-nodpi/example_picture_large.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-nodpi/example_picture_small.png b/templates/other/Notification/root/res/drawable-nodpi/example_picture_small.png
new file mode 100644
index 0000000..e0627f5
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-nodpi/example_picture_small.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_reply.png b/templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_reply.png
new file mode 100644
index 0000000..4cc854a
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_reply.png
Binary files differ
diff --git a/templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_share.png b/templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_share.png
new file mode 100644
index 0000000..15549b0
--- /dev/null
+++ b/templates/other/Notification/root/res/drawable-xhdpi/ic_action_stat_share.png
Binary files differ
diff --git a/templates/other/Notification/root/res/values/strings.xml.ftl b/templates/other/Notification/root/res/values/strings.xml.ftl
new file mode 100644
index 0000000..5f3da57
--- /dev/null
+++ b/templates/other/Notification/root/res/values/strings.xml.ftl
@@ -0,0 +1,13 @@
+<resources>
+
+ <string name="${notification_name}_notification_title_template">${escapeXmlString(display_title)}: %1$s</string>
+
+ <!-- TODO: remove this placeholder text -->
+ <string name="${notification_name}_notification_placeholder_text_template">You said %1$s and lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non enim magna. Morbi dictum, velit vel semper venenatis, magna odio volutpat velit, at ullamcorper nulla lacus sed turpis. Pellentesque vitae metus elit, nec tincidunt tellus. Integer sed nisl sem, ullamcorper ornare lacus. Duis ac mauris sed massa congue volutpat. Donec sed erat sit amet turpis viverra rhoncus sit amet nec magna. Donec lacinia ligula at libero volutpat volutpat nec nec tortor.</string>
+
+ <#if moreActions>
+ <string name="action_share">Share</string>
+ <string name="action_reply">Reply</string>
+ </#if>
+
+</resources>
diff --git a/templates/other/Notification/root/src/app_package/NotificationHelper.java.ftl b/templates/other/Notification/root/src/app_package/NotificationHelper.java.ftl
new file mode 100644
index 0000000..af69d5a
--- /dev/null
+++ b/templates/other/Notification/root/src/app_package/NotificationHelper.java.ftl
@@ -0,0 +1,205 @@
+package ${packageName};
+
+import android.annotation.TargetApi;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.os.Build;
+import android.support.v4.app.NotificationCompat;
+<#if expandedStyle == 'list'>
+import android.graphics.Color;
+import android.text.SpannableStringBuilder;
+import android.text.style.ForegroundColorSpan;
+</#if>
+
+/**
+ * Helper class for showing and canceling ${display_title?lower_case}
+ * notifications.
+ * <p>
+ * This class makes heavy use of the {@link NotificationCompat.Builder} helper
+ * class to create notifications in a backward-compatible way.
+ */
+public class ${className} {
+ /**
+ * The unique identifier for this type of notification.
+ */
+ private static final String NOTIFICATION_TAG = "${notificationName}";
+
+ /**
+ * Shows the notification, or updates a previously shown notification of
+ * this type, with the given parameters.
+ * <p>
+ * TODO: Customize this method's arguments to present relevant content in
+ * the notification.
+ * <p>
+ * TODO: Customize the contents of this method to tweak the behavior and
+ * presentation of ${display_title?lower_case} notifications. Make
+ * sure to follow the
+ * <a href="https://developer.android.com/design/patterns/notifications.html">
+ * Notification design guidelines</a> when doing so.
+ *
+ * @see #cancel(Context)
+ */
+ public static void notify(final Context context,
+ final String exampleString, final int number) {
+ final Resources res = context.getResources();
+
+ <#if expandedStyle == "picture">
+ // This image is used as the notification's large icon (thumbnail) when
+ // the notification is collapsed, and as the big picture to show when
+ // the notification is expanded.
+ <#else>
+ // This image is used as the notification's large icon (thumbnail).
+ // TODO: Remove this if your notification has no relevant thumbnail.
+ </#if>
+ final Bitmap picture = BitmapFactory.decodeResource(res, R.drawable.example_picture);
+
+ <#if expandedStyle == 'list'>
+ final SpannableStringBuilder exampleItem = new SpannableStringBuilder();
+ exampleItem.append("Dummy");
+ exampleItem.setSpan(new ForegroundColorSpan(Color.WHITE), 0, exampleItem.length(), 0);
+ exampleItem.append(" Example content");
+ </#if>
+
+ final String ticker = exampleString;
+ final String title = res.getString(
+ R.string.${notification_name}_notification_title_template, exampleString);
+ final String text = res.getString(
+ R.string.${notification_name}_notification_placeholder_text_template, exampleString);
+
+ final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
+
+ // Set appropriate defaults for the notification light, sound,
+ // and vibration.
+ .setDefaults(Notification.DEFAULT_ALL)
+
+ // Set required fields, including the small icon, the
+ // notification title, and text.
+ .setSmallIcon(R.drawable.${icon_resource})
+ .setContentTitle(title)
+ .setContentText(text)
+
+ // All fields below this line are optional.
+
+ // Use a default priority (recognized on devices running Android
+ // 4.1 or later)
+ .setPriority(NotificationCompat.PRIORITY_DEFAULT)
+
+ // Provide a large icon, shown with the notification in the
+ // notification drawer on devices running Android 3.0 or later.
+ .setLargeIcon(picture)
+
+ // Set ticker text (preview) information for this notification.
+ .setTicker(ticker)
+
+ // Show a number. This is useful when stacking notifications of
+ // a single type.
+ .setNumber(number)
+
+ // If this notification relates to a past or upcoming event, you
+ // should set the relevant time information using the setWhen
+ // method below. If this call is omitted, the notification's
+ // timestamp will by set to the time at which it was shown.
+ // TODO: Call setWhen if this notification relates to a past or
+ // upcoming event. The sole argument to this method should be
+ // the notification timestamp in milliseconds.
+ //.setWhen(...)
+
+ // Set the pending intent to be initiated when the user touches
+ // the notification.
+ .setContentIntent(
+ PendingIntent.getActivity(
+ context,
+ 0,
+ new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")),
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ <#if expandedStyle == 'picture'>
+
+ // Show an expanded photo on devices running Android 4.1 or
+ // later.
+ .setStyle(new NotificationCompat.BigPictureStyle()<#--
+ TODO: .bigLargeIcon(null) when the support library supports it -->
+ .bigPicture(picture)
+ .setBigContentTitle(title)
+ .setSummaryText("Dummy summary text"))
+ <#elseif expandedStyle == 'list'>
+
+ // Show an expanded list of items on devices running Android 4.1
+ // or later.
+ .setStyle(new NotificationCompat.InboxStyle()
+ .addLine(exampleItem)
+ .addLine(exampleItem)
+ .addLine(exampleItem)
+ .addLine(exampleItem)
+ .setBigContentTitle(title)
+ .setSummaryText("Dummy summary text"))
+ <#elseif expandedStyle == 'text'>
+
+ // Show expanded text content on devices running Android 4.1 or
+ // later.
+ .setStyle(new NotificationCompat.BigTextStyle()
+ .bigText(text)
+ .setBigContentTitle(title)
+ .setSummaryText("Dummy summary text"))
+ </#if>
+ <#if moreActions>
+
+ // Example additional actions for this notification. These will
+ // only show on devices running Android 4.1 or later, so you
+ // should ensure that the activity in this notification's
+ // content intent provides access to the same actions in
+ // another way.
+ .addAction(
+ R.drawable.ic_action_stat_share,
+ res.getString(R.string.action_share),
+ PendingIntent.getActivity(
+ context,
+ 0,
+ Intent.createChooser(new Intent(Intent.ACTION_SEND)
+ .setType("text/plain")
+ .putExtra(Intent.EXTRA_TEXT, "Dummy text"), "Dummy title"),
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ .addAction(
+ R.drawable.ic_action_stat_reply,
+ res.getString(R.string.action_reply),
+ null)
+ </#if>
+
+ // Automatically dismiss the notification when it is touched.
+ .setAutoCancel(true);
+
+ notify(context, builder.build());
+ }
+
+ @TargetApi(Build.VERSION_CODES.ECLAIR)
+ private static void notify(final Context context, final Notification notification) {
+ final NotificationManager nm = (NotificationManager) context
+ .getSystemService(Context.NOTIFICATION_SERVICE);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
+ nm.notify(NOTIFICATION_TAG, 0, notification);
+ } else {
+ nm.notify(NOTIFICATION_TAG.hashCode(), notification);
+ }
+ }
+
+ /**
+ * Cancels any notifications of this type previously shown using
+ * {@link #notify(Context, String, int)}.
+ */
+ @TargetApi(Build.VERSION_CODES.ECLAIR)
+ public static void cancel(final Context context) {
+ final NotificationManager nm = (NotificationManager) context
+ .getSystemService(Context.NOTIFICATION_SERVICE);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
+ nm.cancel(NOTIFICATION_TAG, 0);
+ } else {
+ nm.cancel(NOTIFICATION_TAG.hashCode());
+ }
+ }
+} \ No newline at end of file
diff --git a/templates/other/Notification/template.xml b/templates/other/Notification/template.xml
new file mode 100644
index 0000000..61fbc59
--- /dev/null
+++ b/templates/other/Notification/template.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<template
+ format="3"
+ revision="1"
+ name="New Notification"
+ description="Creates a new helper class that can show or cancel a status bar notification."
+ minApi="4">
+
+ <dependency name="android-support-v4" revision="10" />
+
+ <category value="Other" />
+
+ <parameter
+ id="className"
+ name="Class Name"
+ type="string"
+ constraints="class|unique|nonempty"
+ default="NewMessageNotification"
+ help="The name of the notification helper class to create, e.g. 'NewMessageNotification'." />
+
+ <parameter
+ id="expandedStyle"
+ name="Style when Expanded"
+ type="enum"
+ default="text"
+ help="The expanded notification style to use for devices running Android 4.1 or later." >
+ <option id="none">None</option>
+ <option id="text" default="true">More text</option>
+ <option id="picture">Picture</option>
+ <option id="list">List</option>
+ </parameter>
+
+ <parameter
+ id="moreActions"
+ name="Show Additional Actions"
+ type="boolean"
+ default="true"
+ help="If true, this notification will contain additional actions when expanded on devices running Android 4.1 or later." />
+
+ <globals file="globals.xml.ftl" />
+ <execute file="recipe.xml.ftl" />
+
+ <thumbs>
+ <thumb>template_notification_text_actions.png</thumb>
+ <thumb expandedStyle="none">template_notification_none.png</thumb>
+ <thumb expandedStyle="none" moreActions="true">template_notification_none_actions.png</thumb>
+ <thumb expandedStyle="text">template_notification_text.png</thumb>
+ <thumb expandedStyle="text" moreActions="true">template_notification_text_actions.png</thumb>
+ <thumb expandedStyle="list">template_notification_list.png</thumb>
+ <thumb expandedStyle="list" moreActions="true">template_notification_list_actions.png</thumb>
+ <thumb expandedStyle="picture">template_notification_picture.png</thumb>
+ <thumb expandedStyle="picture" moreActions="true">template_notification_picture_actions.png</thumb>
+ </thumbs>
+
+ <icons
+ type="notification"
+ name="ic_stat_${camelCaseToUnderscore(className?replace('notification','','i'))}" />
+</template>
diff --git a/templates/other/Notification/template_notification_list.png b/templates/other/Notification/template_notification_list.png
new file mode 100644
index 0000000..f858daa
--- /dev/null
+++ b/templates/other/Notification/template_notification_list.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_list_actions.png b/templates/other/Notification/template_notification_list_actions.png
new file mode 100644
index 0000000..a095525
--- /dev/null
+++ b/templates/other/Notification/template_notification_list_actions.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_none.png b/templates/other/Notification/template_notification_none.png
new file mode 100644
index 0000000..abbee9d
--- /dev/null
+++ b/templates/other/Notification/template_notification_none.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_none_actions.png b/templates/other/Notification/template_notification_none_actions.png
new file mode 100644
index 0000000..69a4a50
--- /dev/null
+++ b/templates/other/Notification/template_notification_none_actions.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_picture.png b/templates/other/Notification/template_notification_picture.png
new file mode 100644
index 0000000..d535661
--- /dev/null
+++ b/templates/other/Notification/template_notification_picture.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_picture_actions.png b/templates/other/Notification/template_notification_picture_actions.png
new file mode 100644
index 0000000..300431f
--- /dev/null
+++ b/templates/other/Notification/template_notification_picture_actions.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_text.png b/templates/other/Notification/template_notification_text.png
new file mode 100644
index 0000000..790ecc0
--- /dev/null
+++ b/templates/other/Notification/template_notification_text.png
Binary files differ
diff --git a/templates/other/Notification/template_notification_text_actions.png b/templates/other/Notification/template_notification_text_actions.png
new file mode 100644
index 0000000..6514069
--- /dev/null
+++ b/templates/other/Notification/template_notification_text_actions.png
Binary files differ