Merge branch 'feature/slider' into 'master'
Feature/slider See merge request !20
This commit is contained in:
@@ -15,10 +15,18 @@
|
||||
*/
|
||||
package pub.doric.plugin;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
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 +37,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 +77,151 @@ 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DoricMethod(name = "confirm", thread = ThreadMode.UI)
|
||||
public void confirm(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");
|
||||
JSValue cancelBtn = jsObject.getProperty("cancelLabel");
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getDoricContext().getContext(), R.style.Theme_Doric_Modal_Confirm);
|
||||
if (titleVal.isString()) {
|
||||
builder.setTitle(titleVal.asString().value());
|
||||
}
|
||||
String okLabel = getDoricContext().getContext().getString(android.R.string.ok);
|
||||
if (okBtn.isString()) {
|
||||
okLabel = okBtn.asString().value();
|
||||
}
|
||||
String cancelLabel = getDoricContext().getContext().getString(android.R.string.cancel);
|
||||
if (cancelBtn.isString()) {
|
||||
cancelLabel = cancelBtn.asString().value();
|
||||
}
|
||||
builder.setMessage(msgVal.asString().value())
|
||||
.setPositiveButton(okLabel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
promise.resolve();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(cancelLabel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
promise.reject();
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DoricMethod(name = "prompt", thread = ThreadMode.UI)
|
||||
public void prompt(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");
|
||||
JSValue cancelBtn = jsObject.getProperty("cancelLabel");
|
||||
JSValue defaultVal = jsObject.getProperty("defaultText");
|
||||
JSValue text = jsObject.getProperty("text");
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getDoricContext().getContext(), R.style.Theme_Doric_Modal_Prompt);
|
||||
if (titleVal.isString()) {
|
||||
builder.setTitle(titleVal.asString().value());
|
||||
}
|
||||
String okLabel = getDoricContext().getContext().getString(android.R.string.ok);
|
||||
if (okBtn.isString()) {
|
||||
okLabel = okBtn.asString().value();
|
||||
}
|
||||
String cancelLabel = getDoricContext().getContext().getString(android.R.string.cancel);
|
||||
if (cancelBtn.isString()) {
|
||||
cancelLabel = cancelBtn.asString().value();
|
||||
}
|
||||
|
||||
|
||||
View v = LayoutInflater.from(getDoricContext().getContext()).inflate(R.layout.doric_modal_prompt, null);
|
||||
TextView tvMsg = v.findViewById(R.id.tv_msg);
|
||||
tvMsg.setText(msgVal.asString().value());
|
||||
final EditText editText = v.findViewById(R.id.edit_input);
|
||||
if (defaultVal.isString()) {
|
||||
editText.setHint(defaultVal.asString().value());
|
||||
}
|
||||
if (text.isString()) {
|
||||
editText.setText(text.asString().value());
|
||||
editText.setSelection(text.asString().value().length());
|
||||
}
|
||||
builder.setView(v);
|
||||
builder
|
||||
.setPositiveButton(okLabel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
promise.resolve(new JavaValue(editText.getText().toString()));
|
||||
}
|
||||
})
|
||||
.setNegativeButton(cancelLabel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
promise.reject(new JavaValue(editText.getText().toString()));
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
21
Android/doric/src/main/res/layout/doric_modal_prompt.xml
Normal file
21
Android/doric/src/main/res/layout/doric_modal_prompt.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_msg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginBottom="15dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/Theme.Doric.Modal.Prompt.EditText" />
|
||||
</LinearLayout>
|
5
Android/doric/src/main/res/values-v21/styles.xml
Normal file
5
Android/doric/src/main/res/values-v21/styles.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Theme.Doric.Modal" parent="android:Theme.Material.Light.Dialog.Alert" />
|
||||
</resources>
|
15
Android/doric/src/main/res/values/styles.xml
Normal file
15
Android/doric/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<resources>
|
||||
|
||||
<style name="Theme.Doric.Modal" parent="android:style/Theme.Holo.Light.Dialog">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Doric.Modal.Alert" parent="Theme.Doric.Modal" />
|
||||
|
||||
<style name="Theme.Doric.Modal.Confirm" parent="Theme.Doric.Modal" />
|
||||
|
||||
<style name="Theme.Doric.Modal.Prompt" parent="Theme.Doric.Modal" />
|
||||
|
||||
<style name="Theme.Doric.Modal.Prompt.EditText" parent="Theme.AppCompat.Light" />
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user