Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to set input type on android #2405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.view.SurfaceView;
import android.view.ViewGroup;
import android.view.View;
Expand Down Expand Up @@ -632,4 +633,12 @@ public void requestPermissionsWithRequestCode(String[] permissions, int requestC
public void requestPermissions(String[] permissions) {
requestPermissionsWithRequestCode(permissions, 1);
}

public static void changeKeyboard(int inputType) {
if (SDLActivity.keyboardInputType != inputType){
SDLActivity.keyboardInputType = inputType;
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mTextEdit);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK nice, then someone could write the Python wrapper in pythonforandroid/recipes/android/src/android/ later, correct?
If you already have done so for your project you could share the code snipped in some comments. Or better make a follow up PR after this one is merged

Copy link
Contributor Author

@dwmoffatt dwmoffatt Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it could be.

This change keyboard function is being utilized kivy/kivy#7231

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
--- a/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/src/main/java/org/libsdl/app/SDLActivity.java
@@ -196,6 +196,15 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
@@ -94,6 +94,8 @@
// This is what SDL runs in. It invokes SDL_main(), eventually
protected static Thread mSDLThread;

+ public static int keyboardInputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So at the end the changes you made to this SDLActivity.java.patch file is only using this const and clearing some trailing whitespaces, correct or I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct.

+
protected static SDLGenericMotionListener_API12 getMotionListener() {
if (mMotionListener == null) {
if (Build.VERSION.SDK_INT >= 26) {
@@ -196,6 +198,15 @@
Log.v(TAG, "onCreate()");
super.onCreate(savedInstanceState);

+ SDLActivity.initialize();
+ // So we can call stuff from static callbacks
+ mSingleton = this;
Expand All @@ -16,19 +25,19 @@
// Load shared libraries
String errorMsgBrokenLib = "";
try {
@@ -639,7 +648,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
@@ -639,7 +650,7 @@
Handler commandHandler = new SDLCommandHandler();

// Send a message from the SDLMain thread
- boolean sendCommand(int command, Object data) {
+ protected boolean sendCommand(int command, Object data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god it's so hard to read a diff of a diff, I initially tought you changed that.
You actually just removed some trailing whitespace so GitHub is showing the context which contains the previous diff, that's so confusing to read 🤯 but that's fine I'll manage

Message msg = commandHandler.obtainMessage();
msg.arg1 = command;
msg.obj = data;
@@ -1051,6 +1061,21 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
@@ -1051,6 +1062,21 @@
return Arrays.copyOf(filtered, used);
}

+ /**
+ * Calls turnActive() on singleton to keep loading screen active
+ */
Expand All @@ -45,11 +54,11 @@
+
+
// APK expansion files support

/** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
@@ -1341,14 +1366,13 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
@@ -1341,14 +1367,13 @@
};

public void onSystemUiVisibilityChange(int visibility) {
- if (SDLActivity.mFullscreenModeActive && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
-
Expand All @@ -62,13 +71,21 @@
}
-
}
}
@@ -1475,6 +1499,7 @@ class SDLMain implements Runnable {
}

@@ -1475,6 +1500,7 @@
String[] arguments = SDLActivity.mSingleton.getArguments();

Log.v("SDL", "Running main function " + function + " from library " + library);
+ SDLActivity.mSingleton.appConfirmedActive();
SDLActivity.nativeRunMain(library, function, arguments);

Log.v("SDL", "Finished main function");
@@ -2002,7 +2028,7 @@
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);

- outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+ outAttrs.inputType = SDLActivity.keyboardInputType;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
| EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;