summaryrefslogtreecommitdiffstats
path: root/android/src
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2010-11-06 01:18:32 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2010-11-06 01:18:32 +0000
commitc31a2f3bbb5e30c49e39b6ebc71bafa77ff3f655 (patch)
treea331187f2ca8727b918c7409ebe5310ed7060070 /android/src
parent988bdc1cc4d4cbe88da848de80d79aeac195464e (diff)
downloadrockbox-c31a2f3bbb5e30c49e39b6ebc71bafa77ff3f655.tar.gz
rockbox-c31a2f3bbb5e30c49e39b6ebc71bafa77ff3f655.tar.bz2
rockbox-c31a2f3bbb5e30c49e39b6ebc71bafa77ff3f655.zip
Android: greatly simplify Android YesNo and KeyboardInput widgets
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28513 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'android/src')
-rw-r--r--android/src/org/rockbox/HostCallback.java8
-rw-r--r--android/src/org/rockbox/KeyboardActivity.java49
-rw-r--r--android/src/org/rockbox/RockboxActivity.java17
-rw-r--r--android/src/org/rockbox/RockboxKeyboardInput.java58
-rw-r--r--android/src/org/rockbox/RockboxYesno.java37
-rw-r--r--android/src/org/rockbox/YesnoActivity.java36
6 files changed, 69 insertions, 136 deletions
diff --git a/android/src/org/rockbox/HostCallback.java b/android/src/org/rockbox/HostCallback.java
deleted file mode 100644
index 8584fedd6a..0000000000
--- a/android/src/org/rockbox/HostCallback.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.rockbox;
-
-import android.content.Intent;
-
-public interface HostCallback
-{
- public void onComplete(int resultCode, Intent data);
-}
diff --git a/android/src/org/rockbox/KeyboardActivity.java b/android/src/org/rockbox/KeyboardActivity.java
deleted file mode 100644
index 7436031f9d..0000000000
--- a/android/src/org/rockbox/KeyboardActivity.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.rockbox;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.text.Editable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.EditText;
-
-public class KeyboardActivity extends Activity
-{
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- LayoutInflater inflater=LayoutInflater.from(this);
- View addView=inflater.inflate(R.layout.keyboardinput, null);
- EditText input = (EditText) addView.findViewById(R.id.KbdInput);
- input.setText(getIntent().getStringExtra("value"));
- new AlertDialog.Builder(this)
- .setTitle(R.string.KbdInputTitle)
- .setView(addView)
- .setIcon(R.drawable.icon)
- .setCancelable(false)
- .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton) {
- EditText input = (EditText)((Dialog)dialog)
- .findViewById(R.id.KbdInput);
- Editable s = input.getText();
- getIntent().putExtra("value", s.toString());
- setResult(RESULT_OK, getIntent());
- finish();
- }
- })
-
- .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
- setResult(RESULT_CANCELED, getIntent());
- finish();
- }
- })
- .show();
- }
-}
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index c9681e306c..f5c658871f 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -145,23 +145,6 @@ public class RockboxActivity extends Activity
super.onDestroy();
rbservice.set_activity(null);
}
-
- private HostCallback hostcallback = null;
- public void waitForActivity(Intent i, HostCallback callback)
- {
- if (hostcallback != null)
- {
- LOG("Something has gone wrong");
- }
- hostcallback = callback;
- startActivityForResult(i, 0);
- }
-
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- hostcallback.onComplete(resultCode, data);
- hostcallback = null;
- }
private void LOG(CharSequence text)
{
diff --git a/android/src/org/rockbox/RockboxKeyboardInput.java b/android/src/org/rockbox/RockboxKeyboardInput.java
index 210cbbd258..b7dd812f35 100644
--- a/android/src/org/rockbox/RockboxKeyboardInput.java
+++ b/android/src/org/rockbox/RockboxKeyboardInput.java
@@ -23,33 +23,57 @@ package org.rockbox;
import android.app.Activity;
-import android.content.Intent;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.text.Editable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
public class RockboxKeyboardInput
{
- private String result;
-
- public RockboxKeyboardInput()
+ public void kbd_input(final String text)
{
- result = null;
- }
+ final Activity c = RockboxService.get_instance().get_activity();
- public void kbd_input(String text)
- {
- RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity();
- Intent kbd = new Intent(a, KeyboardActivity.class);
- kbd.putExtra("value", text);
- a.waitForActivity(kbd, new HostCallback()
- {
- public void onComplete(int resultCode, Intent data)
+ c.runOnUiThread(new Runnable() {
+ @Override
+ public void run()
{
- put_result(resultCode == Activity.RESULT_OK,
- data.getStringExtra("value"));
+ LayoutInflater inflater = LayoutInflater.from(c);
+ View addView = inflater.inflate(R.layout.keyboardinput, null);
+ EditText input = (EditText) addView.findViewById(R.id.KbdInput);
+ input.setText(text);
+ new AlertDialog.Builder(c)
+ .setTitle(R.string.KbdInputTitle)
+ .setView(addView)
+ .setIcon(R.drawable.icon)
+ .setCancelable(false)
+ .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ EditText input = (EditText)((Dialog)dialog)
+ .findViewById(R.id.KbdInput);
+ Editable s = input.getText();
+ put_result(true, s.toString());
+ }
+ })
+ .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+ put_result(false, "");
+ }
+ })
+ .show();
}
});
}
-
+
private native void put_result(boolean accepted, String new_string);
+
+ @SuppressWarnings("unused")
public boolean is_usable()
{
return RockboxService.get_instance().get_activity() != null;
diff --git a/android/src/org/rockbox/RockboxYesno.java b/android/src/org/rockbox/RockboxYesno.java
index aa5e83d749..9481d69d01 100644
--- a/android/src/org/rockbox/RockboxYesno.java
+++ b/android/src/org/rockbox/RockboxYesno.java
@@ -22,21 +22,40 @@
package org.rockbox;
import android.app.Activity;
-import android.content.Intent;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
public class RockboxYesno
{
@SuppressWarnings("unused")
- private void yesno_display(String text)
+ private void yesno_display(final String text)
{
- RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity();
- Intent kbd = new Intent(a, YesnoActivity.class);
- kbd.putExtra("value", text);
- a.waitForActivity(kbd, new HostCallback()
- {
- public void onComplete(int resultCode, Intent data)
+ final Activity c = RockboxService.get_instance().get_activity();
+
+ c.runOnUiThread(new Runnable() {
+ @Override
+ public void run()
{
- put_result(resultCode == Activity.RESULT_OK);
+ new AlertDialog.Builder(c)
+ .setTitle(R.string.KbdInputTitle)
+ .setIcon(R.drawable.icon)
+ .setCancelable(false)
+ .setMessage(text)
+ .setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+ put_result(true);
+ }
+ })
+ .setNegativeButton(R.string.No, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+ put_result(false);
+ }
+ })
+ .show();
}
});
}
diff --git a/android/src/org/rockbox/YesnoActivity.java b/android/src/org/rockbox/YesnoActivity.java
deleted file mode 100644
index 35e064fef5..0000000000
--- a/android/src/org/rockbox/YesnoActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.rockbox;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-
-public class YesnoActivity extends Activity
-{
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- new AlertDialog.Builder(this)
- .setTitle(R.string.KbdInputTitle)
- .setIcon(R.drawable.icon)
- .setCancelable(false)
- .setMessage(getIntent().getStringExtra("value"))
- .setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton) {
- setResult(RESULT_OK, getIntent());
- finish();
- }
- })
-
- .setNegativeButton(R.string.No, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
- setResult(RESULT_CANCELED, getIntent());
- finish();
- }
- })
- .show();
- }
-}