summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2025-04-10 15:21:15 +0800
committerPo Lu <luangruo@yahoo.com>2025-04-10 15:25:38 +0800
commit884ede7c959b1331e1ede0b1b80f01a06c048bf5 (patch)
tree5ca2198d6e17931492b14d99393d83e798a7f011 /java
parentcb339ad8f4e386505f1eae9e45c4162feea61f53 (diff)
Respond to display configuration updates on Android
* java/org/gnu/emacs/EmacsNative.java (sendConfigurationChanged): Declare function. * java/org/gnu/emacs/EmacsSdk7FontDriver.java (Sdk7FontEntity) (Sdk7FontObject): Do not access `metrics' field deleted from `EmacsService'. * java/org/gnu/emacs/EmacsService.java (EmacsService) <metrics, resources>: Delete fields. <dpiX, dpiY, dpiScaled>: New fields. (onCreate): Adjust accordingly. Record current display metrics for subsequent comparison. (onConfigurationChanged): New function. * lisp/dynamic-setting.el (font-setting-change-default-font): Enable on systems where font-get-system-font is not defined if invoked with SET-FONT nil. * src/android.c (sendConfigurationChanged): New function. * src/androidgui.h (ANDROID_CONFIGURATION_CHANGED): New enumerator. (struct android_configuration_changed): New structure. (union android_event): Add `config' member. * src/androidterm.c (handle_one_android_event): Handle ANDROID_CONFIGURATION_CHANGED events. (syms_of_androidterm): Define Qfont_render, and Qdynamic_setting. Provide the latter.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsNative.java4
-rw-r--r--java/org/gnu/emacs/EmacsSdk7FontDriver.java10
-rw-r--r--java/org/gnu/emacs/EmacsService.java66
3 files changed, 64 insertions, 16 deletions
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java
index 94df9ff39b4..49a21ce1c4d 100644
--- a/java/org/gnu/emacs/EmacsNative.java
+++ b/java/org/gnu/emacs/EmacsNative.java
@@ -196,6 +196,10 @@ public final class EmacsNative
/* Send an ANDROID_NOTIFICATION_ACTION event. */
public static native void sendNotificationAction (String tag, String action);
+ /* Send an ANDROID_CONFIGURATION_CHANGED event. */
+ public static native void sendConfigurationChanged (float dpiX, float dpiY,
+ float dpiScaled);
+
/* Return the file name associated with the specified file
descriptor, or NULL if there is none. */
public static native byte[] getProcName (int fd);
diff --git a/java/org/gnu/emacs/EmacsSdk7FontDriver.java b/java/org/gnu/emacs/EmacsSdk7FontDriver.java
index 2fc40551984..b426c3ba74e 100644
--- a/java/org/gnu/emacs/EmacsSdk7FontDriver.java
+++ b/java/org/gnu/emacs/EmacsSdk7FontDriver.java
@@ -29,6 +29,7 @@ import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Canvas;
+import android.util.DisplayMetrics;
import android.util.Log;
@@ -103,6 +104,8 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
public
Sdk7FontEntity (Sdk7Typeface typeface)
{
+ DisplayMetrics metrics;
+
foundry = "Google";
family = typeface.familyName;
adstyle = null;
@@ -110,7 +113,8 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
slant = typeface.slant;
spacing = typeface.spacing;
width = typeface.width;
- dpi = Math.round (EmacsService.SERVICE.metrics.scaledDensity * 160f);
+ metrics = EmacsService.SERVICE.getResources ().getDisplayMetrics ();
+ dpi = Math.round (metrics.scaledDensity * 160f);
this.typeface = typeface;
}
@@ -127,6 +131,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
{
float totalWidth;
String testWidth, testString;
+ DisplayMetrics metrics;
this.typeface = typeface;
this.pixelSize = pixelSize;
@@ -137,7 +142,8 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
slant = typeface.slant;
spacing = typeface.spacing;
width = typeface.width;
- dpi = Math.round (EmacsService.SERVICE.metrics.scaledDensity * 160f);
+ metrics = EmacsService.SERVICE.getResources ().getDisplayMetrics ();
+ dpi = Math.round (metrics.scaledDensity * 160f);
/* Compute the ascent and descent. */
typeface.typefacePaint.setTextSize (pixelSize);
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index babf2626ba5..3630329839f 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -123,9 +123,6 @@ public final class EmacsService extends Service
public static final int IC_MODE_TEXT = 2;
public static final int IC_MODE_PASSWORD = 3;
- /* Display metrics used by font backends. */
- public DisplayMetrics metrics;
-
/* Flag that says whether or not to print verbose debugging
information when responding to an input method. */
public static final boolean DEBUG_IC = false;
@@ -149,8 +146,9 @@ public final class EmacsService extends Service
thread. */
private Thread mainThread;
- /* "Resources" object required by GContext bookkeeping. */
- public static Resources resources;
+ /* The display's horizontal and vertical density and that which is
+ consulted for font scaling. */
+ private double dpiX, dpiY, dpiScaled;
static
{
@@ -236,10 +234,12 @@ public final class EmacsService extends Service
final AssetManager manager;
Context app_context;
final String filesDir, libDir, cacheDir, classPath;
- final double pixelDensityX;
- final double pixelDensityY;
- final double scaledDensity;
- double tempScaledDensity;
+ final float pixelDensityX;
+ final float pixelDensityY;
+ final float scaledDensity;
+ float tempScaledDensity;
+ Resources resources;
+ DisplayMetrics metrics;
super.onCreate ();
@@ -265,13 +265,18 @@ public final class EmacsService extends Service
corresponds to 1 pixel, not 72 or 96 as used elsewhere. This
difference is codified in PT_PER_INCH defined in font.h. */
- if (tempScaledDensity < 160)
- tempScaledDensity = 160;
+ if (tempScaledDensity < 160.0f)
+ tempScaledDensity = 160.0f;
/* scaledDensity is const as required to refer to it from within
the nested function below. */
scaledDensity = tempScaledDensity;
+ /* Save these fields for future reference. */
+ dpiX = pixelDensityX;
+ dpiY = pixelDensityY;
+ dpiScaled = scaledDensity;
+
/* Remove all tasks from previous Emacs sessions but the task
created by the system at startup. */
EmacsWindowManager.MANAGER.removeOldTasks (this);
@@ -304,9 +309,8 @@ public final class EmacsService extends Service
run ()
{
EmacsNative.setEmacsParams (manager, filesDir, libDir,
- cacheDir, (float) pixelDensityX,
- (float) pixelDensityY,
- (float) scaledDensity,
+ cacheDir, pixelDensityX,
+ pixelDensityY, scaledDensity,
classPath, EmacsService.this,
Build.VERSION.SDK_INT);
}
@@ -344,6 +348,40 @@ public final class EmacsService extends Service
super.onLowMemory ();
}
+ @Override
+ public void
+ onConfigurationChanged (Configuration newConfig)
+ {
+ DisplayMetrics metrics;
+ float pixelDensityX, pixelDensityY, scaledDensity;
+
+ metrics = getResources ().getDisplayMetrics ();
+
+ /* The display configuration may have been altered. Retrieve the
+ revised display density and deliver an event if so. */
+ pixelDensityX = metrics.xdpi;
+ pixelDensityY = metrics.ydpi;
+ scaledDensity = ((getScaledDensity (metrics)
+ / metrics.density) * pixelDensityX);
+
+ /* A density below 160 probably indicates a system bug. See
+ onCreate for more commentary. */
+ if (scaledDensity < 160.0f)
+ scaledDensity = 160.0f;
+
+ if (pixelDensityX != dpiX || pixelDensityY != dpiY
+ || scaledDensity != dpiScaled)
+ {
+ dpiX = pixelDensityX;
+ dpiY = pixelDensityY;
+ dpiScaled = scaledDensity;
+ EmacsNative.sendConfigurationChanged (pixelDensityX, pixelDensityY,
+ scaledDensity);
+ }
+
+ super.onConfigurationChanged (newConfig);
+ }
+
/* Functions from here on must only be called from the Emacs