forked from github/Toast-PhoneGap-Plugin
further impl Android
This commit is contained in:
parent
37b3857673
commit
f5ab4e7baf
@ -18,27 +18,10 @@ public class Toast extends CordovaPlugin {
|
|||||||
final String duration = args.getString(1);
|
final String duration = args.getString(1);
|
||||||
final String position = args.getString(2);
|
final String position = args.getString(2);
|
||||||
|
|
||||||
if (!"top".equals(position) && !"center".equals(position) && !"bottom".equals(position)) {
|
|
||||||
callbackContext.error("invalid position. valid options are 'top', 'center' and 'bottom'");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int durationInt;
|
|
||||||
if ("short".equals(duration)) {
|
|
||||||
durationInt = android.widget.Toast.LENGTH_SHORT;
|
|
||||||
} else if ("long".equals(duration)) {
|
|
||||||
durationInt = android.widget.Toast.LENGTH_LONG;
|
|
||||||
} else {
|
|
||||||
callbackContext.error("invalid duration. valid options are 'short' and 'long'");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
android.widget.Toast toast = android.widget.Toast.makeText(
|
android.widget.Toast toast = new android.widget.Toast(webView.getContext());
|
||||||
webView.getContext(),
|
toast.setText(message);
|
||||||
message,
|
|
||||||
durationInt);
|
|
||||||
|
|
||||||
if ("top".equals(position)) {
|
if ("top".equals(position)) {
|
||||||
// TODO correct position
|
// TODO correct position
|
||||||
@ -46,12 +29,21 @@ public class Toast extends CordovaPlugin {
|
|||||||
} else if ("bottom".equals(position)) {
|
} else if ("bottom".equals(position)) {
|
||||||
// TODO correct position
|
// TODO correct position
|
||||||
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
|
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||||
} else {
|
} else if ("center".equals(position)) {
|
||||||
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
|
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||||
|
} else {
|
||||||
|
callbackContext.error("invalid position. valid options are 'top', 'center' and 'bottom'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("short".equals(duration)) {
|
||||||
|
toast.setDuration(android.widget.Toast.LENGTH_SHORT);
|
||||||
|
} else if ("long".equals(duration)) {
|
||||||
|
toast.setDuration(android.widget.Toast.LENGTH_LONG);
|
||||||
|
} else {
|
||||||
|
callbackContext.error("invalid duration. valid options are 'short' and 'long'");
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.show();
|
toast.show();
|
||||||
|
|
||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user