summaryrefslogtreecommitdiff
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
parent2ffde90c690aa07072bd09bbf9697e2795eee087 (diff)
downloadrockbox-ef382216026d9f7e6e08da511c1bc43adbdd2311.tar.gz
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
-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;
27 27
28public class RockboxYesno 28public class RockboxYesno
29{ 29{
30 private class Listener implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener
31 {
32 /* default to "No" if onClick isn't called at all */
33 private boolean result = false;
34
35 /* called when the user presses the Yes or the No button */
36 @Override
37 public void onClick(DialogInterface dialog, int which)
38 {
39 result = (which == DialogInterface.BUTTON_POSITIVE);
40 }
41
42 /* onDismiss is (hopefully) also called when the dialog is closed
43 * for any reason other than clicking yes or no. This should
44 * avoid the native code waiting for the result indefinitely in
45 * case the dialog just disappears */
46 @Override
47 public void onDismiss(DialogInterface dialog)
48 {
49 put_result(result);
50 }
51 }
52
30 private void yesno_display(final String text, final String yes, final String no) 53 private void yesno_display(final String text, final String yes, final String no)
31 { 54 {
32 final Activity c = RockboxService.getInstance().getActivity(); 55 final Activity c = RockboxService.getInstance().getActivity();
@@ -34,26 +57,15 @@ public class RockboxYesno
34 c.runOnUiThread(new Runnable() { 57 c.runOnUiThread(new Runnable() {
35 public void run() 58 public void run()
36 { 59 {
60 Listener l = new Listener();
37 new AlertDialog.Builder(c) 61 new AlertDialog.Builder(c)
38 .setTitle(R.string.KbdInputTitle) 62 .setTitle(R.string.KbdInputTitle)
39 .setIcon(R.drawable.icon) 63 .setIcon(R.drawable.icon)
40 .setCancelable(false)
41 .setMessage(text) 64 .setMessage(text)
42 .setPositiveButton(yes, new DialogInterface.OnClickListener() 65 .setPositiveButton(yes, l)
43 { 66 .setNegativeButton(no, l)
44 public void onClick(DialogInterface dialog, int whichButton) 67 .show()
45 { 68 .setOnDismissListener(l);
46 put_result(true);
47 }
48 })
49 .setNegativeButton(no, new DialogInterface.OnClickListener()
50 {
51 public void onClick(DialogInterface dialog, int whichButton)
52 {
53 put_result(false);
54 }
55 })
56 .show();
57 } 69 }
58 }); 70 });
59 } 71 }