"> 23
// 进度条加载时变换的颜色
public static final int blue_btn_bg_color = Color.parseColor("#AEDEF4");
public static final int material_deep_teal_50 = Color
.parseColor("#ff009688");
public static final int success_stroke_color = Color.parseColor("#F27474");
public static final int material_deep_teal_20 = Color
.parseColor("#ff80cbc4");
public static final int material_blue_grey_80 = Color
.parseColor("#ff37474f");
public static final int warning_stroke_color = Color.parseColor("#F8BB86");
public MobileUIWithSAD(IWadeMobile wademobile) {
super(wademobile);
}
/**
* js传参数,调用原生方法
*
* @param param
* @throws Exception
*/
public void alert(JSONArray param) throws Exception {
JSONObject jsonObject = param.getJSONObject(0);
JSONObject map = jsonObject.getJSONObject("map");
String content = map.getString("content");
String title = map.getString("title");
Boolean cancelable = map.getBoolean("cancelable");
int alertType = map.getInt("alertType");
int imageID = map.getInt("imageID");
alert(content, title, cancelable, alertType, imageID);
}
/**
* 普通类型的几种提示框
*
* @param content
* 文本
* @param title
* 标题
* @param cancelable
* 是否可取消
* @param alertType
* 提示框类型
* @param imageID
* 图片资源ID
* @throws Exception
*/
public void alert(String content, String title, boolean cancelable,
int alertType, int imageID) throws Exception {
final SweetAlertDialog dialog = new SweetAlertDialog(context, alertType);
if (title != null) {
dialog.setTitleText(title);
}
if (!content.equals("")) {
dialog.setContentText(content);
}else
{
dialog.setContentText(null);
}
if (imageID != 0) {
dialog.setCustomImage(imageID);
} else {
dialog.setCustomImage(null);
}
dialog.setCancelable(cancelable);
dialog.show();
}
/**
* js传参数,调用原生方法
*
* @param param
* @throws Exception
*/
public void confirm(JSONArray param) throws Exception {
JSONObject jsonObject = param.getJSONObject(0);
JSONObject map = jsonObject.getJSONObject("map");
String content = map.getString("content");
String title = map.getString("title");
Boolean cancelable = map.getBoolean("cancelable");
String cancelText = map.getString("cancelText");
String confirmText = map.getString("confirmText");
String cancelEvent = map.getString("cancelEvent");
String confirmEvent = map.getString("confirmEvent");
Boolean isCancel = map.getBoolean("isCancel");
confirm(content, title, cancelable, cancelText, confirmText, isCancel,
cancelEvent, confirmEvent);
}
/**
* 确认-取消提示框
*
* @param content
* 文本
* @param title
* 标题
* @param cancelable
* 是否可取消
* @param cancelText
* 取消按钮文本
* @param confirmText
* 确认按钮文本
* @param isCancel
* 是否显示取消按钮
* @param cancelEvent
* 取消按钮点击事件
* @param confirmEvent
* 确认按钮点击事件
* @throws Exception
*/
public void confirm(String content, String title, boolean cancelable,
String cancelText, String confirmText, boolean isCancel,
final String cancelEvent, final String confirmEvent)
throws Exception {
final SweetAlertDialog dialog;
if (cancelText != null && isCancel != false) {
dialog = new SweetAlertDialog(context, WARNING_TYPE)
.setTitleText(title)
.setContentText(content)
.setCancelText(cancelText)
.setConfirmText(confirmText)
.showCancelButton(isCancel)
.setCancelClickListener(
new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sdialog) {
if (cancelEvent != null) {
sdialog.dismiss();
MobileUIWithSAD.this
.executeJs("WadeMobile.customEvents."
+ cancelEvent + "();");
}
}
})
.setConfirmClickListener(
new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sdialog) {
if (confirmEvent != null) {
sdialog.dismiss();
MobileUIWithSAD.this
.executeJs("WadeMobile.customEvents."
+ confirmEvent + "();");
}
}
});
} else {
dialog = new SweetAlertDialog(context, WARNING_TYPE)
.setTitleText(title)
.setContentText(content)
.setConfirmText(confirmText)
.showCancelButton(isCancel)
.setConfirmClickListener(
new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sdialog) {
if (confirmEvent != null) {
sdialog.dismiss();
MobileUIWithSAD.this
.executeJs("WadeMobile.customEvents."
+ confirmEvent + "();");
}
}
});
}
dialog.setCancelable(cancelable);
dialog.show();
}
/**
* js传参数,调用原生方法
*
* @param param
* @throws Exception
*/
public void loading(JSONArray param) throws Exception {
JSONObject jsonObject = param.getJSONObject(0);
JSONObject map = jsonObject.getJSONObject("map");
String title = map.getString("title");
Boolean cancelable = map.getBoolean("cancelable");
Long millisInFuture = map.getLong("millisInFuture");
Long countDownInterval = map.getLong("countDownInterval");
String nextEvent = map.getString("nextEvent");
Boolean hasNext = map.getBoolean("hasNext");
loading(title, cancelable, millisInFuture, countDownInterval, hasNext,
nextEvent);
}
/**
* 进度条提示框
*
* @param title
* 标题
* @param cancelable
* 是否可取消
* @param millisInFuture
* 倒计时总时间(毫秒)
* @param countDownInterval
* 间隔时间(毫秒)
* @param hasNext
* 是否继续弹出对话框
* @param nextEvent
* 对话框事件(JS定义弹出新对话框)
* @throws Exception
*/
public void loading(String title, boolean cancelable, long millisInFuture,
long countDownInterval, final boolean hasNext,
final String nextEvent) throws Exception {
final SweetAlertDialog pDialog = new SweetAlertDialog(context,
PROGRESS_TYPE).setTitleText(title);
pDialog.setCancelable(cancelable);
pDialog.show();
new CountDownTimer(millisInFuture, countDownInterval) {
public void onTick(long millisUntilFinished) {
// you can change the progress bar color by ProgressHelper every
// countDownInterval millis
i++;
switch (i) {
case 0:
pDialog.getProgressHelper().setBarColor(blue_btn_bg_color);
break;
case 1:
pDialog.getProgressHelper().setBarColor(
material_deep_teal_50);
break;
case 2:
pDialog.getProgressHelper().setBarColor(
success_stroke_color);
break;
case 3:
pDialog.getProgressHelper().setBarColor(
material_deep_teal_20);
break;
case 4:
pDialog.getProgressHelper().setBarColor(
material_blue_grey_80);
break;
case 5:
pDialog.getProgressHelper().setBarColor(
warning_stroke_color);
break;
case 6:
pDialog.getProgressHelper().setBarColor(
success_stroke_color);
break;
}
}
public void onFinish() {
i = -1;
pDialog.dismiss();
if (hasNext && nextEvent != null) {
MobileUIWithSAD.this.executeJs("WadeMobile.customEvents."
+ nextEvent + "();");
}
}
}.start();
}
}