v0.7.5: decoupled android-based text input from SPD-classes
This commit is contained in:
parent
f37186ba3c
commit
0724717abf
|
@ -73,7 +73,7 @@ public class Game implements ApplicationListener {
|
||||||
|
|
||||||
protected static InputHandler inputHandler;
|
protected static InputHandler inputHandler;
|
||||||
|
|
||||||
protected static PlatformSupport platform;
|
public static PlatformSupport platform;
|
||||||
|
|
||||||
public Game(Class<? extends Scene> c, PlatformSupport platform) {
|
public Game(Class<? extends Scene> c, PlatformSupport platform) {
|
||||||
sceneClass = c;
|
sceneClass = c;
|
||||||
|
|
|
@ -27,4 +27,13 @@ public abstract class PlatformSupport {
|
||||||
|
|
||||||
public abstract void updateSystemUI();
|
public abstract void updateSystemUI();
|
||||||
|
|
||||||
|
//FIXME this is currently used because no platform-agnostic text input has been implemented.
|
||||||
|
//should look into doing that using either plain openGL or Libgdx's libraries
|
||||||
|
public abstract void promptTextInput( String title, String hintText, int maxLen, boolean multiLine,
|
||||||
|
String posTxt, String negTxt, TextCallback callback);
|
||||||
|
|
||||||
|
public static abstract class TextCallback {
|
||||||
|
public abstract void onSelect( boolean positive, String text );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,9 @@ import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.android.windows.WndAndroidTextInput;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.utils.DeviceCompat;
|
|
||||||
import com.watabou.utils.PlatformSupport;
|
import com.watabou.utils.PlatformSupport;
|
||||||
|
|
||||||
public class AndroidPlatformSupport extends PlatformSupport {
|
public class AndroidPlatformSupport extends PlatformSupport {
|
||||||
|
@ -131,4 +131,13 @@ public class AndroidPlatformSupport extends PlatformSupport {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, final TextCallback callback) {
|
||||||
|
Game.scene().addToFront(new WndAndroidTextInput(title, hintText, maxLen, multiLine, posTxt, negTxt){
|
||||||
|
@Override
|
||||||
|
protected void onSelect(boolean positive) {
|
||||||
|
callback.onSelect(positive, getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.windows;
|
package com.shatteredpixel.shatteredpixeldungeon.android.windows;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.text.InputFilter;
|
import android.text.InputFilter;
|
||||||
|
@ -47,8 +47,8 @@ import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.RenderedText;
|
import com.watabou.noosa.RenderedText;
|
||||||
|
|
||||||
//This class makes use of the android EditText component to handle text input
|
//This class makes use of the android EditText component to handle text input
|
||||||
//TODO externalize android-specific code to SPD-classes
|
//FIXME this window is currently android-specific, should generalize it
|
||||||
public class WndTextInput extends Window {
|
public class WndAndroidTextInput extends Window {
|
||||||
|
|
||||||
private EditText textInput;
|
private EditText textInput;
|
||||||
|
|
||||||
|
@ -61,11 +61,11 @@ public class WndTextInput extends Window {
|
||||||
private static final int MAX_LEN_SINGLE = 20;
|
private static final int MAX_LEN_SINGLE = 20;
|
||||||
private static final int MAX_LEN_MULTI = 2000;
|
private static final int MAX_LEN_MULTI = 2000;
|
||||||
|
|
||||||
public WndTextInput( String title, String initialValue, boolean multiLine, String posTxt, String negTxt){
|
public WndAndroidTextInput(String title, String initialValue, boolean multiLine, String posTxt, String negTxt){
|
||||||
this( title, initialValue, multiLine ? MAX_LEN_MULTI : MAX_LEN_SINGLE, multiLine, posTxt, negTxt);
|
this( title, initialValue, multiLine ? MAX_LEN_MULTI : MAX_LEN_SINGLE, multiLine, posTxt, negTxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WndTextInput(final String title, final String initialValue, final int maxLength,
|
public WndAndroidTextInput(final String title, final String initialValue, final int maxLength,
|
||||||
final boolean multiLine, final String posTxt, final String negTxt){
|
final boolean multiLine, final String posTxt, final String negTxt){
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public class WndTextInput extends Window {
|
||||||
return textInput.getText().toString().trim();
|
return textInput.getText().toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSelect( boolean positive ) {};
|
protected void onSelect( boolean positive ) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
@ -215,4 +215,9 @@ public class WndTextInput extends Window {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
//Do nothing, prevents accidentally losing writing
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user