forked from github/cordova-android
Update alert() to implement navigator.notification.alert API. This update is from janmonschke (Jan Monschke).
This commit is contained in:
parent
dc960b9835
commit
98206852de
5
framework/assets/js/notification.js
Normal file → Executable file
5
framework/assets/js/notification.js
Normal file → Executable file
@ -11,8 +11,9 @@ function Notification() {
|
|||||||
* @param {String} [buttonLabel="OK"] Label of the close button (default: OK)
|
* @param {String} [buttonLabel="OK"] Label of the close button (default: OK)
|
||||||
*/
|
*/
|
||||||
Notification.prototype.alert = function(message, title, buttonLabel) {
|
Notification.prototype.alert = function(message, title, buttonLabel) {
|
||||||
// Default is to use a browser alert; this will use "index.html" as the title though
|
var _title = (title || "Alert");
|
||||||
alert(message);
|
var _buttonLabel = (buttonLabel || "OK");
|
||||||
|
PhoneGap.execAsync(null, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,9 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.media.Ringtone;
|
import android.media.Ringtone;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -40,6 +42,9 @@ public class Notification extends Plugin {
|
|||||||
else if (action.equals("vibrate")) {
|
else if (action.equals("vibrate")) {
|
||||||
this.vibrate(args.getLong(0));
|
this.vibrate(args.getLong(0));
|
||||||
}
|
}
|
||||||
|
else if (action.equals("alert")) {
|
||||||
|
this.alert(args.getString(0),args.getString(1),args.getString(2));
|
||||||
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
@ -53,6 +58,9 @@ public class Notification extends Plugin {
|
|||||||
* @return T=returns value
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
|
if(action.equals("alert"))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,4 +107,25 @@ public class Notification extends Plugin {
|
|||||||
vibrator.vibrate(time);
|
vibrator.vibrate(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and shows a native Android alert with given Strings
|
||||||
|
* @param message The message the alert should display
|
||||||
|
* @param title The title of the alert
|
||||||
|
* @param buttonLabel The label of the button
|
||||||
|
*/
|
||||||
|
public synchronized void alert(String message,String title,String buttonLabel){
|
||||||
|
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
||||||
|
dlg.setMessage(message);
|
||||||
|
dlg.setTitle(title);
|
||||||
|
dlg.setCancelable(false);
|
||||||
|
dlg.setPositiveButton(buttonLabel,
|
||||||
|
new AlertDialog.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlg.create();
|
||||||
|
dlg.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user