Revert "Virtual keyboard size adjustment fixes"

Also reverts "[3.2] Move PopupWindow logic to GodotEditText on Android".

This reverts commits 69db38742f and.
ff0ada164b.
This commit is contained in:
Rémi Verschelde 2020-08-12 14:30:18 +02:00
parent a97b84378c
commit 5972495d99
2 changed files with 49 additions and 74 deletions

View File

@ -53,6 +53,8 @@ import android.content.SharedPreferences.Editor;
import android.content.pm.ConfigurationInfo; import android.content.pm.ConfigurationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.SensorEvent; import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
@ -73,6 +75,7 @@ import android.view.Surface;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
@ -245,8 +248,6 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
public GodotView mView; public GodotView mView;
private boolean godot_initialized = false; private boolean godot_initialized = false;
private GodotEditText mEditText;
private SensorManager mSensorManager; private SensorManager mSensorManager;
private Sensor mAccelerometer; private Sensor mAccelerometer;
private Sensor mGravity; private Sensor mGravity;
@ -315,11 +316,29 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(layout); setContentView(layout);
// GodotEditText layout
GodotEditText edittext = new GodotEditText(this);
edittext.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
// ...add to FrameLayout
layout.addView(edittext);
mView = new GodotView(this, xrMode, use_gl3, use_32_bits, use_debug_opengl); mView = new GodotView(this, xrMode, use_gl3, use_32_bits, use_debug_opengl);
layout.addView(mView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); layout.addView(mView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
edittext.setView(mView);
io.setEdit(edittext);
mEditText = new GodotEditText(this, mView); mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
io.setEdit(mEditText); @Override
public void onGlobalLayout() {
Point fullSize = new Point();
getWindowManager().getDefaultDisplay().getSize(fullSize);
Rect gameSize = new Rect();
mView.getWindowVisibleDisplayFrame(gameSize);
final int keyboardHeight = fullSize.y - gameSize.bottom;
GodotLib.setVirtualKeyboardHeight(keyboardHeight);
}
});
final String[] current_command_line = command_line; final String[] current_command_line = command_line;
mView.queueEvent(new Runnable() { mView.queueEvent(new Runnable() {
@ -552,7 +571,6 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
super.onCreate(icicle); super.onCreate(icicle);
Window window = getWindow(); Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
mClipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); mClipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
pluginRegistry = GodotPluginRegistry.initializePluginRegistry(this); pluginRegistry = GodotPluginRegistry.initializePluginRegistry(this);
@ -691,21 +709,8 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
initializeGodot(); initializeGodot();
} }
@Override
protected void onStart() {
super.onStart();
mView.post(new Runnable() {
@Override
public void run() {
mEditText.onInitView();
}
});
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
mEditText.onDestroyView();
for (int i = 0; i < singleton_count; i++) { for (int i = 0; i < singleton_count; i++) {
singletons[i].onMainDestroy(); singletons[i].onMainDestroy();

View File

@ -32,27 +32,16 @@ package org.godotengine.godot.input;
import org.godotengine.godot.*; import org.godotengine.godot.*;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -67,8 +56,6 @@ public class GodotEditText extends EditText {
// Fields // Fields
// =========================================================== // ===========================================================
private GodotView mView; private GodotView mView;
private View mKeyboardView;
private PopupWindow mKeyboardWindow;
private GodotTextInputWrapper mInputWrapper; private GodotTextInputWrapper mInputWrapper;
private EditHandler sHandler = new EditHandler(this); private EditHandler sHandler = new EditHandler(this);
private String mOriginText; private String mOriginText;
@ -93,52 +80,24 @@ public class GodotEditText extends EditText {
// =========================================================== // ===========================================================
// Constructors // Constructors
// =========================================================== // ===========================================================
public GodotEditText(final Context context, final GodotView view) { public GodotEditText(final Context context) {
super(context); super(context);
this.initView();
setPadding(0, 0, 0, 0);
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
mView = view;
mInputWrapper = new GodotTextInputWrapper(mView, this);
setOnEditorActionListener(mInputWrapper);
view.requestFocus();
// Create a popup window with an invisible layout for the virtual keyboard,
// so the view can be resized to get the vk height without resizing the main godot view.
final FrameLayout keyboardLayout = new FrameLayout(context);
keyboardLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
keyboardLayout.setVisibility(View.INVISIBLE);
keyboardLayout.addView(this);
mKeyboardView = keyboardLayout;
mKeyboardWindow = new PopupWindow(keyboardLayout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mKeyboardWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
mKeyboardWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
mKeyboardWindow.setFocusable(true); // for the text edit to work
mKeyboardWindow.setTouchable(false); // inputs need to go through
keyboardLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Point fullSize = new Point();
((Activity)mView.getContext()).getWindowManager().getDefaultDisplay().getSize(fullSize);
Rect gameSize = new Rect();
mKeyboardWindow.getContentView().getWindowVisibleDisplayFrame(gameSize);
final int keyboardHeight = fullSize.y - gameSize.bottom;
GodotLib.setVirtualKeyboardHeight(keyboardHeight);
}
});
} }
public void onInitView() { public GodotEditText(final Context context, final AttributeSet attrs) {
mKeyboardWindow.showAtLocation(mView, Gravity.NO_GRAVITY, 0, 0); super(context, attrs);
this.initView();
} }
public void onDestroyView() { public GodotEditText(final Context context, final AttributeSet attrs, final int defStyle) {
mKeyboardWindow.dismiss(); super(context, attrs, defStyle);
this.initView();
}
protected void initView() {
this.setPadding(0, 0, 0, 0);
this.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE);
} }
public boolean isMultiline() { public boolean isMultiline() {
@ -170,7 +129,7 @@ public class GodotEditText extends EditText {
edit.mInputWrapper.setOriginText(text); edit.mInputWrapper.setOriginText(text);
edit.addTextChangedListener(edit.mInputWrapper); edit.addTextChangedListener(edit.mInputWrapper);
final InputMethodManager imm = (InputMethodManager)mKeyboardView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edit, 0); imm.showSoftInput(edit, 0);
} }
} break; } break;
@ -179,7 +138,7 @@ public class GodotEditText extends EditText {
GodotEditText edit = (GodotEditText)msg.obj; GodotEditText edit = (GodotEditText)msg.obj;
edit.removeTextChangedListener(mInputWrapper); edit.removeTextChangedListener(mInputWrapper);
final InputMethodManager imm = (InputMethodManager)mKeyboardView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0); imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
edit.mView.requestFocus(); edit.mView.requestFocus();
} break; } break;
@ -192,6 +151,17 @@ public class GodotEditText extends EditText {
p_edit_text.setFilters(filters); p_edit_text.setFilters(filters);
} }
// ===========================================================
// Getter & Setter
// ===========================================================
public void setView(final GodotView view) {
this.mView = view;
if (mInputWrapper == null)
mInputWrapper = new GodotTextInputWrapper(mView, this);
this.setOnEditorActionListener(mInputWrapper);
view.requestFocus();
}
// =========================================================== // ===========================================================
// Methods for/from SuperClass/Interfaces // Methods for/from SuperClass/Interfaces
// =========================================================== // ===========================================================