diff options
| author | Po Lu | 2024-03-21 14:23:40 +0800 |
|---|---|---|
| committer | Po Lu | 2024-03-21 14:23:40 +0800 |
| commit | ad0492c5a97aaad7f784f7834772400d9af96b69 (patch) | |
| tree | b1235f7921dd6e4c5e9d3be50df960f68c3a4d32 /java | |
| parent | 0df28dc00edd0db343619d02aa41999a7bfce5fb (diff) | |
| download | emacs-ad0492c5a97aaad7f784f7834772400d9af96b69.tar.gz emacs-ad0492c5a97aaad7f784f7834772400d9af96b69.zip | |
Android compatibility fixes
* doc/emacs/android.texi (Android Windowing): Document
restrictions on number of windows under Android 4.4 and earlier.
* java/AndroidManifest.xml.in <EmacsActivity>
<EmacsOpenActivity, EmacsMultitaskActivity>: Assign each class
of activity a unique task affinity.
* java/org/gnu/emacs/EmacsDesktopNotification.java (display1):
Remove redundant priority assignment.
* java/org/gnu/emacs/EmacsOpenActivity.java (onCreate): Handle
file URIs when processing attachments from a mailto URI, and
check for KitKat before opening content ones.
* java/org/gnu/emacs/EmacsWindow.java <pointerMap>
(figureChange): Replace coordinate HashMap with a SparseArray.
* java/org/gnu/emacs/EmacsWindowAttachmentManager.java
(registerWindow): Don't specify FLAG_ACTIVITY_NEW_DOCUMENT on
systems where it is absent.
Diffstat (limited to 'java')
| -rw-r--r-- | java/AndroidManifest.xml.in | 4 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsDesktopNotification.java | 35 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsOpenActivity.java | 34 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindow.java | 12 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindowAttachmentManager.java | 9 |
5 files changed, 64 insertions, 30 deletions
diff --git a/java/AndroidManifest.xml.in b/java/AndroidManifest.xml.in index 4d23c752747..563914fb02c 100644 --- a/java/AndroidManifest.xml.in +++ b/java/AndroidManifest.xml.in | |||
| @@ -218,6 +218,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. --> | |||
| 218 | 218 | ||
| 219 | <activity android:name="org.gnu.emacs.EmacsActivity" | 219 | <activity android:name="org.gnu.emacs.EmacsActivity" |
| 220 | android:launchMode="singleInstance" | 220 | android:launchMode="singleInstance" |
| 221 | android:taskAffinity="emacs.primary_frame" | ||
| 221 | android:windowSoftInputMode="adjustResize" | 222 | android:windowSoftInputMode="adjustResize" |
| 222 | android:exported="true" | 223 | android:exported="true" |
| 223 | android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale|fontScale"> | 224 | android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale|fontScale"> |
| @@ -229,7 +230,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. --> | |||
| 229 | </activity> | 230 | </activity> |
| 230 | 231 | ||
| 231 | <activity android:name="org.gnu.emacs.EmacsOpenActivity" | 232 | <activity android:name="org.gnu.emacs.EmacsOpenActivity" |
| 232 | android:taskAffinity="open.dialog" | 233 | android:taskAffinity="emacs.open_dialog" |
| 233 | android:excludeFromRecents="true" | 234 | android:excludeFromRecents="true" |
| 234 | android:exported="true"> | 235 | android:exported="true"> |
| 235 | 236 | ||
| @@ -273,6 +274,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. --> | |||
| 273 | </activity> | 274 | </activity> |
| 274 | 275 | ||
| 275 | <activity android:name="org.gnu.emacs.EmacsMultitaskActivity" | 276 | <activity android:name="org.gnu.emacs.EmacsMultitaskActivity" |
| 277 | android:taskAffinity="emacs.secondary_frame" | ||
| 276 | android:windowSoftInputMode="adjustResize" | 278 | android:windowSoftInputMode="adjustResize" |
| 277 | android:exported="true" | 279 | android:exported="true" |
| 278 | android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale|fontScale"/> | 280 | android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale|fontScale"/> |
diff --git a/java/org/gnu/emacs/EmacsDesktopNotification.java b/java/org/gnu/emacs/EmacsDesktopNotification.java index c80aa21b4fe..72569631a8c 100644 --- a/java/org/gnu/emacs/EmacsDesktopNotification.java +++ b/java/org/gnu/emacs/EmacsDesktopNotification.java | |||
| @@ -208,22 +208,6 @@ public final class EmacsDesktopNotification | |||
| 208 | distinct categories, but permit an importance to be | 208 | distinct categories, but permit an importance to be |
| 209 | assigned to each individual notification. */ | 209 | assigned to each individual notification. */ |
| 210 | 210 | ||
| 211 | switch (importance) | ||
| 212 | { | ||
| 213 | case 2: /* IMPORTANCE_LOW */ | ||
| 214 | default: | ||
| 215 | priority = Notification.PRIORITY_LOW; | ||
| 216 | break; | ||
| 217 | |||
| 218 | case 3: /* IMPORTANCE_DEFAULT */ | ||
| 219 | priority = Notification.PRIORITY_DEFAULT; | ||
| 220 | break; | ||
| 221 | |||
| 222 | case 4: /* IMPORTANCE_HIGH */ | ||
| 223 | priority = Notification.PRIORITY_HIGH; | ||
| 224 | break; | ||
| 225 | } | ||
| 226 | |||
| 227 | builder = new Notification.Builder (context); | 211 | builder = new Notification.Builder (context); |
| 228 | builder.setContentTitle (title); | 212 | builder.setContentTitle (title); |
| 229 | builder.setContentText (content); | 213 | builder.setContentText (content); |
| @@ -231,15 +215,28 @@ public final class EmacsDesktopNotification | |||
| 231 | 215 | ||
| 232 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) | 216 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) |
| 233 | { | 217 | { |
| 218 | switch (importance) | ||
| 219 | { | ||
| 220 | case 2: /* IMPORTANCE_LOW */ | ||
| 221 | default: | ||
| 222 | priority = Notification.PRIORITY_LOW; | ||
| 223 | break; | ||
| 224 | |||
| 225 | case 3: /* IMPORTANCE_DEFAULT */ | ||
| 226 | priority = Notification.PRIORITY_DEFAULT; | ||
| 227 | break; | ||
| 228 | |||
| 229 | case 4: /* IMPORTANCE_HIGH */ | ||
| 230 | priority = Notification.PRIORITY_HIGH; | ||
| 231 | break; | ||
| 232 | } | ||
| 233 | |||
| 234 | builder.setPriority (priority); | 234 | builder.setPriority (priority); |
| 235 | insertActions (context, builder); | 235 | insertActions (context, builder); |
| 236 | notification = builder.build (); | 236 | notification = builder.build (); |
| 237 | } | 237 | } |
| 238 | else | 238 | else |
| 239 | notification = builder.getNotification (); | 239 | notification = builder.getNotification (); |
| 240 | |||
| 241 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) | ||
| 242 | notification.priority = priority; | ||
| 243 | } | 240 | } |
| 244 | else | 241 | else |
| 245 | { | 242 | { |
diff --git a/java/org/gnu/emacs/EmacsOpenActivity.java b/java/org/gnu/emacs/EmacsOpenActivity.java index 2cdfa2ec776..327a53bc417 100644 --- a/java/org/gnu/emacs/EmacsOpenActivity.java +++ b/java/org/gnu/emacs/EmacsOpenActivity.java | |||
| @@ -535,7 +535,9 @@ public final class EmacsOpenActivity extends Activity | |||
| 535 | uri = intent.getParcelableExtra (Intent.EXTRA_STREAM); | 535 | uri = intent.getParcelableExtra (Intent.EXTRA_STREAM); |
| 536 | 536 | ||
| 537 | if ((scheme = uri.getScheme ()) != null | 537 | if ((scheme = uri.getScheme ()) != null |
| 538 | && scheme.equals ("content")) | 538 | && scheme.equals ("content") |
| 539 | && (Build.VERSION.SDK_INT | ||
| 540 | >= Build.VERSION_CODES.KITKAT)) | ||
| 539 | { | 541 | { |
| 540 | tem1 = EmacsService.buildContentName (uri, resolver); | 542 | tem1 = EmacsService.buildContentName (uri, resolver); |
| 541 | attachmentString = ("'(\"" + (tem1.replace ("\\", "\\\\") | 543 | attachmentString = ("'(\"" + (tem1.replace ("\\", "\\\\") |
| @@ -543,6 +545,14 @@ public final class EmacsOpenActivity extends Activity | |||
| 543 | .replace ("$", "\\$")) | 545 | .replace ("$", "\\$")) |
| 544 | + "\")"); | 546 | + "\")"); |
| 545 | } | 547 | } |
| 548 | else if (scheme != null && scheme.equals ("file")) | ||
| 549 | { | ||
| 550 | tem1 = uri.getPath (); | ||
| 551 | attachmentString = ("'(\"" + (tem1.replace ("\\", "\\\\") | ||
| 552 | .replace ("\"", "\\\"") | ||
| 553 | .replace ("$", "\\$")) | ||
| 554 | + "\")"); | ||
| 555 | } | ||
| 546 | } | 556 | } |
| 547 | else | 557 | else |
| 548 | { | 558 | { |
| @@ -567,7 +577,9 @@ public final class EmacsOpenActivity extends Activity | |||
| 567 | 577 | ||
| 568 | if (uri != null | 578 | if (uri != null |
| 569 | && (scheme = uri.getScheme ()) != null | 579 | && (scheme = uri.getScheme ()) != null |
| 570 | && scheme.equals ("content")) | 580 | && scheme.equals ("content") |
| 581 | && (Build.VERSION.SDK_INT | ||
| 582 | >= Build.VERSION_CODES.KITKAT)) | ||
| 571 | { | 583 | { |
| 572 | tem1 | 584 | tem1 |
| 573 | = EmacsService.buildContentName (uri, resolver); | 585 | = EmacsService.buildContentName (uri, resolver); |
| @@ -577,6 +589,16 @@ public final class EmacsOpenActivity extends Activity | |||
| 577 | .replace ("$", "\\$")); | 589 | .replace ("$", "\\$")); |
| 578 | builder.append ("\""); | 590 | builder.append ("\""); |
| 579 | } | 591 | } |
| 592 | else if (scheme != null | ||
| 593 | && scheme.equals ("file")) | ||
| 594 | { | ||
| 595 | tem1 = uri.getPath (); | ||
| 596 | builder.append ("\""); | ||
| 597 | builder.append (tem1.replace ("\\", "\\\\") | ||
| 598 | .replace ("\"", "\\\"") | ||
| 599 | .replace ("$", "\\$")); | ||
| 600 | builder.append ("\""); | ||
| 601 | } | ||
| 580 | } | 602 | } |
| 581 | 603 | ||
| 582 | builder.append (")"); | 604 | builder.append (")"); |
| @@ -604,7 +626,13 @@ public final class EmacsOpenActivity extends Activity | |||
| 604 | { | 626 | { |
| 605 | fileName = null; | 627 | fileName = null; |
| 606 | 628 | ||
| 607 | if (scheme.equals ("content")) | 629 | if (scheme.equals ("content") |
| 630 | /* Retrieving the native file descriptor of a | ||
| 631 | ParcelFileDescriptor requires Honeycomb, and | ||
| 632 | proceeding without this capability is pointless on | ||
| 633 | systems before KitKat, since Emacs doesn't support | ||
| 634 | opening content files on those. */ | ||
| 635 | && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) | ||
| 608 | { | 636 | { |
| 609 | /* This is one of the annoying Android ``content'' | 637 | /* This is one of the annoying Android ``content'' |
| 610 | URIs. Most of the time, there is actually an | 638 | URIs. Most of the time, there is actually an |
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 93a512cc7ef..2baede1d2d0 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java | |||
| @@ -23,7 +23,6 @@ import java.lang.IllegalStateException; | |||
| 23 | import java.util.ArrayList; | 23 | import java.util.ArrayList; |
| 24 | import java.util.List; | 24 | import java.util.List; |
| 25 | import java.util.ListIterator; | 25 | import java.util.ListIterator; |
| 26 | import java.util.HashMap; | ||
| 27 | import java.util.LinkedHashMap; | 26 | import java.util.LinkedHashMap; |
| 28 | import java.util.Map; | 27 | import java.util.Map; |
| 29 | 28 | ||
| @@ -50,6 +49,7 @@ import android.view.View; | |||
| 50 | import android.view.ViewManager; | 49 | import android.view.ViewManager; |
| 51 | import android.view.WindowManager; | 50 | import android.view.WindowManager; |
| 52 | 51 | ||
| 52 | import android.util.SparseArray; | ||
| 53 | import android.util.Log; | 53 | import android.util.Log; |
| 54 | 54 | ||
| 55 | import android.os.Build; | 55 | import android.os.Build; |
| @@ -109,7 +109,7 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 109 | 109 | ||
| 110 | /* Map between pointer identifiers and last known position. Used to | 110 | /* Map between pointer identifiers and last known position. Used to |
| 111 | compute which pointer changed upon a touch event. */ | 111 | compute which pointer changed upon a touch event. */ |
| 112 | private HashMap<Integer, Coordinate> pointerMap; | 112 | private SparseArray<Coordinate> pointerMap; |
| 113 | 113 | ||
| 114 | /* The window consumer currently attached, if it exists. */ | 114 | /* The window consumer currently attached, if it exists. */ |
| 115 | private EmacsWindowAttachmentManager.WindowConsumer attached; | 115 | private EmacsWindowAttachmentManager.WindowConsumer attached; |
| @@ -166,7 +166,7 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 166 | super (handle); | 166 | super (handle); |
| 167 | 167 | ||
| 168 | rect = new Rect (x, y, x + width, y + height); | 168 | rect = new Rect (x, y, x + width, y + height); |
| 169 | pointerMap = new HashMap<Integer, Coordinate> (); | 169 | pointerMap = new SparseArray<Coordinate> (); |
| 170 | 170 | ||
| 171 | /* Create the view from the context's UI thread. The window is | 171 | /* Create the view from the context's UI thread. The window is |
| 172 | unmapped, so the view is GONE. */ | 172 | unmapped, so the view is GONE. */ |
| @@ -1001,7 +1001,8 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 1001 | case MotionEvent.ACTION_CANCEL: | 1001 | case MotionEvent.ACTION_CANCEL: |
| 1002 | /* Primary pointer released with index 0. */ | 1002 | /* Primary pointer released with index 0. */ |
| 1003 | pointerID = event.getPointerId (0); | 1003 | pointerID = event.getPointerId (0); |
| 1004 | coordinate = pointerMap.remove (pointerID); | 1004 | coordinate = pointerMap.get (pointerID); |
| 1005 | pointerMap.delete (pointerID); | ||
| 1005 | break; | 1006 | break; |
| 1006 | 1007 | ||
| 1007 | case MotionEvent.ACTION_POINTER_DOWN: | 1008 | case MotionEvent.ACTION_POINTER_DOWN: |
| @@ -1020,7 +1021,8 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 1020 | /* Pointer removed. Remove it from the map. */ | 1021 | /* Pointer removed. Remove it from the map. */ |
| 1021 | pointerIndex = event.getActionIndex (); | 1022 | pointerIndex = event.getActionIndex (); |
| 1022 | pointerID = event.getPointerId (pointerIndex); | 1023 | pointerID = event.getPointerId (pointerIndex); |
| 1023 | coordinate = pointerMap.remove (pointerID); | 1024 | coordinate = pointerMap.get (pointerID); |
| 1025 | pointerMap.delete (pointerID); | ||
| 1024 | break; | 1026 | break; |
| 1025 | 1027 | ||
| 1026 | default: | 1028 | default: |
diff --git a/java/org/gnu/emacs/EmacsWindowAttachmentManager.java b/java/org/gnu/emacs/EmacsWindowAttachmentManager.java index 18bdb6dbf60..aae4e2ee49b 100644 --- a/java/org/gnu/emacs/EmacsWindowAttachmentManager.java +++ b/java/org/gnu/emacs/EmacsWindowAttachmentManager.java | |||
| @@ -124,10 +124,15 @@ public final class EmacsWindowAttachmentManager | |||
| 124 | 124 | ||
| 125 | intent = new Intent (EmacsService.SERVICE, | 125 | intent = new Intent (EmacsService.SERVICE, |
| 126 | EmacsMultitaskActivity.class); | 126 | EmacsMultitaskActivity.class); |
| 127 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_DOCUMENT | 127 | |
| 128 | | Intent.FLAG_ACTIVITY_NEW_TASK | 128 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK |
| 129 | | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); | 129 | | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 130 | 130 | ||
| 131 | /* Intent.FLAG_ACTIVITY_NEW_DOCUMENT is lamentably unavailable on | ||
| 132 | older systems than Lolipop. */ | ||
| 133 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) | ||
| 134 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_DOCUMENT); | ||
| 135 | |||
| 131 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) | 136 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) |
| 132 | EmacsService.SERVICE.startActivity (intent); | 137 | EmacsService.SERVICE.startActivity (intent); |
| 133 | else | 138 | else |