下面列出了怎么用android.content.res.TypedArray的API类实例代码及写法,或者点击链接到github查看源代码。
private void loadStateFromAttrs(AttributeSet attributeSet) {
if (attributeSet == null) {
return; // quick exit
}
TypedArray a = null;
try {
a = getContext().obtainStyledAttributes(attributeSet, R.styleable.editor);
this.editorSettings.placeHolder = a.getString(R.styleable.editor_placeholder);
this.editorSettings.autoFocus = a.getBoolean(R.styleable.editor_auto_focus, true);
String renderType = a.getString(R.styleable.editor_render_type);
if (TextUtils.isEmpty(renderType)) {
this.editorSettings.renderType = com.github.irshulx.models.RenderType.Editor;
} else {
this.editorSettings.renderType = renderType.toLowerCase().equals("renderer") ? RenderType.Renderer : RenderType.Editor;
}
} finally {
if (a != null) {
a.recycle(); // ensure this is always called
}
}
}
public BottomBar(Context context, AttributeSet attrs)
{
super(context, attrs);
mCircleRadius = getResources()
.getDimensionPixelSize(R.dimen.video_capture_circle_diameter) / 2;
mBackgroundAlphaOverlay = getResources()
.getInteger(R.integer.bottom_bar_background_alpha_overlay);
mBackgroundAlphaDefault = getResources()
.getInteger(R.integer.bottom_bar_background_alpha);
// preload all the drawable BGs
TypedArray ar = context.getResources()
.obtainTypedArray(R.array.shutter_button_backgrounds);
int len = ar.length();
mShutterButtonBackgroundConstantStates = new Drawable.ConstantState[len];
for (int i = 0; i < len; i++)
{
int drawableId = ar.getResourceId(i, -1);
mShutterButtonBackgroundConstantStates[i] =
context.getResources().getDrawable(drawableId).getConstantState();
}
ar.recycle();
}
public GridLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mDefaultGap = context.getResources().getDimensionPixelOffset(R.dimen.default_gap);
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.GridLayout, defStyleAttr, defStyleRes);
try {
setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION));
setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS));
setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE));
setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
} finally {
a.recycle();
}
}
public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
android.preference.RingtonePreference proxyPreference;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
proxyPreference = new android.preference.RingtonePreference(context, attrs, defStyleAttr, defStyleRes);
} else {
proxyPreference = new android.preference.RingtonePreference(context, attrs, defStyleAttr);
}
ringtoneType = proxyPreference.getRingtoneType();
showDefault = proxyPreference.getShowDefault();
showSilent = proxyPreference.getShowSilent();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RingtonePreference, defStyleAttr, 0);
showAdd = a.getBoolean(R.styleable.RingtonePreference_showAdd, true);
// summaryHasRingtone = a.getText(R.styleable.RingtonePreference_summaryHasRingtone);
a.recycle();
// summary = super.getSummary();
}
MoviesAdapter(Context context) {
// Get the default accent color
Resources.Theme theme = context.getTheme();
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {
R.attr.colorAccent, R.attr.dimmedNeutralColor
});
themeAccentColor = styledAttributes.getColor(styledAttributes.getIndex(0), getResources().getColor(R.color.default_accent));
dimmedNeutralColor = styledAttributes.getColor(styledAttributes.getIndex(1), getResources().getColor(R.color.white_dim_26pct));
styledAttributes.recycle();
this.hostManager = HostManager.getInstance(context);
// Get the art dimensions
// Use the same dimensions as in the details fragment, so that it hits Picasso's cache when
// the user transitions to that fragment, avoiding another call and imediatelly showing the image
Resources resources = context.getResources();
artWidth = (int)(resources.getDimension(R.dimen.now_playing_poster_width) /
UIUtils.IMAGE_RESIZE_FACTOR);
artHeight = (int)(resources.getDimension(R.dimen.now_playing_poster_height) /
UIUtils.IMAGE_RESIZE_FACTOR);
}
public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
paint = new Paint();
TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgressBar);
// 获取自定义属性和默认值
int color = GosDeploy.setConfigProgressViewColor();
roundColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundColor, color);
roundProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundProgressColor, color);
textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.BLACK);
textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 35);
roundWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_roundWidth, 3);
max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100);
textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true);
style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0);
mTypedArray.recycle();
}
@SuppressWarnings("ResourceType")
@Override
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
Context context = mView.getContext();
TypedArray a = context.obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
for (int tintIndex = 0; tintIndex < 4; tintIndex++) {
int modeIndex = tintIndex + 4;
mCompoundDrawableResIds[tintIndex] = a.getResourceId(tintIndex, 0);
mCompoundDrawableTintResIds[tintIndex] = a.getResourceId(tintIndex, 0);
if (a.hasValue(modeIndex)) {
mCompoundDrawableTintModes[tintIndex] = DrawableUtils.parseTintMode(a.getInt(modeIndex, 0), null);
}
}
mCompoundDrawableResIds[0] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableLeft);
mCompoundDrawableResIds[1] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableTop);
mCompoundDrawableResIds[2] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableRight);
mCompoundDrawableResIds[3] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableBottom);
a.recycle();
setCompoundDrawablesWithIntrinsicBounds(getCompoundDrawableByPosition(0), getCompoundDrawableByPosition(1), getCompoundDrawableByPosition(2), getCompoundDrawableByPosition(3));
}
private void init(Context context, AttributeSet attributeSet) {
mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));
mLabelsMargin = getResources().getDimensionPixelSize(R.dimen.fab_labels_margin);
mLabelsVerticalOffset = getResources().getDimensionPixelSize(R.dimen.fab_shadow_offset);
mTouchDelegateGroup = new TouchDelegateGroup(this);
setTouchDelegate(mTouchDelegateGroup);
TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonPlusIconColor, getColor(android.R.color.white));
mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
mAddButtonSize = attr.getInt(R.styleable.FloatingActionsMenu_fab_addButtonSize, FloatingActionButton.SIZE_NORMAL);
mAddButtonStrokeVisible = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_addButtonStrokeVisible, true);
mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP);
mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionsMenu_fab_labelStyle, 0);
mLabelsPosition = attr.getInt(R.styleable.FloatingActionsMenu_fab_labelsPosition, LABELS_ON_LEFT_SIDE);
attr.recycle();
if (mLabelsStyle != 0 && expandsHorizontally()) {
throw new IllegalStateException("Action labels in horizontal expand orientation is not supported.");
}
createAddButton(context);
}
public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
super.setScaleType(SCALE_TYPE);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);
a.recycle();
mReady = true;
if (mSetupPending) {
setup();
mSetupPending = false;
}
}
/**
* Retrieve styles attributes
*/
private void getAttributes(AttributeSet attrs) {
TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.PickerUI, 0, 0);
if (typedArray != null) {
try {
mUseBlur = typedArray.getBoolean(R.styleable.PickerUI_blur,
PickerUIBlur.DEFAULT_USE_BLUR);
mBlurRadius = typedArray.getInteger(R.styleable.PickerUI_blur_radius,
PickerUIBlur.DEFAULT_BLUR_RADIUS);
mDownScaleFactor = typedArray.getFloat(R.styleable.PickerUI_blur_downScaleFactor,
PickerUIBlur.DEFAULT_DOWNSCALE_FACTOR);
mFilterColor = typedArray.getColor(R.styleable.PickerUI_blur_FilterColor, -1);
mUseRenderScript = typedArray.getBoolean(R.styleable.PickerUI_blur_use_renderscript,
PickerUIBlur.DEFAULT_USE_BLUR_RENDERSCRIPT);
} catch (Exception e) {
Log.e(LOG_TAG, "Error while creating the view PickerUI with PickerUIBlurHelper: ",
e);
} finally {
typedArray.recycle();
}
}
}
public EaseSwitchButton(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.EaseSwitchButton);
Drawable openDrawable = ta.getDrawable(R.styleable.EaseSwitchButton_switchOpenImage);
Drawable closeDrawable = ta.getDrawable(R.styleable.EaseSwitchButton_switchCloseImage);
int switchStatus = ta.getInt(R.styleable.EaseSwitchButton_switchStatus, 0);
ta.recycle();
LayoutInflater.from(context).inflate(R.layout.ease_widget_switch_button, this);
openImage = (ImageView) findViewById(R.id.iv_switch_open);
closeImage = (ImageView) findViewById(R.id.iv_switch_close);
if(openDrawable != null){
openImage.setImageDrawable(openDrawable);
}
if(closeDrawable != null){
closeImage.setImageDrawable(closeDrawable);
}
if(switchStatus == 1){
closeSwitch();
}
}
@Override
protected void apply(TextView view, TypedArray typedArray) {
mTextView = view;
boolean isAutofit = typedArray.getBoolean(R.styleable.AutofitDecorator_decorAutofitText, false);
if(!isAutofit) return;
float scaledDensity = mTextView.getContext().getResources().getDisplayMetrics().scaledDensity;
boolean sizeToFit = true;
int minTextSize = (int) scaledDensity * DEFAULT_MIN_TEXT_SIZE;
float precision = PRECISION;
//TODO: deal with case when one of these values is absent
sizeToFit = typedArray.getBoolean(R.styleable.AutofitDecorator_decorSizeToFit, sizeToFit);
minTextSize = typedArray.getDimensionPixelSize(R.styleable.AutofitDecorator_decorMinTextSize, minTextSize);
precision = typedArray.getFloat(R.styleable.AutofitDecorator_decorPrecision, precision);
mPaint = new TextPaint();
setSizeToFit(sizeToFit);
setRawTextSize(mTextView.getTextSize());
setRawMinTextSize(minTextSize);
setPrecision(precision);
}
/**
* Obtains the üadding from a specific theme.
*
* @param themeResourceId
* The resource id of the theme, the padding should be obtained from, as an {@link
* Integer} value
*/
private void obtainPadding(@StyleRes final int themeResourceId) {
TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
new int[]{R.attr.materialDialogPaddingLeft, R.attr.materialDialogPaddingTop,
R.attr.materialDialogPaddingRight, R.attr.materialDialogPaddingBottom});
int defaultLeftPadding =
getContext().getResources().getDimensionPixelSize(R.dimen.dialog_left_padding);
int defaultTopPadding =
getContext().getResources().getDimensionPixelSize(R.dimen.dialog_top_padding);
int defaultRightPadding =
getContext().getResources().getDimensionPixelSize(R.dimen.dialog_right_padding);
int defaultBottomPadding =
getContext().getResources().getDimensionPixelSize(R.dimen.dialog_bottom_padding);
int left = typedArray.getDimensionPixelSize(0, defaultLeftPadding);
int top = typedArray.getDimensionPixelSize(1, defaultTopPadding);
int right = typedArray.getDimensionPixelSize(2, defaultRightPadding);
int bottom = typedArray.getDimensionPixelSize(3, defaultBottomPadding);
setPadding(left, top, right, bottom);
}
@SuppressWarnings("ResourceType")
public void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
TypedArray array = mSwitchCompat.getContext().obtainStyledAttributes(attrs, sAttrs, defStyleAttr, 0);
if (array.hasValue(1)) {
mTintResId = array.getResourceId(1, 0);
if (array.hasValue(2)) {
setSupportDrawableTintMode(mTintMode = DrawableUtils.parseTintMode(array.getInt(2, 0), null));
}
setSupportDrawableTint(mTintResId);
} else {
Drawable drawable = mTintManager.getDrawable(mResId = array.getResourceId(0, 0));
if (drawable != null) {
setDrawable(drawable);
}
}
array.recycle();
}
private void initView(Context context, AttributeSet attrs) {
color = Color.WHITE;
width = dpToPx(context, DEFAULT_WIDTH);
shadowPosition = dpToPx(getContext(), DEFAULT_SHADOW_POSITION);
speedOfDegree = DEFAULT_SPEED_OF_DEGREE;
if (null != attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RotateLoading);
color = typedArray.getColor(R.styleable.RotateLoading_loading_color, Color.WHITE);
width = typedArray.getDimensionPixelSize(R.styleable.RotateLoading_loading_width, dpToPx(context, DEFAULT_WIDTH));
shadowPosition = typedArray.getInt(R.styleable.RotateLoading_shadow_position, DEFAULT_SHADOW_POSITION);
speedOfDegree = typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE);
typedArray.recycle();
}
speedOfArc = speedOfDegree / 4;
mPaint = new Paint();
mPaint.setColor(color);
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(width);
mPaint.setStrokeCap(Paint.Cap.ROUND);
}
public MongolLabel(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.MongolLabel, 0, 0);
try {
String text = a.getString(R.styleable.MongolLabel_text);
if (text == null) text = "";
mUnicodeText = text;
mTextSizePx = a.getDimensionPixelSize(R.styleable.MongolLabel_textSize, 0);
mTextColor = a.getColor(R.styleable.MongolLabel_textColor, Color.BLACK);
} finally {
a.recycle();
}
mContext = context;
init();
}
public LabelView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray attr = context.obtainStyledAttributes(
attrs, R.styleable.LabelView, defStyleAttr, 0);
// Background values
mBackgroundColor = attr.getColor(R.styleable.LabelView_labelBackgroundColor, 0);
mRippleColor = attr.getColor(R.styleable.LabelView_labelRippleColor, 0);
mCornerRadius = attr.getDimension(R.styleable.LabelView_labelCornerRadius, 0f);
mElevation = attr.getDimension(R.styleable.LabelView_labelElevation, 0f);
// Padding values
int paddingHorizontal = attr.getDimensionPixelSize(
R.styleable.LabelView_labelPaddingHorizontal, 0);
int paddingVertical = attr.getDimensionPixelSize(
R.styleable.LabelView_labelPaddingVertical, 0);
attr.recycle();
setFocusable(true);
setClickable(true);
initBackground();
setCompatPadding(paddingHorizontal, paddingVertical, paddingHorizontal, paddingVertical);
}
private void initialize(Context ctx, AttributeSet attrs, int defStyle) {
mContext = ctx;
mViewTreeObserber = getViewTreeObserver();
// 当布局可视后开始绘制标签
mViewTreeObserber.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (!mInitialized) {
mInitialized = true;
drawTags();
}
}
});
// get AttributeSet
TypedArray typeArray = ctx.obtainStyledAttributes(attrs, R.styleable.TagView, defStyle, defStyle);
this.lineMargin =(int) typeArray.getDimension(R.styleable.TagView_lineMargin, dipToPx(this.getContext(), Constants.DEFAULT_LINE_MARGIN));
this.tagMargin =(int) typeArray.getDimension(R.styleable.TagView_tagMargin, dipToPx(this.getContext(), Constants.DEFAULT_TAG_MARGIN));
this.textPaddingLeft =(int) typeArray.getDimension(R.styleable.TagView_textPaddingLeft, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_LEFT));
this.textPaddingRight =(int) typeArray.getDimension(R.styleable.TagView_textPaddingRight, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_RIGHT));
this.textPaddingTop =(int) typeArray.getDimension(R.styleable.TagView_textPaddingTop, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_TOP));
this.texPaddingBottom =(int) typeArray.getDimension(R.styleable.TagView_textPaddingBottom, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_BOTTOM));
this.backgrond = (int) typeArray.getColor(R.styleable.TagView_label_background, Constants.DEFAULT_TAG_LAYOUT_COLOR);
typeArray.recycle();
}
public RotateLoadingLayout(Context context, com.handmark.pulltorefresh.library.PullToRefreshBase.Mode mode, com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation orientation, TypedArray typedarray)
{
super(context, mode, orientation, typedarray);
h = typedarray.getBoolean(15, true);
mHeaderImage.setScaleType(android.widget.ImageView.ScaleType.MATRIX);
mHeaderImage.setImageMatrix(e);
d.setInterpolator(c);
d.setDuration(1200L);
d.setRepeatCount(-1);
d.setRepeatMode(1);
}
public static boolean getThemeAttrColor(Context context, int attr) {
TEMP_ARRAY[0] = attr;
TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY);
try {
return a.getBoolean(0, false);
} finally {
a.recycle();
}
}
private void obtainAttributes(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CommonTabLayout);
mIndicatorColorResId = ta.getResourceId(R.styleable.CommonTabLayout_tl_indicator_color, INVALID_ID);
mIndicatorColorResId = SkinCompatHelper.checkResourceId(mIndicatorColorResId);
mUnderlineColorResId = ta.getResourceId(R.styleable.CommonTabLayout_tl_underline_color, INVALID_ID);
mUnderlineColorResId = SkinCompatHelper.checkResourceId(mUnderlineColorResId);
mDividerColorResId = ta.getResourceId(R.styleable.CommonTabLayout_tl_divider_color, INVALID_ID);
mDividerColorResId = SkinCompatHelper.checkResourceId(mDividerColorResId);
mTextSelectColorResId = ta.getResourceId(R.styleable.CommonTabLayout_tl_textSelectColor, INVALID_ID);
mTextSelectColorResId = SkinCompatHelper.checkResourceId(mTextSelectColorResId);
mTextUnselectColorResId = ta.getResourceId(R.styleable.CommonTabLayout_tl_textUnselectColor, INVALID_ID);
mTextUnselectColorResId = SkinCompatHelper.checkResourceId(mTextUnselectColorResId);
ta.recycle();
applyCommonTabLayoutResources();
}
public BaseGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.GradientLine);
int ordinal = ta.getInt(R.styleable.GradientLine_gl_mode, Mode.None.ordinal());
mMode = Mode.values()[ordinal];
ta.recycle();
setLayerType(View.LAYER_TYPE_SOFTWARE, null); // 开启硬件加速,不然垂直虚线没效果
init();
}
private void initColors(Context context)
{
int[] colorAttrs = { android.R.attr.textColorPrimary };
TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
int def = Color.WHITE;
color_textTimeDelta = ContextCompat.getColor(context, typedArray.getResourceId(0, def));
typedArray.recycle();
}
/**
* Init custom attrs.
*
* @param attrs
* @param defStyle
*/
protected void initAttrs(AttributeSet attrs, int defStyle) {
TypedArray a = getContext().getTheme().obtainStyledAttributes(
attrs, R.styleable.card_options, defStyle, defStyle);
try {
card_layout_resourceID = a.getResourceId(R.styleable.card_options_card_layout_resourceID, card_layout_resourceID);
} finally {
a.recycle();
}
}
public RatioImage(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RatioImage, defStyleAttr, 0);
if (ta != null) {
ratioWidth = ta.getFloat(R.styleable.RatioImage_ri_ratio_width, 1);
ratioHeight = ta.getFloat(R.styleable.RatioImage_ri_ratio_height, 1);
standard = ta.getInt(R.styleable.RatioImage_ri_standard, 0);
ta.recycle();
}
}
private void initCustomAttrs(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BGABanner);
final int N = typedArray.getIndexCount();
for (int i = 0; i < N; i++) {
initCustomAttr(typedArray.getIndex(i), typedArray);
}
typedArray.recycle();
}
public MaterialRippleLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setWillNotDraw(false);
gestureDetector = new GestureDetector(context, longClickListener);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialRippleLayout);
rippleColor = a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleColor, DEFAULT_COLOR);
rippleDiameter = a.getDimensionPixelSize(
R.styleable.MaterialRippleLayout_mrl_rippleDimension,
(int) dpToPx(getResources(), DEFAULT_DIAMETER_DP)
);
rippleOverlay = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleOverlay, DEFAULT_RIPPLE_OVERLAY);
rippleHover = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleHover, DEFAULT_HOVER);
rippleDuration = a.getInt(R.styleable.MaterialRippleLayout_mrl_rippleDuration, DEFAULT_DURATION);
rippleAlpha = (int) (255 * a.getFloat(R.styleable.MaterialRippleLayout_mrl_rippleAlpha, DEFAULT_ALPHA));
rippleDelayClick = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleDelayClick, DEFAULT_DELAY_CLICK);
rippleFadeDuration = a.getInteger(R.styleable.MaterialRippleLayout_mrl_rippleFadeDuration, DEFAULT_FADE_DURATION);
rippleBackground = new ColorDrawable(a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleBackground, DEFAULT_BACKGROUND));
ripplePersistent = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_ripplePersistent, DEFAULT_PERSISTENT);
rippleInAdapter = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleInAdapter, DEFAULT_SEARCH_ADAPTER);
rippleRoundedCorners = a.getDimensionPixelSize(R.styleable.MaterialRippleLayout_mrl_rippleRoundedCorners, DEFAULT_ROUNDED_CORNERS);
a.recycle();
paint.setColor(rippleColor);
paint.setAlpha(rippleAlpha);
enableClipPathSupportIfNecessary();
}
public RangeBarVertical(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RangeBarVertical, 0, 0);
System.out.println(a.getIndexCount());
activeColor = a.getColor(R.styleable.RangeBarVertical_activeColor, Color.parseColor("#007FFF"));
inactiveColor = a.getColor(R.styleable.RangeBarVertical_inactiveColor, Color.parseColor("#808080"));
a.recycle();
initialize(context);
}
/**
* Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a
* {@link LinearLayoutManager}.
*
* @param context Current context, it will be used to access resources.
* @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}.
*/
public DividerItemDecoration(Context context, int orientation) {
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
if (mDivider == null) {
Log.w(TAG, "@android:attr/listDivider was not set in the theme used for this "
+ "DividerItemDecoration. Please set that attribute all call setDrawable()");
}
a.recycle();
setOrientation(orientation);
}
/**
* takes primary and primaryDark colors from context
*
* @return {@link ColorStateList} object, with primary color at selected state
* and primaryDark on unselected state
*/
private ColorStateList getContextColors() {
TypedValue typedValue = new TypedValue();
TypedArray a = getContext().obtainStyledAttributes(typedValue.data, new int[]{
R.attr.colorPrimary, R.attr.colorPrimaryDark});
int primaryColor = a.getColor(0, 0);
int primaryDarkColor = a.getColor(1, 0);
a.recycle();
return createColorStateList(primaryDarkColor, primaryColor);
}