Merge branch 'dev' of https://github.com/hyb1996/NoRootScriptDroid into dev
# Conflicts: # autojs/src/main/java/com/stardust/autojs/core/ui/inflater/inflaters/SpinnerInflater.java
This commit is contained in:
@@ -10,6 +10,7 @@ import com.stardust.autojs.annotation.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.api.AbstractConsole;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.autojs.util.FloatingPermission;
|
||||
import com.stardust.concurrent.ConcurrentArrayList;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
@@ -151,8 +152,8 @@ public class StardustConsole extends AbstractConsole {
|
||||
if (mShown) {
|
||||
return;
|
||||
}
|
||||
if (!SettingsCompat.canDrawOverlays(mUiHandler.getContext())) {
|
||||
SettingsCompat.manageDrawOverlays(mUiHandler.getContext());
|
||||
if (!FloatingPermission.canDrawOverlays(mUiHandler.getContext())) {
|
||||
FloatingPermission.manageDrawOverlays(mUiHandler.getContext());
|
||||
mUiHandler.toast(R.string.text_no_floating_window_permission);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.stardust.autojs.core.ui.inflater.inflaters.TimePickerInflater;
|
||||
import com.stardust.autojs.core.ui.inflater.inflaters.ToolbarInflater;
|
||||
import com.stardust.autojs.core.ui.inflater.inflaters.ViewGroupInflater;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Res;
|
||||
import com.stardust.autojs.core.ui.widget.JsSpinner;
|
||||
import com.stardust.autojs.core.ui.widget.JsTabLayout;
|
||||
import com.stardust.autojs.core.ui.widget.JsToolbar;
|
||||
import com.stardust.autojs.core.ui.xml.XmlConverter;
|
||||
@@ -126,7 +127,7 @@ public class DynamicLayoutInflater {
|
||||
registerViewAttrSetter(DatePicker.class.getName(), new DatePickerInflater(mResourceParser));
|
||||
registerViewAttrSetter(RadioGroup.class.getName(), new RadioGroupInflater<>(mResourceParser));
|
||||
registerViewAttrSetter(ProgressBar.class.getName(), new ProgressBarInflater<>(mResourceParser));
|
||||
registerViewAttrSetter(Spinner.class.getName(), new SpinnerInflater(mResourceParser));
|
||||
registerViewAttrSetter(JsSpinner.class.getName(), new SpinnerInflater(mResourceParser));
|
||||
registerViewAttrSetter(TimePicker.class.getName(), new TimePickerInflater(mResourceParser));
|
||||
registerViewAttrSetter(AppBarLayout.class.getName(), new AppBarInflater<>(mResourceParser));
|
||||
registerViewAttrSetter(JsTabLayout.class.getName(), new TabLayoutInflater<>(mResourceParser));
|
||||
|
||||
@@ -2,17 +2,22 @@ package com.stardust.autojs.core.ui.inflater.inflaters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.ui.inflater.ResourceParser;
|
||||
import com.stardust.autojs.core.ui.inflater.ViewCreator;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Colors;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Dimensions;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Strings;
|
||||
import com.stardust.autojs.core.ui.inflater.util.ValueMapper;
|
||||
import com.stardust.autojs.core.ui.widget.JsSpinner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -21,7 +26,7 @@ import java.util.Map;
|
||||
* Created by Stardust on 2017/11/29.
|
||||
*/
|
||||
|
||||
public class SpinnerInflater extends BaseViewInflater<Spinner> {
|
||||
public class SpinnerInflater extends BaseViewInflater<JsSpinner> {
|
||||
|
||||
protected static final ValueMapper<Integer> SPINNER_MODES = new ValueMapper<Integer>("spinnerMode")
|
||||
.map("dialog", Spinner.MODE_DIALOG)
|
||||
@@ -32,38 +37,48 @@ public class SpinnerInflater extends BaseViewInflater<Spinner> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setAttr(Spinner view, String attr, String value, ViewGroup parent, Map<String, String> attrs) {
|
||||
public boolean setAttr(JsSpinner view, String attr, String value, ViewGroup parent, Map<String, String> attrs) {
|
||||
switch (attr) {
|
||||
case "dropDownHorizontalOffset":
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
view.setDropDownHorizontalOffset(Dimensions.parseToIntPixel(value, view));
|
||||
}
|
||||
view.setDropDownHorizontalOffset(Dimensions.parseToIntPixel(value, view));
|
||||
break;
|
||||
case "dropDownSelector":
|
||||
Exceptions.unsupports(view, attr, value);
|
||||
break;
|
||||
case "dropDownVerticalOffset":
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
view.setDropDownVerticalOffset(Dimensions.parseToIntPixel(value, view));
|
||||
}
|
||||
view.setDropDownVerticalOffset(Dimensions.parseToIntPixel(value, view));
|
||||
break;
|
||||
case "dropDownWidth":
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
view.setDropDownWidth(Dimensions.parseToIntPixel(value, view));
|
||||
}
|
||||
view.setDropDownWidth(Dimensions.parseToIntPixel(value, view));
|
||||
break;
|
||||
case "popupBackground":
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
view.setPopupBackgroundDrawable(getDrawables().parse(view, value));
|
||||
}
|
||||
view.setPopupBackgroundDrawable(getDrawables().parse(view, value));
|
||||
break;
|
||||
case "prompt":
|
||||
view.setPrompt(Strings.parse(view, value));
|
||||
break;
|
||||
case "entries":
|
||||
view.setAdapter(new ArrayAdapter<>(view.getContext(),
|
||||
view.setAdapter(view.new Adapter(view.getContext(),
|
||||
android.R.layout.simple_spinner_dropdown_item, value.split("[|]")));
|
||||
break;
|
||||
case "textStyle":
|
||||
view.setTextStyle(TextViewInflater.TEXT_STYLES.split(value));
|
||||
break;
|
||||
case "textColor":
|
||||
view.setTextColor(Colors.parse(view.getContext(), value));
|
||||
break;
|
||||
case "textSize":
|
||||
view.setTextSize(Dimensions.parseToPixel(value, view));
|
||||
break;
|
||||
case "entryTextStyle":
|
||||
view.setEntryTextStyle(TextViewInflater.TEXT_STYLES.split(value));
|
||||
break;
|
||||
case "entryTextColor":
|
||||
view.setEntryTextColor(Colors.parse(view.getContext(), value));
|
||||
break;
|
||||
case "entryTextSize":
|
||||
view.setEntryTextSize(Dimensions.parseToPixel(value, view));
|
||||
break;
|
||||
default:
|
||||
return super.setAttr(view, attr, value, parent, attrs);
|
||||
}
|
||||
@@ -76,16 +91,11 @@ public class SpinnerInflater extends BaseViewInflater<Spinner> {
|
||||
return (context, attrs) -> {
|
||||
String mode = attrs.remove("android:spinnerMode");
|
||||
if (mode == null) {
|
||||
return new Spinner(context);
|
||||
return new JsSpinner(context);
|
||||
}
|
||||
return new Spinner(context, SPINNER_MODES.get(mode));
|
||||
return new JsSpinner(context, SPINNER_MODES.get(mode));
|
||||
};
|
||||
}
|
||||
|
||||
private static class EntryAdapter extends SimpleAdapter {
|
||||
|
||||
public EntryAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
|
||||
super(context, data, resource, from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.stardust.autojs.core.ui.inflater.inflaters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -15,7 +14,6 @@ import com.stardust.autojs.core.ui.inflater.util.Colors;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Dimensions;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Gravities;
|
||||
import com.stardust.autojs.core.ui.inflater.util.ValueMapper;
|
||||
import com.stardust.autojs.core.ui.widget.JsTabLayout;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TextViewInflater<V extends TextView> extends BaseViewInflater<V> {
|
||||
.map("number", InputType.TYPE_CLASS_NUMBER)
|
||||
.map("signed", InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
|
||||
private static final ValueMapper<Integer> TEXT_STYLES = new ValueMapper<Integer>("textStyle")
|
||||
static final ValueMapper<Integer> TEXT_STYLES = new ValueMapper<Integer>("textStyle")
|
||||
.map("bold", Typeface.BOLD)
|
||||
.map("italic", Typeface.ITALIC)
|
||||
.map("normal", Typeface.NORMAL);
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.stardust.autojs.core.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class JsSpinner extends android.support.v7.widget.AppCompatSpinner {
|
||||
|
||||
private float mTextSize = -1;
|
||||
private int mTextStyle = -1;
|
||||
private int mTextColor = 0;
|
||||
|
||||
private float mEntryTextSize = -1;
|
||||
private int mEntryTextStyle = -1;
|
||||
private int mEntryTextColor = 0;
|
||||
|
||||
public JsSpinner(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public JsSpinner(Context context, int mode) {
|
||||
super(context, mode);
|
||||
}
|
||||
|
||||
public JsSpinner(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public JsSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public JsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) {
|
||||
super(context, attrs, defStyleAttr, mode);
|
||||
}
|
||||
|
||||
public JsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) {
|
||||
super(context, attrs, defStyleAttr, mode, popupTheme);
|
||||
}
|
||||
|
||||
|
||||
public float getTextSize() {
|
||||
return mTextSize;
|
||||
}
|
||||
|
||||
public float getEntryTextSize() {
|
||||
return mEntryTextSize;
|
||||
}
|
||||
|
||||
public void setEntryTextSize(float entryTextSize) {
|
||||
mEntryTextSize = entryTextSize;
|
||||
}
|
||||
|
||||
public int getEntryTextStyle() {
|
||||
return mEntryTextStyle;
|
||||
}
|
||||
|
||||
public void setEntryTextStyle(int entryTextStyle) {
|
||||
mEntryTextStyle = entryTextStyle;
|
||||
}
|
||||
|
||||
public int getEntryTextColor() {
|
||||
return mEntryTextColor;
|
||||
}
|
||||
|
||||
public void setEntryTextColor(int entryTextColor) {
|
||||
mEntryTextColor = entryTextColor;
|
||||
}
|
||||
|
||||
public void setTextSize(float textSize) {
|
||||
mTextSize = textSize;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child instanceof TextView) {
|
||||
((TextView) child).setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getTextStyle() {
|
||||
return mTextStyle;
|
||||
}
|
||||
|
||||
public void setTextStyle(int textStyle) {
|
||||
mTextStyle = textStyle;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child instanceof TextView) {
|
||||
((TextView) child).setTypeface(((TextView) child).getTypeface(), mTextStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getTextColor() {
|
||||
return mTextColor;
|
||||
}
|
||||
|
||||
public void setTextColor(int textColor) {
|
||||
mTextColor = textColor;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child instanceof TextView) {
|
||||
((TextView) child).setTextColor(mTextColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Adapter extends ArrayAdapter<String> {
|
||||
|
||||
public Adapter(@NonNull Context context, int resource, @NonNull String[] objects) {
|
||||
super(context, resource, objects);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
if (!(view instanceof TextView)) {
|
||||
return view;
|
||||
}
|
||||
TextView textView = (TextView) view;
|
||||
if (mTextColor != 0) {
|
||||
textView.setTextColor(mTextColor);
|
||||
}
|
||||
if (mTextSize != -1) {
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
|
||||
}
|
||||
if (mTextStyle != -1) {
|
||||
textView.setTypeface(textView.getTypeface(), mTextStyle);
|
||||
}
|
||||
return textView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
View view = super.getDropDownView(position, convertView, parent);
|
||||
if (!(view instanceof TextView)) {
|
||||
return view;
|
||||
}
|
||||
TextView textView = (TextView) view;
|
||||
if (mEntryTextColor != 0) {
|
||||
textView.setTextColor(mEntryTextColor);
|
||||
}
|
||||
if (mEntryTextSize != -1) {
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mEntryTextSize);
|
||||
}
|
||||
if (mEntryTextStyle != -1) {
|
||||
textView.setTypeface(textView.getTypeface(), mEntryTextStyle);
|
||||
}
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.stardust.autojs.core.ui.widget.JsImageView;
|
||||
import com.stardust.autojs.core.ui.widget.JsLinearLayout;
|
||||
import com.stardust.autojs.core.ui.widget.JsListView;
|
||||
import com.stardust.autojs.core.ui.widget.JsRelativeLayout;
|
||||
import com.stardust.autojs.core.ui.widget.JsSpinner;
|
||||
import com.stardust.autojs.core.ui.widget.JsTabLayout;
|
||||
import com.stardust.autojs.core.ui.widget.JsTextView;
|
||||
import com.stardust.autojs.core.ui.widget.JsToolbar;
|
||||
@@ -68,7 +69,7 @@ public class XmlConverter {
|
||||
.map("webview", JsWebView.class.getName())
|
||||
.map("progressbar", ProgressBar.class.getName())
|
||||
.map("seekbar", SeekBar.class.getName())
|
||||
.map("spinner", Spinner.class.getName())
|
||||
.map("spinner", JsSpinner.class.getName())
|
||||
.map("radio", RadioButton.class.getName())
|
||||
.map("radiogroup", RadioGroup.class.getName())
|
||||
.map("checkbox", CheckBox.class.getName())
|
||||
|
||||
@@ -4,9 +4,11 @@ import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.pio.PFileInterface;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/1/23.
|
||||
@@ -82,10 +84,23 @@ public class Files {
|
||||
return PFiles.read(path(path), encoding);
|
||||
}
|
||||
|
||||
|
||||
public String read(String path) {
|
||||
return PFiles.read(path(path));
|
||||
}
|
||||
|
||||
public String readAssets(String path, String encoding){
|
||||
try {
|
||||
return PFiles.read(mRuntime.getUiHandler().getContext().getAssets().open(path), encoding);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String readAssets(String path){
|
||||
return readAssets(path, "UTF-8");
|
||||
}
|
||||
|
||||
public byte[] readBytes(String path){
|
||||
return PFiles.readBytes(path(path));
|
||||
}
|
||||
@@ -185,4 +200,5 @@ public class Files {
|
||||
public String getSimplifiedPath(String path) {
|
||||
return PFiles.getSimplifiedPath(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.stardust.autojs.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.R;
|
||||
@@ -10,6 +16,11 @@ import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.enhancedfloaty.util.FloatingWindowPermissionUtil;
|
||||
import com.stardust.lang.ThreadCompat;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
import ezy.assist.compat.RomUtil;
|
||||
import ezy.assist.compat.SettingsCompat;
|
||||
|
||||
/**
|
||||
@@ -19,8 +30,20 @@ import ezy.assist.compat.SettingsCompat;
|
||||
public class FloatingPermission {
|
||||
|
||||
|
||||
private static final int OP_SYSTEM_ALERT_WINDOW = 24;
|
||||
private static Method sCheckOp;
|
||||
|
||||
static {
|
||||
try {
|
||||
sCheckOp = SettingsCompat.class.getDeclaredMethod("checkOp", Context.class, int.class);
|
||||
sCheckOp.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ensurePermissionGranted(Context context) {
|
||||
if (!SettingsCompat.canDrawOverlays(context)) {
|
||||
if (!canDrawOverlays(context)) {
|
||||
Toast.makeText(context, R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
manageDrawOverlays(context);
|
||||
return;
|
||||
@@ -28,7 +51,7 @@ public class FloatingPermission {
|
||||
}
|
||||
|
||||
public static void waitForPermissionGranted(Context context) throws InterruptedException {
|
||||
if (SettingsCompat.canDrawOverlays(context)) {
|
||||
if (canDrawOverlays(context)) {
|
||||
return;
|
||||
}
|
||||
Runnable r = () -> {
|
||||
@@ -41,7 +64,7 @@ public class FloatingPermission {
|
||||
r.run();
|
||||
}
|
||||
while (true) {
|
||||
if (SettingsCompat.canDrawOverlays(context))
|
||||
if (canDrawOverlays(context))
|
||||
return;
|
||||
Thread.sleep(200);
|
||||
}
|
||||
@@ -51,11 +74,42 @@ public class FloatingPermission {
|
||||
|
||||
public static void manageDrawOverlays(Context context) {
|
||||
try {
|
||||
SettingsCompat.manageDrawOverlays(context);
|
||||
if (RomUtil.isMiui() && TextUtils.equals("V10", RomUtil.getVersion())
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
manageDrawOverlaysForAndroidM(context);
|
||||
} else {
|
||||
SettingsCompat.manageDrawOverlays(context);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
FloatingWindowPermissionUtil.goToAppDetailSettings(context, context.getPackageName());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
manageDrawOverlaysForAndroidM(context);
|
||||
} else {
|
||||
FloatingWindowPermissionUtil.goToAppDetailSettings(context, context.getPackageName());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static void manageDrawOverlaysForAndroidM(Context context) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public static boolean canDrawOverlays(Context context) {
|
||||
return SettingsCompat.canDrawOverlays(context);
|
||||
}
|
||||
|
||||
private static boolean checkOp(Context context, int op) {
|
||||
if (sCheckOp == null) {
|
||||
return SettingsCompat.canDrawOverlays(context);
|
||||
}
|
||||
try {
|
||||
return (boolean) sCheckOp.invoke(null, context, op);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user