summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/notification/NotificationInfo.java
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-01-20 09:38:25 -0800
committerTony Wickham <twickham@google.com>2017-01-25 17:36:31 -0800
commit9438ed414fdabadb4cd09da184867b1c44b91095 (patch)
tree9d84de236a89cde247b9de8f11408e815e6d6702 /src/com/android/launcher3/notification/NotificationInfo.java
parentf3d02e4716f89d14d9017851db9ad6141ad26875 (diff)
downloadpackages_apps_Trebuchet-9438ed414fdabadb4cd09da184867b1c44b91095.tar.gz
packages_apps_Trebuchet-9438ed414fdabadb4cd09da184867b1c44b91095.tar.bz2
packages_apps_Trebuchet-9438ed414fdabadb4cd09da184867b1c44b91095.zip
Add swipe-to-dismiss notifications in popup menu.
- Next secondary icon animates up to replace dismissed main notification - Add padding around main notification so it always aligns with the straight edges of the view (not the rounded corners); looks more dismissable - Notification view collapses as notifications are dismissed - To mimic system notification behavior, we copy SwipeHelper, FlingAnimationUtils, and Interpolators. We also apply elevation to notifications and reveal a darker color beneath when dismissing. Bug: 32410600 Change-Id: I9fbf10e73bb4996f17ef061c856efb013967d972
Diffstat (limited to 'src/com/android/launcher3/notification/NotificationInfo.java')
-rw-r--r--src/com/android/launcher3/notification/NotificationInfo.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/com/android/launcher3/notification/NotificationInfo.java b/src/com/android/launcher3/notification/NotificationInfo.java
new file mode 100644
index 000000000..33ab96679
--- /dev/null
+++ b/src/com/android/launcher3/notification/NotificationInfo.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.launcher3.notification;
+
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
+import android.service.notification.StatusBarNotification;
+import android.view.View;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.popup.PopupContainerWithArrow;
+import com.android.launcher3.util.PackageUserKey;
+
+/**
+ * An object that contains relevant information from a {@link StatusBarNotification}. This should
+ * only be created when we need to show the notification contents on the UI; until then, a
+ * {@link com.android.launcher3.badge.BadgeInfo} with only the notification key should
+ * be passed around, and then this can be constructed using the StatusBarNotification from
+ * {@link NotificationListener#getNotificationsForKeys(String[])}.
+ */
+public class NotificationInfo implements View.OnClickListener {
+
+ public final PackageUserKey packageUserKey;
+ public final String notificationKey;
+ public final CharSequence title;
+ public final CharSequence text;
+ public final Drawable iconDrawable;
+ public final PendingIntent intent;
+ public final boolean autoCancel;
+ public final boolean dismissable;
+
+ /**
+ * Extracts the data that we need from the StatusBarNotification.
+ */
+ public NotificationInfo(Context context, StatusBarNotification statusBarNotification) {
+ packageUserKey = PackageUserKey.fromNotification(statusBarNotification);
+ notificationKey = statusBarNotification.getKey();
+ Notification notification = statusBarNotification.getNotification();
+ title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
+ text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
+ Icon icon = notification.getLargeIcon();
+ if (icon == null) {
+ icon = notification.getSmallIcon();
+ iconDrawable = icon.loadDrawable(context);
+ iconDrawable.setTint(statusBarNotification.getNotification().color);
+ } else {
+ iconDrawable = icon.loadDrawable(context);
+ }
+ intent = notification.contentIntent;
+ autoCancel = (notification.flags & Notification.FLAG_AUTO_CANCEL) != 0;
+ dismissable = (notification.flags & Notification.FLAG_ONGOING_EVENT) == 0;
+ }
+
+ @Override
+ public void onClick(View view) {
+ final Launcher launcher = Launcher.getLauncher(view.getContext());
+ try {
+ intent.send();
+ } catch (PendingIntent.CanceledException e) {
+ e.printStackTrace();
+ }
+ if (autoCancel) {
+ launcher.getPopupDataProvider().cancelNotification(notificationKey);
+ }
+ PopupContainerWithArrow.getOpen(launcher).close(true);
+ }
+}