Toggling text input shows screen keyboard automatically, updated fheroes2
This commit is contained in:
@@ -61,6 +61,8 @@ import android.text.SpannedString;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
@@ -208,6 +210,7 @@ public class MainActivity extends Activity {
|
||||
_layout2 = null;
|
||||
_btn = null;
|
||||
_tv = null;
|
||||
_inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
_videoLayout = new FrameLayout(this);
|
||||
setContentView(_videoLayout);
|
||||
mGLView = new DemoGLSurfaceView(this);
|
||||
@@ -266,32 +269,11 @@ public class MainActivity extends Activity {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void hideScreenKeyboard()
|
||||
{
|
||||
if(_screenKeyboard == null)
|
||||
return;
|
||||
|
||||
synchronized(textInput)
|
||||
{
|
||||
String text = _screenKeyboard.getText().toString();
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
DemoRenderer.nativeTextInput( (int)text.charAt(i), (int)text.codePointAt(i) );
|
||||
}
|
||||
}
|
||||
DemoRenderer.nativeTextInputFinished();
|
||||
_videoLayout.removeView(_screenKeyboard);
|
||||
_screenKeyboard = null;
|
||||
mGLView.setFocusableInTouchMode(true);
|
||||
mGLView.setFocusable(true);
|
||||
mGLView.requestFocus();
|
||||
};
|
||||
|
||||
public void showScreenKeyboard(final String oldText, boolean sendBackspace)
|
||||
{
|
||||
if(_screenKeyboard != null)
|
||||
return;
|
||||
class myKeyListener implements OnKeyListener
|
||||
class myKeyListener implements OnKeyListener
|
||||
{
|
||||
MainActivity _parent;
|
||||
boolean sendBackspace;
|
||||
@@ -318,18 +300,33 @@ public class MainActivity extends Activity {
|
||||
_screenKeyboard.setOnKeyListener(new myKeyListener(this, sendBackspace));
|
||||
_screenKeyboard.setHint(R.string.text_edit_click_here);
|
||||
_screenKeyboard.setText(oldText);
|
||||
final Window window = getWindow();
|
||||
_screenKeyboard.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
public void onFocusChange(View v, boolean hasFocus)
|
||||
{
|
||||
if (hasFocus)
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
});
|
||||
_screenKeyboard.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.NONE, false));
|
||||
_screenKeyboard.setFocusableInTouchMode(true);
|
||||
_screenKeyboard.setFocusable(true);
|
||||
_screenKeyboard.requestFocus();
|
||||
_inputManager.showSoftInput(_screenKeyboard, InputMethodManager.SHOW_FORCED);
|
||||
};
|
||||
|
||||
public void hideScreenKeyboard()
|
||||
{
|
||||
if(_screenKeyboard == null)
|
||||
return;
|
||||
|
||||
synchronized(textInput)
|
||||
{
|
||||
String text = _screenKeyboard.getText().toString();
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
DemoRenderer.nativeTextInput( (int)text.charAt(i), (int)text.codePointAt(i) );
|
||||
}
|
||||
}
|
||||
DemoRenderer.nativeTextInputFinished();
|
||||
_inputManager.hideSoftInputFromWindow(_screenKeyboard.getWindowToken(), 0);
|
||||
_videoLayout.removeView(_screenKeyboard);
|
||||
_screenKeyboard = null;
|
||||
mGLView.setFocusableInTouchMode(true);
|
||||
mGLView.setFocusable(true);
|
||||
mGLView.requestFocus();
|
||||
};
|
||||
|
||||
@Override
|
||||
@@ -686,6 +683,7 @@ public class MainActivity extends Activity {
|
||||
public Settings.TouchEventsListener touchListener = null;
|
||||
public Settings.KeyEventsListener keyListener = null;
|
||||
boolean _isPaused = false;
|
||||
private InputMethodManager _inputManager = null;
|
||||
|
||||
public LinkedList<Integer> textInput = new LinkedList<Integer> ();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ AppName="Free Heroes 2"
|
||||
AppFullName=net.sourceforge.fheroes2
|
||||
ScreenOrientation=h
|
||||
InhibitSuspend=n
|
||||
AppDataDownloadUrl="Heroes 2 DEMO data files (45 Mb)|http://downloads.pcworld.com/pub/new/fun_and_games/adventure_strategy/h2demo.zip|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/h2demo.zip/download^MIDI music support (18 Mb)|http://sourceforge.net/projects/libsdl-android/files/timidity.zip/download^Essential map pack (9 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/EssentialMapPack.zip/download^Additional map pack (95 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/AdditionalMapPack.zip/download^Mega map pack (280 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/MegaMapPack.zip/download^Russian translation|:fheroes2.cfg:fheroes2-ru.cfg^Czech translation|:fheroes2.cfg:fheroes2-cs.cfg^Spanish translation|:fheroes2.cfg:fheroes2-es.cfg^French translation|:fheroes2.cfg:fheroes2-fr.cfg^Hungarian translation|:fheroes2.cfg:fheroes2-hu.cfg^Polish translation|:fheroes2.cfg:fheroes2-pl.cfg^Portugese translation|:fheroes2.cfg:fheroes2-pt_BR.cfg^Swedish translation|:fheroes2.cfg:fheroes2-sv.cfg^!Game data|data12.zip^!Game fonts|fonts2.zip"
|
||||
AppDataDownloadUrl="Heroes 2 DEMO (45 Mb) - required to play|http://downloads.pcworld.com/pub/new/fun_and_games/adventure_strategy/h2demo.zip|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/h2demo.zip/download^MIDI music support (18 Mb)|http://sourceforge.net/projects/libsdl-android/files/timidity.zip/download^Essential map pack (9 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/EssentialMapPack.zip/download^Additional map pack (95 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/AdditionalMapPack.zip/download^Mega map pack (280 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/MegaMapPack.zip/download^!Game data|data12.zip^!Game data 2|data-cfg-fonts.zip^Russian translation|:fheroes2.cfg:fheroes2-ru.cfg^Czech translation|:fheroes2.cfg:fheroes2-cs.cfg^Spanish translation|:fheroes2.cfg:fheroes2-es.cfg^French translation|:fheroes2.cfg:fheroes2-fr.cfg^Hungarian translation|:fheroes2.cfg:fheroes2-hu.cfg^Polish translation|:fheroes2.cfg:fheroes2-pl.cfg^Portugese translation|:fheroes2.cfg:fheroes2-pt_BR.cfg^Swedish translation|:fheroes2.cfg:fheroes2-sv.cfg"
|
||||
VideoDepthBpp=16
|
||||
NeedDepthBuffer=n
|
||||
NeedStencilBuffer=n
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -26,7 +26,6 @@
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_keysym.h"
|
||||
#include <jni.h>
|
||||
|
||||
/* On-screen keyboard exposed to the application, it's yet available on Android platform only */
|
||||
|
||||
@@ -77,16 +76,12 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_ToggleScreenKeyboardTextInput(const char
|
||||
|
||||
/* Show Android on-screen keyboard, and pass entered text back to application in a buffer,
|
||||
using buffer contents as previous text (UTF-8 encoded), the buffer may be of any size -
|
||||
this call will block until user typed all text */
|
||||
this call will block until user typed all text. */
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSize);
|
||||
|
||||
/* 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();
|
||||
|
||||
/** Exports for Java environment and Video object instance */
|
||||
extern DECLSPEC JNIEnv* SDL_ANDROID_JniEnv();
|
||||
extern DECLSPEC jobject SDL_ANDROID_JniVideoObject();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -120,7 +120,7 @@ int oldMouseButtons = 0;
|
||||
|
||||
static int UnicodeToUtf8(int src, char * dest)
|
||||
{
|
||||
int len = 0;
|
||||
int len = 0;
|
||||
if ( src <= 0x007f) {
|
||||
*dest++ = (char)src;
|
||||
len = 1;
|
||||
@@ -713,7 +713,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeTextInput) ( JNIEnv* env, jobject thiz, jin
|
||||
SDL_ANDROID_MainThreadPushText(ascii, unicode);
|
||||
else
|
||||
{
|
||||
if( textInputBufferPos < textInputBufferLen + 4 )
|
||||
if( textInputBufferPos < textInputBufferLen + 4 && ascii != SDLK_RETURN && ascii != '\r' && ascii != '\n' )
|
||||
{
|
||||
textInputBufferPos += UnicodeToUtf8(unicode, textInputBuffer + textInputBufferPos);
|
||||
}
|
||||
|
||||
18
readme.txt
18
readme.txt
@@ -324,27 +324,19 @@ heap memory limit on most phones is 24 Mb.
|
||||
License information
|
||||
===================
|
||||
|
||||
The SDL port itself is licensed under LGPL, so you may use it for commercial purposes
|
||||
The SDL 1.2 port is licensed under LGPL, so you may use it for commercial purposes
|
||||
without releasing source code, however to fullfill LGPL requirements you'll have to publish
|
||||
the file AndroidAppSettings.cfg to allow linking other version of SDL with the libraries
|
||||
the file AndroidAppSettings.cfg to allow linking other version of libsdl-1.2.so with the libraries
|
||||
in the binary package you're distributing - typically libapplication.so and other
|
||||
closed-source libraries in your .apk file.
|
||||
|
||||
The Java source files are licensed under zlib license, which means
|
||||
you may modify them as you like without releasing source code,
|
||||
as long as your binary package can be linked and executed without error
|
||||
against the SDL shared library compiled from the original source code.
|
||||
This implies that you may not modify Java-to-C interface,
|
||||
or you'll have to publish all your changes to both C and Java files.
|
||||
|
||||
Please note that SDL 1.3 Andorid port from libsdl.org has changed it's license type
|
||||
to zlib, however I've used older release of SDL 1.3 to create this port,
|
||||
and I cannot switch license type for the C source files I didn't write myself.
|
||||
The SDL 1.3 port and Java source files are licensed under zlib license, which means
|
||||
you may modify them as you like without releasing source code.
|
||||
|
||||
The libraries under project/jni have their own license, I've tried to compile all LGPL-ed libs
|
||||
as shared libs but you should anyway inspect the licenses of the libraries you're linking to.
|
||||
libmad and liblzo2 are licensed under GPL, so if you're planning to make commercial app you should avoid
|
||||
using them, otherwise you'll have to release your application sources under GPL too.
|
||||
using them, otherwise you'll have to release your whole application sources under GPL too.
|
||||
|
||||
The "Ultimate Droid" on-screen keyboard theme by Sean Stieber is licensed under Creative Commons - Attribution license.
|
||||
The "Simple Theme" on-screen keyboard theme by Dmitry Matveev is licensed under zlib license.
|
||||
|
||||
Reference in New Issue
Block a user