summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryingying <yingying@codeaurora.org>2013-12-27 18:37:07 +0800
committerAdnan <adnan@cyngn.com>2014-09-03 15:41:22 -0700
commit6a21a9a61394681dcb03878aaa8aacf67a9660ad (patch)
treef41ba78aca1f1cf42ce95cd49f133af2e630d301
parent0dfaa88298dcbe2856af29f7965e3113118dde94 (diff)
downloadandroid_packages_apps_UnifiedEmail-6a21a9a61394681dcb03878aaa8aacf67a9660ad.tar.gz
android_packages_apps_UnifiedEmail-6a21a9a61394681dcb03878aaa8aacf67a9660ad.tar.bz2
android_packages_apps_UnifiedEmail-6a21a9a61394681dcb03878aaa8aacf67a9660ad.zip
UnifiedEmail: Support customize the notification icon for different account.
- Add one xml file to provider the different notification icon defined. - Show the defined icon for the notification if the account customize it. - If the account didn't defined the special icon, it will show as default. Change-Id: Ic565dbcb8426c22bc6302f261d52f0595d92c4c5
-rw-r--r--res/drawable/stat_notify_email_189.xml32
-rw-r--r--res/xml/notify_icon_providers.xml40
-rw-r--r--src/com/android/emailcommon/utility/NotifyIconUtilities.java115
-rw-r--r--src/com/android/mail/utils/NotificationActionUtils.java7
-rw-r--r--src/com/android/mail/utils/NotificationUtils.java11
5 files changed, 201 insertions, 4 deletions
diff --git a/res/drawable/stat_notify_email_189.xml b/res/drawable/stat_notify_email_189.xml
new file mode 100644
index 000000000..56bcd29fc
--- /dev/null
+++ b/res/drawable/stat_notify_email_189.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2013, The Linux Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ -->
+
+<!-- As we need runtime overlay this drawable for 189 mail, so we added this drawable file -->
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/stat_notify_email" /> \ No newline at end of file
diff --git a/res/xml/notify_icon_providers.xml b/res/xml/notify_icon_providers.xml
new file mode 100644
index 000000000..4b6a6ca76
--- /dev/null
+++ b/res/xml/notify_icon_providers.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ Not a Contribution.
+
+ Copyright (C) 2008 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<!--
+ This file contains configuration data for account's notify icon.
+
+ ==== TEMPLATES ====
+
+ Valid substitution values for all templates are:
+ $domain - the string after the @ sign in the email address the user entered
+ $icon - the icon's name which you want to show in the notification
+
+ For example:
+ <provider id="***" domain="***" icon="stat_notify_email" />
+
+ Note:
+ If you want to runtime overlay this xml, and use another icon for special email
+ account, you need make sure the icon is exist in the email's drawable list. It
+ is caused by the runtime overlay couldn't add new resouce in the overlay package.
+ -->
+
+<providers xmlns:android="http://schemas.android.com/apk/res/android" >
+ <!-- The content could edit for product -->
+</providers>
diff --git a/src/com/android/emailcommon/utility/NotifyIconUtilities.java b/src/com/android/emailcommon/utility/NotifyIconUtilities.java
new file mode 100644
index 000000000..016d691f1
--- /dev/null
+++ b/src/com/android/emailcommon/utility/NotifyIconUtilities.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ * Not a Contribution.
+ *
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.emailcommon.utility;
+
+import android.content.Context;
+import android.content.res.XmlResourceParser;
+
+import com.android.mail.utils.LogUtils;
+
+public class NotifyIconUtilities {
+ private static final String LOG_TAG = "NotifyIconUtilities";
+
+ private final static String ADDRESS_SEPARATOR = "@";
+ /** Pattern to match any part of a domain */
+ private final static String WILD_STRING = "*";
+ /** Will match any, single character */
+ private final static char WILD_CHARACTER = '?';
+ private final static String DOMAIN_SEPARATOR = "\\.";
+
+ public static int findNotifyIconForAccountDomain(Context context, int iconProviders,
+ String address, int defaultIcon) {
+ LogUtils.i(LOG_TAG, "find the notify icon for account: ", address);
+
+ int notify_icon_res = defaultIcon;
+ String domain = address.split(ADDRESS_SEPARATOR)[1];
+ try {
+ XmlResourceParser xml = context.getResources().getXml(iconProviders);
+ int xmlEventType;
+ boolean foundNotifyIcon = false;
+ while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) {
+ if (xmlEventType == XmlResourceParser.START_TAG
+ && "provider".equals(xml.getName())) {
+ String providerDomain = xml.getAttributeValue(null, "domain");
+ try {
+ if (matchProvider(domain, providerDomain)) {
+ String notify_icon_res_name = xml.getAttributeValue(null, "icon");
+ int resId = context.getResources().
+ getIdentifier(notify_icon_res_name, "drawable",
+ context.getPackageName());
+ if (resId > 0) {
+ notify_icon_res = resId;
+ }
+ foundNotifyIcon = true;
+ }
+ } catch (IllegalArgumentException e) {
+ LogUtils.w(LOG_TAG, "providers line: " + xml.getLineNumber() +
+ "; Domain contains multiple globals");
+ }
+ } else if (xmlEventType == XmlResourceParser.END_TAG
+ && "provider".equals(xml.getName())
+ && foundNotifyIcon) {
+ return notify_icon_res;
+ }
+ }
+ } catch (Exception e) {
+ LogUtils.e(LOG_TAG, "Error while trying to load provider settings.", e);
+ }
+ return notify_icon_res;
+ }
+
+ /**
+ * Returns true if the string <code>s1</code> matches the string <code>s2</code>. The string
+ * <code>s2</code> may contain any number of wildcards -- a '?' character -- and/or asterisk
+ * characters -- '*'. Wildcards match any single character, while the asterisk matches a domain
+ * part (i.e. substring demarcated by a period, '.')
+ */
+ private static boolean matchProvider(String testDomain, String providerDomain) {
+ String[] testParts = testDomain.split(DOMAIN_SEPARATOR);
+ String[] providerParts = providerDomain.split(DOMAIN_SEPARATOR);
+ if (testParts.length != providerParts.length) {
+ return false;
+ }
+ for (int i = 0; i < testParts.length; i++) {
+ String testPart = testParts[i].toLowerCase();
+ String providerPart = providerParts[i].toLowerCase();
+ if (!providerPart.equals(WILD_STRING) &&
+ !matchWithWildcards(testPart, providerPart)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean matchWithWildcards(String testPart, String providerPart) {
+ int providerLength = providerPart.length();
+ if (testPart.length() != providerLength){
+ return false;
+ }
+ for (int i = 0; i < providerLength; i++) {
+ char testChar = testPart.charAt(i);
+ char providerChar = providerPart.charAt(i);
+ if (testChar != providerChar && providerChar != WILD_CHARACTER) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/mail/utils/NotificationActionUtils.java b/src/com/android/mail/utils/NotificationActionUtils.java
index 9443537b6..be99729e8 100644
--- a/src/com/android/mail/utils/NotificationActionUtils.java
+++ b/src/com/android/mail/utils/NotificationActionUtils.java
@@ -32,6 +32,7 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.widget.RemoteViews;
+import com.android.emailcommon.utility.NotifyIconUtilities;
import com.android.mail.MailIntentService;
import com.android.mail.NotificationActionIntentService;
import com.android.mail.R;
@@ -523,7 +524,11 @@ public class NotificationActionUtils {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
- builder.setSmallIcon(R.drawable.stat_notify_email);
+ int iconResId = NotifyIconUtilities.findNotifyIconForAccountDomain(context,
+ R.xml.notify_icon_providers, notificationAction.getAccount().getEmailAddress(),
+ R.drawable.stat_notify_email);
+
+ builder.setSmallIcon(iconResId);
builder.setWhen(notificationAction.getWhen());
final RemoteViews undoView =
diff --git a/src/com/android/mail/utils/NotificationUtils.java b/src/com/android/mail/utils/NotificationUtils.java
index 9a0caf945..4d3dfcc1c 100644
--- a/src/com/android/mail/utils/NotificationUtils.java
+++ b/src/com/android/mail/utils/NotificationUtils.java
@@ -41,6 +41,7 @@ import android.text.style.TextAppearanceSpan;
import android.util.Pair;
import android.util.SparseArray;
+import com.android.emailcommon.utility.NotifyIconUtilities;
import com.android.mail.EmailAddress;
import com.android.mail.MailIntentService;
import com.android.mail.R;
@@ -130,7 +131,7 @@ public class NotificationUtils {
extends ConcurrentHashMap<NotificationKey, Pair<Integer, Integer>> {
private static final String NOTIFICATION_PART_SEPARATOR = " ";
- private static final int NUM_NOTIFICATION_PARTS= 4;
+ private static final int NUM_NOTIFICATION_PARTS = 4;
/**
* Retuns the unread count for the given NotificationKey.
@@ -228,7 +229,8 @@ public class NotificationUtils {
if (unreadCount != null && unseenCount != null) {
final String[] partValues = new String[] {
key.account.uri.toString(), key.folder.folderUri.fullUri.toString(),
- unreadCount.toString(), unseenCount.toString()};
+ unreadCount.toString(), unseenCount.toString()
+ };
notificationSet.add(TextUtils.join(NOTIFICATION_PART_SEPARATOR, partValues));
}
}
@@ -524,8 +526,11 @@ public class NotificationUtils {
// We now have all we need to create the notification and the pending intent
PendingIntent clickIntent;
+ int iconResId = NotifyIconUtilities.findNotifyIconForAccountDomain(context,
+ R.xml.notify_icon_providers, account.getEmailAddress(),
+ R.drawable.stat_notify_email);
NotificationCompat.Builder notification = new NotificationCompat.Builder(context);
- notification.setSmallIcon(R.drawable.stat_notify_email);
+ notification.setSmallIcon(iconResId);
notification.setTicker(account.name);
final long when;