From c4af642a71824447130cdb1701d220261b86814f Mon Sep 17 00:00:00 2001 From: Twaik Yont Date: Mon, 19 Aug 2019 22:07:11 +0300 Subject: [PATCH] Fix for surface_height=0 on some devices after keyboard shown --- ...id_gradle_build_lorie_arm64-v8a.stdout.txt | 16 +------ ...droid_gradle_build_lorie_x86_64.stdout.txt | 48 +------------------ app/app.iml | 1 + app/src/main/AndroidManifest.xml | 3 +- .../termux/x11/AdditionalKeyboardView.java | 39 +++++++++++++-- .../java/com/termux/x11/LorieService.java | 12 ++--- .../java/com/termux/x11/MainActivity.java | 19 +------- app/src/main/res/layout/main_activity.xml | 22 +++------ 8 files changed, 53 insertions(+), 107 deletions(-) diff --git a/app/.externalNativeBuild/ndkBuild/debug/arm64-v8a/android_gradle_build_lorie_arm64-v8a.stdout.txt b/app/.externalNativeBuild/ndkBuild/debug/arm64-v8a/android_gradle_build_lorie_arm64-v8a.stdout.txt index 30feada..67b35f7 100644 --- a/app/.externalNativeBuild/ndkBuild/debug/arm64-v8a/android_gradle_build_lorie_arm64-v8a.stdout.txt +++ b/app/.externalNativeBuild/ndkBuild/debug/arm64-v8a/android_gradle_build_lorie_arm64-v8a.stdout.txt @@ -2,18 +2,4 @@ Android NDK: WARNING:/home/twaik/TermuxX11/app/src/main/jni/lorie/Android.mk:lor Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the Android NDK: current module -[arm64-v8a] Compile++ : lorie <= client.cpp -[arm64-v8a] Compile++ : lorie <= clipboard.cpp -[arm64-v8a] Compile++ : lorie <= compositor.cpp -[arm64-v8a] Compile++ : lorie <= egl-helper.cpp -[arm64-v8a] Compile++ : lorie <= message-queue.cpp -[arm64-v8a] Compile++ : lorie <= renderer.cpp -[arm64-v8a] Compile++ : lorie <= seat.cpp -[arm64-v8a] Compile++ : lorie <= surface.cpp -[arm64-v8a] Compile++ : lorie <= output.cpp -[arm64-v8a] Compile++ : lorie <= log.cpp -[arm64-v8a] Compile++ : lorie <= utils.cpp -[arm64-v8a] Compile++ : lorie <= wayland.cpp -[arm64-v8a] Compile++ : lorie <= android-app.cpp -[arm64-v8a] Compile : lorie <= utils.c -[arm64-v8a] SharedLibrary : liblorie.so +make: `/home/twaik/TermuxX11/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/liblorie.so' is up to date. diff --git a/app/.externalNativeBuild/ndkBuild/debug/x86_64/android_gradle_build_lorie_x86_64.stdout.txt b/app/.externalNativeBuild/ndkBuild/debug/x86_64/android_gradle_build_lorie_x86_64.stdout.txt index 4d292fe..97214e1 100644 --- a/app/.externalNativeBuild/ndkBuild/debug/x86_64/android_gradle_build_lorie_x86_64.stdout.txt +++ b/app/.externalNativeBuild/ndkBuild/debug/x86_64/android_gradle_build_lorie_x86_64.stdout.txt @@ -2,50 +2,4 @@ Android NDK: WARNING:/home/twaik/TermuxX11/app/src/main/jni/lorie/Android.mk:lor Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the Android NDK: current module -[x86_64] Compile++ : lorie <= client.cpp -[x86_64] Compile++ : lorie <= clipboard.cpp -[x86_64] Compile++ : lorie <= compositor.cpp -[x86_64] Compile++ : lorie <= egl-helper.cpp -[x86_64] Compile++ : lorie <= message-queue.cpp -[x86_64] Compile++ : lorie <= renderer.cpp -[x86_64] Compile++ : lorie <= seat.cpp -[x86_64] Compile++ : lorie <= surface.cpp -[x86_64] Compile++ : lorie <= output.cpp -[x86_64] Compile++ : lorie <= log.cpp -[x86_64] Compile++ : lorie <= utils.cpp -[x86_64] Compile++ : lorie <= wayland.cpp -[x86_64] Compile++ : lorie <= android-app.cpp -[x86_64] Compile : lorie <= utils.c -[x86_64] Compile : xkbcommon <= parser.c -[x86_64] Compile : xkbcommon <= paths.c -[x86_64] Compile : xkbcommon <= state.c -[x86_64] Compile : xkbcommon <= table.c -[x86_64] Compile : xkbcommon <= action.c -[x86_64] Compile : xkbcommon <= ast-build.c -[x86_64] Compile : xkbcommon <= compat.c -[x86_64] Compile : xkbcommon <= expr.c -[x86_64] Compile : xkbcommon <= include.c -[x86_64] Compile : xkbcommon <= keycodes.c -[x86_64] Compile : xkbcommon <= keymap.c -[x86_64] Compile : xkbcommon <= keymap-dump.c -[x86_64] Compile : xkbcommon <= keywords.c -[x86_64] Compile : xkbcommon <= parser.c -[x86_64] Compile : xkbcommon <= rules.c -[x86_64] Compile : xkbcommon <= scanner.c -[x86_64] Compile : xkbcommon <= symbols.c -[x86_64] Compile : xkbcommon <= types.c -[x86_64] Compile : xkbcommon <= vmod.c -[x86_64] Compile : xkbcommon <= xkbcomp.c -[x86_64] Compile : xkbcommon <= atom.c -[x86_64] Compile : xkbcommon <= context.c -[x86_64] Compile : xkbcommon <= context-priv.c -[x86_64] Compile : xkbcommon <= keysym.c -[x86_64] Compile : xkbcommon <= keysym-utf.c -[x86_64] Compile : xkbcommon <= keymap.c -[x86_64] Compile : xkbcommon <= keymap-priv.c -[x86_64] Compile : xkbcommon <= state.c -[x86_64] Compile : xkbcommon <= text.c -[x86_64] Compile : xkbcommon <= utf8.c -[x86_64] Compile : xkbcommon <= utils.c -[x86_64] SharedLibrary : libxkbcommon.so -[x86_64] SharedLibrary : liblorie.so +make: `/home/twaik/TermuxX11/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/liblorie.so' is up to date. diff --git a/app/app.iml b/app/app.iml index 7a8def1..f7ab6c7 100644 --- a/app/app.iml +++ b/app/app.iml @@ -133,6 +133,7 @@ + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 37a4dce..43c8a61 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,7 +31,8 @@ + android:configChanges="fontScale|orientation|screenSize|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|screenLayout|touchscreen|uiMode|smallestScreenSize|density" + android:windowSoftInputMode="adjustPan"> diff --git a/app/src/main/java/com/termux/x11/AdditionalKeyboardView.java b/app/src/main/java/com/termux/x11/AdditionalKeyboardView.java index 3cc396e..7ca9aa1 100644 --- a/app/src/main/java/com/termux/x11/AdditionalKeyboardView.java +++ b/app/src/main/java/com/termux/x11/AdditionalKeyboardView.java @@ -2,7 +2,9 @@ package com.termux.x11; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Rect; +import android.preference.PreferenceManager; import android.support.v7.widget.AppCompatTextView; import android.util.AttributeSet; import android.util.Log; @@ -10,6 +12,7 @@ import android.view.Gravity; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.ViewTreeObserver; import android.widget.HorizontalScrollView; import android.widget.LinearLayout; @@ -17,9 +20,10 @@ import java.util.HashMap; import java.util.Map; @SuppressWarnings("unused") -public class AdditionalKeyboardView extends HorizontalScrollView { - private final static int KEYCODE_BASE = KeyEvent.KEYCODE_REFRESH + 100; +public class AdditionalKeyboardView extends HorizontalScrollView implements ViewTreeObserver.OnGlobalLayoutListener { + private final static int KEYCODE_BASE = 300; public final static int PREFERENCES_KEY = KEYCODE_BASE + 1; + public final static int KEY_HEIGHT_DP = 35; Context ctx; View targetView = null; View.OnKeyListener targetListener = null; @@ -39,15 +43,42 @@ public class AdditionalKeyboardView extends HorizontalScrollView { ctx = context; density = (int) context.getResources().getDisplayMetrics().density; - //setFillViewport(true); + getViewTreeObserver().addOnGlobalLayoutListener(this); + setBackgroundColor(0xFF000000); - LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, KEY_HEIGHT_DP * density); root = new LinearLayout(context); root.setLayoutParams(lp); root.setOrientation(LinearLayout.HORIZONTAL); addView(root); } + @Override + public void onGlobalLayout() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx); + if (!preferences.getBoolean("showAdditionalKbd", true)) { + if (getVisibility() != View.GONE) + setVisibility(View.GONE); + return; + } + + Rect r = new Rect(); + getWindowVisibleDisplayFrame(r); + + float mScreenDensity = getResources().getDisplayMetrics().density; + int MAGIC_NUMBER = 200; + + int heightDiff = getRootView().getHeight() - (r.bottom - r.top); + float dp = heightDiff/ mScreenDensity; + int visibility = (dp > MAGIC_NUMBER)?View.VISIBLE:View.INVISIBLE; + + if (getVisibility() == visibility) return; + + if (visibility == View.VISIBLE) + setY(r.bottom - r.top - getHeight()); + setVisibility(visibility); + } + public void reload(int[] keys, View TargetView, View.OnKeyListener TargetListener) { targetView = TargetView; targetListener = TargetListener; diff --git a/app/src/main/java/com/termux/x11/LorieService.java b/app/src/main/java/com/termux/x11/LorieService.java index 1c1d0e3..98854ec 100644 --- a/app/src/main/java/com/termux/x11/LorieService.java +++ b/app/src/main/java/com/termux/x11/LorieService.java @@ -31,7 +31,7 @@ import android.view.SurfaceView; import android.view.View; import android.widget.Toast; -@SuppressWarnings("ConstantConditions") +@SuppressWarnings({"ConstantConditions", "SameParameterValue"}) @SuppressLint({"ClickableViewAccessibility", "StaticFieldLeak"}) public class LorieService extends Service { @@ -68,6 +68,7 @@ public class LorieService extends Service { } } + @SuppressLint("BatteryLife") @Override public void onCreate() { if (isServiceRunningInForeground(this, LorieService.class)) return; @@ -155,12 +156,8 @@ public class LorieService extends Service { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(instance); - instance.mTP.setMode( - Integer.parseInt( - preferences.getString("touchMode", "1") - ) - ); - act.showAdditionalKbd = preferences.getBoolean("showAdditionalKbd", true); + int mode = Integer.parseInt(preferences.getString("touchMode", "1")); + instance.mTP.setMode(mode); Log.e("LorieService", "Preferences changed"); } @@ -233,6 +230,7 @@ public class LorieService extends Service { return null; } + @SuppressWarnings("SameParameterValue") private static class ServiceEventListener implements SurfaceHolder.Callback, View.OnTouchListener, View.OnKeyListener, View.OnHoverListener, View.OnGenericMotionListener, TouchParser.OnTouchParseListener { LorieService svc; diff --git a/app/src/main/java/com/termux/x11/MainActivity.java b/app/src/main/java/com/termux/x11/MainActivity.java index e996d61..62be88b 100644 --- a/app/src/main/java/com/termux/x11/MainActivity.java +++ b/app/src/main/java/com/termux/x11/MainActivity.java @@ -1,10 +1,8 @@ package com.termux.x11; import android.content.SharedPreferences; -import android.inputmethodservice.InputMethodService; import android.os.Build; import android.preference.PreferenceManager; -import android.provider.Settings; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.KeyEvent; @@ -13,9 +11,8 @@ import android.view.SurfaceView; import android.view.View; import android.view.Window; import android.view.WindowManager; -import android.view.inputmethod.InputMethodManager; -public class MainActivity extends AppCompatActivity implements KeyboardUtils.SoftKeyboardToggleListener { +public class MainActivity extends AppCompatActivity { private static int[] keys = { KeyEvent.KEYCODE_ESCAPE, @@ -29,31 +26,24 @@ public class MainActivity extends AppCompatActivity implements KeyboardUtils.Sof }; AdditionalKeyboardView kbd; - boolean showAdditionalKbd = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); LorieService.setMainActivity(this); LorieService.start(LorieService.ACTION_START_FROM_ACTIVITY); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - requestWindowFeature(Window.FEATURE_NO_TITLE); - setContentView(R.layout.main_activity); kbd = findViewById(R.id.additionalKbd); - kbd.setVisibility(View.INVISIBLE); - KeyboardUtils.addKeyboardToggleListener(this, this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) getWindow(). getDecorView(). setPointerIcon(PointerIcon.getSystemIcon(this, PointerIcon.TYPE_NULL)); - getResources().getConfiguration(); } public void onLorieServiceStart(LorieService instance) { @@ -88,13 +78,6 @@ public class MainActivity extends AppCompatActivity implements KeyboardUtils.Sof } } - - @Override - public void onToggleSoftKeyboard(boolean isVisible) { - if (kbd != null && showAdditionalKbd) - kbd.setVisibility((isVisible)?View.VISIBLE:View.INVISIBLE); - } - @Override public void onBackPressed() {} } diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index b13d208..0cbed7d 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -7,21 +7,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> - + android:layout_height="wrap_content" /> - - - - - + + \ No newline at end of file