Java Code Examples for android.content.res.TypedArray#getColorStateList()
The following examples show how to use
android.content.res.TypedArray#getColorStateList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MorphButton.java From CanDialog with Apache License 2.0 | 6 votes |
private void readTintAttributes(TypedArray a) { mBackgroundTint = new TintInfo(); mForegroundTint = new TintInfo(); mBackgroundTint.mTintList = a.getColorStateList(R.styleable.MorphButton_vc_backgroundTint); mBackgroundTint.mHasTintList = mBackgroundTint.mTintList != null; mBackgroundTint.mTintMode = DrawableCompat.parseTintMode(a.getInt( R.styleable.MorphButton_vc_backgroundTintMode, -1), null); mBackgroundTint.mHasTintMode = mBackgroundTint.mTintMode != null; mForegroundTint.mTintList = a.getColorStateList(R.styleable.MorphButton_vc_foregroundTint); mForegroundTint.mHasTintList = mForegroundTint.mTintList != null; mForegroundTint.mTintMode = DrawableCompat.parseTintMode(a.getInt( R.styleable.MorphButton_vc_foregroundTintMode, -1), null); mForegroundTint.mHasTintMode = mForegroundTint.mTintMode != null; }
Example 2
Source File: IconImageView.java From edx-app-android with Apache License 2.0 | 6 votes |
public IconImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.IconImageView, defStyleAttr, 0); ColorStateList colorStateList = a.getColorStateList(R.styleable.IconImageView_iconColor); if (colorStateList != null) { this.colorStateList = colorStateList; } String iconKey = a.getString(R.styleable.IconImageView_iconName); if (iconKey != null) { IconDrawable drawable = new IconDrawable(context, iconKey); switch (Animation.values()[a.getInt(R.styleable.IconImageView_iconAnimation, Animation.NONE.ordinal())]) { case SPIN: drawable.spin(); break; case PULSE: drawable.pulse(); break; } setImageDrawable(drawable); } a.recycle(); }
Example 3
Source File: Carbon.java From Carbon with Apache License 2.0 | 6 votes |
public static void initElevation(ShadowView view, TypedArray a, int[] ids) { int carbon_elevation = ids[0]; int carbon_shadowColor = ids[1]; int carbon_ambientShadowColor = ids[2]; int carbon_spotShadowColor = ids[3]; float elevation = a.getDimension(carbon_elevation, 0); view.setElevation(elevation); if (elevation > 0) AnimUtils.setupElevationAnimator(((StateAnimatorView) view).getStateAnimator(), view); ColorStateList shadowColor = a.getColorStateList(carbon_shadowColor); view.setElevationShadowColor(shadowColor != null ? shadowColor.withAlpha(255) : null); if (a.hasValue(carbon_ambientShadowColor)) { ColorStateList ambientShadowColor = a.getColorStateList(carbon_ambientShadowColor); view.setOutlineAmbientShadowColor(ambientShadowColor != null ? ambientShadowColor.withAlpha(255) : null); } if (a.hasValue(carbon_spotShadowColor)) { ColorStateList spotShadowColor = a.getColorStateList(carbon_spotShadowColor); view.setOutlineSpotShadowColor(spotShadowColor != null ? spotShadowColor.withAlpha(255) : null); } }
Example 4
Source File: CalcImageButton.java From ncalc with GNU General Public License v3.0 | 5 votes |
private void setup(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CalcImageButton); mColorStateList = ta.getColorStateList(R.styleable.CalcImageButton_android_textColor); refreshDrawableState(); ta.recycle(); } }
Example 5
Source File: Utils.java From DateTimePicker with Apache License 2.0 | 5 votes |
@Nullable public static Drawable getDrawable(Context context, TypedArray original, int index, int tintResId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return original.getDrawable(index); } int resId = original.getResourceId(index, 0); Drawable drawable = AppCompatResources.getDrawable(context, resId); if (drawable != null) { Drawable wrapped = DrawableCompat.wrap(drawable); DrawableCompat.applyTheme(wrapped, context.getTheme()); TypedArray a = context.obtainStyledAttributes(new int[]{tintResId}); ColorStateList tintList = a.getColorStateList(0); if (tintList != null) { DrawableCompat.setTintList(wrapped, tintList); } drawable = wrapped; a.recycle(); } return drawable; }
Example 6
Source File: HelperTextInputLayout.java From ETHWallet with GNU General Public License v3.0 | 5 votes |
public HelperTextInputLayout(Context _context, AttributeSet _attrs) { super(_context, _attrs); final TypedArray a = getContext().obtainStyledAttributes( _attrs, R.styleable.HelperTextInputLayout,0,0); try { mHelperTextColor = a.getColorStateList(R.styleable.HelperTextInputLayout_helperTextColor); mHelperText = a.getText(R.styleable.HelperTextInputLayout_helperText); } finally { a.recycle(); } }
Example 7
Source File: SVGImageView.java From SVG-Android with Apache License 2.0 | 5 votes |
public SVGImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SVGView); mSvgColor = a.getColorStateList(R.styleable.SVGView_svgColor); mSvgAlpha = a.getFloat(R.styleable.SVGView_svgAlpha, 1.0f); mSvgWidth = a.getDimensionPixelSize(R.styleable.SVGView_svgWidth, -1); mSvgHeight = a.getDimensionPixelSize(R.styleable.SVGView_svgHeight, -1); mSvgRotation = a.getFloat(R.styleable.SVGView_svgRotation, 0) % 360; a.recycle(); resetImageDrawable(); }
Example 8
Source File: Utils.java From AndroidFastScroll with Apache License 2.0 | 5 votes |
@Nullable public static ColorStateList getColorStateListFromAttrRes(@AttrRes int attrRes, @NonNull Context context) { TypedArray a = context.obtainStyledAttributes(new int[] { attrRes }); int resId; try { resId = a.getResourceId(0, 0); if (resId != 0) { return AppCompatResources.getColorStateList(context, resId); } return a.getColorStateList(0); } finally { a.recycle(); } }
Example 9
Source File: ActiveItemImageView.java From letv with Apache License 2.0 | 5 votes |
public ActiveItemImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.cornerRadius = 0.0f; this.borderWidth = 0.0f; this.borderColor = ColorStateList.valueOf(-16777216); this.isOval = false; this.mutateBackground = false; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0); int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1); if (index >= 0) { setScaleType(SCALE_TYPES[index]); } else { setScaleType(ScaleType.FIT_CENTER); } this.cornerRadius = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1); this.borderWidth = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_border_width, -1); if (this.cornerRadius < 0.0f) { this.cornerRadius = 0.0f; } if (this.borderWidth < 0.0f) { this.borderWidth = 0.0f; } this.borderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color); if (this.borderColor == null) { this.borderColor = ColorStateList.valueOf(-16777216); } this.mutateBackground = a.getBoolean(R.styleable.RoundedImageView_riv_mutate_background, false); this.isOval = a.getBoolean(R.styleable.RoundedImageView_riv_oval, false); updateDrawableAttrs(); updateBackgroundDrawableAttrs(true); a.recycle(); }
Example 10
Source File: TintableImageView.java From SmartTabLayout with Apache License 2.0 | 5 votes |
private void init(Context context, AttributeSet attrs, int defStyle) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TintableImageView, defStyle, 0); tint = a.getColorStateList( R.styleable.TintableImageView_tint); a.recycle(); }
Example 11
Source File: ClipImageView.java From ProjectX with Apache License 2.0 | 5 votes |
private void initView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.ClipImageView, defStyleAttr, defStyleRes); final int type = custom.getInt(R.styleable.ClipImageView_civClipType, 0); final float radius = custom.getDimension(R.styleable.ClipImageView_civRoundRectRadius, 0); final float width = custom.getDimension(R.styleable.ClipImageView_civBorderWidth, 0); final ColorStateList color = custom.getColorStateList( R.styleable.ClipImageView_civBorderColor); final String name = custom.getString(R.styleable.ClipImageView_civClipOutlineProvider); custom.recycle(); mClipPath.setFillType(Path.FillType.EVEN_ODD); mOutlinePath.setFillType(Path.FillType.EVEN_ODD); switch (type) { default: break; case 1: mProvider = ClipOutlineProvider.CIRCLE; break; case 2: mProvider = ClipOutlineProvider.OVAL; break; case 3: mProvider = ClipOutlineProvider.FULL_ROUND_RECT; break; case 4: mProvider = new RoundRectClipOutlineProvider(radius); break; } final ClipOutlineProvider provider = ConstructorHelper.newInstance(context, name, isInEditMode(), this, ClipOutlineProvider.class, attrs, defStyleAttr, defStyleRes); if (provider != null) mProvider = provider; mBorderWidth = width; mBorderColor = color; }
Example 12
Source File: SVGImageButton.java From SVG-Android with Apache License 2.0 | 5 votes |
private void initImageButton(Context context, AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SVGView); mSvgColor = a.getColorStateList(R.styleable.SVGView_svgColor); mSvgAlpha = a.getFloat(R.styleable.SVGView_svgAlpha, 1.0f); mSvgWidth = a.getDimensionPixelSize(R.styleable.SVGView_svgWidth, -1); mSvgHeight = a.getDimensionPixelSize(R.styleable.SVGView_svgHeight, -1); mSvgRotation = a.getFloat(R.styleable.SVGView_svgRotation, 0) % 360; a.recycle(); resetImageDrawable(); }
Example 13
Source File: FastScroller.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
private void init(Context context) { // Get both the scrollbar states drawables final Resources res = context.getResources(); useThumbDrawable(context, res.getDrawable( R.drawable.scrollbar_handle_accelerated_anim2));// Jota Text Editor // Jota Text Editor // mOverlayDrawable = res.getDrawable( // com.android.internal.R.drawable.menu_submenu_background); mScrollCompleted = true; getSectionsFromIndexer(); // Jota Text Editor // mOverlaySize = context.getResources().getDimensionPixelSize( // com.android.internal.R.dimen.fastscroll_overlay_size); // mOverlayPos = new RectF(); mScrollFade = new ScrollFade(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextAlign(Paint.Align.CENTER); // Jota Text Editor TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary }); ColorStateList textColor = ta.getColorStateList(ta.getIndex(0)); int textColorNormal = textColor.getDefaultColor(); mPaint.setColor(textColorNormal); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mState = STATE_NONE; }
Example 14
Source File: VectorDrawable.java From Mover with Apache License 2.0 | 4 votes |
private void updateStateFromTypedArray(TypedArray array) throws XmlPullParserException { final VectorDrawableState state = mVectorState; final VPathRenderer pathRenderer = state.mVPathRenderer; // Account for any configuration changes. state.mChangingConfigurations |= Utils.getChangingConfigurations(array); // Extract the theme attributes, if any. state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs(); final int tintMode = array.getInt(R.styleable.VectorDrawable_tintMode, -1); if (tintMode != -1) { state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE); } final ColorStateList tint = array.getColorStateList(R.styleable.VectorDrawable_tint); if (tint != null) { state.mTint = tint; } state.mAutoMirrored = array.getBoolean( R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored); pathRenderer.mViewportWidth = array.getFloat( R.styleable.VectorDrawable_viewportWidth, pathRenderer.mViewportWidth); pathRenderer.mViewportHeight = array.getFloat( R.styleable.VectorDrawable_viewportHeight, pathRenderer.mViewportHeight); if (pathRenderer.mViewportWidth <= 0) { throw new XmlPullParserException(array.getPositionDescription() + String.format(" %s, <vector> tag requires width > 0 (%s)", mResourceName, pathRenderer.mBaseWidth)); } else if (pathRenderer.mViewportHeight <= 0) { throw new XmlPullParserException(array.getPositionDescription() + String.format("%s, <vector> tag requires width > 0 (%s)", mResourceName, pathRenderer.mViewportHeight)); } pathRenderer.mBaseHeight = array.getDimension( R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight); pathRenderer.mBaseWidth = array.getDimension( R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth); if (pathRenderer.mBaseWidth <= 0) { throw new XmlPullParserException(array.getPositionDescription() + String.format("%s <vector> tag requires width > 0 (%s)", mResourceName, pathRenderer.mBaseWidth)); } else if (pathRenderer.mBaseHeight <= 0) { throw new XmlPullParserException(array.getPositionDescription() + String.format("%s <vector> tag requires width > 0 (%s)",mResourceName, pathRenderer.mBaseHeight)); } final float alphaInFloat = array.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha()); pathRenderer.setAlpha(alphaInFloat); final String name = array.getString(R.styleable.VectorDrawable_name); if (name != null) { pathRenderer.mRootName = name; pathRenderer.mVGTargetsMap.put(name, pathRenderer); } }
Example 15
Source File: MenuSlidingTabStrip.java From AndroidPullMenu with Apache License 2.0 | 4 votes |
public MenuSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true); setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize); ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX); int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white); if (colorStateList != null) { tabTextColor = colorStateList; } else { tabTextColor = getColorStateList(textPrimaryColor); } underlineColor = textPrimaryColor; dividerColor = textPrimaryColor; indicatorColor = textPrimaryColor; int paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, padding); int paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, padding); a.recycle(); //In case we have the padding they must be equal so we take the biggest if (paddingRight < paddingLeft) { padding = paddingLeft; } if (paddingLeft < paddingRight) { padding = paddingRight; } // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.MenuSlidingTabStrip); indicatorColor = a.getColor(R.styleable.MenuSlidingTabStrip_mstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.MenuSlidingTabStrip_mstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.MenuSlidingTabStrip_mstsDividerColor, dividerColor); dividerWidth = a.getDimensionPixelSize(R.styleable.MenuSlidingTabStrip_mstsDividerWidth, dividerWidth); indicatorHeight = a.getDimensionPixelSize(R.styleable.MenuSlidingTabStrip_mstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.MenuSlidingTabStrip_mstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.MenuSlidingTabStrip_mstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.MenuSlidingTabStrip_mstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.MenuSlidingTabStrip_mstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.MenuSlidingTabStrip_mstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.MenuSlidingTabStrip_mstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.MenuSlidingTabStrip_mstsTextAllCaps, textAllCaps); isPaddingMiddle = a.getBoolean(R.styleable.MenuSlidingTabStrip_mstsPaddingMiddle, isPaddingMiddle); tabTypefaceStyle = a.getInt(R.styleable.MenuSlidingTabStrip_mstsTextStyle, Typeface.BOLD); tabTypefaceSelectedStyle = a.getInt(R.styleable.MenuSlidingTabStrip_mstsTextSelectedStyle, Typeface.BOLD); tabTextAlpha = a.getFloat(R.styleable.MenuSlidingTabStrip_mstsTextAlpha, HALF_TRANSP); tabTextSelectedAlpha = a.getFloat(R.styleable.MenuSlidingTabStrip_mstsTextSelectedAlpha, OPAQUE); a.recycle(); setMarginBottomTabContainer(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
Example 16
Source File: Carbon.java From Carbon with Apache License 2.0 | 4 votes |
public static ColorStateList getColorStateList(View view, TypedArray a, int id) { ColorStateList color = getDefaultColorStateList(view, a, id); if (color == null) color = a.getColorStateList(id); return color; }
Example 17
Source File: EditText.java From Genius-Android with Apache License 2.0 | 4 votes |
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) { if (attrs == null) return; // Get the super padding top mTruePaddingTop = super.getPaddingTop(); final Context context = getContext(); final Resources resources = getResources(); TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.EditText, defStyleAttr, defStyleRes); String fontFile = a.getString(R.styleable.EditText_gFont); int lineSize = a.getDimensionPixelSize(R.styleable.EditText_gLineSize, resources.getDimensionPixelSize(R.dimen.g_editText_lineSize)); ColorStateList lineColor = a.getColorStateList(R.styleable.EditText_gLineColor); // Set HintProperty int titleModel = a.getInt(R.styleable.EditText_gHintTitle, 1); int titleTextSize = a.getDimensionPixelSize(R.styleable.EditText_gHintTitleTextSize, resources.getDimensionPixelSize(R.dimen.g_editText_hintTitleTextSize)); int titlePaddingTop = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingTop, 0); int titlePaddingBottom = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingBottom, 0); int titlePaddingLeft = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingLeft, 0); int titlePaddingRight = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingRight, 0); a.recycle(); // Init color if (lineColor == null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { lineColor = resources.getColorStateList(R.color.g_default_edit_view_line, null); } else { //noinspection deprecation lineColor = resources.getColorStateList(R.color.g_default_edit_view_line); } } if (!Ui.isHaveAttribute(attrs, "textColorHint") || getHintTextColors() == null) { ColorStateList hintColor; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { hintColor = resources.getColorStateList(R.color.g_default_edit_view_hint, null); } else { //noinspection deprecation hintColor = resources.getColorStateList(R.color.g_default_edit_view_hint); } setHintTextColor(hintColor); } // Set same values setLineSize(lineSize); setLineColor(lineColor); setHintTitleTextSize(titleTextSize); setHintTitleModel(titleModel); // check for IDE preview render if (!this.isInEditMode()) { // Set Font if (fontFile != null && fontFile.length() > 0) { Typeface typeface = Ui.getFont(context, fontFile); if (typeface != null) setTypeface(typeface); } } // Init background and title if (!Ui.isHaveAttribute(attrs, "background")) { initBackground(); } initHintTitleText(); // SetHintPadding setHintTitlePadding(titlePaddingLeft, titlePaddingTop, titlePaddingRight, titlePaddingBottom); }
Example 18
Source File: RoundedImageView.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0); int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1); if (index >= 0) { setScaleType(SCALE_TYPES[index]); } else { // default scaletype to FIT_CENTER setScaleType(ScaleType.FIT_CENTER); } float cornerRadiusOverride = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1); mCornerRadii[Corner.TOP_LEFT.ordinal()] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1); mCornerRadii[Corner.TOP_RIGHT.ordinal()] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1); mCornerRadii[Corner.BOTTOM_RIGHT.ordinal()] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1); mCornerRadii[Corner.BOTTOM_LEFT.ordinal()] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1); boolean any = false; for (int i = 0, len = mCornerRadii.length; i < len; i++) { if (mCornerRadii[i] < 0) { mCornerRadii[i] = 0f; } else { any = true; } } if (!any) { if (cornerRadiusOverride < 0) { cornerRadiusOverride = DEFAULT_RADIUS; } for (int i = 0, len = mCornerRadii.length; i < len; i++) { mCornerRadii[i] = cornerRadiusOverride; } } mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_border_width, -1); if (mBorderWidth < 0) { mBorderWidth = DEFAULT_BORDER_WIDTH; } mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color); if (mBorderColor == null) { mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); } mMutateBackground = a.getBoolean(R.styleable.RoundedImageView_riv_mutate_background, false); mIsOval = a.getBoolean(R.styleable.RoundedImageView_riv_oval, false); final int tileMode = a.getInt(R.styleable.RoundedImageView_riv_tile_mode, TILE_MODE_UNDEFINED); if (tileMode != TILE_MODE_UNDEFINED) { setTileModeX(parseTileMode(tileMode)); setTileModeY(parseTileMode(tileMode)); } final int tileModeX = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_x, TILE_MODE_UNDEFINED); if (tileModeX != TILE_MODE_UNDEFINED) { setTileModeX(parseTileMode(tileModeX)); } final int tileModeY = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_y, TILE_MODE_UNDEFINED); if (tileModeY != TILE_MODE_UNDEFINED) { setTileModeY(parseTileMode(tileModeY)); } updateDrawableAttrs(); updateBackgroundDrawableAttrs(true); a.recycle(); }
Example 19
Source File: Marker.java From Sky31Radio with Apache License 2.0 | 4 votes |
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) { super(context, attrs, defStyleAttr); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, R.attr.discreteSeekBarStyle, R.style.DefaultSeekBar); int padding = (int) (PADDING_DP * displayMetrics.density) * 2; int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance, R.style.DefaultIndicatorTextAppearance); mNumber = new TextView(context); //Add some padding to this textView so the bubble has some space to breath mNumber.setPadding(padding, 0, padding, 0); mNumber.setTextAppearance(context, textAppearanceId); mNumber.setGravity(Gravity.CENTER); mNumber.setText(maxValue); mNumber.setMaxLines(1); mNumber.setSingleLine(true); SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE); mNumber.setVisibility(View.INVISIBLE); //add some padding for the elevation shadow not to be clipped //I'm sure there are better ways of doing this... setPadding(padding, padding, padding, padding); resetSizes(maxValue); mSeparation = (int) (SEPARATION_DP * displayMetrics.density); int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density); ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor); mMarkerDrawable = new MarkerDrawable(color, thumbSize); mMarkerDrawable.setCallback(this); mMarkerDrawable.setMarkerListener(this); mMarkerDrawable.setExternalOffset(padding); //Elevation for anroid 5+ float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation, ELEVATION_DP * displayMetrics.density); ViewCompat.setElevation(this, elevation); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SeekBarCompat.setOutlineProvider(this, mMarkerDrawable); } a.recycle(); }
Example 20
Source File: NumberPadTimePicker.java From BottomSheetPickers with Apache License 2.0 | 4 votes |
NumberPadTimePickerComponent(NumberPadTimePicker timePicker, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final View root = inflate(context, timePicker); mNumberPad = (NumberPadView) root.findViewById(R.id.bsp_numberpad_time_picker_view); mTimeDisplay = (TextView) root.findViewById(R.id.bsp_input_time); mAmPmDisplay = (TextView) root.findViewById(R.id.bsp_input_ampm); mBackspace = (ImageButton) root.findViewById(R.id.bsp_backspace); mDivider = (ImageView) root.findViewById(R.id.bsp_divider); mHeader = root.findViewById(R.id.bsp_header); final TypedArray timePickerAttrs = context.obtainStyledAttributes(attrs, R.styleable.BSP_NumberPadTimePicker, defStyleAttr, defStyleRes); final int inputTimeTextColor = timePickerAttrs.getColor( R.styleable.BSP_NumberPadTimePicker_bsp_inputTimeTextColor, 0); final int inputAmPmTextColor = timePickerAttrs.getColor( R.styleable.BSP_NumberPadTimePicker_bsp_inputAmPmTextColor, 0); final ColorStateList backspaceTint = timePickerAttrs.getColorStateList( R.styleable.BSP_NumberPadTimePicker_bsp_backspaceTint); final ColorStateList numberKeysTextColor = timePickerAttrs.getColorStateList( R.styleable.BSP_NumberPadTimePicker_bsp_numberKeysTextColor); final ColorStateList altKeysTextColor = timePickerAttrs.getColorStateList( R.styleable.BSP_NumberPadTimePicker_bsp_altKeysTextColor); final Drawable headerBackground = timePickerAttrs.getDrawable( R.styleable.BSP_NumberPadTimePicker_bsp_headerBackground); final Drawable divider = timePickerAttrs.getDrawable( R.styleable.BSP_NumberPadTimePicker_bsp_divider); final Drawable numberPadBackground = timePickerAttrs.getDrawable( R.styleable.BSP_NumberPadTimePicker_bsp_numberPadBackground); timePickerAttrs.recycle(); if (inputTimeTextColor != 0) { setInputTimeTextColor(inputTimeTextColor); } if (inputAmPmTextColor != 0) { setInputAmPmTextColor(inputAmPmTextColor); } if (backspaceTint != null) { setBackspaceTint(backspaceTint); } if (numberKeysTextColor != null) { setNumberKeysTextColor(numberKeysTextColor); } if (altKeysTextColor != null) { setAltKeysTextColor(altKeysTextColor); } if (headerBackground != null) { setHeaderBackground(headerBackground); } if (divider != null) { setDivider(divider); } if (numberPadBackground != null) { setNumberPadBackground(numberPadBackground); } }