mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 23:42:53 +08:00
Alert dialog only has OK button. Add confirm dialog with OK and CANCEL.
This commit is contained in:
parent
6d403c5864
commit
5c24abcafd
@ -391,51 +391,67 @@ public class DroidGap extends Activity {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the client to display a javascript alert dialog.
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
* @param url
|
||||||
|
* @param message
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
|
||||||
Log.d(LOG_TAG, message);
|
Log.d(LOG_TAG, message);
|
||||||
// This shows the dialog box. This can be commented out for dev
|
AlertDialog.Builder dlg = new AlertDialog.Builder(mCtx);
|
||||||
AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx);
|
dlg.setMessage(message);
|
||||||
GapOKDialog okHook = new GapOKDialog();
|
dlg.setTitle("Alert");
|
||||||
GapCancelDialog cancelHook = new GapCancelDialog();
|
dlg.setCancelable(false);
|
||||||
alertBldr.setMessage(message);
|
dlg.setPositiveButton(android.R.string.ok,
|
||||||
alertBldr.setTitle("Alert");
|
new AlertDialog.OnClickListener() {
|
||||||
alertBldr.setCancelable(true);
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
alertBldr.setPositiveButton("OK", okHook);
|
|
||||||
alertBldr.setNegativeButton("Cancel", cancelHook);
|
|
||||||
alertBldr.show();
|
|
||||||
result.confirm();
|
result.confirm();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlg.create();
|
||||||
|
dlg.show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* This is the Code for the OK Button
|
* Tell the client to display a confirm dialog to the user.
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
* @param url
|
||||||
|
* @param message
|
||||||
|
* @param result
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public class GapOKDialog implements DialogInterface.OnClickListener {
|
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) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// TODO Auto-generated method stub
|
result.confirm();
|
||||||
dialog.dismiss();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
dlg.setNegativeButton(android.R.string.cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
public class GapCancelDialog implements DialogInterface.OnClickListener {
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// TODO Auto-generated method stub
|
result.cancel();
|
||||||
dialog.dismiss();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
dlg.create();
|
||||||
|
dlg.show();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class EclairClient extends GapClient
|
public final class EclairClient extends GapClient
|
||||||
|
Loading…
Reference in New Issue
Block a user