diff options
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | src/com/android/mail/compose/ComposeActivity.java | 40 | ||||
-rw-r--r-- | src/com/android/mail/utils/NotificationActionUtils.java | 12 | ||||
-rw-r--r-- | src/com/android/mail/utils/NotificationUtils.java | 51 |
4 files changed, 58 insertions, 46 deletions
diff --git a/Android.mk b/Android.mk index bdf747eba..75a374751 100644 --- a/Android.mk +++ b/Android.mk @@ -39,7 +39,6 @@ LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13 LOCAL_STATIC_JAVA_LIBRARIES += android-opt-datetimepicker LOCAL_STATIC_JAVA_LIBRARIES += owasp-html-sanitizer -LOCAL_STATIC_JAVA_LIBRARIES += prebuilt-wearable-support-1170785 LOCAL_SDK_VERSION := current diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java index 3781479bd..743b7b1d9 100644 --- a/src/com/android/mail/compose/ComposeActivity.java +++ b/src/com/android/mail/compose/ComposeActivity.java @@ -47,7 +47,7 @@ import android.os.HandlerThread; import android.os.ParcelFileDescriptor; import android.os.Parcelable; import android.provider.BaseColumns; -import android.support.wearable.notifications.RemoteInput; +import android.support.v4.app.RemoteInput; import android.text.Editable; import android.text.Html; import android.text.SpannableString; @@ -56,7 +56,6 @@ import android.text.TextUtils; import android.text.TextWatcher; import android.text.util.Rfc822Token; import android.text.util.Rfc822Tokenizer; -import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -108,7 +107,6 @@ import com.android.mail.utils.ContentProviderTask; import com.android.mail.utils.LogTag; import com.android.mail.utils.LogUtils; import com.android.mail.utils.NotificationActionUtils; -import com.android.mail.utils.NotificationUtils; import com.android.mail.utils.Utils; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; @@ -188,6 +186,8 @@ public class ComposeActivity extends Activity implements OnClickListener, OnNavi static final String[] ALL_EXTRAS = { EXTRA_SUBJECT, EXTRA_BODY, EXTRA_TO, EXTRA_CC, EXTRA_BCC, EXTRA_QUOTED_TEXT }; + private static final String LEGACY_WEAR_EXTRA = "com.google.android.wearable.extras"; + private static SendOrSaveCallback sTestSendOrSaveCallback = null; // Map containing information about requests to create new messages, and the id of the // messages that were the result of those requests. @@ -554,19 +554,35 @@ public class ComposeActivity extends Activity implements OnClickListener, OnNavi if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); + String wearReply = null; if (remoteInput != null) { - String wearReply = remoteInput.getString( + LogUtils.d(LOG_TAG, "Got remote input from new api"); + CharSequence input = remoteInput.getCharSequence( NotificationActionUtils.WEAR_REPLY_INPUT); - if (!TextUtils.isEmpty(wearReply)) { - createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, - mComposeMode, wearReply).execute(); - finish(); - return; - } else { - LogUtils.w(LOG_TAG, "remote input string is null"); + if (input != null) { + wearReply = input.toString(); + } + } else { + // TODO: remove after legacy code has been removed. + LogUtils.d(LOG_TAG, + "No remote input from new api, falling back to compatibility mode"); + ClipData clipData = intent.getClipData(); + if (clipData != null + && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) { + Bundle extras = clipData.getItemAt(0).getIntent().getExtras(); + if (extras != null) { + wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT); + } } + } + + if (!TextUtils.isEmpty(wearReply)) { + createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, + mComposeMode, wearReply).execute(); + finish(); + return; } else { - LogUtils.d(LOG_TAG, "No remote input"); + LogUtils.w(LOG_TAG, "remote input string is null"); } } diff --git a/src/com/android/mail/utils/NotificationActionUtils.java b/src/com/android/mail/utils/NotificationActionUtils.java index c22dcf994..00b773a90 100644 --- a/src/com/android/mail/utils/NotificationActionUtils.java +++ b/src/com/android/mail/utils/NotificationActionUtils.java @@ -29,10 +29,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.RemoteInput; import android.support.v4.app.TaskStackBuilder; -import android.support.wearable.notifications.RemoteInput; -import android.support.wearable.notifications.WearableAction; -import android.support.wearable.notifications.WearableNotificationOptions; import android.widget.RemoteViews; import com.android.mail.MailIntentService; @@ -199,7 +197,7 @@ public class NotificationActionUtils { */ public static void addNotificationActions(final Context context, final Intent notificationIntent, final NotificationCompat.Builder notification, - WearableNotificationOptions.Builder wearableNotification, final Account account, + NotificationCompat.WearableExtender wearExtender, final Account account, final Conversation conversation, final Message message, final Folder folder, final int notificationId, final long when, final Set<String> notificationActions) { @@ -218,8 +216,8 @@ public class NotificationActionUtils { // Always add all actions to both standard and wearable notifications. notification.addAction(actionIconResId, title, pendingIntent); - WearableAction.Builder wearableActionBuilder = new WearableAction.Builder( - actionIconResId, title, pendingIntent); + NotificationCompat.Action.Builder wearableActionBuilder = + new NotificationCompat.Action.Builder(actionIconResId, title, pendingIntent); if (notificationAction == NotificationActionType.REPLY || notificationAction == NotificationActionType.REPLY_ALL) { String[] choices = context.getResources().getStringArray(R.array.reply_choices); @@ -232,7 +230,7 @@ public class NotificationActionUtils { LogUtils.d(LOG_TAG, "Adding wearable action!!"); } - wearableNotification.addAction(wearableActionBuilder.build()); + wearExtender.addAction(wearableActionBuilder.build()); } } diff --git a/src/com/android/mail/utils/NotificationUtils.java b/src/com/android/mail/utils/NotificationUtils.java index 76cac0c54..122a5fb56 100644 --- a/src/com/android/mail/utils/NotificationUtils.java +++ b/src/com/android/mail/utils/NotificationUtils.java @@ -30,12 +30,10 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Email; -import android.provider.ContactsContract.Contacts.Photo; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; import android.support.v4.text.BidiFormatter; import android.support.v4.util.ArrayMap; -import android.support.wearable.app.NotificationManagerCompat; -import android.support.wearable.notifications.WearableNotificationOptions; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -73,7 +71,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.io.Closeables; -import java.io.ByteArrayInputStream; import java.io.InputStream; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -578,8 +575,8 @@ public class NotificationUtils { PendingIntent clickIntent; NotificationCompat.Builder notification = new NotificationCompat.Builder(context); - WearableNotificationOptions.Builder wearableNotification = - new WearableNotificationOptions.Builder(); + NotificationCompat.WearableExtender wearableExtender = + new NotificationCompat.WearableExtender(); Map<Integer, NotificationBuilders> msgNotifications = new ArrayMap<Integer, NotificationBuilders>(); notification.setSmallIcon(R.drawable.stat_notify_email); @@ -662,7 +659,7 @@ public class NotificationUtils { clickIntent = createClickPendingIntent(context, notificationIntent); configureLatestEventInfoFromConversation(context, account, folderPreferences, - notification, wearableNotification, msgNotifications, notificationId, + notification, wearableExtender, msgNotifications, notificationId, cursor, clickIntent, notificationIntent, unreadCount, unseenCount, folder, when); eventInfoConfigured = true; @@ -737,7 +734,7 @@ public class NotificationUtils { notification.setTicker(null); } - wearableNotification.build().applyTo(notification); + notification.extend(wearableExtender); nm.notify(notificationId, notification.build()); if (prevChildNotifications != null) { @@ -753,7 +750,7 @@ public class NotificationUtils { for (Map.Entry<Integer, NotificationBuilders> entry : msgNotifications.entrySet()) { NotificationBuilders builders = entry.getValue(); - builders.wearableNotifBuilder.build().applyTo(builders.notifBuilder); + builders.notifBuilder.extend(builders.wearableNotifBuilder); nm.notify(entry.getKey(), builders.notifBuilder.build()); LogUtils.d(LOG_TAG, "notifying child notification %s", entry.getKey()); } @@ -858,7 +855,7 @@ public class NotificationUtils { private static void configureLatestEventInfoFromConversation(final Context context, final Account account, final FolderPreferences folderPreferences, final NotificationCompat.Builder notification, - final WearableNotificationOptions.Builder summaryWearNotif, + final NotificationCompat.WearableExtender wearableExtender, final Map<Integer, NotificationBuilders> msgNotifications, final int summaryNotificationId, final Cursor conversationCursor, final PendingIntent clickIntent, final Intent notificationIntent, @@ -909,7 +906,7 @@ public class NotificationUtils { // Group by account. String notificationGroupKey = account.uri.toString() + "/" + folder.folderUri.fullUri; - summaryWearNotif.setGroup(notificationGroupKey).setGroupSummary(true); + notification.setGroup(notificationGroupKey).setGroupSummary(true); ConfigResult firstResult = null; int numDigestItems = 0; @@ -980,20 +977,22 @@ public class NotificationUtils { // TODO: Use a stable sort key if possible, e.g. message post time // + msgid hash String groupSortKey = String.format("%010d", numDigestItems); - WearableNotificationOptions.Builder childWearNotif = - new WearableNotificationOptions.Builder() - .setGroup(notificationGroupKey) - .setSortKey(groupSortKey); + childNotif.setGroup(notificationGroupKey); + childNotif.setSortKey(groupSortKey); + int childNotificationId = getNotificationId(summaryNotificationId, conversation.hashCode()); + NotificationCompat.WearableExtender childWearExtender = + new NotificationCompat.WearableExtender(); + ConfigResult result = configureNotifForOneConversation(context, account, - folderPreferences, childNotif, childWearNotif, + folderPreferences, childNotif, childWearExtender, conversationCursor, notificationIntent, folder, when, res, notificationAccountDisplayName, notificationAccountEmail, isInbox, notificationLabelName, childNotificationId); msgNotifications.put(childNotificationId, - NotificationBuilders.of(childNotif, childWearNotif)); + NotificationBuilders.of(childNotif, childWearExtender)); if (firstResult == null) { firstResult = result; @@ -1010,10 +1009,10 @@ public class NotificationUtils { } while (numDigestItems <= maxNumDigestItems && conversationCursor.moveToNext()); if (firstResult != null && firstResult.contactIconInfo != null) { - summaryWearNotif.setBackground(firstResult.contactIconInfo.wearableBg); + wearableExtender.setBackground(firstResult.contactIconInfo.wearableBg); } else { LogUtils.w(LOG_TAG, "First contact icon is null!"); - summaryWearNotif.setBackground(getDefaultWearableBg(context)); + wearableExtender.setBackground(getDefaultWearableBg(context)); } } else { // The body of the notification is the account name, or the label name. @@ -1028,13 +1027,13 @@ public class NotificationUtils { seekToLatestUnreadConversation(conversationCursor); ConfigResult result = configureNotifForOneConversation(context, account, - folderPreferences, notification, summaryWearNotif, conversationCursor, + folderPreferences, notification, wearableExtender, conversationCursor, notificationIntent, folder, when, res, notificationAccountDisplayName, notificationAccountEmail, isInbox, notificationLabelName, summaryNotificationId); notificationTicker = result.notificationTicker; - summaryWearNotif.setBackground(result.contactIconInfo.wearableBg); + wearableExtender.setBackground(result.contactIconInfo.wearableBg); } // Build the notification ticker @@ -1064,7 +1063,7 @@ public class NotificationUtils { private static ConfigResult configureNotifForOneConversation(Context context, Account account, FolderPreferences folderPreferences, NotificationCompat.Builder notification, - WearableNotificationOptions.Builder summaryWearNotif, Cursor conversationCursor, + NotificationCompat.WearableExtender wearExtender, Cursor conversationCursor, Intent notificationIntent, Folder folder, long when, Resources res, String notificationAccountDisplayName, String notificationAccountEmail, boolean isInbox, String notificationLabelName, int notificationId) { @@ -1166,7 +1165,7 @@ public class NotificationUtils { folderPreferences.getNotificationActions(account); NotificationActionUtils.addNotificationActions(context, notificationIntent, - notification, summaryWearNotif, account, conversation, message, + notification, wearExtender, account, conversation, message, folder, notificationId, when, notificationActions); } } else { @@ -1803,16 +1802,16 @@ public class NotificationUtils { private static class NotificationBuilders { public final NotificationCompat.Builder notifBuilder; - public final WearableNotificationOptions.Builder wearableNotifBuilder; + public final NotificationCompat.WearableExtender wearableNotifBuilder; private NotificationBuilders(NotificationCompat.Builder notifBuilder, - WearableNotificationOptions.Builder wearableNotifBuilder) { + NotificationCompat.WearableExtender wearableNotifBuilder) { this.notifBuilder = notifBuilder; this.wearableNotifBuilder = wearableNotifBuilder; } public static NotificationBuilders of(NotificationCompat.Builder notifBuilder, - WearableNotificationOptions.Builder wearableNotifBuilder) { + NotificationCompat.WearableExtender wearableNotifBuilder) { return new NotificationBuilders(notifBuilder, wearableNotifBuilder); } } |