Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package com.github.rosjava.android_remocons.rocon_remocon.dialogs;
00036
00037 import android.app.Activity;
00038 import android.app.AlertDialog;
00039 import android.content.DialogInterface;
00040
00046 public class AlertDialogWrapper {
00047 protected int state;
00048 protected AlertDialog dialog;
00049 protected Activity context;
00050 protected boolean enablePositive = true;
00051
00052 public AlertDialogWrapper(Activity context,
00053 AlertDialog.Builder builder, String yesButton, String noButton) {
00054 state = 0;
00055 this.context = context;
00056 dialog = builder
00057 .setPositiveButton(yesButton,
00058 new DialogInterface.OnClickListener() {
00059 public void onClick(DialogInterface dialog,
00060 int which) {
00061 state = 1;
00062 }
00063 })
00064 .setNegativeButton(noButton,
00065 new DialogInterface.OnClickListener() {
00066 public void onClick(DialogInterface dialog,
00067 int which) {
00068 state = 2;
00069 }
00070 }).create();
00071 }
00072
00073 public AlertDialogWrapper(Activity context,
00074 AlertDialog.Builder builder, String okButton) {
00075 state = 0;
00076 this.context = context;
00077 dialog = builder.setNeutralButton(okButton,
00078 new DialogInterface.OnClickListener() {
00079 public void onClick(DialogInterface dialog, int which) {
00080 state = 1;
00081 }
00082 }).create();
00083 }
00084
00085 public void setTitle(String m) {
00086 dialog.setTitle(m);
00087 }
00088
00089 public void setMessage(String m) {
00090 dialog.setMessage(m);
00091 }
00092
00093 public boolean show(String m) {
00094 setMessage(m);
00095 return show();
00096 }
00097
00098 public boolean show() {
00099 state = 0;
00100 context.runOnUiThread(new Runnable() {
00101 public void run() {
00102 dialog.show();
00103 dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enablePositive);
00104 }
00105 });
00106
00107 while (state == 0) {
00108 try {
00109 Thread.sleep(1L);
00110 } catch (Exception e) {
00111 break;
00112 }
00113 }
00114 dismiss();
00115 return state == 1;
00116 }
00117
00118 public void dismiss() {
00119 if (dialog != null) {
00120 dialog.dismiss();
00121 }
00122 }
00123 }