mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
feat(ui): spinner: textSize, textColor, textStyle, entryTextSize, entryTextColor, entryTextStyle
This commit is contained in:
parent
5251028b0b
commit
093a19c491
Binary file not shown.
@ -8,8 +8,8 @@ android {
|
||||
applicationId "org.autojs.autojs"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 403
|
||||
versionName "4.0.2 Alpha"
|
||||
versionCode 406
|
||||
versionName "4.0.2 Alpha2"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
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.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);
|
||||
}
|
||||
@ -73,22 +88,14 @@ public class SpinnerInflater extends BaseViewInflater<Spinner> {
|
||||
@Nullable
|
||||
@Override
|
||||
public ViewCreator<Spinner> getCreator() {
|
||||
return new ViewCreator<Spinner>() {
|
||||
@Override
|
||||
public Spinner create(Context context, Map<String, String> attrs) {
|
||||
String mode = attrs.remove("android:spinnerMode");
|
||||
if (mode == null) {
|
||||
return new Spinner(context);
|
||||
}
|
||||
return new Spinner(context, SPINNER_MODES.get(mode));
|
||||
return (context, attrs) -> {
|
||||
String mode = attrs.remove("android:spinnerMode");
|
||||
if (mode == null) {
|
||||
return new JsSpinner(context);
|
||||
}
|
||||
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("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())
|
||||
|
||||
@ -84,6 +84,7 @@ public class IntentUtil {
|
||||
return goToAppDetailSettings(context, context.getPackageName());
|
||||
}
|
||||
|
||||
// FIXME: 2018/7/11 Permission denial
|
||||
public static void installApk(Context context, String path) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user