[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 5b4dea0fc78: Update Android port
From: |
Po Lu |
Subject: |
feature/android 5b4dea0fc78: Update Android port |
Date: |
Tue, 6 Jun 2023 02:35:49 -0400 (EDT) |
branch: feature/android
commit 5b4dea0fc781fe40548e7b58fe5bd201a05f3913
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
java/org/gnu/emacs/EmacsContextMenu.java | 4 +-
java/org/gnu/emacs/EmacsDialog.java | 17 ++-
java/org/gnu/emacs/EmacsDialogButtonLayout.java | 152 ++++++++++++++++++++++++
java/org/gnu/emacs/EmacsDrawLine.java | 2 -
java/org/gnu/emacs/EmacsFillPolygon.java | 2 -
java/org/gnu/emacs/EmacsHolder.java | 30 +++++
java/org/gnu/emacs/EmacsService.java | 13 +-
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
final int yPosition, final int serial)
{
Runnable runnable;
- final Holder<Boolean> rc;
+ final EmacsHolder<Boolean> rc;
- rc = new Holder<Boolean> ();
+ rc = new EmacsHolder<Boolean> ();
runnable = new Runnable () {
@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
AlertDialog dialog;
int size;
EmacsButton button;
- LinearLayout layout;
+ EmacsDialogButtonLayout layout;
Button buttonView;
ViewGroup.LayoutParams layoutParams;
@@ -192,19 +192,16 @@ public final class EmacsDialog implements
DialogInterface.OnDismissListener
}
else
{
- /* There are more than 4 buttons. Add them all to a
- LinearLayout. */
- layout = new LinearLayout (context);
- layoutParams
- = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ /* There are more than 3 buttons. Add them all to a special
+ container widget that handles wrapping. */
+
+ layout = new EmacsDialogButtonLayout (context);
for (EmacsButton emacsButton : buttons)
{
buttonView = new Button (context);
buttonView.setText (emacsButton.name);
buttonView.setOnClickListener (emacsButton);
- buttonView.setLayoutParams (layoutParams);
buttonView.setEnabled (emacsButton.enabled);
layout.addView (buttonView);
}
@@ -336,9 +333,9 @@ public final class EmacsDialog implements
DialogInterface.OnDismissListener
display ()
{
Runnable runnable;
- final Holder<Boolean> rc;
+ final EmacsHolder<Boolean> rc;
- rc = new Holder<Boolean> ();
+ rc = new EmacsHolder<Boolean> ();
runnable = new Runnable () {
@Override
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 @@
+/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
+
+package org.gnu.emacs;
+
+
+
+import android.content.Context;
+
+import android.view.View;
+import android.view.View.MeasureSpec;
+import android.view.ViewGroup;
+
+
+
+/* This ``view group'' implements a container widget for multiple
+ buttons of the type found in pop-up dialogs. It is used when
+ displaying a dialog box that contains more than three buttons, as
+ the default dialog box widget is not capable of holding more than
+ that many. */
+
+
+
+public class EmacsDialogButtonLayout extends ViewGroup
+{
+ public
+ EmacsDialogButtonLayout (Context context)
+ {
+ super (context);
+ }
+
+ @Override
+ protected void
+ onMeasure (int widthMeasureSpec, int heightMeasureSpec)
+ {
+ int width, count, i, x, y, height, spec, tempSpec;
+ View view;
+
+ /* Obtain the width of this widget and create the measure
+ specification used to measure children. */
+
+ width = MeasureSpec.getSize (widthMeasureSpec);
+ spec = MeasureSpec.makeMeasureSpec (0, MeasureSpec.UNSPECIFIED);
+ tempSpec
+ = MeasureSpec.makeMeasureSpec (width, MeasureSpec.AT_MOST);
+ x = y = height = 0;
+
+ /* Run through each widget. */
+
+ count = getChildCount ();
+
+ for (i = 0; i < count; ++i)
+ {
+ view = getChildAt (i);
+
+ /* Measure this view. */
+ view.measure (spec, spec);
+
+ if (width - x < view.getMeasuredWidth ())
+ {
+ /* Move onto the next line, unless this line is empty. */
+
+ if (x != 0)
+ {
+ y += height;
+ height = x = 0;
+ }
+
+ if (view.getMeasuredWidth () > width)
+ /* Measure the view again, this time forcing it to be at
+ most width wide, if it is not already. */
+ view.measure (tempSpec, spec);
+ }
+
+ height = Math.max (height, view.getMeasuredHeight ());
+ x += view.getMeasuredWidth ();
+ }
+
+ /* Now set the measured size of this widget. */
+ setMeasuredDimension (width, y + height);
+ }
+
+ @Override
+ protected void
+ onLayout (boolean changed, int left, int top, int right,
+ int bottom)
+ {
+ int width, count, i, x, y, height, spec, tempSpec;
+ View view;
+
+ /* Obtain the width of this widget and create the measure
+ specification used to measure children. */
+
+ width = getMeasuredWidth ();
+ spec = MeasureSpec.makeMeasureSpec (0, MeasureSpec.UNSPECIFIED);
+ tempSpec
+ = MeasureSpec.makeMeasureSpec (width, MeasureSpec.AT_MOST);
+ x = y = height = 0;
+
+ /* Run through each widget. */
+
+ count = getChildCount ();
+
+ for (i = 0; i < count; ++i)
+ {
+ view = getChildAt (i);
+
+ /* Measure this view. */
+ view.measure (spec, spec);
+
+ if (width - x < view.getMeasuredWidth ())
+ {
+ /* Move onto the next line, unless this line is empty. */
+
+ if (x != 0)
+ {
+ y += height;
+ height = x = 0;
+ }
+
+ if (view.getMeasuredWidth () > width)
+ /* Measure the view again, this time forcing it to be at
+ most width wide, if it is not already. */
+ view.measure (tempSpec, spec);
+ }
+
+ /* Now assign this view its position. */
+ view.layout (x, y, x + view.getMeasuredWidth (),
+ y + view.getMeasuredHeight ());
+
+ /* And move on to the next widget. */
+ height = Math.max (height, view.getMeasuredHeight ());
+ x += view.getMeasuredWidth ();
+ }
+ }
+};
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/>. */
package org.gnu.emacs;
-import java.lang.Math;
-
import android.graphics.Canvas;
import android.graphics.Paint;
import 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/>. */
package org.gnu.emacs;
-import java.lang.Math;
-
import android.graphics.Canvas;
import android.graphics.Paint;
import 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 @@
+/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
+
+package org.gnu.emacs;
+
+
+
+/* This class serves as a simple reference to an object of type T.
+ Nothing could be found inside the standard library. */
+
+public class EmacsHolder<T>
+{
+ T thing;
+};
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;
import android.widget.Toast;
-class Holder<T>
-{
- T thing;
-};
-
/* EmacsService is the service that starts the thread running Emacs
and handles requests by that Emacs instance. */
@@ -282,9 +277,9 @@ public final class EmacsService extends Service
final boolean isFocusedByDefault)
{
Runnable runnable;
- final Holder<EmacsView> view;
+ final EmacsHolder<EmacsView> view;
- view = new Holder<EmacsView> ();
+ view = new EmacsHolder<EmacsView> ();
runnable = new Runnable () {
public void
@@ -604,10 +599,10 @@ public final class EmacsService extends Service
public ClipboardManager
getClipboardManager ()
{
- final Holder<ClipboardManager> manager;
+ final EmacsHolder<ClipboardManager> manager;
Runnable runnable;
- manager = new Holder<ClipboardManager> ();
+ manager = new EmacsHolder<ClipboardManager> ();
runnable = new Runnable () {
public void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/android 5b4dea0fc78: Update Android port,
Po Lu <=