aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-06-06 14:35:19 +0800
committerPo Lu2023-06-06 14:35:19 +0800
commit5b4dea0fc781fe40548e7b58fe5bd201a05f3913 (patch)
treee005baf57dcbf33a0755ab706d9dfa5395a6b70b /java
parent5f09df3d6a359fabb2485c83549a0176a0ba2796 (diff)
downloademacs-5b4dea0fc781fe40548e7b58fe5bd201a05f3913.tar.gz
emacs-5b4dea0fc781fe40548e7b58fe5bd201a05f3913.zip
Update Android port
* java/org/gnu/emacs/EmacsContextMenu.java (display): Use `EmacsHolder' instead of `Holder'. * java/org/gnu/emacs/EmacsDialog.java (toAlertDialog): Use `EmacsDialogButtonLayout' to ensure that buttons are wrapped properly. (display): Adjust for new holder class. * java/org/gnu/emacs/EmacsDialogButtonLayout.java (EmacsDialogButtonLayout, onMeasure, onLayout): New functions. * java/org/gnu/emacs/EmacsDrawLine.java: * java/org/gnu/emacs/EmacsFillPolygon.java: Remove redundant imports. * java/org/gnu/emacs/EmacsHolder.java (EmacsHolder<T>): * java/org/gnu/emacs/EmacsService.java (class Holder<T>) (getEmacsView, EmacsService): Rename `Holder' to `EmacsHolder' and make it public.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsContextMenu.java4
-rw-r--r--java/org/gnu/emacs/EmacsDialog.java17
-rw-r--r--java/org/gnu/emacs/EmacsDialogButtonLayout.java152
-rw-r--r--java/org/gnu/emacs/EmacsDrawLine.java2
-rw-r--r--java/org/gnu/emacs/EmacsFillPolygon.java2
-rw-r--r--java/org/gnu/emacs/EmacsHolder.java30
-rw-r--r--java/org/gnu/emacs/EmacsService.java13
7 files changed, 195 insertions, 25 deletions
diff --git a/java/org/gnu/emacs/EmacsContextMenu.java b/java/org/gnu/emacs/EmacsContextMenu.java
index 5bae41bd61d..60f2db67fb0 100644
--- a/java/org/gnu/emacs/EmacsContextMenu.java
+++ b/java/org/gnu/emacs/EmacsContextMenu.java
@@ -331,9 +331,9 @@ public final class EmacsContextMenu
331 final int yPosition, final int serial) 331 final int yPosition, final int serial)
332 { 332 {
333 Runnable runnable; 333 Runnable runnable;
334 final Holder<Boolean> rc; 334 final EmacsHolder<Boolean> rc;
335 335
336 rc = new Holder<Boolean> (); 336 rc = new EmacsHolder<Boolean> ();
337 337
338 runnable = new Runnable () { 338 runnable = new Runnable () {
339 @Override 339 @Override
diff --git a/java/org/gnu/emacs/EmacsDialog.java b/java/org/gnu/emacs/EmacsDialog.java
index 3a5f22021fc..afdce3c50ec 100644
--- a/java/org/gnu/emacs/EmacsDialog.java
+++ b/java/org/gnu/emacs/EmacsDialog.java
@@ -150,7 +150,7 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener
150 AlertDialog dialog; 150 AlertDialog dialog;
151 int size; 151 int size;
152 EmacsButton button; 152 EmacsButton button;
153 LinearLayout layout; 153 EmacsDialogButtonLayout layout;
154 Button buttonView; 154 Button buttonView;
155 ViewGroup.LayoutParams layoutParams; 155 ViewGroup.LayoutParams layoutParams;
156 156
@@ -192,19 +192,16 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener
192 } 192 }
193 else 193 else
194 { 194 {
195 /* There are more than 4 buttons. Add them all to a 195 /* There are more than 3 buttons. Add them all to a special
196 LinearLayout. */ 196 container widget that handles wrapping. */
197 layout = new LinearLayout (context); 197
198 layoutParams 198 layout = new EmacsDialogButtonLayout (context);
199 = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.WRAP_CONTENT,
200 ViewGroup.LayoutParams.WRAP_CONTENT);
201 199
202 for (EmacsButton emacsButton : buttons) 200 for (EmacsButton emacsButton : buttons)
203 { 201 {
204 buttonView = new Button (context); 202 buttonView = new Button (context);
205 buttonView.setText (emacsButton.name); 203 buttonView.setText (emacsButton.name);
206 buttonView.setOnClickListener (emacsButton); 204 buttonView.setOnClickListener (emacsButton);
207 buttonView.setLayoutParams (layoutParams);
208 buttonView.setEnabled (emacsButton.enabled); 205 buttonView.setEnabled (emacsButton.enabled);
209 layout.addView (buttonView); 206 layout.addView (buttonView);
210 } 207 }
@@ -336,9 +333,9 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener
336 display () 333 display ()
337 { 334 {
338 Runnable runnable; 335 Runnable runnable;
339 final Holder<Boolean> rc; 336 final EmacsHolder<Boolean> rc;
340 337
341 rc = new Holder<Boolean> (); 338 rc = new EmacsHolder<Boolean> ();
342 runnable = new Runnable () { 339 runnable = new Runnable () {
343 @Override 340 @Override
344 public void 341 public void
diff --git a/java/org/gnu/emacs/EmacsDialogButtonLayout.java b/java/org/gnu/emacs/EmacsDialogButtonLayout.java
new file mode 100644
index 00000000000..5d97eea32aa
--- /dev/null
+++ b/java/org/gnu/emacs/EmacsDialogButtonLayout.java
@@ -0,0 +1,152 @@
1/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
2
3Copyright (C) 2023 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20package org.gnu.emacs;
21
22
23
24import android.content.Context;
25
26import android.view.View;
27import android.view.View.MeasureSpec;
28import android.view.ViewGroup;
29
30
31
32/* This ``view group'' implements a container widget for multiple
33 buttons of the type found in pop-up dialogs. It is used when
34 displaying a dialog box that contains more than three buttons, as
35 the default dialog box widget is not capable of holding more than
36 that many. */
37
38
39
40public class EmacsDialogButtonLayout extends ViewGroup
41{
42 public
43 EmacsDialogButtonLayout (Context context)
44 {
45 super (context);
46 }
47
48 @Override
49 protected void
50 onMeasure (int widthMeasureSpec, int heightMeasureSpec)
51 {
52 int width, count, i, x, y, height, spec, tempSpec;
53 View view;
54
55 /* Obtain the width of this widget and create the measure
56 specification used to measure children. */
57
58 width = MeasureSpec.getSize (widthMeasureSpec);
59 spec = MeasureSpec.makeMeasureSpec (0, MeasureSpec.UNSPECIFIED);
60 tempSpec
61 = MeasureSpec.makeMeasureSpec (width, MeasureSpec.AT_MOST);
62 x = y = height = 0;
63
64 /* Run through each widget. */
65
66 count = getChildCount ();
67
68 for (i = 0; i < count; ++i)
69 {
70 view = getChildAt (i);
71
72 /* Measure this view. */
73 view.measure (spec, spec);
74
75 if (width - x < view.getMeasuredWidth ())
76 {
77 /* Move onto the next line, unless this line is empty. */
78
79 if (x != 0)
80 {
81 y += height;
82 height = x = 0;
83 }
84
85 if (view.getMeasuredWidth () > width)
86 /* Measure the view again, this time forcing it to be at
87 most width wide, if it is not already. */
88 view.measure (tempSpec, spec);
89 }
90
91 height = Math.max (height, view.getMeasuredHeight ());
92 x += view.getMeasuredWidth ();
93 }
94
95 /* Now set the measured size of this widget. */
96 setMeasuredDimension (width, y + height);
97 }
98
99 @Override
100 protected void
101 onLayout (boolean changed, int left, int top, int right,
102 int bottom)
103 {
104 int width, count, i, x, y, height, spec, tempSpec;
105 View view;
106
107 /* Obtain the width of this widget and create the measure
108 specification used to measure children. */
109
110 width = getMeasuredWidth ();
111 spec = MeasureSpec.makeMeasureSpec (0, MeasureSpec.UNSPECIFIED);
112 tempSpec
113 = MeasureSpec.makeMeasureSpec (width, MeasureSpec.AT_MOST);
114 x = y = height = 0;
115
116 /* Run through each widget. */
117
118 count = getChildCount ();
119
120 for (i = 0; i < count; ++i)
121 {
122 view = getChildAt (i);
123
124 /* Measure this view. */
125 view.measure (spec, spec);
126
127 if (width - x < view.getMeasuredWidth ())
128 {
129 /* Move onto the next line, unless this line is empty. */
130
131 if (x != 0)
132 {
133 y += height;
134 height = x = 0;
135 }
136
137 if (view.getMeasuredWidth () > width)
138 /* Measure the view again, this time forcing it to be at
139 most width wide, if it is not already. */
140 view.measure (tempSpec, spec);
141 }
142
143 /* Now assign this view its position. */
144 view.layout (x, y, x + view.getMeasuredWidth (),
145 y + view.getMeasuredHeight ());
146
147 /* And move on to the next widget. */
148 height = Math.max (height, view.getMeasuredHeight ());
149 x += view.getMeasuredWidth ();
150 }
151 }
152};
diff --git a/java/org/gnu/emacs/EmacsDrawLine.java b/java/org/gnu/emacs/EmacsDrawLine.java
index 92e03c48e26..3f5067c0bdd 100644
--- a/java/org/gnu/emacs/EmacsDrawLine.java
+++ b/java/org/gnu/emacs/EmacsDrawLine.java
@@ -19,8 +19,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19 19
20package org.gnu.emacs; 20package org.gnu.emacs;
21 21
22import java.lang.Math;
23
24import android.graphics.Canvas; 22import android.graphics.Canvas;
25import android.graphics.Paint; 23import android.graphics.Paint;
26import android.graphics.Rect; 24import android.graphics.Rect;
diff --git a/java/org/gnu/emacs/EmacsFillPolygon.java b/java/org/gnu/emacs/EmacsFillPolygon.java
index ea8324c543c..4ae3882cab4 100644
--- a/java/org/gnu/emacs/EmacsFillPolygon.java
+++ b/java/org/gnu/emacs/EmacsFillPolygon.java
@@ -19,8 +19,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19 19
20package org.gnu.emacs; 20package org.gnu.emacs;
21 21
22import java.lang.Math;
23
24import android.graphics.Canvas; 22import android.graphics.Canvas;
25import android.graphics.Paint; 23import android.graphics.Paint;
26import android.graphics.Path; 24import android.graphics.Path;
diff --git a/java/org/gnu/emacs/EmacsHolder.java b/java/org/gnu/emacs/EmacsHolder.java
new file mode 100644
index 00000000000..3ca803d1640
--- /dev/null
+++ b/java/org/gnu/emacs/EmacsHolder.java
@@ -0,0 +1,30 @@
1/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
2
3Copyright (C) 2023 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20package org.gnu.emacs;
21
22
23
24/* This class serves as a simple reference to an object of type T.
25 Nothing could be found inside the standard library. */
26
27public class EmacsHolder<T>
28{
29 T thing;
30};
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index 6d70536faf0..2074a5b7c2b 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -71,11 +71,6 @@ import android.util.DisplayMetrics;
71 71
72import android.widget.Toast; 72import android.widget.Toast;
73 73
74class Holder<T>
75{
76 T thing;
77};
78
79/* EmacsService is the service that starts the thread running Emacs 74/* EmacsService is the service that starts the thread running Emacs
80 and handles requests by that Emacs instance. */ 75 and handles requests by that Emacs instance. */
81 76
@@ -282,9 +277,9 @@ public final class EmacsService extends Service
282 final boolean isFocusedByDefault) 277 final boolean isFocusedByDefault)
283 { 278 {
284 Runnable runnable; 279 Runnable runnable;
285 final Holder<EmacsView> view; 280 final EmacsHolder<EmacsView> view;
286 281
287 view = new Holder<EmacsView> (); 282 view = new EmacsHolder<EmacsView> ();
288 283
289 runnable = new Runnable () { 284 runnable = new Runnable () {
290 public void 285 public void
@@ -604,10 +599,10 @@ public final class EmacsService extends Service
604 public ClipboardManager 599 public ClipboardManager
605 getClipboardManager () 600 getClipboardManager ()
606 { 601 {
607 final Holder<ClipboardManager> manager; 602 final EmacsHolder<ClipboardManager> manager;
608 Runnable runnable; 603 Runnable runnable;
609 604
610 manager = new Holder<ClipboardManager> (); 605 manager = new EmacsHolder<ClipboardManager> ();
611 606
612 runnable = new Runnable () { 607 runnable = new Runnable () {
613 public void 608 public void