From bc9239eb51b1a346dac8a7f0f20b857143114bae Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 3 Mar 2023 15:23:21 +0800 Subject: Update Android port * java/org/gnu/emacs/EmacsActivity.java (EmacsActivity) (onCreate): Add view tree observer. (onGlobalLayout): Sync fullscreen state. (syncFullscreenWith): Improve visibility flag setting. * src/textconv.c (select_window): New function. (textconv_query): (restore_selected_window): (really_commit_text): (really_set_composing_text): (really_set_composing_region): (really_delete_surrounding_text): (really_set_point_and_mark): (get_extracted_text): Call it instead of Fselect_window to avoid selecting the mini window if it is no longer active. --- java/org/gnu/emacs/EmacsActivity.java | 42 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'java/org/gnu') diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index bcfee3f7080..62bef33fab3 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java @@ -31,6 +31,7 @@ import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowInsets; import android.view.WindowInsetsController; @@ -38,7 +39,8 @@ import android.widget.FrameLayout.LayoutParams; import android.widget.FrameLayout; public class EmacsActivity extends Activity - implements EmacsWindowAttachmentManager.WindowConsumer + implements EmacsWindowAttachmentManager.WindowConsumer, + ViewTreeObserver.OnGlobalLayoutListener { public static final String TAG = "EmacsActivity"; @@ -180,6 +182,8 @@ public class EmacsActivity extends Activity { FrameLayout.LayoutParams params; Intent intent; + View decorView; + ViewTreeObserver observer; /* See if Emacs should be started with -Q. */ intent = getIntent (); @@ -203,9 +207,29 @@ public class EmacsActivity extends Activity /* Add this activity to the list of available activities. */ EmacsWindowAttachmentManager.MANAGER.registerWindowConsumer (this); + /* Start observing global layout changes between Jelly Bean and Q. + This is required to restore the fullscreen state whenever the + on screen keyboard is displayed, as there is otherwise no way + to determine when the on screen keyboard becomes visible. */ + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN + && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) + { + decorView = getWindow ().getDecorView (); + observer = decorView.getViewTreeObserver (); + observer.addOnGlobalLayoutListener (this); + } + super.onCreate (savedInstanceState); } + @Override + public final void + onGlobalLayout () + { + syncFullscreenWith (window); + } + @Override public final void onDestroy () @@ -348,22 +372,20 @@ public class EmacsActivity extends Activity if (isFullscreen) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) - /* This flag means that Emacs will be full screen, but - the system will cancel the full screen state upon - switching to another program. */ - view.setSystemUiVisibility (View.SYSTEM_UI_FLAG_FULLSCREEN); - else + flags = 0; + flags |= View.SYSTEM_UI_FLAG_FULLSCREEN; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { /* These flags means that Emacs will be full screen as long as the state flag is set. */ - flags = 0; - flags |= View.SYSTEM_UI_FLAG_FULLSCREEN; flags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; flags |= View.SYSTEM_UI_FLAG_IMMERSIVE; flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; - view.setSystemUiVisibility (flags); } + + /* Apply the given flags. */ + view.setSystemUiVisibility (flags); } else view.setSystemUiVisibility (View.SYSTEM_UI_FLAG_VISIBLE); -- cgit v1.2.1