fix(autojs): bridges.call() convert boolean to java.lang.Boolean
This commit is contained in:
@@ -24,44 +24,7 @@ runtime.init();
|
||||
global.device = runtime.device;
|
||||
|
||||
//设置JavaScriptBridges用于与Java层的交互和数据转换
|
||||
runtime.bridges.setBridges({
|
||||
call: function(func, target, args){
|
||||
var arr = [];
|
||||
var len = args.length;
|
||||
for(var i = 0; i < len; i++){
|
||||
arr.push(args[i]);
|
||||
}
|
||||
return func.apply(target, arr);
|
||||
},
|
||||
asArray: function(list){
|
||||
var arr = [];
|
||||
for(var i = 0; i < list.size(); i++){
|
||||
arr.push(list.get(i));
|
||||
}
|
||||
for(var key in list){
|
||||
if(typeof(key) == 'number')
|
||||
continue;
|
||||
var v = list[key];
|
||||
if(typeof(v) == 'function'){
|
||||
arr[key] = v.bind(list);
|
||||
}else{
|
||||
arr[key] = v;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
toArray: function(iterable){
|
||||
var iterator = iterable.iterator();
|
||||
var arr = [];
|
||||
while(iterator.hasNext()){
|
||||
arr.push(iterator.next());
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
toString: function(o){
|
||||
return String(o);
|
||||
}
|
||||
});
|
||||
runtime.bridges.setBridges(require('__bridges__.js'));
|
||||
|
||||
//一些内部函数
|
||||
global.__asGlobal__ = function(obj, functions){
|
||||
@@ -88,8 +51,9 @@ runtime.init();
|
||||
}
|
||||
};
|
||||
|
||||
//初始化一般模块
|
||||
//初始化全局函数
|
||||
require("__globals__")(runtime, global);
|
||||
//初始化一般模块
|
||||
(function(scope){
|
||||
var modules = ['app', 'automator', 'console', 'dialogs', 'io', 'selector', 'shell', 'web', 'ui',
|
||||
"images", "timers", "threads", "events", "engines", "RootAutomator", "http", "storages", "floaty",
|
||||
|
||||
63
autojs/src/main/assets/modules/__bridges__.js
Normal file
63
autojs/src/main/assets/modules/__bridges__.js
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
var bridges = {};
|
||||
|
||||
bridges.call = function (func, target, args) {
|
||||
var arr = [];
|
||||
var len = args.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
arr.push(wrap(args[i]));
|
||||
}
|
||||
return func.apply(target, arr);
|
||||
};
|
||||
|
||||
function wrap(value){
|
||||
if(!(typeof(value) == 'object' && 'getClass' in value && util.isFunction(value.getClass))){
|
||||
return value;
|
||||
}
|
||||
var c = value.getClass();
|
||||
if(!('getName' in c && util.isFunction(c.getName))){
|
||||
return value;
|
||||
}
|
||||
var name = c.getName();
|
||||
if(name == 'java.lang.Boolean'){
|
||||
return Boolean(value);
|
||||
}
|
||||
//TODO: is is necessary?
|
||||
if(name == 'java.lang.Integer' || name == 'java.lang.Long' || name == 'java.lang.Double'
|
||||
|| name == 'java.lang.Float'){
|
||||
return Number(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bridges.asArray = function (list) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < list.size(); i++) {
|
||||
arr.push(list.get(i));
|
||||
}
|
||||
for (var key in list) {
|
||||
if (typeof (key) == 'number')
|
||||
continue;
|
||||
var v = list[key];
|
||||
if (typeof (v) == 'function') {
|
||||
arr[key] = v.bind(list);
|
||||
} else {
|
||||
arr[key] = v;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
bridges.toArray = function (iterable) {
|
||||
var iterator = iterable.iterator();
|
||||
var arr = [];
|
||||
while (iterator.hasNext()) {
|
||||
arr.push(iterator.next());
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
bridges.toString = function (o) {
|
||||
return String(o);
|
||||
};
|
||||
|
||||
|
||||
module.exports = bridges;
|
||||
@@ -119,9 +119,7 @@ module.exports = function(__runtime__, scope){
|
||||
"negative": {method: "negativeText"},
|
||||
"negativeColor": {adapter: parseColor},
|
||||
"cancelable": null,
|
||||
"canceledOnTouchOutside": null,
|
||||
"checkBoxPrompt": null,
|
||||
"checkBoxChecked": null
|
||||
"canceledOnTouchOutside": null
|
||||
};
|
||||
|
||||
dialogs.build = function(properties){
|
||||
@@ -133,16 +131,16 @@ module.exports = function(__runtime__, scope){
|
||||
applyDialogProperty(builder, name, properties[name]);
|
||||
}
|
||||
applyOtherDialogProperties(builder, properties);
|
||||
return ui.run(()=> builder.build());
|
||||
return ui.run(()=> builder.buildDialog());
|
||||
}
|
||||
|
||||
function applyDialogProperty(builder, name, value){
|
||||
if(!propertySetters.hasOwnProperty(name)){
|
||||
return;
|
||||
}
|
||||
var propertySetter = propertySetters[name];
|
||||
if(propertySetter == null){
|
||||
propertySetter = {method: name};
|
||||
var propertySetter = propertySetters[name] || {};
|
||||
if(propertySetter.method == undefined){
|
||||
propertySetter.method = name;
|
||||
}
|
||||
if(propertySetter.adapter){
|
||||
value = propertySetter.adapter(value);
|
||||
@@ -155,25 +153,28 @@ module.exports = function(__runtime__, scope){
|
||||
builder.input(wrapNonNullString(properties.inputHint), wrapNonNullString(properties.inputPrefill),
|
||||
function(dialog, input){
|
||||
input = input.toString();
|
||||
dialog.emit("input_change", dialog, input);
|
||||
}, true);
|
||||
builder.emit("input_change", dialog, input);
|
||||
})
|
||||
.alwaysCallInputCallback();
|
||||
}
|
||||
if(properties.items != undefined){
|
||||
var itemsSelectMode = properties.itemSelectMode;
|
||||
var itemsSelectMode = properties.itemsSelectMode;
|
||||
if(itemsSelectMode == undefined || itemsSelectMode == 'select'){
|
||||
builder.itemsCallback(function(dialog, view, position, text){
|
||||
dialog.emit("item_select", position, text.toString(), dialog);
|
||||
});
|
||||
}else if(itemsSelectMode == 'singleChoice'){
|
||||
}else if(itemsSelectMode == 'single'){
|
||||
builder.itemsCallbackSingleChoice(properties.itemsSelectedIndex == undefined ? -1 : properties.itemsSelectedIndex,
|
||||
function(dialog, view, which, text){
|
||||
dialog.emit("single_choice", which, text.toString(), dialog)
|
||||
dialog.emit("single_choice", which, text.toString(), dialog);
|
||||
return true;
|
||||
});
|
||||
}else if(itemsSelectMode == 'multiChoice'){
|
||||
builder.itemsCallbackMultiChoice(properties.itemsSelectedIndex == undefined ? -1 : properties.itemsSelectedIndex,
|
||||
}else if(itemsSelectMode == 'multi'){
|
||||
builder.itemsCallbackMultiChoice(properties.itemsSelectedIndex == undefined ? null : properties.itemsSelectedIndex,
|
||||
function(dialog, view, indices, texts){
|
||||
dialog.emit("multi_choice", toJsArray(indices, (l, i)=> parseInt(l.get(i)),
|
||||
toJsArray(texts, (l, i)=> l.get(i).toString())), dialog);
|
||||
return true;
|
||||
});
|
||||
}else{
|
||||
throw new Error("unknown itemsSelecteMode " + itemsSelectMode);
|
||||
@@ -182,8 +183,14 @@ module.exports = function(__runtime__, scope){
|
||||
if(properties.progress != undefined){
|
||||
var progress = properties.progress;
|
||||
var indeterminate = (progress.max == -1);
|
||||
builder.progress(indeterminate, progress.max, progress.showMinMax);
|
||||
builder.progressIndeterminateStyle(progress.horizontal);
|
||||
builder.progress(indeterminate, progress.max, !!progress.showMinMax);
|
||||
builder.progressIndeterminateStyle(!!progress.horizontal);
|
||||
}
|
||||
if(properties.checkBoxPrompt != undefined || properties.checkBoxChecked != undefined){
|
||||
builder.checkBoxPrompt(wrapNonNullString(properties.checkBoxPrompt), !!properties.checkBoxChecked,
|
||||
function(view, checked){
|
||||
builder.emit("check", checked, builder.getDialog());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,644 @@
|
||||
package com.stardust.autojs.core.ui.dialog;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ActionMode;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.KeyboardShortcutGroup;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SearchEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.internal.MDButton;
|
||||
import com.stardust.app.DialogUtils;
|
||||
import com.stardust.autojs.core.eventloop.EventEmitter;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/4/17.
|
||||
*/
|
||||
|
||||
public class JsDialog extends MaterialDialog {
|
||||
public class JsDialog {
|
||||
|
||||
private final EventEmitter mEmitter;
|
||||
private final UiHandler mUiHandler;
|
||||
private final MaterialDialog mDialog;
|
||||
|
||||
public JsDialog(Builder builder, EventEmitter emitter, UiHandler uiHandler) {
|
||||
super(builder);
|
||||
public JsDialog(MaterialDialog dialog, EventEmitter emitter, UiHandler uiHandler) {
|
||||
mDialog = dialog;
|
||||
mEmitter = emitter;
|
||||
mUiHandler = uiHandler;
|
||||
}
|
||||
|
||||
public EventEmitter once(String eventName, Object listener) {
|
||||
return mEmitter.once(eventName, listener);
|
||||
public MaterialDialog.Builder getBuilder() {
|
||||
return mDialog.getBuilder();
|
||||
}
|
||||
|
||||
public EventEmitter on(String eventName, Object listener) {
|
||||
return mEmitter.on(eventName, listener);
|
||||
public void setTypeface(TextView target, Typeface t) {
|
||||
mDialog.setTypeface(target, t);
|
||||
}
|
||||
|
||||
public EventEmitter addListener(String eventName, Object listener) {
|
||||
return mEmitter.addListener(eventName, listener);
|
||||
@Nullable
|
||||
public Object getTag() {
|
||||
return mDialog.getTag();
|
||||
}
|
||||
|
||||
public boolean onItemSelected(MaterialDialog dialog, View view, int position, CharSequence text, boolean longPress) {
|
||||
return mDialog.onItemSelected(dialog, view, position, text, longPress);
|
||||
}
|
||||
|
||||
public RecyclerView getRecyclerView() {
|
||||
return mDialog.getRecyclerView();
|
||||
}
|
||||
|
||||
public boolean isPromptCheckBoxChecked() {
|
||||
return mDialog.isPromptCheckBoxChecked();
|
||||
}
|
||||
|
||||
public void setPromptCheckBoxChecked(boolean checked) {
|
||||
mDialog.setPromptCheckBoxChecked(checked);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
mDialog.onClick(v);
|
||||
}
|
||||
|
||||
public MDButton getActionButton(@NonNull DialogAction which) {
|
||||
return mDialog.getActionButton(which);
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mDialog.getView();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EditText getInputEditText() {
|
||||
return mDialog.getInputEditText();
|
||||
}
|
||||
|
||||
public TextView getTitleView() {
|
||||
return mDialog.getTitleView();
|
||||
}
|
||||
|
||||
public ImageView getIconView() {
|
||||
return mDialog.getIconView();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TextView getContentView() {
|
||||
return mDialog.getContentView();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public View getCustomView() {
|
||||
return mDialog.getCustomView();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setActionButton(@NonNull DialogAction which, CharSequence title) {
|
||||
mDialog.setActionButton(which, title);
|
||||
}
|
||||
|
||||
public void setActionButton(DialogAction which, int titleRes) {
|
||||
mDialog.setActionButton(which, titleRes);
|
||||
}
|
||||
|
||||
public boolean hasActionButtons() {
|
||||
return mDialog.hasActionButtons();
|
||||
}
|
||||
|
||||
public int numberOfActionButtons() {
|
||||
return mDialog.numberOfActionButtons();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setTitle(@NonNull CharSequence newTitle) {
|
||||
mDialog.setTitle(newTitle);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setTitle(int newTitleRes) {
|
||||
mDialog.setTitle(newTitleRes);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setTitle(int newTitleRes, @Nullable Object... formatArgs) {
|
||||
mDialog.setTitle(newTitleRes, formatArgs);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setIcon(int resId) {
|
||||
mDialog.setIcon(resId);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setIcon(Drawable d) {
|
||||
mDialog.setIcon(d);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setIconAttribute(int attrId) {
|
||||
mDialog.setIconAttribute(attrId);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setContent(CharSequence newContent) {
|
||||
mDialog.setContent(newContent);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setContent(int newContentRes) {
|
||||
mDialog.setContent(newContentRes);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setContent(int newContentRes, @Nullable Object... formatArgs) {
|
||||
mDialog.setContent(newContentRes, formatArgs);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMessage(CharSequence message) {
|
||||
mDialog.setMessage(message);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ArrayList<CharSequence> getItems() {
|
||||
return mDialog.getItems();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setItems(CharSequence... items) {
|
||||
mDialog.setItems(items);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void notifyItemInserted(int index) {
|
||||
mDialog.notifyItemInserted(index);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void notifyItemChanged(int index) {
|
||||
mDialog.notifyItemChanged(index);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void notifyItemsChanged() {
|
||||
mDialog.notifyItemsChanged();
|
||||
}
|
||||
|
||||
public int getCurrentProgress() {
|
||||
return mDialog.getCurrentProgress();
|
||||
}
|
||||
|
||||
public ProgressBar getProgressBar() {
|
||||
return mDialog.getProgressBar();
|
||||
}
|
||||
|
||||
public void incrementProgress(int by) {
|
||||
mDialog.incrementProgress(by);
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
mDialog.setProgress(progress);
|
||||
}
|
||||
|
||||
public void setMaxProgress(int max) {
|
||||
mDialog.setMaxProgress(max);
|
||||
}
|
||||
|
||||
public boolean isIndeterminateProgress() {
|
||||
return mDialog.isIndeterminateProgress();
|
||||
}
|
||||
|
||||
public int getMaxProgress() {
|
||||
return mDialog.getMaxProgress();
|
||||
}
|
||||
|
||||
public void setProgressPercentFormat(NumberFormat format) {
|
||||
mDialog.setProgressPercentFormat(format);
|
||||
}
|
||||
|
||||
public void setProgressNumberFormat(String format) {
|
||||
mDialog.setProgressNumberFormat(format);
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return mDialog.isCancelled();
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return mDialog.getSelectedIndex();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer[] getSelectedIndices() {
|
||||
return mDialog.getSelectedIndices();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setSelectedIndex(int index) {
|
||||
mDialog.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setSelectedIndices(@NonNull Integer[] indices) {
|
||||
mDialog.setSelectedIndices(indices);
|
||||
}
|
||||
|
||||
public void clearSelectedIndices() {
|
||||
mDialog.clearSelectedIndices();
|
||||
}
|
||||
|
||||
public void clearSelectedIndices(boolean sendCallback) {
|
||||
mDialog.clearSelectedIndices(sendCallback);
|
||||
}
|
||||
|
||||
public void selectAllIndices() {
|
||||
mDialog.selectAllIndices();
|
||||
}
|
||||
|
||||
public void selectAllIndices(boolean sendCallback) {
|
||||
mDialog.selectAllIndices(sendCallback);
|
||||
}
|
||||
|
||||
public void onShow(DialogInterface dialog) {
|
||||
mDialog.onShow(dialog);
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
|
||||
public View findViewById(int id) {
|
||||
return mDialog.findViewById(id);
|
||||
}
|
||||
|
||||
public void setOnShowListener(DialogInterface.OnShowListener listener) {
|
||||
mDialog.setOnShowListener(listener);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setContentView(int layoutResID) throws IllegalAccessError {
|
||||
mDialog.setContentView(layoutResID);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setContentView(@NonNull View view) throws IllegalAccessError {
|
||||
mDialog.setContentView(view);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setContentView(@NonNull View view, ViewGroup.LayoutParams params) throws IllegalAccessError {
|
||||
mDialog.setContentView(view, params);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mDialog.getContext();
|
||||
}
|
||||
|
||||
public ActionBar getActionBar() {
|
||||
return mDialog.getActionBar();
|
||||
}
|
||||
|
||||
public void setOwnerActivity(@NonNull Activity activity) {
|
||||
mDialog.setOwnerActivity(activity);
|
||||
}
|
||||
|
||||
public Activity getOwnerActivity() {
|
||||
return mDialog.getOwnerActivity();
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mDialog.isShowing();
|
||||
}
|
||||
|
||||
public void create() {
|
||||
mDialog.create();
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
mDialog.hide();
|
||||
}
|
||||
|
||||
public Bundle onSaveInstanceState() {
|
||||
return mDialog.onSaveInstanceState();
|
||||
}
|
||||
|
||||
public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||
mDialog.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
return mDialog.getWindow();
|
||||
}
|
||||
|
||||
public View getCurrentFocus() {
|
||||
return mDialog.getCurrentFocus();
|
||||
}
|
||||
|
||||
public void addContentView(@NonNull View view, @Nullable ViewGroup.LayoutParams params) {
|
||||
mDialog.addContentView(view, params);
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
|
||||
return mDialog.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public boolean onKeyLongPress(int keyCode, @NonNull KeyEvent event) {
|
||||
return mDialog.onKeyLongPress(keyCode, event);
|
||||
}
|
||||
|
||||
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
|
||||
return mDialog.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
public boolean onKeyMultiple(int keyCode, int repeatCount, @NonNull KeyEvent event) {
|
||||
return mDialog.onKeyMultiple(keyCode, repeatCount, event);
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
mDialog.onBackPressed();
|
||||
}
|
||||
|
||||
public boolean onKeyShortcut(int keyCode, @NonNull KeyEvent event) {
|
||||
return mDialog.onKeyShortcut(keyCode, event);
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(@NonNull MotionEvent event) {
|
||||
return mDialog.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public boolean onTrackballEvent(@NonNull MotionEvent event) {
|
||||
return mDialog.onTrackballEvent(event);
|
||||
}
|
||||
|
||||
public boolean onGenericMotionEvent(@NonNull MotionEvent event) {
|
||||
return mDialog.onGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
|
||||
mDialog.onWindowAttributesChanged(params);
|
||||
}
|
||||
|
||||
public void onContentChanged() {
|
||||
mDialog.onContentChanged();
|
||||
}
|
||||
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
mDialog.onWindowFocusChanged(hasFocus);
|
||||
}
|
||||
|
||||
public void onAttachedToWindow() {
|
||||
mDialog.onAttachedToWindow();
|
||||
}
|
||||
|
||||
public void onDetachedFromWindow() {
|
||||
mDialog.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
|
||||
return mDialog.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
public boolean dispatchKeyShortcutEvent(@NonNull KeyEvent event) {
|
||||
return mDialog.dispatchKeyShortcutEvent(event);
|
||||
}
|
||||
|
||||
public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
|
||||
return mDialog.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
public boolean dispatchTrackballEvent(@NonNull MotionEvent ev) {
|
||||
return mDialog.dispatchTrackballEvent(ev);
|
||||
}
|
||||
|
||||
public boolean dispatchGenericMotionEvent(@NonNull MotionEvent ev) {
|
||||
return mDialog.dispatchGenericMotionEvent(ev);
|
||||
}
|
||||
|
||||
public boolean dispatchPopulateAccessibilityEvent(@NonNull AccessibilityEvent event) {
|
||||
return mDialog.dispatchPopulateAccessibilityEvent(event);
|
||||
}
|
||||
|
||||
public View onCreatePanelView(int featureId) {
|
||||
return mDialog.onCreatePanelView(featureId);
|
||||
}
|
||||
|
||||
public boolean onCreatePanelMenu(int featureId, @NonNull Menu menu) {
|
||||
return mDialog.onCreatePanelMenu(featureId, menu);
|
||||
}
|
||||
|
||||
public boolean onPreparePanel(int featureId, View view, Menu menu) {
|
||||
return mDialog.onPreparePanel(featureId, view, menu);
|
||||
}
|
||||
|
||||
public boolean onMenuOpened(int featureId, Menu menu) {
|
||||
return mDialog.onMenuOpened(featureId, menu);
|
||||
}
|
||||
|
||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||
return mDialog.onMenuItemSelected(featureId, item);
|
||||
}
|
||||
|
||||
public void onPanelClosed(int featureId, Menu menu) {
|
||||
mDialog.onPanelClosed(featureId, menu);
|
||||
}
|
||||
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
return mDialog.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
public boolean onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
return mDialog.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
return mDialog.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void onOptionsMenuClosed(@NonNull Menu menu) {
|
||||
mDialog.onOptionsMenuClosed(menu);
|
||||
}
|
||||
|
||||
public void openOptionsMenu() {
|
||||
mDialog.openOptionsMenu();
|
||||
}
|
||||
|
||||
public void closeOptionsMenu() {
|
||||
mDialog.closeOptionsMenu();
|
||||
}
|
||||
|
||||
public void invalidateOptionsMenu() {
|
||||
mDialog.invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
mDialog.onCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
|
||||
public void registerForContextMenu(@NonNull View view) {
|
||||
mDialog.registerForContextMenu(view);
|
||||
}
|
||||
|
||||
public void unregisterForContextMenu(@NonNull View view) {
|
||||
mDialog.unregisterForContextMenu(view);
|
||||
}
|
||||
|
||||
public void openContextMenu(@NonNull View view) {
|
||||
mDialog.openContextMenu(view);
|
||||
}
|
||||
|
||||
public boolean onContextItemSelected(@NonNull MenuItem item) {
|
||||
return mDialog.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
public void onContextMenuClosed(@NonNull Menu menu) {
|
||||
mDialog.onContextMenuClosed(menu);
|
||||
}
|
||||
|
||||
public boolean onSearchRequested(@NonNull SearchEvent searchEvent) {
|
||||
return mDialog.onSearchRequested(searchEvent);
|
||||
}
|
||||
|
||||
public boolean onSearchRequested() {
|
||||
return mDialog.onSearchRequested();
|
||||
}
|
||||
|
||||
public SearchEvent getSearchEvent() {
|
||||
return mDialog.getSearchEvent();
|
||||
}
|
||||
|
||||
public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
|
||||
return mDialog.onWindowStartingActionMode(callback);
|
||||
}
|
||||
|
||||
public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) {
|
||||
return mDialog.onWindowStartingActionMode(callback, type);
|
||||
}
|
||||
|
||||
public void onActionModeStarted(ActionMode mode) {
|
||||
mDialog.onActionModeStarted(mode);
|
||||
}
|
||||
|
||||
public void onActionModeFinished(ActionMode mode) {
|
||||
mDialog.onActionModeFinished(mode);
|
||||
}
|
||||
|
||||
public void takeKeyEvents(boolean get) {
|
||||
mDialog.takeKeyEvents(get);
|
||||
}
|
||||
|
||||
public boolean requestWindowFeature(int featureId) {
|
||||
return mDialog.requestWindowFeature(featureId);
|
||||
}
|
||||
|
||||
public void setFeatureDrawableResource(int featureId, int resId) {
|
||||
mDialog.setFeatureDrawableResource(featureId, resId);
|
||||
}
|
||||
|
||||
public void setFeatureDrawableUri(int featureId, @Nullable Uri uri) {
|
||||
mDialog.setFeatureDrawableUri(featureId, uri);
|
||||
}
|
||||
|
||||
public void setFeatureDrawable(int featureId, @Nullable Drawable drawable) {
|
||||
mDialog.setFeatureDrawable(featureId, drawable);
|
||||
}
|
||||
|
||||
public void setFeatureDrawableAlpha(int featureId, int alpha) {
|
||||
mDialog.setFeatureDrawableAlpha(featureId, alpha);
|
||||
}
|
||||
|
||||
public LayoutInflater getLayoutInflater() {
|
||||
return mDialog.getLayoutInflater();
|
||||
}
|
||||
|
||||
public void setCancelable(boolean flag) {
|
||||
mDialog.setCancelable(flag);
|
||||
}
|
||||
|
||||
public void setCanceledOnTouchOutside(boolean cancel) {
|
||||
mDialog.setCanceledOnTouchOutside(cancel);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
mDialog.cancel();
|
||||
}
|
||||
|
||||
public void setOnCancelListener(@Nullable DialogInterface.OnCancelListener listener) {
|
||||
mDialog.setOnCancelListener(listener);
|
||||
}
|
||||
|
||||
public void setCancelMessage(@Nullable Message msg) {
|
||||
mDialog.setCancelMessage(msg);
|
||||
}
|
||||
|
||||
public void setOnDismissListener(@Nullable DialogInterface.OnDismissListener listener) {
|
||||
mDialog.setOnDismissListener(listener);
|
||||
}
|
||||
|
||||
public void setDismissMessage(@Nullable Message msg) {
|
||||
mDialog.setDismissMessage(msg);
|
||||
}
|
||||
|
||||
public void setVolumeControlStream(int streamType) {
|
||||
mDialog.setVolumeControlStream(streamType);
|
||||
}
|
||||
|
||||
public int getVolumeControlStream() {
|
||||
return mDialog.getVolumeControlStream();
|
||||
}
|
||||
|
||||
public void setOnKeyListener(@Nullable DialogInterface.OnKeyListener onKeyListener) {
|
||||
mDialog.setOnKeyListener(onKeyListener);
|
||||
}
|
||||
|
||||
public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) {
|
||||
mDialog.onProvideKeyboardShortcuts(data, menu, deviceId);
|
||||
}
|
||||
|
||||
public JsDialog once(String eventName, Object listener) {
|
||||
mEmitter.once(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsDialog on(String eventName, Object listener) {
|
||||
mEmitter.on(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsDialog addListener(String eventName, Object listener) {
|
||||
mEmitter.addListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean emit(String eventName, Object... args) {
|
||||
@@ -53,28 +657,34 @@ public class JsDialog extends MaterialDialog {
|
||||
return mEmitter.listeners(eventName);
|
||||
}
|
||||
|
||||
public EventEmitter prependListener(String eventName, Object listener) {
|
||||
return mEmitter.prependListener(eventName, listener);
|
||||
public JsDialog prependListener(String eventName, Object listener) {
|
||||
mEmitter.prependListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter prependOnceListener(String eventName, Object listener) {
|
||||
return mEmitter.prependOnceListener(eventName, listener);
|
||||
public JsDialog prependOnceListener(String eventName, Object listener) {
|
||||
mEmitter.prependOnceListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter removeAllListeners() {
|
||||
return mEmitter.removeAllListeners();
|
||||
public JsDialog removeAllListeners() {
|
||||
mEmitter.removeAllListeners();
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter removeAllListeners(String eventName) {
|
||||
return mEmitter.removeAllListeners(eventName);
|
||||
public JsDialog removeAllListeners(String eventName) {
|
||||
mEmitter.removeAllListeners(eventName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter removeListener(String eventName, Object listener) {
|
||||
return mEmitter.removeListener(eventName, listener);
|
||||
public JsDialog removeListener(String eventName, Object listener) {
|
||||
mEmitter.removeListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter setMaxListeners(int n) {
|
||||
return mEmitter.setMaxListeners(n);
|
||||
public JsDialog setMaxListeners(int n) {
|
||||
mEmitter.setMaxListeners(n);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMaxListeners() {
|
||||
@@ -85,20 +695,20 @@ public class JsDialog extends MaterialDialog {
|
||||
return EventEmitter.defaultMaxListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
public JsDialog show() {
|
||||
checkWindowType();
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
super.show();
|
||||
mDialog.show();
|
||||
} else {
|
||||
mUiHandler.post(super::show);
|
||||
mUiHandler.post(mDialog::show);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void checkWindowType() {
|
||||
Context context = getContext();
|
||||
Context context = mDialog.getContext();
|
||||
if (!DialogUtils.isActivityContext(context)) {
|
||||
Window window = getWindow();
|
||||
Window window = mDialog.getWindow();
|
||||
if (window != null)
|
||||
window.setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.afollestad.materialdialogs.StackingBehavior;
|
||||
import com.afollestad.materialdialogs.Theme;
|
||||
import com.stardust.autojs.core.eventloop.EventEmitter;
|
||||
import com.stardust.autojs.runtime.ScriptBridges;
|
||||
import com.stardust.util.ArrayUtils;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
@@ -32,6 +33,7 @@ public class JsDialogBuilder extends MaterialDialog.Builder {
|
||||
|
||||
private final EventEmitter mEmitter;
|
||||
private final UiHandler mUiHandler;
|
||||
private JsDialog mDialog;
|
||||
|
||||
public JsDialogBuilder(@NonNull Context context, ScriptBridges bridges, UiHandler uiHandler) {
|
||||
super(context);
|
||||
@@ -66,21 +68,28 @@ public class JsDialogBuilder extends MaterialDialog.Builder {
|
||||
cancelListener(dialog -> emit("cancel", dialog));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialDialog build() {
|
||||
return new JsDialog(this, mEmitter, mUiHandler);
|
||||
public JsDialog getDialog() {
|
||||
return mDialog;
|
||||
}
|
||||
|
||||
public EventEmitter once(String eventName, Object listener) {
|
||||
return mEmitter.once(eventName, listener);
|
||||
public JsDialog buildDialog() {
|
||||
mDialog = new JsDialog(super.build(), mEmitter, mUiHandler);
|
||||
return mDialog;
|
||||
}
|
||||
|
||||
public EventEmitter on(String eventName, Object listener) {
|
||||
return mEmitter.on(eventName, listener);
|
||||
public JsDialogBuilder once(String eventName, Object listener) {
|
||||
mEmitter.once(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter addListener(String eventName, Object listener) {
|
||||
return mEmitter.addListener(eventName, listener);
|
||||
public JsDialogBuilder on(String eventName, Object listener) {
|
||||
mEmitter.on(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsDialogBuilder addListener(String eventName, Object listener) {
|
||||
mEmitter.addListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean emit(String eventName, Object... args) {
|
||||
@@ -99,28 +108,34 @@ public class JsDialogBuilder extends MaterialDialog.Builder {
|
||||
return mEmitter.listeners(eventName);
|
||||
}
|
||||
|
||||
public EventEmitter prependListener(String eventName, Object listener) {
|
||||
return mEmitter.prependListener(eventName, listener);
|
||||
public JsDialogBuilder prependListener(String eventName, Object listener) {
|
||||
mEmitter.prependListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter prependOnceListener(String eventName, Object listener) {
|
||||
return mEmitter.prependOnceListener(eventName, listener);
|
||||
public JsDialogBuilder prependOnceListener(String eventName, Object listener) {
|
||||
mEmitter.prependOnceListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter removeAllListeners() {
|
||||
return mEmitter.removeAllListeners();
|
||||
public JsDialogBuilder removeAllListeners() {
|
||||
mEmitter.removeAllListeners();
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter removeAllListeners(String eventName) {
|
||||
return mEmitter.removeAllListeners(eventName);
|
||||
public JsDialogBuilder removeAllListeners(String eventName) {
|
||||
mEmitter.removeAllListeners(eventName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter removeListener(String eventName, Object listener) {
|
||||
return mEmitter.removeListener(eventName, listener);
|
||||
public JsDialogBuilder removeListener(String eventName, Object listener) {
|
||||
mEmitter.removeListener(eventName, listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventEmitter setMaxListeners(int n) {
|
||||
return mEmitter.setMaxListeners(n);
|
||||
public JsDialogBuilder setMaxListeners(int n) {
|
||||
mEmitter.setMaxListeners(n);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMaxListeners() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.Theme;
|
||||
@@ -82,6 +83,12 @@ public class Dialogs {
|
||||
return ((BlockedMaterialDialog.Builder) dialogBuilder(callback)
|
||||
.itemsCallback()
|
||||
.title(title)
|
||||
.checkBoxPrompt("", true, new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
|
||||
}
|
||||
})
|
||||
.items((CharSequence[]) items))
|
||||
.showAndGet();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user