aboutsummaryrefslogtreecommitdiffstats
path: root/src/androidfns.c
diff options
context:
space:
mode:
authorPo Lu2023-12-14 13:24:42 +0800
committerPo Lu2023-12-14 13:24:42 +0800
commitde25aaa11a8ef264c6f76841daa7e2a721c60937 (patch)
tree4908399a7456506b1107d4c66f4c99f9a1532684 /src/androidfns.c
parent33aa46fe94f5551d3158a6b2dcb3e81e908bdbd1 (diff)
downloademacs-de25aaa11a8ef264c6f76841daa7e2a721c60937.tar.gz
emacs-de25aaa11a8ef264c6f76841daa7e2a721c60937.zip
Respect Language & Input preferences under Android
* doc/emacs/android.texi (Android Environment): * doc/emacs/cmdargs.texi (General Variables): Mention the manner in which the default language environment is selected on Android. * lisp/startup.el (normal-top-level): If android and initial-window-system, call android-locale-for-system-language for the default locale name. * lisp/term/android-win.el (android-locale-for-system-language): New function. * src/androidfns.c (syms_of_androidfns_for_pdumper): New function. (syms_of_androidfns) <Vandroid_os_language>: New variable. Call syms_of_androidfns_for_pdumper both now and after loading the dump image.
Diffstat (limited to 'src/androidfns.c')
-rw-r--r--src/androidfns.c203
1 files changed, 203 insertions, 0 deletions
diff --git a/src/androidfns.c b/src/androidfns.c
index 31a4924e34d..60ace4fd453 100644
--- a/src/androidfns.c
+++ b/src/androidfns.c
@@ -27,6 +27,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
27#include "keyboard.h" 27#include "keyboard.h"
28#include "buffer.h" 28#include "buffer.h"
29#include "androidgui.h" 29#include "androidgui.h"
30#include "pdumper.h"
30 31
31#ifndef ANDROID_STUBIFY 32#ifndef ANDROID_STUBIFY
32 33
@@ -3170,6 +3171,186 @@ android_set_preeditarea (struct window *w, int x, int y)
3170 3171
3171 3172
3172 3173
3174#ifndef ANDROID_STUBIFY
3175
3176static void
3177syms_of_androidfns_for_pdumper (void)
3178{
3179 jclass locale;
3180 jmethodID method;
3181 jobject object;
3182 jstring string;
3183 Lisp_Object language, country, script, variant;
3184 const char *data;
3185
3186 /* Find the Locale class. */
3187
3188 locale = (*android_java_env)->FindClass (android_java_env,
3189 "java/util/Locale");
3190 if (!locale)
3191 emacs_abort ();
3192
3193 /* And the method from which the default locale can be
3194 extracted. */
3195
3196 method = (*android_java_env)->GetStaticMethodID (android_java_env,
3197 locale,
3198 "getDefault",
3199 "()Ljava/util/Locale;");
3200 if (!method)
3201 emacs_abort ();
3202
3203 /* Retrieve the default locale. */
3204
3205 object = (*android_java_env)->CallStaticObjectMethod (android_java_env,
3206 locale, method);
3207 android_exception_check_1 (locale);
3208
3209 if (!object)
3210 emacs_abort ();
3211
3212 /* Retrieve its language field. Each of these methods is liable to
3213 return the empty string, though if language is empty, the locale
3214 is malformed. */
3215
3216 method = (*android_java_env)->GetMethodID (android_java_env, locale,
3217 "getLanguage",
3218 "()Ljava/lang/String;");
3219 if (!method)
3220 emacs_abort ();
3221
3222 string = (*android_java_env)->CallObjectMethod (android_java_env, object,
3223 method);
3224 android_exception_check_2 (object, locale);
3225
3226 if (!string)
3227 language = empty_unibyte_string;
3228 else
3229 {
3230 data = (*android_java_env)->GetStringUTFChars (android_java_env,
3231 string, NULL);
3232 android_exception_check_3 (object, locale, string);
3233
3234 if (!data)
3235 language = empty_unibyte_string;
3236 else
3237 {
3238 language = build_unibyte_string (data);
3239 (*android_java_env)->ReleaseStringUTFChars (android_java_env,
3240 string, data);
3241 }
3242 }
3243
3244 /* Delete the reference to this string. */
3245 ANDROID_DELETE_LOCAL_REF (string);
3246
3247 /* Proceed to retrieve the country code. */
3248
3249 method = (*android_java_env)->GetMethodID (android_java_env, locale,
3250 "getCountry",
3251 "()Ljava/lang/String;");
3252 if (!method)
3253 emacs_abort ();
3254
3255 string = (*android_java_env)->CallObjectMethod (android_java_env, object,
3256 method);
3257 android_exception_check_2 (object, locale);
3258
3259 if (!string)
3260 country = empty_unibyte_string;
3261 else
3262 {
3263 data = (*android_java_env)->GetStringUTFChars (android_java_env,
3264 string, NULL);
3265 android_exception_check_3 (object, locale, string);
3266
3267 if (!data)
3268 country = empty_unibyte_string;
3269 else
3270 {
3271 country = build_unibyte_string (data);
3272 (*android_java_env)->ReleaseStringUTFChars (android_java_env,
3273 string, data);
3274 }
3275 }
3276
3277 ANDROID_DELETE_LOCAL_REF (string);
3278
3279 /* Proceed to retrieve the script. */
3280
3281 method = (*android_java_env)->GetMethodID (android_java_env, locale,
3282 "getScript",
3283 "()Ljava/lang/String;");
3284 if (!method)
3285 emacs_abort ();
3286
3287 string = (*android_java_env)->CallObjectMethod (android_java_env, object,
3288 method);
3289 android_exception_check_2 (object, locale);
3290
3291 if (!string)
3292 script = empty_unibyte_string;
3293 else
3294 {
3295 data = (*android_java_env)->GetStringUTFChars (android_java_env,
3296 string, NULL);
3297 android_exception_check_3 (object, locale, string);
3298
3299 if (!data)
3300 script = empty_unibyte_string;
3301 else
3302 {
3303 script = build_unibyte_string (data);
3304 (*android_java_env)->ReleaseStringUTFChars (android_java_env,
3305 string, data);
3306 }
3307 }
3308
3309 ANDROID_DELETE_LOCAL_REF (string);
3310
3311 /* And variant. */
3312
3313 method = (*android_java_env)->GetMethodID (android_java_env, locale,
3314 "getVariant",
3315 "()Ljava/lang/String;");
3316 if (!method)
3317 emacs_abort ();
3318
3319 string = (*android_java_env)->CallObjectMethod (android_java_env, object,
3320 method);
3321 android_exception_check_2 (object, locale);
3322
3323 if (!string)
3324 variant = empty_unibyte_string;
3325 else
3326 {
3327 data = (*android_java_env)->GetStringUTFChars (android_java_env,
3328 string, NULL);
3329 android_exception_check_3 (object, locale, string);
3330
3331 if (!data)
3332 variant = empty_unibyte_string;
3333 else
3334 {
3335 variant = build_unibyte_string (data);
3336 (*android_java_env)->ReleaseStringUTFChars (android_java_env,
3337 string, data);
3338 }
3339 }
3340
3341 /* Delete the reference to this string. */
3342 ANDROID_DELETE_LOCAL_REF (string);
3343
3344 /* And other remaining local references. */
3345 ANDROID_DELETE_LOCAL_REF (object);
3346 ANDROID_DELETE_LOCAL_REF (locale);
3347
3348 /* Set Vandroid_os_language. */
3349 Vandroid_os_language = list4 (language, country, script, variant);
3350}
3351
3352#endif /* ANDROID_STUBIFY */
3353
3173void 3354void
3174syms_of_androidfns (void) 3355syms_of_androidfns (void)
3175{ 3356{
@@ -3313,6 +3494,26 @@ element that is activated for a given number of milliseconds upon the
3313bell being rung. */); 3494bell being rung. */);
3314 android_keyboard_bell_duration = 50; 3495 android_keyboard_bell_duration = 50;
3315 3496
3497 DEFVAR_LISP ("android-os-language", Vandroid_os_language,
3498 doc: /* List representing the system language configured.
3499This list incorporates four elements LANGUAGE, COUNTRY, SCRIPT
3500and VARIANT, of which:
3501
3502LANGUAGE and COUNTRY are ISO language and country codes identical to
3503those stored within POSIX locales.
3504
3505SCRIPT is an ISO 15924 script tag, representing the script used
3506if available, or if required to disambiguate between distinct
3507writing systems for the same combination of language and country.
3508
3509VARIANT is an arbitrary string representing the variant of the
3510LANGUAGE or SCRIPT represented.
3511
3512Each of these fields might be empty or nil, but the locale is invalid
3513if LANGUAGE is empty. Users of this variable should consider the
3514language US English in this scenario. */);
3515 Vandroid_os_language = Qnil;
3516
3316 /* Functions defined. */ 3517 /* Functions defined. */
3317 defsubr (&Sx_create_frame); 3518 defsubr (&Sx_create_frame);
3318 defsubr (&Sxw_color_defined_p); 3519 defsubr (&Sxw_color_defined_p);
@@ -3363,5 +3564,7 @@ bell being rung. */);
3363 staticpro (&tip_dx); 3564 staticpro (&tip_dx);
3364 tip_dy = Qnil; 3565 tip_dy = Qnil;
3365 staticpro (&tip_dy); 3566 staticpro (&tip_dy);
3567
3568 pdumper_do_now_and_after_load (syms_of_androidfns_for_pdumper);
3366#endif /* !ANDROID_STUBIFY */ 3569#endif /* !ANDROID_STUBIFY */
3367} 3570}