Fix for surface_height=0 on some devices after keyboard shown

This commit is contained in:
Twaik Yont 2019-08-19 22:07:11 +03:00
parent 12b7b00710
commit c4af642a71
8 changed files with 53 additions and 107 deletions

View File

@ -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.

View File

@ -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.

View File

@ -133,6 +133,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/validate_signing_config" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />

View File

@ -31,7 +31,8 @@
<activity android:name=".MainActivity"
android:theme="@style/NoActionBar"
android:launchMode="singleInstance"
android:configChanges="fontScale|orientation|screenSize|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|screenLayout|touchscreen|uiMode|smallestScreenSize|density">
android:configChanges="fontScale|orientation|screenSize|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|screenLayout|touchscreen|uiMode|smallestScreenSize|density"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -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;

View File

@ -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;

View File

@ -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() {}
}

View File

@ -7,21 +7,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
<com.termux.x11.AdditionalKeyboardView
android:id="@+id/additionalKbd"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/additionalKbd" />
<com.termux.x11.AdditionalKeyboardView
android:id="@+id/additionalKbd"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
<!-- Without this view AdditionalKeyboard view sometimes dissapear -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>