新增 dialogs.build()支持customView属性和wrapInScrollView属性
This commit is contained in:
@@ -194,6 +194,14 @@ module.exports = function(__runtime__, scope){
|
||||
builder.getDialog().emit("check", checked, builder.getDialog());
|
||||
});
|
||||
}
|
||||
if(properties.customView != undefined) {
|
||||
let customView = properties.customView;
|
||||
if(typeof(customView) == 'xml' || typeof(customView) == 'string') {
|
||||
customView = ui.run(() => ui.inflate(customView));
|
||||
}
|
||||
let wrapInScrollView = (properties.wrapInScrollView === undefined) ? true : properties.wrapInScrollView;
|
||||
builder.customView(customView, wrapInScrollView);
|
||||
}
|
||||
}
|
||||
|
||||
function wrapNonNullString(str){
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = function (runtime, global) {
|
||||
ui.__defineGetter__("emitter", ()=> activity ? activity.getEventEmitter() : null);
|
||||
|
||||
ui.layout = function (xml) {
|
||||
if(!activity){
|
||||
if(typeof(activity) == 'undefined'){
|
||||
throw new Error("需要在ui模式下运行才能使用该函数");
|
||||
}
|
||||
runtime.ui.layoutInflater.setContext(activity);
|
||||
@@ -24,15 +24,18 @@ module.exports = function (runtime, global) {
|
||||
}
|
||||
|
||||
ui.inflate = function(xml, parent, attachToParent){
|
||||
if(!activity){
|
||||
throw new Error("需要在ui模式下运行才能使用该函数");
|
||||
}
|
||||
if(typeof(xml) == 'xml'){
|
||||
xml = xml.toXMLString();
|
||||
}
|
||||
parent = parent || null;
|
||||
attachToParent = !!attachToParent;
|
||||
runtime.ui.layoutInflater.setContext(activity);
|
||||
let ctx;
|
||||
if(typeof(activity) == 'undefined') {
|
||||
ctx = new android.view.ContextThemeWrapper(context, com.stardust.autojs.R.style.ScriptTheme);
|
||||
} else {
|
||||
ctx = activity;
|
||||
}
|
||||
runtime.ui.layoutInflater.setContext(ctx);
|
||||
return runtime.ui.layoutInflater.inflate(xml.toString(), parent, attachToParent);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,13 @@ import org.mozilla.javascript.Context;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/29.
|
||||
*/
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public class Loopers implements MessageQueue.IdleHandler {
|
||||
|
||||
private static final String LOG_TAG = "Loopers";
|
||||
@@ -32,9 +35,27 @@ public class Loopers implements MessageQueue.IdleHandler {
|
||||
private static final Runnable EMPTY_RUNNABLE = () -> {
|
||||
};
|
||||
|
||||
private volatile ThreadLocal<Boolean> waitWhenIdle = new ThreadLocal<>();
|
||||
private volatile ThreadLocal<HashSet<Integer>> waitIds = new ThreadLocal<>();
|
||||
private volatile ThreadLocal<Integer> maxWaitId = new ThreadLocal<>();
|
||||
private volatile ThreadLocal<Boolean> waitWhenIdle = new ThreadLocal<Boolean>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected Boolean initialValue() {
|
||||
return Looper.myLooper() == Looper.getMainLooper();
|
||||
}
|
||||
};
|
||||
private volatile ThreadLocal<HashSet<Integer>> waitIds = new ThreadLocal<HashSet<Integer>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected HashSet<Integer> initialValue() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
};
|
||||
private volatile ThreadLocal<Integer> maxWaitId = new ThreadLocal<Integer>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected Integer initialValue() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
private volatile ThreadLocal<CopyOnWriteArrayList<LooperQuitHandler>> looperQuitHandlers = new ThreadLocal<>();
|
||||
private volatile Looper mServantLooper;
|
||||
private Timers mTimers;
|
||||
@@ -126,7 +147,7 @@ public class Loopers implements MessageQueue.IdleHandler {
|
||||
return mServantLooper;
|
||||
}
|
||||
|
||||
public void quitServantLooper() {
|
||||
private void quitServantLooper() {
|
||||
if (mServantLooper == null)
|
||||
return;
|
||||
mServantLooper.quit();
|
||||
@@ -134,12 +155,14 @@ public class Loopers implements MessageQueue.IdleHandler {
|
||||
|
||||
public int waitWhenIdle() {
|
||||
int id = maxWaitId.get();
|
||||
Log.d(LOG_TAG, "waitWhenIdle: " + id);
|
||||
maxWaitId.set(id + 1);
|
||||
waitIds.get().add(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public void doNotWaitWhenIdle(int waitId) {
|
||||
Log.d(LOG_TAG, "doNotWaitWhenIdle: " + waitId);
|
||||
waitIds.get().remove(waitId);
|
||||
}
|
||||
|
||||
@@ -181,9 +204,6 @@ public class Loopers implements MessageQueue.IdleHandler {
|
||||
if (Looper.myLooper() == null)
|
||||
LooperHelper.prepare();
|
||||
Looper.myQueue().addIdleHandler(this);
|
||||
waitWhenIdle.set(Looper.myLooper() == Looper.getMainLooper());
|
||||
waitIds.set(new HashSet<>());
|
||||
maxWaitId.set(0);
|
||||
}
|
||||
|
||||
public void notifyThreadExit(TimerThread thread) {
|
||||
|
||||
@@ -89,6 +89,10 @@ public class Timer {
|
||||
}
|
||||
}
|
||||
|
||||
public void post(Runnable r) {
|
||||
|
||||
}
|
||||
|
||||
public boolean clearInterval(int id) {
|
||||
return clearCallback(id);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class JsDialogBuilder extends MaterialDialog.Builder {
|
||||
super(context);
|
||||
mTimer = runtime.timers.getTimerForCurrentThread();
|
||||
mLoopers = runtime.loopers;
|
||||
mEmitter = new EventEmitter(runtime.bridges, mTimer);
|
||||
mEmitter = new EventEmitter(runtime.bridges);
|
||||
mUiHandler = runtime.uiHandler;
|
||||
setUpEvents();
|
||||
}
|
||||
@@ -70,7 +70,6 @@ public class JsDialogBuilder extends MaterialDialog.Builder {
|
||||
|
||||
public void onShowCalled() {
|
||||
mTimer.postDelayed(() -> mWaitId = mLoopers.waitWhenIdle(), 0);
|
||||
|
||||
}
|
||||
|
||||
public JsDialog getDialog() {
|
||||
|
||||
@@ -144,7 +144,6 @@ public class Dialogs {
|
||||
}
|
||||
return new JsDialogBuilder(context, mRuntime)
|
||||
.theme(Theme.LIGHT);
|
||||
|
||||
}
|
||||
|
||||
public class NonUiDialogs {
|
||||
|
||||
Reference in New Issue
Block a user