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>
</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"/>
<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

@ -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)
{

View file

@ -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;

View file

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

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