1
0
Fork 0
forked from len0rd/rockbox

Android: greatly simplify Android YesNo and KeyboardInput widgets

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28513 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Maurus Cuelenaere 2010-11-06 01:18:32 +00:00
parent 988bdc1cc4
commit c31a2f3bbb
7 changed files with 69 additions and 144 deletions

View file

@ -19,14 +19,6 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="KeyboardActivity"
android:theme="@android:style/Theme.Dialog">
</activity>
<activity android:name="YesnoActivity"
android:theme="@android:style/Theme.Dialog">
</activity>
<service android:name=".RockboxService"/> <service android:name=".RockboxService"/>
<receiver android:name=".Helper.MediaButtonReceiver$MediaReceiver" <receiver android:name=".Helper.MediaButtonReceiver$MediaReceiver"

View file

@ -1,8 +0,0 @@
package org.rockbox;
import android.content.Intent;
public interface HostCallback
{
public void onComplete(int resultCode, Intent data);
}

View file

@ -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();
}
}

View file

@ -146,23 +146,6 @@ public class RockboxActivity extends Activity
rbservice.set_activity(null); 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) private void LOG(CharSequence text)
{ {
Log.d("Rockbox", (String) text); Log.d("Rockbox", (String) text);

View file

@ -23,33 +23,57 @@ package org.rockbox;
import android.app.Activity; 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 public class RockboxKeyboardInput
{ {
private String result; public void kbd_input(final String text)
public RockboxKeyboardInput()
{ {
result = null; final Activity c = RockboxService.get_instance().get_activity();
}
public void kbd_input(String text) c.runOnUiThread(new Runnable() {
{ @Override
RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity(); public void run()
Intent kbd = new Intent(a, KeyboardActivity.class);
kbd.putExtra("value", text);
a.waitForActivity(kbd, new HostCallback()
{
public void onComplete(int resultCode, Intent data)
{ {
put_result(resultCode == Activity.RESULT_OK, LayoutInflater inflater = LayoutInflater.from(c);
data.getStringExtra("value")); 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); private native void put_result(boolean accepted, String new_string);
@SuppressWarnings("unused")
public boolean is_usable() public boolean is_usable()
{ {
return RockboxService.get_instance().get_activity() != null; return RockboxService.get_instance().get_activity() != null;

View file

@ -22,21 +22,40 @@
package org.rockbox; package org.rockbox;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.app.AlertDialog;
import android.content.DialogInterface;
public class RockboxYesno public class RockboxYesno
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private void yesno_display(String text) private void yesno_display(final String text)
{ {
RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity(); final Activity c = RockboxService.get_instance().get_activity();
Intent kbd = new Intent(a, YesnoActivity.class);
kbd.putExtra("value", text); c.runOnUiThread(new Runnable() {
a.waitForActivity(kbd, new HostCallback() @Override
{ public void run()
public void onComplete(int resultCode, Intent data)
{ {
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();
} }
}); });
} }

View file

@ -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();
}
}