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 PlatformSupport platform;
|
||||
public static PlatformSupport platform;
|
||||
|
||||
public Game(Class<? extends Scene> c, PlatformSupport platform) {
|
||||
sceneClass = c;
|
||||
|
|
|
@ -26,5 +26,14 @@ public abstract class PlatformSupport {
|
|||
public abstract void updateDisplaySize();
|
||||
|
||||
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 com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.android.windows.WndAndroidTextInput;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.utils.DeviceCompat;
|
||||
import com.watabou.utils.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/>
|
||||
*/
|
||||
|
||||
package com.shatteredpixel.shatteredpixeldungeon.windows;
|
||||
package com.shatteredpixel.shatteredpixeldungeon.android.windows;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.text.InputFilter;
|
||||
|
@ -47,8 +47,8 @@ import com.watabou.noosa.Game;
|
|||
import com.watabou.noosa.RenderedText;
|
||||
|
||||
//This class makes use of the android EditText component to handle text input
|
||||
//TODO externalize android-specific code to SPD-classes
|
||||
public class WndTextInput extends Window {
|
||||
//FIXME this window is currently android-specific, should generalize it
|
||||
public class WndAndroidTextInput extends Window {
|
||||
|
||||
private EditText textInput;
|
||||
|
||||
|
@ -61,12 +61,12 @@ public class WndTextInput extends Window {
|
|||
private static final int MAX_LEN_SINGLE = 20;
|
||||
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);
|
||||
}
|
||||
|
||||
public WndTextInput(final String title, final String initialValue, final int maxLength,
|
||||
final boolean multiLine, final String posTxt, final String negTxt){
|
||||
public WndAndroidTextInput(final String title, final String initialValue, final int maxLength,
|
||||
final boolean multiLine, final String posTxt, final String negTxt){
|
||||
super();
|
||||
|
||||
//need to offset to give space for the soft keyboard
|
||||
|
@ -192,7 +192,7 @@ public class WndTextInput extends Window {
|
|||
return textInput.getText().toString().trim();
|
||||
}
|
||||
|
||||
protected void onSelect( boolean positive ) {};
|
||||
protected void onSelect( boolean positive ) {}
|
||||
|
||||
@Override
|
||||
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