summaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-01-18 09:43:04 +0100
committerThomas Martitz <kugel@rockbox.org>2013-01-18 09:49:46 +0100
commitef382216026d9f7e6e08da511c1bc43adbdd2311 (patch)
treeed61be16dbc1ba74ac2efd0cc66c333615f2632e /android
parent2ffde90c690aa07072bd09bbf9697e2795eee087 (diff)
downloadrockbox-ef382216026d9f7e6e08da511c1bc43adbdd2311.tar.gz
rockbox-ef382216026d9f7e6e08da511c1bc43adbdd2311.tar.bz2
rockbox-ef382216026d9f7e6e08da511c1bc43adbdd2311.zip
android: Hopefully fix a rare hang of the UI.
Sometimes (and perhaps only on some devices) Android's YesNo dialog loses focus and is put to the background. Since the native code waits on the result (which is then impossible to happen) it would become impossible to further control Rockbox. This is an attempt to fix as I cannot reproduce the problem on my device(s). Change-Id: Iff849ff4be5e8f41922fb7d36491d860486c6441
Diffstat (limited to 'android')
-rw-r--r--android/src/org/rockbox/RockboxYesno.java44
1 files changed, 28 insertions, 16 deletions
diff --git a/android/src/org/rockbox/RockboxYesno.java b/android/src/org/rockbox/RockboxYesno.java
index de8f88ab5f..c7ab729cfc 100644
--- a/android/src/org/rockbox/RockboxYesno.java
+++ b/android/src/org/rockbox/RockboxYesno.java
@@ -27,6 +27,29 @@ import android.content.DialogInterface;
public class RockboxYesno
{
+ private class Listener implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener
+ {
+ /* default to "No" if onClick isn't called at all */
+ private boolean result = false;
+
+ /* called when the user presses the Yes or the No button */
+ @Override
+ public void onClick(DialogInterface dialog, int which)
+ {
+ result = (which == DialogInterface.BUTTON_POSITIVE);
+ }
+
+ /* onDismiss is (hopefully) also called when the dialog is closed
+ * for any reason other than clicking yes or no. This should
+ * avoid the native code waiting for the result indefinitely in
+ * case the dialog just disappears */
+ @Override
+ public void onDismiss(DialogInterface dialog)
+ {
+ put_result(result);
+ }
+ }
+
private void yesno_display(final String text, final String yes, final String no)
{
final Activity c = RockboxService.getInstance().getActivity();
@@ -34,26 +57,15 @@ public class RockboxYesno
c.runOnUiThread(new Runnable() {
public void run()
{
+ Listener l = new Listener();
new AlertDialog.Builder(c)
.setTitle(R.string.KbdInputTitle)
.setIcon(R.drawable.icon)
- .setCancelable(false)
.setMessage(text)
- .setPositiveButton(yes, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
- put_result(true);
- }
- })
- .setNegativeButton(no, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
- put_result(false);
- }
- })
- .show();
+ .setPositiveButton(yes, l)
+ .setNegativeButton(no, l)
+ .show()
+ .setOnDismissListener(l);
}
});
}