update dynamic layout inflater to latest version; add some ui samples

This commit is contained in:
hyb1996 2017-11-30 00:49:06 +08:00
parent 92f296cc19
commit 7bf9b3f0d9
14 changed files with 368 additions and 37 deletions

View File

@ -0,0 +1,16 @@
"ui";
ui.layout(
<vertical padding="16">
<text textSize="40sp">大字</text>
<text textSize="12sp">小字</text>
<text textStyle="bold" textColor="black">加粗</text>
<text textStyle="italic">斜体</text>
<text textColor="#00ff00">原谅色</text>
<text margin="8">Android是一种基于Linux的自由及开放源代码的操作系统主要使用于移动设备如智能手机和平板电脑由Google公司和开放手机联盟领导及开发尚未有统一中文名称中国大陆地区较多人使用安卓安致Android操作系统最初由Andy Rubin开发主要支持手机2005年8月由Google收购注资2007年11月Google与84家硬件制造商软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统</text>
<text maxLines="1" ellipsize="end" marginTop="8">Android是一种基于Linux的自由及开放源代码的操作系统主要使用于移动设备如智能手机和平板电脑由Google公司和开放手机联盟领导及开发尚未有统一中文名称中国大陆地区较多人使用安卓安致Android操作系统最初由Andy Rubin开发主要支持手机2005年8月由Google收购注资2007年11月Google与84家硬件制造商软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统</text>
<text maxLines="2" ellipsize="end" margin="8">Android是一种基于Linux的自由及开放源代码的操作系统主要使用于移动设备如智能手机和平板电脑由Google公司和开放手机联盟领导及开发尚未有统一中文名称中国大陆地区较多人使用安卓安致Android操作系统最初由Andy Rubin开发主要支持手机2005年8月由Google收购注资2007年11月Google与84家硬件制造商软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统</text>
<text w="*" gravity="center">居中</text>
<text autoLink="all">自动超链接网址www.baidu.com, 邮箱 123@qq.com等</text>
</vertical>
);

View File

