Add some code to pop up an inputbox on android.

This commit is contained in:
Henrik Rydgard
2012-07-16 15:00:52 +02:00
parent c762d1c0a5
commit 9d531d717a
4 changed files with 67 additions and 3 deletions
@@ -9,7 +9,9 @@ import java.util.UUID;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
@@ -26,10 +28,14 @@ import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Toast;
class Installation {
@@ -84,6 +90,8 @@ public class NativeActivity extends Activity {
public static String installID;
private EditText editText;
String getApplicationLibraryDir(ApplicationInfo application) {
String libdir = null;
try {
@@ -168,6 +176,14 @@ public class NativeActivity extends Activity {
if (!useOpenSL)
audioPlayer = new NativeAudioPlayer();
lightsOut();
/*
editText = new EditText(this);
editText.setText("Hello world");
addContentView(editText, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
*/
inputBox("Please ener a s", "", "Save");
}
@SuppressLint("NewApi")
@@ -281,6 +297,45 @@ public class NativeActivity extends Activity {
super.onConfigurationChanged(newConfig);
}
public static boolean inputBoxCancelled;
@SuppressWarnings("deprecation")
public String inputBox(String title, String defaultText, String defaultAction) {
final FrameLayout fl = new FrameLayout(this);
final EditText input = new EditText(this);
input.setGravity(Gravity.CENTER);
inputBoxCancelled = false;
FrameLayout.LayoutParams editBoxLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
editBoxLayout.setMargins(2, 20, 2, 20);
fl.addView(input, editBoxLayout);
input.setText(defaultText);
input.selectAll();
AlertDialog dlg = new AlertDialog.Builder(this)
.setView(fl)
.setTitle(title)
.setPositiveButton(defaultAction, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface d, int which) {
d.dismiss();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface d, int which) {
d.cancel();
NativeActivity.inputBoxCancelled = false;
}
}).create();
dlg.setCancelable(false);
dlg.show();
if (inputBoxCancelled)
return null;
// Toast.makeText(this, "Value: " + input.getText().toString(), Toast.LENGTH_LONG).show();
return input.getText().toString();
}
public void processCommand(String command, String params) {
if (command.equals("launchBrowser")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params));
@@ -304,6 +359,8 @@ public class NativeActivity extends Activity {
} else if (command.equals("showkeyboard")) {
//InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//inputMethodManager.toggleSoftInputFromWindow(this, InputMethodManager.SHOW_FORCED, 0);
} else if (command.equals("gettext")) {
inputBox("Enter text", params, "OK");
} else {
Log.e(TAG, "Unsupported command " + command + " , param: " + params);
}
+2 -1
View File
@@ -25,9 +25,10 @@
#include "base/NativeApp.h"
#include "net/resolve.h"
// Simple implementations of System functions
void SystemToast(const char *text) {
#ifdef _WIN32
MessageBox(0, text, "Toast!", MB_ICONINFORMATION);
+5 -2
View File
@@ -21,9 +21,11 @@ void ScreenManager::switchScreen(Screen *screen) {
// will only become apparent if the dialog is closed. The previous screen will stick around
// until that switch.
if (nextScreen_ != 0) {
FLOG("WTF? Already had nextScreen_");
FLOG("WTF? Already had a nextScreen_");
}
if (screen != currentScreen_) {
nextScreen_ = screen;
}
nextScreen_ = screen;
}
void ScreenManager::update(const InputState &input) {
@@ -47,6 +49,7 @@ void ScreenManager::update(const InputState &input) {
void ScreenManager::render() {
if (dialog_.size()) {
dialog_.back()->render();
return;
}
if (currentScreen_) {
currentScreen_->render();
+3
View File
@@ -14,6 +14,7 @@
#pragma once
#include <list>
#include "base/basictypes.h"
#include "base/display.h"
struct InputState;
@@ -25,6 +26,8 @@ public:
virtual void update(const InputState &input) = 0;
virtual void render() {}
virtual void dialogFinished(const Screen &dialog) {}
private:
DISALLOW_COPY_AND_ASSIGN(Screen);
};
class Transition {