Android: Dismiss keyboard when clicking on empty space, disable auto suggest in input fields

This commit is contained in:
UnknownShadow200 2024-04-29 20:11:06 +10:00
parent 92dc6aafa0
commit 328fe3fbf1
3 changed files with 24 additions and 24 deletions

View file

@ -5,10 +5,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
@ -30,27 +28,18 @@ import android.net.Uri;
import android.os.Bundle;
import android.provider.OpenableColumns;
import android.provider.Settings.Secure;
import android.text.Editable;
import android.text.InputType;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.ListAdapter;
import android.widget.ListView;
// This class contains all the glue/interop code for bridging ClassiCube to the java Android world.
// Some functionality is only available on later Android versions - try {} catch {} is used in such places
@ -515,7 +504,7 @@ public class MainActivity extends Activity
void create3DView() {
// setContentView, requestFocus, getHolder, addCallback, RGBX_8888 - API level 1
createSurfaceCallback();
CCView view = new CCView(this);
View3D view = new View3D(this);
launcher = false;
view.getHolder().addCallback(callback);
@ -616,7 +605,7 @@ public class MainActivity extends Activity
if (curView == null) return;
// Try to avoid restarting input if possible
CCView view = (CCView)curView;
View3D view = (View3D)curView;
if (view.kbText != null) {
String curText = view.kbText.toString();
if (text.equals(curText)) return;

View file

@ -8,12 +8,14 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.text.Editable;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.View;
import android.widget.AdapterView;
@ -61,15 +63,19 @@ public class UIBackend
static final int _WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
interface UICallback { void execute(); }
public void create2DView_async() {
activity.runOnUiThread(new Runnable() {
public void run() { create2DView(); }
});
}
void create2DView() {
View view = new CC2DLayout(activity);
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
// If the main view has focus, then no child view is being clicked
// (I.e. user clicked somewhere on the launcher background)
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) activity.closeKeyboard();
}
});
activity.launcher = true;
activity.setActiveView(new CC2DLayout(activity));
activity.setActiveView(view);
activity.pushCmd(MainActivity.CMD_UI_CREATED);
}
@ -106,7 +112,12 @@ public class UIBackend
class CC2DLayout extends ViewGroup
{
public CC2DLayout(Context context) { super(context, null); }
public CC2DLayout(Context context) {
super(context, null);
setClickable(true);
setFocusable(true);
setFocusableInTouchMode(true);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@ -259,7 +270,7 @@ public class UIBackend
ipt.setBackgroundColor(Color.WHITE);
ipt.setPadding(ipt.getPaddingLeft(), 0, ipt.getPaddingRight(), 0);
ipt.setHint(placeholder);
ipt.setInputType(MainActivity.calcKeyboardType(flags));
ipt.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | MainActivity.calcKeyboardType(flags));
ipt.setImeOptions(MainActivity.calcKeyboardOptions(flags));
ipt.addTextChangedListener(new TextWatcher() {

View file

@ -9,11 +9,11 @@ import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
public class CCView extends SurfaceView {
public class View3D extends SurfaceView {
SpannableStringBuilder kbText;
MainActivity activity;
public CCView(MainActivity activity) {
public View3D(MainActivity activity) {
// setFocusable, setFocusableInTouchMode - API level 1
super(activity);
this.activity = activity;