From 9a6f2d7f9f151effe3464905587e5d39d4fb0764 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 20 Nov 2019 20:16:55 +0800 Subject: [PATCH 1/4] feat:add Android alert --- .../java/pub/doric/plugin/ModalPlugin.java | 40 +++++++++++++++++++ .../doric/src/main/res/values-v21/styles.xml | 5 +++ Android/doric/src/main/res/values/styles.xml | 15 +++++++ demo/src/ModalDemo.ts | 26 ++++++++++++ js-framework/src/util/modal.ts | 28 ++++++++++++- 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 Android/doric/src/main/res/values-v21/styles.xml create mode 100644 Android/doric/src/main/res/values/styles.xml diff --git a/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java index 2122f284..518f58ba 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java @@ -15,10 +15,14 @@ */ package pub.doric.plugin; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.text.TextUtils; import android.view.Gravity; import android.widget.Toast; import pub.doric.DoricContext; +import pub.doric.R; import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricMethod; import pub.doric.extension.bridge.DoricPromise; @@ -29,6 +33,7 @@ import com.github.pengfeizhou.jscore.ArchiveException; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; +import com.github.pengfeizhou.jscore.JavaValue; /** * @Description: Doric @@ -68,4 +73,39 @@ public class ModalPlugin extends DoricJavaPlugin { e.printStackTrace(); } } + + @DoricMethod(name = "alert", thread = ThreadMode.UI) + public void alert(JSDecoder decoder, final DoricPromise promise) { + try { + JSObject jsObject = decoder.decode().asObject(); + JSValue titleVal = jsObject.getProperty("title"); + JSValue msgVal = jsObject.getProperty("msg"); + JSValue okBtn = jsObject.getProperty("okLabel"); + + AlertDialog.Builder builder = new AlertDialog.Builder(getDoricContext().getContext(), R.style.Theme_Doric_Modal_Alert); + if (titleVal.isString()) { + builder.setTitle(titleVal.asString().value()); + } + String btnTitle = getDoricContext().getContext().getString(android.R.string.ok); + if (okBtn.isString()) { + btnTitle = okBtn.asString().value(); + } + builder.setMessage(msgVal.asString().value()) + .setPositiveButton(btnTitle, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + promise.resolve(); + } + }); + builder.setCancelable(false); + try { + builder.show(); + } catch (Exception e) { + e.printStackTrace(); + } + } catch (ArchiveException e) { + e.printStackTrace(); + promise.reject(new JavaValue(e.getLocalizedMessage())); + } + } } diff --git a/Android/doric/src/main/res/values-v21/styles.xml b/Android/doric/src/main/res/values-v21/styles.xml new file mode 100644 index 00000000..5c99d8c1 --- /dev/null +++ b/Android/doric/src/main/res/values-v21/styles.xml @@ -0,0 +1,5 @@ + + + + + +