feat(ui): spinner: textSize, textColor, textStyle, entryTextSize, entryTextColor, entryTextStyle
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -8,8 +8,8 @@ android {
|
|||||||
applicationId "org.autojs.autojs"
|
applicationId "org.autojs.autojs"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 403
|
versionCode 406
|
||||||
versionName "4.0.2 Alpha"
|
versionName "4.0.2 Alpha2"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -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.ToolbarInflater;
|
||||||
import com.stardust.autojs.core.ui.inflater.inflaters.ViewGroupInflater;
|
import com.stardust.autojs.core.ui.inflater.inflaters.ViewGroupInflater;
|
||||||
import com.stardust.autojs.core.ui.inflater.util.Res;
|
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.JsTabLayout;
|
||||||
import com.stardust.autojs.core.ui.widget.JsToolbar;
|
import com.stardust.autojs.core.ui.widget.JsToolbar;
|
||||||
import com.stardust.autojs.core.ui.xml.XmlConverter;
|
import com.stardust.autojs.core.ui.xml.XmlConverter;
|
||||||
@@ -126,7 +127,7 @@ public class DynamicLayoutInflater {
|
|||||||
registerViewAttrSetter(DatePicker.class.getName(), new DatePickerInflater(mResourceParser));
|
registerViewAttrSetter(DatePicker.class.getName(), new DatePickerInflater(mResourceParser));
|
||||||
registerViewAttrSetter(RadioGroup.class.getName(), new RadioGroupInflater<>(mResourceParser));
|
registerViewAttrSetter(RadioGroup.class.getName(), new RadioGroupInflater<>(mResourceParser));
|
||||||
registerViewAttrSetter(ProgressBar.class.getName(), new ProgressBarInflater<>(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(TimePicker.class.getName(), new TimePickerInflater(mResourceParser));
|
||||||
registerViewAttrSetter(AppBarLayout.class.getName(), new AppBarInflater<>(mResourceParser));
|
registerViewAttrSetter(AppBarLayout.class.getName(), new AppBarInflater<>(mResourceParser));
|
||||||
registerViewAttrSetter(JsTabLayout.class.getName(), new TabLayoutInflater<>(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.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.SimpleAdapter;
|
import android.widget.SimpleAdapter;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
import com.stardust.autojs.R;
|
||||||
import com.stardust.autojs.core.ui.inflater.ResourceParser;
|
import com.stardust.autojs.core.ui.inflater.ResourceParser;
|
||||||
import com.stardust.autojs.core.ui.inflater.ViewCreator;
|
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.Dimensions;
|
||||||
import com.stardust.autojs.core.ui.inflater.util.Strings;
|
import com.stardust.autojs.core.ui.inflater.util.Strings;
|
||||||
import com.stardust.autojs.core.ui.inflater.util.ValueMapper;
|
import com.stardust.autojs.core.ui.inflater.util.ValueMapper;
|
||||||
|
import com.stardust.autojs.core.ui.widget.JsSpinner;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -21,7 +26,7 @@ import java.util.Map;
|
|||||||
* Created by Stardust on 2017/11/29.
|
* 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")
|
protected static final ValueMapper<Integer> SPINNER_MODES = new ValueMapper<Integer>("spinnerMode")
|
||||||
.map("dialog", Spinner.MODE_DIALOG)
|
.map("dialog", Spinner.MODE_DIALOG)
|
||||||
@@ -32,38 +37,48 @@ public class SpinnerInflater extends BaseViewInflater<Spinner> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
switch (attr) {
|
||||||
case "dropDownHorizontalOffset":
|
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;
|
break;
|
||||||
case "dropDownSelector":
|
case "dropDownSelector":
|
||||||
Exceptions.unsupports(view, attr, value);
|
Exceptions.unsupports(view, attr, value);
|
||||||
break;
|
break;
|
||||||
case "dropDownVerticalOffset":
|
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;
|
break;
|
||||||
case "dropDownWidth":
|
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;
|
break;
|
||||||
case "popupBackground":
|
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;
|
break;
|
||||||
case "prompt":
|
case "prompt":
|
||||||
view.setPrompt(Strings.parse(view, value));
|
view.setPrompt(Strings.parse(view, value));
|
||||||
break;
|
break;
|
||||||
case "entries":
|
case "entries":
|
||||||
view.setAdapter(new ArrayAdapter<>(view.getContext(),
|
view.setAdapter(view.new Adapter(view.getContext(),
|
||||||
android.R.layout.simple_spinner_dropdown_item, value.split("[|]")));
|
android.R.layout.simple_spinner_dropdown_item, value.split("[|]")));
|
||||||
break;
|
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:
|
default:
|
||||||
return super.setAttr(view, attr, value, parent, attrs);
|
return super.setAttr(view, attr, value, parent, attrs);
|
||||||
}
|
}
|
||||||
@@ -73,22 +88,14 @@ public class SpinnerInflater extends BaseViewInflater<Spinner> {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public ViewCreator<Spinner> getCreator() {
|
public ViewCreator<Spinner> getCreator() {
|
||||||
return new ViewCreator<Spinner>() {
|
return (context, attrs) -> {
|
||||||
@Override
|
String mode = attrs.remove("android:spinnerMode");
|
||||||
public Spinner create(Context context, Map<String, String> attrs) {
|
if (mode == null) {
|
||||||
String mode = attrs.remove("android:spinnerMode");
|
return new JsSpinner(context);
|
||||||
if (mode == null) {
|
|
||||||
return new Spinner(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class TextViewInflater<V extends TextView> extends BaseViewInflater<V> {
|
|||||||
.map("number", InputType.TYPE_CLASS_NUMBER)
|
.map("number", InputType.TYPE_CLASS_NUMBER)
|
||||||
.map("signed", InputType.TYPE_NUMBER_FLAG_SIGNED);
|
.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("bold", Typeface.BOLD)
|
||||||
.map("italic", Typeface.ITALIC)
|
.map("italic", Typeface.ITALIC)
|
||||||
.map("normal", Typeface.NORMAL);
|
.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.JsLinearLayout;
|
||||||
import com.stardust.autojs.core.ui.widget.JsListView;
|
import com.stardust.autojs.core.ui.widget.JsListView;
|
||||||
import com.stardust.autojs.core.ui.widget.JsRelativeLayout;
|
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.JsTabLayout;
|
||||||
import com.stardust.autojs.core.ui.widget.JsTextView;
|
import com.stardust.autojs.core.ui.widget.JsTextView;
|
||||||
import com.stardust.autojs.core.ui.widget.JsToolbar;
|
import com.stardust.autojs.core.ui.widget.JsToolbar;
|
||||||
@@ -68,7 +69,7 @@ public class XmlConverter {
|
|||||||
.map("webview", JsWebView.class.getName())
|
.map("webview", JsWebView.class.getName())
|
||||||
.map("progressbar", ProgressBar.class.getName())
|
.map("progressbar", ProgressBar.class.getName())
|
||||||
.map("seekbar", SeekBar.class.getName())
|
.map("seekbar", SeekBar.class.getName())
|
||||||
.map("spinner", Spinner.class.getName())
|
.map("spinner", JsSpinner.class.getName())
|
||||||
.map("radio", RadioButton.class.getName())
|
.map("radio", RadioButton.class.getName())
|
||||||
.map("radiogroup", RadioGroup.class.getName())
|
.map("radiogroup", RadioGroup.class.getName())
|
||||||
.map("checkbox", CheckBox.class.getName())
|
.map("checkbox", CheckBox.class.getName())
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ public class IntentUtil {
|
|||||||
return goToAppDetailSettings(context, context.getPackageName());
|
return goToAppDetailSettings(context, context.getPackageName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: 2018/7/11 Permission denial
|
||||||
public static void installApk(Context context, String path) {
|
public static void installApk(Context context, String path) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user