Alert dialog only has OK button. Add confirm dialog with OK and CANCEL.

This commit is contained in:
Bryce Curtis 2010-09-07 10:33:08 -05:00
parent 6d403c5864
commit 5c24abcafd

View File

@ -384,59 +384,75 @@ public class DroidGap extends Activity {
return this.callbackServer.getPort(); return this.callbackServer.getPort();
} }
/** /**
* Provides a hook for calling "alert" from javascript. Useful for * Provides a hook for calling "alert" from javascript. Useful for
* debugging your javascript. * debugging your javascript.
*/ */
public class GapClient extends WebChromeClient { public class GapClient extends WebChromeClient {
Context mCtx; Context mCtx;
public GapClient(Context ctx) public GapClient(Context ctx) {
{ mCtx = ctx;
mCtx = ctx; }
}
@Override /**
public boolean onJsAlert(WebView view, String url, String message, JsResult result) { * Tell the client to display a javascript alert dialog.
Log.d(LOG_TAG, message); *
// This shows the dialog box. This can be commented out for dev * @param view
AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx); * @param url
GapOKDialog okHook = new GapOKDialog(); * @param message
GapCancelDialog cancelHook = new GapCancelDialog(); * @param result
alertBldr.setMessage(message); */
alertBldr.setTitle("Alert"); @Override
alertBldr.setCancelable(true); public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
alertBldr.setPositiveButton("OK", okHook); Log.d(LOG_TAG, message);
alertBldr.setNegativeButton("Cancel", cancelHook); AlertDialog.Builder dlg = new AlertDialog.Builder(mCtx);
alertBldr.show(); dlg.setMessage(message);
result.confirm(); dlg.setTitle("Alert");
return true; dlg.setCancelable(false);
} dlg.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener() {
/* public void onClick(DialogInterface dialog, int which) {
* This is the Code for the OK Button result.confirm();
*/ }
});
public class GapOKDialog implements DialogInterface.OnClickListener { dlg.create();
dlg.show();
return true;
}
public void onClick(DialogInterface dialog, int which) { /**
// TODO Auto-generated method stub * Tell the client to display a confirm dialog to the user.
dialog.dismiss(); *
} * @param view
* @param url
} * @param message
* @param result
public class GapCancelDialog implements DialogInterface.OnClickListener { */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder dlg = new AlertDialog.Builder(mCtx);
dlg.setMessage(message);
dlg.setTitle("Confirm");
dlg.setCancelable(false);
dlg.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
});
dlg.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
});
dlg.create();
dlg.show();
return true;
}
public void onClick(DialogInterface dialog, int which) { }
// TODO Auto-generated method stub
dialog.dismiss();
}
}
}
public final class EclairClient extends GapClient public final class EclairClient extends GapClient
{ {