diff options
| author | Po Lu | 2023-08-21 09:36:52 +0800 |
|---|---|---|
| committer | Po Lu | 2023-08-21 09:36:52 +0800 |
| commit | b1e498ac8c067b265c5f3de778e0a2722f7948a6 (patch) | |
| tree | bee97091b8a44db86654aec71c2382336837276e /java | |
| parent | 652e45b70d82e6f615febe00553dbded80557845 (diff) | |
| download | emacs-b1e498ac8c067b265c5f3de778e0a2722f7948a6.tar.gz emacs-b1e498ac8c067b265c5f3de778e0a2722f7948a6.zip | |
Enable providing icons for Android desktop notifications
* doc/lispref/os.texi (Desktop Notifications)
<android-notifications-notify>: Mention the :icon parameter.
* java/org/gnu/emacs/EmacsDesktopNotification.java
(EmacsDesktopNotification) <icon>: New field.
(<init>): New argument ICON. Set this.icon to its value.
(display1): Use provided icon and always supply a pending intent
to open Emacs once the notification is clicked.
* java/res/layout/sdk8_notifications_view.xml
(sdk8_notifications_title, sdk8_notifications_content): Set
foreground color to #000000.
* src/androidselect.c (android_init_emacs_desktop_notification):
Update signature of <init>.
(android_locate_icon): New function.
(android_notifications_notify_1): New arg ICON.
(Fandroid_notifications_notify): New parameter icon.
(syms_of_androidselect): <QCicon>: New symbol.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsDesktopNotification.java | 33 | ||||
| -rw-r--r-- | java/res/layout/sdk8_notifications_view.xml | 2 |
2 files changed, 24 insertions, 11 deletions
diff --git a/java/org/gnu/emacs/EmacsDesktopNotification.java b/java/org/gnu/emacs/EmacsDesktopNotification.java index b73ef1022fa..c6ebbc6ae48 100644 --- a/java/org/gnu/emacs/EmacsDesktopNotification.java +++ b/java/org/gnu/emacs/EmacsDesktopNotification.java | |||
| @@ -60,17 +60,22 @@ public final class EmacsDesktopNotification | |||
| 60 | function. */ | 60 | function. */ |
| 61 | public final String tag; | 61 | public final String tag; |
| 62 | 62 | ||
| 63 | /* The identifier of this notification's icon. */ | ||
| 64 | public final int icon; | ||
| 65 | |||
| 63 | /* The importance of this notification's group. */ | 66 | /* The importance of this notification's group. */ |
| 64 | public final int importance; | 67 | public final int importance; |
| 65 | 68 | ||
| 66 | public | 69 | public |
| 67 | EmacsDesktopNotification (String title, String content, | 70 | EmacsDesktopNotification (String title, String content, |
| 68 | String group, String tag, int importance) | 71 | String group, String tag, int icon, |
| 72 | int importance) | ||
| 69 | { | 73 | { |
| 70 | this.content = content; | 74 | this.content = content; |
| 71 | this.title = title; | 75 | this.title = title; |
| 72 | this.group = group; | 76 | this.group = group; |
| 73 | this.tag = tag; | 77 | this.tag = tag; |
| 78 | this.icon = icon; | ||
| 74 | this.importance = importance; | 79 | this.importance = importance; |
| 75 | } | 80 | } |
| 76 | 81 | ||
| @@ -107,19 +112,19 @@ public final class EmacsDesktopNotification | |||
| 107 | notification = (new Notification.Builder (context, group) | 112 | notification = (new Notification.Builder (context, group) |
| 108 | .setContentTitle (title) | 113 | .setContentTitle (title) |
| 109 | .setContentText (content) | 114 | .setContentText (content) |
| 110 | .setSmallIcon (R.drawable.emacs) | 115 | .setSmallIcon (icon) |
| 111 | .build ()); | 116 | .build ()); |
| 112 | } | 117 | } |
| 113 | else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) | 118 | else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) |
| 114 | notification = (new Notification.Builder (context) | 119 | notification = (new Notification.Builder (context) |
| 115 | .setContentTitle (title) | 120 | .setContentTitle (title) |
| 116 | .setContentText (content) | 121 | .setContentText (content) |
| 117 | .setSmallIcon (R.drawable.emacs) | 122 | .setSmallIcon (icon) |
| 118 | .build ()); | 123 | .build ()); |
| 119 | else | 124 | else |
| 120 | { | 125 | { |
| 121 | notification = new Notification (); | 126 | notification = new Notification (); |
| 122 | notification.icon = R.drawable.emacs; | 127 | notification.icon = icon; |
| 123 | 128 | ||
| 124 | /* This remote widget tree is defined in | 129 | /* This remote widget tree is defined in |
| 125 | java/res/layout/sdk8_notifications_view.xml. */ | 130 | java/res/layout/sdk8_notifications_view.xml. */ |
| @@ -131,15 +136,21 @@ public final class EmacsDesktopNotification | |||
| 131 | title); | 136 | title); |
| 132 | contentView.setTextViewText (R.id.sdk8_notifications_content, | 137 | contentView.setTextViewText (R.id.sdk8_notifications_content, |
| 133 | content); | 138 | content); |
| 139 | } | ||
| 134 | 140 | ||
| 135 | /* A content intent must be provided on these old versions of | 141 | /* Provide a content intent which starts Emacs when the |
| 136 | Android. */ | 142 | notification is clicked. */ |
| 137 | 143 | ||
| 138 | intent = new Intent (context, EmacsActivity.class); | 144 | intent = new Intent (context, EmacsActivity.class); |
| 139 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); | 145 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); |
| 140 | pending = PendingIntent.getActivity (context, 0, intent, 0); | 146 | |
| 141 | notification.contentIntent = pending; | 147 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S) |
| 142 | } | 148 | pending = PendingIntent.getActivity (context, 0, intent, |
| 149 | PendingIntent.FLAG_IMMUTABLE); | ||
| 150 | else | ||
| 151 | pending = PendingIntent.getActivity (context, 0, intent, 0); | ||
| 152 | |||
| 153 | notification.contentIntent = pending; | ||
| 143 | 154 | ||
| 144 | manager.notify (tag, 2, notification); | 155 | manager.notify (tag, 2, notification); |
| 145 | } | 156 | } |
diff --git a/java/res/layout/sdk8_notifications_view.xml b/java/res/layout/sdk8_notifications_view.xml index 2daa5beea86..0572f350cff 100644 --- a/java/res/layout/sdk8_notifications_view.xml +++ b/java/res/layout/sdk8_notifications_view.xml | |||
| @@ -23,9 +23,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. --> | |||
| 23 | android:layout_height="wrap_content" | 23 | android:layout_height="wrap_content" |
| 24 | android:padding="8dp"> | 24 | android:padding="8dp"> |
| 25 | <TextView android:id="@+id/sdk8_notifications_title" | 25 | <TextView android:id="@+id/sdk8_notifications_title" |
| 26 | android:textColor="#000000" | ||
| 26 | android:layout_width="wrap_content" | 27 | android:layout_width="wrap_content" |
| 27 | android:layout_height="wrap_content"/> | 28 | android:layout_height="wrap_content"/> |
| 28 | <TextView android:id="@+id/sdk8_notifications_content" | 29 | <TextView android:id="@+id/sdk8_notifications_content" |
| 30 | android:textColor="#000000" | ||
| 29 | android:layout_width="wrap_content" | 31 | android:layout_width="wrap_content" |
| 30 | android:layout_height="wrap_content"/> | 32 | android:layout_height="wrap_content"/> |
| 31 | </LinearLayout> | 33 | </LinearLayout> |