Permalink
Browse files

Application can modify text input hint message

  • Loading branch information...
1 parent f3b1f0d commit 05847089d3f08d3580d527916e161b954eb7cf67 @pelya committed Mar 7, 2013
View
37 project/java/MainActivity.java
@@ -455,10 +455,23 @@ public boolean onKey(View v, int keyCode, KeyEvent event)
}
};
_screenKeyboard = new EditText(this);
- _videoLayout.addView(_screenKeyboard);
- _screenKeyboard.setOnKeyListener(new simpleKeyListener(this, sendBackspace));
- _screenKeyboard.setHint(R.string.text_edit_click_here);
+ // This code does not work
+ /*
+ _screenKeyboard.setMaxLines(100);
+ ViewGroup.LayoutParams layout = _screenKeyboard.getLayoutParams();
+ if( layout != null )
+ {
+ layout.width = ViewGroup.LayoutParams.FILL_PARENT;
+ layout.height = ViewGroup.LayoutParams.FILL_PARENT;
+ _screenKeyboard.setLayoutParams(layout);
+ }
+ _screenKeyboard.setGravity(android.view.Gravity.BOTTOM | android.view.Gravity.LEFT);
+ */
+ String hint = _screenKeyboardHintMessage;
+ _screenKeyboard.setHint(hint != null ? hint : getString(R.string.text_edit_click_here));
_screenKeyboard.setText(oldText);
+ _screenKeyboard.setOnKeyListener(new simpleKeyListener(this, sendBackspace));
+ _videoLayout.addView(_screenKeyboard);
//_screenKeyboard.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.NONE, false));
_screenKeyboard.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
_screenKeyboard.setFocusableInTouchMode(true);
@@ -493,6 +506,23 @@ public boolean isScreenKeyboardShown()
{
return _screenKeyboard != null;
};
+
+ public void setScreenKeyboardHintMessage(String s)
+ {
+ _screenKeyboardHintMessage = s;
+ //System.out.println("setScreenKeyboardHintMessage: " + (_screenKeyboardHintMessage != null ? _screenKeyboardHintMessage : getString(R.string.text_edit_click_here)));
+ runOnUiThread(new Runnable()
+ {
+ public void run()
+ {
+ if( _screenKeyboard != null )
+ {
+ String hint = _screenKeyboardHintMessage;
+ _screenKeyboard.setHint(hint != null ? hint : getString(R.string.text_edit_click_here));
+ }
+ }
+ } );
+ }
final static int ADVERTISEMENT_POSITION_RIGHT = -1;
final static int ADVERTISEMENT_POSITION_BOTTOM = -1;
@@ -1023,6 +1053,7 @@ public boolean isCurrentOrientationHorizontal()
private FrameLayout _videoLayout = null;
private EditText _screenKeyboard = null;
+ private String _screenKeyboardHintMessage = null;
private boolean sdlInited = false;
public Settings.TouchEventsListener touchListener = null;
public Settings.KeyEventsListener keyListener = null;
View
7 project/java/Video.java
@@ -464,7 +464,7 @@ public int swapBuffers() // Called from native code
{
try {
Thread.sleep(50); // Give some time to the keyboard input thread
- catch(Exception e) { };
+ } catch(Exception e) { };
}
return 1;
}
@@ -523,6 +523,11 @@ public int isScreenKeyboardShown() // Called from native code
return context.isScreenKeyboardShown() ? 1 : 0;
}
+ public void setScreenKeyboardHintMessage(String s)
+ {
+ context.setScreenKeyboardHintMessage(s);
+ }
+
public void startAccelerometerGyroscope(int started)
{
accelerometer.openedBySDL = (started != 0);
2 project/jni/application/openarena/vm
@@ -1 +1 @@
-Subproject commit f629e90155edc0287b0fc88a2ffd59f589ea4dd4
+Subproject commit 157d48a0c07d66747d05ce514ea245975ace2dc2
View
3 project/jni/sdl-1.2/include/SDL_screenkeyboard.h
@@ -111,6 +111,9 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBu
/* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser(void);
+/* Set hint message for the text input field, it may be multi-line, set NULL to reset hint to default */
+extern DECLSPEC int SDLCALL SDL_ANDROID_SetScreenKeyboardHintMesage(const char * hint);
+
/* API compatible to SDL2, it's a wrapper to the SDL_ANDROID_ToggleScreenKeyboardWithoutTextInput(), it does not block */
extern DECLSPEC int SDLCALL SDL_HasScreenKeyboardSupport(void *unused);
View
2 project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c
@@ -293,7 +293,7 @@ int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat)
SDL_modelist[20]->w = 640; SDL_modelist[20]->h = 270; // For UAE4ALL2
SDL_modelist[21]->w = 320; SDL_modelist[21]->h = 216; // For UAE4ALL2
SDL_modelist[22]->w = 640; SDL_modelist[22]->h = 216; // For UAE4ALL2
- SDL_modelist[23]->w = 384; SDL_modelist[23]->h = 272; // For VCMI
+ SDL_modelist[23]->w = 384; SDL_modelist[23]->h = 272; // For VICE
SDL_modelist[24] = NULL;
SDL_VideoInit_1_3(NULL, 0);
View
18 project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c
@@ -65,6 +65,7 @@ static jmethodID JavaShowScreenKeyboard = NULL;
static jmethodID JavaToggleScreenKeyboardWithoutTextInput = NULL;
static jmethodID JavaHideScreenKeyboard = NULL;
static jmethodID JavaIsScreenKeyboardShown = NULL;
+static jmethodID JavaSetScreenKeyboardHintMessage = NULL;
static jmethodID JavaStartAccelerometerGyroscope = NULL;
static jmethodID JavaGetAdvertisementParams = NULL;
static jmethodID JavaSetAdvertisementVisible = NULL;
@@ -295,9 +296,25 @@ void SDL_ANDROID_CallJavaHideScreenKeyboard()
int SDL_ANDROID_IsScreenKeyboardShown()
{
+ /*
+ // Efficient implementation sometimes fails for no real reason, so poll Java from time to time
+ // Or maybe not, this was when I've added some debug code, not observed anymore
+ static int safetyCounter = 0;
+ if( safetyCounter >= 60 ) {
+ safetyCounter = 0;
+ SDL_ANDROID_IsScreenKeyboardShownFlag = (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaIsScreenKeyboardShown );
+ }
+ safetyCounter ++;
+ */
+
return SDL_ANDROID_IsScreenKeyboardShownFlag;
}
+void SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(const char *hint)
+{
+ (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaSetScreenKeyboardHintMessage, hint ? (*JavaEnv)->NewStringUTF(JavaEnv, hint) : NULL );
+}
+
void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start)
{
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaStartAccelerometerGyroscope, (jint) start );
@@ -315,6 +332,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t
JavaToggleScreenKeyboardWithoutTextInput = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboardWithoutTextInputField", "()V");
JavaHideScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "hideScreenKeyboard", "()V");
JavaIsScreenKeyboardShown = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "isScreenKeyboardShown", "()I");
+ JavaSetScreenKeyboardHintMessage = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setScreenKeyboardHintMessage", "(Ljava/lang/String;)V");
JavaStartAccelerometerGyroscope = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "startAccelerometerGyroscope", "(I)V");
JavaGetAdvertisementParams = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "getAdvertisementParams", "([I)V");
View
1 project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h
@@ -57,6 +57,7 @@ extern SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect, SDL_ANDROID_ShowScreenUnd
extern int SDL_ANDROID_CallJavaSwapBuffers();
extern void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen);
extern void SDL_ANDROID_CallJavaHideScreenKeyboard();
+extern void SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(const char *hint);
extern int SDL_ANDROID_IsScreenKeyboardShown();
extern int SDL_ANDROID_IsScreenKeyboardShownFlag;
extern int SDL_ANDROID_drawTouchscreenKeyboard();
View
6 project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c
@@ -1134,3 +1134,9 @@ int SDL_ANDROID_GetScreenKeyboardRedefinedByUser()
{
return ScreenKbRedefinedByUser;
}
+
+int SDL_ANDROID_SetScreenKeyboardHintMesage(const char * hint)
+{
+ SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(hint);
+ return 1;
+}

0 comments on commit 0584708

Please sign in to comment.