@ -10,38 +10,38 @@ ui.layout(
<text textSize="16sp" margin="8">1. 您的年龄是?</text>
<input text="18" inputType="number" margin="0 16"/>
<text textSize="16sp" margin="8">2. 您用过其他类似软件(脚本精灵按键精灵等)?</text>
<RadioGroup margin="0 16">
<RadioButton text="没有用过"/>
<RadioButton text="用过"/>
<RadioButton text="用过,感觉不好用"/>
<RadioButton text="没有Root权限无法使用"/>
</RadioGroup>
<radiogroup margin="0 16">
<radio text="没有用过"/>
<radio text="用过"/>
<radio text="用过,感觉不好用"/>
<radio text="没有Root权限无法使用"/>
</radiogroup>
<text textSize="16sp" margin="8">3. 您使用Auto.js通常用于做什么?(多选)</text>
<CheckBox text="游戏辅助" marginLeft="16"/>
<CheckBox text="点赞" marginLeft="16"/>
<CheckBox text="日常生活工作辅助" marginLeft="16"/>
<CheckBox text="练习编程" marginLeft="16"/>
<CheckBox text="自动化测试" marginLeft="16"/>
<checkbox text="游戏辅助" marginLeft="16"/>
<checkbox text="点赞" marginLeft="16"/>
<checkbox text="日常生活工作辅助" marginLeft="16"/>
<checkbox text="练习编程" marginLeft="16"/>
<checkbox text="自动化测试" marginLeft="16"/>
<linear>
<CheckBox text="其他" marginLeft="16"/>
<checkbox text="其他" marginLeft="16"/>
<input w="*" margin="0 16"/>
</linear>
<text textSize="16sp" margin="8">4. 您更喜欢以下哪个图标?</text>
<RadioGroup margin="0 16">
<RadioButton/>
<radiogroup margin="0 16">
<radio/>
<img w="100" h="100" margin="0 16" src="http://www.autojs.org/assets/uploads/profile/3-profileavatar.png"/>
<RadioButton/>
<radio/>
<img w="100" h="100" margin="0 16" src="http://www.autojs.org/assets/uploads/files/1511945512596-autojs_logo.png"/>
</RadioGroup>
</radiogroup>
<text textSize="16sp" margin="8">5. 您是什么时候开始使用Auto.js的呢?</text>
<DatePicker margin="4 16"/>
<datepicker margin="4 16" datePickerMode="spinner"/>
<text textSize="16sp" margin="8">6. 您用过下面这个Auto.js的论坛吗?</text>
<com.stardust.scriptdroid.ui.widget.EWebView id="webview" h="300" margin="0 16"/>
<RadioGroup marginLeft="16" marginTop="16">
<RadioButton text="没有用过"/>
<RadioButton text="用过"/>
<RadioButton text="用过,感觉不好用"/>
</RadioGroup>
<webview id="webview" h="300" margin="0 16"/>
<radiogroup marginLeft="16" marginTop="16">
<radio text="没有用过"/>
<radio text="用过"/>
<radio text="用过,感觉不好用"/>
</radiogroup>
<linear gravity="center">
<button margin="16">提交</button>
<button margin="16">放弃</button>

View File

@ -10,8 +10,6 @@ import android.widget.ImageView;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.flurry.android.FlurryAgent;
import com.nickandjerry.dynamiclayoutinflator.lib.ImageLoader;
import com.nickandjerry.dynamiclayoutinflator.lib.util.Drawables;
import com.raizlabs.android.dbflow.config.DatabaseConfig;
import com.raizlabs.android.dbflow.config.FlowConfig;
import com.raizlabs.android.dbflow.config.FlowManager;
@ -29,6 +27,9 @@ import com.stardust.theme.ThemeColor;
import com.stardust.theme.ThemeColorManager;
import com.stardust.util.UiHandler;
import org.autojs.dynamiclayoutinflater.ImageLoader;
import org.autojs.dynamiclayoutinflater.util.Drawables;
import java.lang.ref.WeakReference;
/**

View File

@ -40,9 +40,7 @@ dependencies {
})
testCompile 'junit:junit:4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.github.hyb1996:DynamicLayoutInflator:0.22', {
exclude group: 'com.android.support'
})
compile('com.github.hyb1996:DynamicLayoutInflator:0.26')
compile 'org.greenrobot:eventbus:3.0.0'
compile 'net.lingala.zip4j:zip4j:1.3.2'
compile('com.afollestad.material-dialogs:core:0.9.2.3', {

View File

@ -100,6 +100,23 @@ module.exports = function(__runtime__, scope){
});
}
function getColorDetector(color, algorithm, threshold){
switch(algorithm){
case "rgb":
return new com.stardust.autojs.core.image.ColorDetector.RGBDistanceDetector(color, threshold);
case "equal":
return new com.stardust.autojs.core.image.ColorDetector.EqualityDetector(color);
case "diff":
return new com.stardust.autojs.core.image.ColorDetector.DifferenceDetector(color, threshold);
case "rgb+":
return new com.stardust.autojs.core.image.ColorDetector.WeightedRGBDistanceDetector(color, threshold);
case "hs":
return new com.stardust.autojs.core.image.ColorDetector.HSDistanceDetector(color, threshold);
}
throw new Error("Unknown algorithm: " + algorithm);
}
function toPointArray(points){
var arr = [];
for(var i = 0; i < points.length; i++){

View File

@ -0,0 +1,199 @@
package com.stardust.autojs.core.image;
import android.graphics.Color;
/**
* Created by Stardust on 2017/5/20.
*/
public interface ColorDetector {
boolean detectsColor(int red, int green, int blue);
abstract class AbstractColorDetector implements ColorDetector {
protected final int mColor;
protected final int mR, mG, mB;
public AbstractColorDetector(int color) {
mColor = color;
mR = Color.red(color);
mG = Color.green(color);
mB = Color.blue(color);
}
}
class EqualityDetector extends AbstractColorDetector {
public EqualityDetector(int color) {
super(color);
}
@Override
public boolean detectsColor(int red, int green, int blue) {
return mR == red && mG == green && mB == blue;
}
}
class DifferenceDetector extends AbstractColorDetector {
private final int mThreshold;
public DifferenceDetector(int color, int threshold) {
super(color);
mThreshold = threshold * 3;
}
@Override
public boolean detectsColor(int R, int G, int B) {
return Math.abs(R - mR) + Math.abs(G - mG) + Math.abs(B - mB) <= mThreshold;
}
}
class RDistanceDetector extends AbstractColorDetector {
private final int mThreshold;
public RDistanceDetector(int color, int threshold) {
super(color);
mThreshold = threshold;
}
@Override
public boolean detectsColor(int R, int G, int B) {
return Math.abs(mR - R) <= mThreshold;
}
}
class RGBDistanceDetector extends AbstractColorDetector {
private final int mThreshold;
public RGBDistanceDetector(int color, int threshold) {
super(color);
mThreshold = threshold * threshold * 3;
}
@Override
public boolean detectsColor(int R, int G, int B) {
int dR = R - mR;
int dG = G - mG;
int dB = B - mB;
int d = dR * dR + dG * dG + dB * dB;
return d <= mThreshold;
}
}
class WeightedRGBDistanceDetector extends AbstractColorDetector {
private final int mThreshold;
private final int mR, mG, mB;
public WeightedRGBDistanceDetector(int color, int threshold) {
super(color);
mR = (color & 0xff0000) >> 16;
mG = (color & 0x00ff00) >> 8;
mB = color & 0xff;
mThreshold = threshold * threshold * 8;
}
@Override
public boolean detectsColor(int R, int G, int B) {
int dR = R - mR;
int dG = G - mG;
int dB = B - mB;
double meanR = (mR + R) / 2;
double weightR = 2 + meanR / 256;
double weightG = 4.0;
double weightB = 2 + (255 - meanR) / 256;
return weightR * dR * dR + weightG * dG * dG + weightB * dB * dB <= mThreshold;
}
}
class HDistanceDetector extends AbstractColorDetector {
private final int mH;
private final int mThreshold;
public HDistanceDetector(int color, int threshold) {
super(color);
mH = getH(mR, mG, mB);
mThreshold = threshold;
}
@Override
public boolean detectsColor(int R, int G, int B) {
return Math.abs(mH - getH(R, G, B)) <= mThreshold;
}
private static int getH(int R, int G, int B) {
int max, min, H;
if (R > G) {
min = Math.min(G, B);
max = Math.max(R, B);
} else {
min = Math.min(R, B);
max = Math.max(G, B);
}
if (R == max) {
H = (G - B) / (max - min) * 60;
} else if (G == max) {
H = 120 + (B - R) / (max - min) * 60;
} else {
H = 240 + (R - G) / (max - min) * 60;
}
if (H < 0) H = H + 360;
return H;
}
}
class HSDistanceDetector extends AbstractColorDetector {
private final int mH, mS;
private final int mThreshold;
public HSDistanceDetector(int color, int threshold) {
super(color);
long HS = getHS(mR, mG, mB);
mH = (int) (HS & 0xffffffffL);
mS = (int) ((HS >> 32) & 0xffffffffL);
mThreshold = threshold * 3729600 / 255;
}
public HSDistanceDetector(int color, float similarity) {
this(color, (int) (1.0f - similarity) * 255);
}
@Override
public boolean detectsColor(int R, int G, int B) {
long hs = getHS(R, G, B);
int dH = (int) (hs & 0xffffffffL) - mH;
int dS = (int) ((hs >> 32) & 0xffffffffL) - mS;
return dH * dH + dS * dS <= mThreshold;
}
private static long getHS(int R, int G, int B) {
int max, min, H;
if (R > G) {
min = Math.min(G, B);
max = Math.max(R, B);
} else {
min = Math.min(R, B);
max = Math.max(G, B);
}
if (R == max) {
H = (G - B) / (max - min) * 60;
} else if (G == max) {
H = 120 + (B - R) / (max - min) * 60;
} else {
H = 240 + (R - G) / (max - min) * 60;
}
if (H < 0) H = H + 360;
int S = (max - min) * 100 / max;
return H & ((long) S << 32);
}
}
}

View File

@ -6,12 +6,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.nickandjerry.dynamiclayoutinflator.lib.DynamicLayoutInflater;
import com.nickandjerry.dynamiclayoutinflator.lib.util.Drawables;
import com.stardust.autojs.core.ui.widget.JsFrameLayout;
import com.stardust.autojs.core.ui.xml.XmlConverter;
import com.stardust.util.MapEntries;
import org.autojs.dynamiclayoutinflater.DynamicLayoutInflater;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

View File

@ -7,7 +7,7 @@ import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import com.nickandjerry.dynamiclayoutinflator.lib.util.Ids;
import org.autojs.dynamiclayoutinflater.util.Ids;
/**
@ -18,7 +18,7 @@ public class JsViewHelper {
@Nullable
public static View findViewByStringId(View view, String id) {
View result = view.findViewById(Ids.getIdFromName(id));
View result = view.findViewById(Ids.parse(id));
if (result != null)
return result;
if (!(view instanceof ViewGroup)) {

View File

@ -1,13 +1,16 @@
package com.stardust.autojs.core.ui.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
/**
* Created by Stardust on 2017/5/15.
*/
public class JsButton extends android.support.v7.widget.AppCompatButton {
@SuppressLint("AppCompatCustomView")
public class JsButton extends Button {
public JsButton(Context context) {
super(context);
}
@ -20,6 +23,10 @@ public class JsButton extends android.support.v7.widget.AppCompatButton {
super(context, attrs, defStyleAttr);
}
public JsButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public String text() {
return getText().toString();
}

View File

@ -1,13 +1,18 @@
package com.stardust.autojs.core.ui.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.EditText;
/**
* Created by Stardust on 2017/5/15.
*/
public class JsEditText extends android.support.v7.widget.AppCompatEditText {
@SuppressLint("AppCompatCustomView")
public class JsEditText extends EditText {
public JsEditText(Context context) {
super(context);
}
@ -18,6 +23,12 @@ public class JsEditText extends android.support.v7.widget.AppCompatEditText {
public JsEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public JsEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public String text() {

View File

@ -1,14 +1,19 @@
package com.stardust.autojs.core.ui.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Created by Stardust on 2017/5/15.
*/
public class JsTextView extends android.support.v7.widget.AppCompatTextView {
@SuppressLint("AppCompatCustomView")
public class JsTextView extends TextView {
public JsTextView(Context context) {
super(context);
}
@ -21,6 +26,11 @@ public class JsTextView extends android.support.v7.widget.AppCompatTextView {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public JsTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public String text() {
return getText().toString();
}

View File

@ -0,0 +1,52 @@
package com.stardust.autojs.core.ui.widget;
import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
/**
* Created by Stardust on 2017/11/29.
*/
public class JsWebView extends WebView {
public JsWebView(Context context) {
super(context);
init();
}
public JsWebView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public JsWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public JsWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
WebSettings settings = getSettings();
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setDisplayZoomControls(false);
setWebViewClient(new WebViewClient());
setWebChromeClient(new WebChromeClient());
}
}

View File

@ -1,11 +1,22 @@
package com.stardust.autojs.core.ui.xml;
import android.webkit.WebView;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TimePicker;
import com.stardust.autojs.core.ui.widget.JsButton;
import com.stardust.autojs.core.ui.widget.JsEditText;
import com.stardust.autojs.core.ui.widget.JsFrameLayout;
import com.stardust.autojs.core.ui.widget.JsLinearLayout;
import com.stardust.autojs.core.ui.widget.JsRelativeLayout;
import com.stardust.autojs.core.ui.widget.JsTextView;
import com.stardust.autojs.core.ui.widget.JsWebView;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@ -16,6 +27,7 @@ import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.StringReader;
import java.util.Date;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -32,11 +44,21 @@ public class XmlConverter {
.defaultHandler(new NodeHandler.MapNameHandler()
.map("frame", JsFrameLayout.class.getName())
.map("linear", JsLinearLayout.class.getName())
.map("horizontal", JsLinearLayout.class.getName())
.map("relative", JsRelativeLayout.class.getName())
.map("button", JsButton.class.getName())
.map("text", JsTextView.class.getName())
.map("input", JsEditText.class.getName())
.map("img", "ImageView")
.map("datepicker", DatePicker.class.getName())
.map("timepicker", TimePicker.class.getName())
.map("webview", JsWebView.class.getName())
.map("progressbar", ProgressBar.class.getName())
.map("seekbar", SeekBar.class.getName())
.map("spinner", Spinner.class.getName())
.map("radio", RadioButton.class.getName())
.map("radiogroup", RadioGroup.class.getName())
.map("checkbox", CheckBox.class.getName())
);
private static final AttributeHandler ATTRIBUTE_HANDLER = new AttributeHandler.AttrNameRouter()

View File

@ -14,8 +14,6 @@ import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
import com.nickandjerry.dynamiclayoutinflator.lib.ImageLoader;
import com.nickandjerry.dynamiclayoutinflator.lib.util.Drawables;
import com.stardust.autojs.annotation.ScriptVariable;
import com.stardust.autojs.core.image.ColorFinder;
import com.stardust.autojs.core.image.ImageWrapper;