mirror of
https://github.com/godotengine/godot.git
synced 2025-01-23 19:12:24 -05:00
Move PopupWindow logic to GodotEditText on Android
This commit is contained in:
parent
cf03f90fa8
commit
cac7eb3a64
2 changed files with 58 additions and 69 deletions
|
@ -56,8 +56,6 @@ 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;
|
||||||
|
@ -70,7 +68,6 @@ import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -78,12 +75,10 @@ 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;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.PopupWindow;
|
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -165,7 +160,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
||||||
public GodotRenderView mRenderView;
|
public GodotRenderView mRenderView;
|
||||||
private boolean godot_initialized = false;
|
private boolean godot_initialized = false;
|
||||||
|
|
||||||
private PopupWindow mKeyboardWindow;
|
private GodotEditText mEditText;
|
||||||
|
|
||||||
private SensorManager mSensorManager;
|
private SensorManager mSensorManager;
|
||||||
private Sensor mAccelerometer;
|
private Sensor mAccelerometer;
|
||||||
|
@ -223,24 +218,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
||||||
containerLayout = new FrameLayout(activity);
|
containerLayout = new FrameLayout(activity);
|
||||||
containerLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
containerLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
// 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(activity);
|
|
||||||
keyboardLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
|
||||||
keyboardLayout.setVisibility(View.INVISIBLE);
|
|
||||||
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
|
|
||||||
|
|
||||||
// GodotEditText layout
|
|
||||||
GodotEditText editText = new GodotEditText(activity);
|
|
||||||
editText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
|
||||||
editText.setKeyboardView(keyboardLayout);
|
|
||||||
// ...add to keyboard layout
|
|
||||||
keyboardLayout.addView(editText);
|
|
||||||
|
|
||||||
GodotLib.setup(command_line);
|
GodotLib.setup(command_line);
|
||||||
|
|
||||||
final String videoDriver = GodotLib.getGlobal("rendering/quality/driver/driver_name");
|
final String videoDriver = GodotLib.getGlobal("rendering/quality/driver/driver_name");
|
||||||
|
@ -253,21 +230,9 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
||||||
|
|
||||||
View view = mRenderView.getView();
|
View view = mRenderView.getView();
|
||||||
containerLayout.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
containerLayout.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||||
editText.setView(mRenderView);
|
|
||||||
io.setEdit(editText);
|
|
||||||
|
|
||||||
keyboardLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
mEditText = new GodotEditText(activity, mRenderView);
|
||||||
@Override
|
io.setEdit(mEditText);
|
||||||
public void onGlobalLayout() {
|
|
||||||
Point fullSize = new Point();
|
|
||||||
activity.getWindowManager().getDefaultDisplay().getSize(fullSize);
|
|
||||||
Rect gameSize = new Rect();
|
|
||||||
mKeyboardWindow.getContentView().getWindowVisibleDisplayFrame(gameSize);
|
|
||||||
|
|
||||||
final int keyboardHeight = fullSize.y - gameSize.bottom;
|
|
||||||
GodotLib.setVirtualKeyboardHeight(keyboardHeight);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mRenderView.queueOnRenderThread(new Runnable() {
|
mRenderView.queueOnRenderThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -626,14 +591,14 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
||||||
mRenderView.getView().post(new Runnable() {
|
mRenderView.getView().post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mKeyboardWindow.showAtLocation(getActivity().getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, 0);
|
mEditText.onInitView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
mKeyboardWindow.dismiss();
|
mEditText.onDestroyView();
|
||||||
|
|
||||||
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
|
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
|
||||||
plugin.onMainDestroy();
|
plugin.onMainDestroy();
|
||||||
|
|
|
@ -32,17 +32,27 @@ 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.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;
|
||||||
|
|
||||||
|
@ -58,6 +68,7 @@ public class GodotEditText extends EditText {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
private GodotRenderView mRenderView;
|
private GodotRenderView mRenderView;
|
||||||
private View mKeyboardView;
|
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;
|
||||||
|
@ -82,24 +93,52 @@ public class GodotEditText extends EditText {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Constructors
|
// Constructors
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
public GodotEditText(final Context context) {
|
public GodotEditText(final Context context, final GodotRenderView view) {
|
||||||
super(context);
|
super(context);
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GodotEditText(final Context context, final AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GodotEditText(final Context context, final AttributeSet attrs, final int defStyle) {
|
|
||||||
super(context, attrs, defStyle);
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initView() {
|
|
||||||
setPadding(0, 0, 0, 0);
|
setPadding(0, 0, 0, 0);
|
||||||
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE);
|
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE);
|
||||||
|
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
mRenderView = view;
|
||||||
|
mInputWrapper = new GodotTextInputWrapper(mRenderView, this);
|
||||||
|
setOnEditorActionListener(mInputWrapper);
|
||||||
|
view.getView().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)mRenderView.getView().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() {
|
||||||
|
mKeyboardWindow.showAtLocation(mRenderView.getView(), Gravity.NO_GRAVITY, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDestroyView() {
|
||||||
|
mKeyboardWindow.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMultiline() {
|
public boolean isMultiline() {
|
||||||
|
@ -153,21 +192,6 @@ public class GodotEditText extends EditText {
|
||||||
p_edit_text.setFilters(filters);
|
p_edit_text.setFilters(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================
|
|
||||||
// Getter & Setter
|
|
||||||
// ===========================================================
|
|
||||||
public void setView(final GodotRenderView view) {
|
|
||||||
mRenderView = view;
|
|
||||||
if (mInputWrapper == null)
|
|
||||||
mInputWrapper = new GodotTextInputWrapper(mRenderView, this);
|
|
||||||
setOnEditorActionListener(mInputWrapper);
|
|
||||||
view.getView().requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyboardView(final View keyboardView) {
|
|
||||||
mKeyboardView = keyboardView;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Methods for/from SuperClass/Interfaces
|
// Methods for/from SuperClass/Interfaces
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue