@Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { mTextSize = -1; mItemHeight = -1; mAnimDuration = -1; mTypeface = Typeface.DEFAULT; mItemRealHeight = -1; setWillNotDraw(false); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); mAdapter = new YearAdapter(); setAdapter(mAdapter); setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY); setSelector(BlankDrawable.getInstance()); setDividerHeight(0); setCacheColorHint(Color.TRANSPARENT); setClipToPadding(false); mPadding = ThemeUtil.dpToPx(context, 4); mSelectionColor = ThemeUtil.colorPrimary(context, 0xFF000000); super.init(context, attrs, defStyleAttr, defStyleRes); }
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes); mBackgroundColor = a.getColor( R.styleable.TimePicker_tp_backgroundColor, ColorUtil.getColor(ThemeUtil.colorPrimary(context, 0xFF000000), 0.25f)); mSelectionColor = a.getColor( R.styleable.TimePicker_tp_selectionColor, ThemeUtil.colorPrimary(context, 0xFF000000)); mSelectionRadius = a.getDimensionPixelOffset( R.styleable.TimePicker_tp_selectionRadius, ThemeUtil.dpToPx(context, 8)); mTickSize = a.getDimensionPixelSize(R.styleable.TimePicker_tp_tickSize, ThemeUtil.dpToPx(context, 1)); mTextSize = a.getDimensionPixelSize( R.styleable.TimePicker_tp_textSize, context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_caption_material)); mTextColor = a.getColor(R.styleable.TimePicker_tp_textColor, 0xFF000000); mTextHighlightColor = a.getColor(R.styleable.TimePicker_tp_textHighlightColor, 0xFFFFFFFF); mAnimDuration = a.getInteger( R.styleable.TimePicker_tp_animDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)); int resId = a.getResourceId(R.styleable.TimePicker_tp_inInterpolator, 0); mInInterpolator = resId == 0 ? new DecelerateInterpolator() : AnimationUtils.loadInterpolator(context, resId); resId = a.getResourceId(R.styleable.TimePicker_tp_outInterpolator, 0); mOutInterpolator = resId == 0 ? new DecelerateInterpolator() : AnimationUtils.loadInterpolator(context, resId); setMode(a.getInteger(R.styleable.TimePicker_tp_mode, mMode), false); set24Hour(a.getBoolean(R.styleable.TimePicker_tp_24Hour, m24Hour)); setHour(a.getInteger(R.styleable.TimePicker_tp_hour, mHour)); setMinute(a.getInteger(R.styleable.TimePicker_tp_minute, mMinute)); String familyName = a.getString(R.styleable.TimePicker_tp_fontFamily); int style = a.getInteger(R.styleable.TimePicker_tp_textStyle, Typeface.NORMAL); mTypeface = TypefaceUtil.load(context, familyName, style); a.recycle(); }
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TabPageIndicator, defStyleAttr, defStyleRes); mTabPadding = a.getDimensionPixelSize( R.styleable.TabPageIndicator_tpi_tabPadding, ThemeUtil.dpToPx(context, 12)); mTabRippleStyle = a.getResourceId(R.styleable.TabPageIndicator_tpi_tabRipple, 0); int indicatorColor = a.getColor( R.styleable.TabPageIndicator_tpi_indicatorColor, ThemeUtil.colorAccent(context, 0xFFFFFFFF)); mIndicatorHeight = a.getDimensionPixelSize( R.styleable.TabPageIndicator_tpi_indicatorHeight, ThemeUtil.dpToPx(context, 2)); mTextApperance = a.getResourceId(R.styleable.TabPageIndicator_android_textAppearance, 0); mMode = a.getInteger(R.styleable.TabPageIndicator_tpi_mode, MODE_SCROLL); a.recycle(); removeAllViews(); if (mMode == MODE_SCROLL) { addView( mTabContainer, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); setFillViewport(false); } else if (mMode == MODE_FIXED) { addView( mTabContainer, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setFillViewport(true); } mPaint.setColor(indicatorColor); }
private void init(Context context, int style) { mContentPadding = ThemeUtil.dpToPx(context, 24); mActionMinWidth = ThemeUtil.dpToPx(context, 64); mActionHeight = ThemeUtil.dpToPx(context, 36); mActionOuterHeight = ThemeUtil.dpToPx(context, 48); mActionPadding = ThemeUtil.dpToPx(context, 8); mActionOuterPadding = ThemeUtil.dpToPx(context, 16); mDialogHorizontalPadding = ThemeUtil.dpToPx(context, 40); mDialogVerticalPadding = ThemeUtil.dpToPx(context, 24); mCardView = new DialogCardView(context); mContainer = new ContainerFrameLayout(context); mTitle = new TextView(context); mPositiveAction = new Button(context); mNegativeAction = new Button(context); mNeutralAction = new Button(context); mCardView.setPreventCornerOverlap(false); mCardView.setUseCompatPadding(true); mTitle.setPadding( mContentPadding, mContentPadding, mContentPadding, mContentPadding - mActionPadding); mPositiveAction.setId(ACTION_POSITIVE); mPositiveAction.setPadding(mActionPadding, 0, mActionPadding, 0); mPositiveAction.setBackgroundResource(0); mNegativeAction.setId(ACTION_NEGATIVE); mNegativeAction.setPadding(mActionPadding, 0, mActionPadding, 0); mNegativeAction.setBackgroundResource(0); mNeutralAction.setId(ACTION_NEUTRAL); mNeutralAction.setPadding(mActionPadding, 0, mActionPadding, 0); mNeutralAction.setBackgroundResource(0); mContainer.addView(mCardView); mCardView.addView(mTitle); mCardView.addView(mPositiveAction); mCardView.addView(mNegativeAction); mCardView.addView(mNeutralAction); cancelable(true); canceledOnTouchOutside(true); clearContent(); onCreate(); applyStyle(style); super.setContentView(mContainer); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { int left = getPaddingLeft(); int top = getPaddingTop(); int size = Math.min( w - getPaddingLeft() - getPaddingRight(), h - getPaddingTop() - getPaddingBottom()); if (mCenterPoint == null) mCenterPoint = new PointF(); mOuterRadius = size / 2f; mCenterPoint.set(left + mOuterRadius, top + mOuterRadius); mInnerRadius = mOuterRadius - mSelectionRadius - ThemeUtil.dpToPx(getContext(), 4); calculateTextLocation(); }
@Override protected void applyStyle( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super.applyStyle(context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.YearPicker, defStyleAttr, defStyleRes); int year = -1; int yearMin = -1; int yearMax = -1; String familyName = null; int style = -1; for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.YearPicker_dp_yearTextSize) mTextSize = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.YearPicker_dp_year) year = a.getInteger(attr, 0); else if (attr == R.styleable.YearPicker_dp_yearMin) yearMin = a.getInteger(attr, 0); else if (attr == R.styleable.YearPicker_dp_yearMax) yearMax = a.getInteger(attr, 0); else if (attr == R.styleable.YearPicker_dp_yearItemHeight) mItemHeight = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.YearPicker_dp_textColor) mTextColors[0] = a.getColor(attr, 0); else if (attr == R.styleable.YearPicker_dp_textHighlightColor) mTextColors[1] = a.getColor(attr, 0); else if (attr == R.styleable.YearPicker_dp_selectionColor) mSelectionColor = a.getColor(attr, 0); else if (attr == R.styleable.YearPicker_dp_animDuration) mAnimDuration = a.getInteger(attr, 0); else if (attr == R.styleable.YearPicker_dp_inInterpolator) mInInterpolator = AnimationUtils.loadInterpolator(context, a.getResourceId(attr, 0)); else if (attr == R.styleable.YearPicker_dp_outInterpolator) mOutInterpolator = AnimationUtils.loadInterpolator(context, a.getResourceId(attr, 0)); else if (attr == R.styleable.YearPicker_dp_fontFamily) familyName = a.getString(attr); else if (attr == R.styleable.YearPicker_dp_textStyle) style = a.getInteger(attr, 0); } a.recycle(); if (mTextSize < 0) mTextSize = context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_title_material); if (mItemHeight < 0) mItemHeight = ThemeUtil.dpToPx(context, 48); if (mAnimDuration < 0) mAnimDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime); if (mInInterpolator == null) mInInterpolator = new DecelerateInterpolator(); if (mOutInterpolator == null) mOutInterpolator = new DecelerateInterpolator(); if (familyName != null || style >= 0) mTypeface = TypefaceUtil.load(context, familyName, style); if (yearMin >= 0 || yearMax >= 0) { if (yearMin < 0) yearMin = mAdapter.getMinYear(); if (yearMax < 0) yearMax = mAdapter.getMaxYear(); if (yearMax < yearMin) yearMax = Integer.MAX_VALUE; setYearRange(yearMin, yearMax); } if (mAdapter.getYear() < 0 && year < 0) { Calendar cal = Calendar.getInstance(); year = cal.get(Calendar.YEAR); } if (year >= 0) { year = Math.max(yearMin, Math.min(yearMax, year)); setYear(year); } mAdapter.notifyDataSetChanged(); requestLayout(); }
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { setWillNotDraw(false); mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ContactView, defStyleAttr, defStyleRes); mAvatarSize = a.getDimensionPixelSize( R.styleable.ContactView_cv_avatarSize, ThemeUtil.dpToPx(context, 40)); mSpacing = a.getDimensionPixelOffset(R.styleable.ContactView_cv_spacing, ThemeUtil.dpToPx(context, 8)); mMinHeight = a.getDimensionPixelOffset(R.styleable.ContactView_android_minHeight, 0); int avatarSrc = a.getResourceId(R.styleable.ContactView_cv_avatarSrc, 0); mNameView = new TextView(context); mNameView.setGravity(GravityCompat.START); mNameView.setSingleLine(true); mNameView.setEllipsize(TextUtils.TruncateAt.END); int nameTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_nameTextSize, 0); ColorStateList nameTextColor = a.getColorStateList(R.styleable.ContactView_cv_nameTextColor); int nameTextAppearance = a.getResourceId(R.styleable.ContactView_cv_nameTextAppearance, 0); if (nameTextAppearance > 0) mNameView.setTextAppearance(context, nameTextAppearance); if (nameTextSize > 0) mNameView.setTextSize(TypedValue.COMPLEX_UNIT_PX, nameTextSize); if (nameTextColor != null) mNameView.setTextColor(nameTextColor); setNameText(a.getString(R.styleable.ContactView_cv_name)); mAddressView = new TextView(context); mAddressView.setGravity(GravityCompat.START); mAddressView.setSingleLine(true); mAddressView.setEllipsize(TextUtils.TruncateAt.END); int addressTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_addressTextSize, 0); ColorStateList addressTextColor = a.getColorStateList(R.styleable.ContactView_cv_addressTextColor); int addressTextAppearance = a.getResourceId(R.styleable.ContactView_cv_addressTextAppearance, 0); if (addressTextAppearance > 0) mAddressView.setTextAppearance(context, addressTextAppearance); if (addressTextSize > 0) mAddressView.setTextSize(TypedValue.COMPLEX_UNIT_PX, addressTextSize); if (addressTextColor != null) mAddressView.setTextColor(addressTextColor); setAddressText(a.getString(R.styleable.ContactView_cv_address)); mButtonSize = a.getDimensionPixelOffset(R.styleable.ContactView_cv_buttonSize, 0); if (mButtonSize > 0) { mButton = new ImageButton(context); int resId = a.getResourceId(R.styleable.ContactView_cv_buttonSrc, 0); if (resId != 0) mButton.setImageResource(resId); ViewUtil.setBackground(mButton, BlankDrawable.getInstance()); mButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); mButton.setFocusableInTouchMode(false); mButton.setFocusable(false); mButton.setClickable(false); } a.recycle(); addView(mNameView); addView(mAddressView); if (mButton != null) addView(mButton); mAvatarDrawable = new AvatarDrawable(); if (avatarSrc != 0) setAvatarResource(avatarSrc); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackBar, defStyleAttr, defStyleRes); int backgroundColor = a.getColor(R.styleable.SnackBar_sb_backgroundColor, 0xFF323232); int backgroundRadius = a.getDimensionPixelSize(R.styleable.SnackBar_sb_backgroundCornerRadius, 0); int horizontalPadding = a.getDimensionPixelSize( R.styleable.SnackBar_sb_horizontalPadding, ThemeUtil.dpToPx(context, 24)); int verticalPadding = a.getDimensionPixelSize(R.styleable.SnackBar_sb_verticalPadding, 0); TypedValue value = a.peekValue(R.styleable.SnackBar_sb_width); if (value != null && value.type == TypedValue.TYPE_INT_DEC) mWidth = a.getInteger(R.styleable.SnackBar_sb_width, MATCH_PARENT); else mWidth = a.getDimensionPixelSize(R.styleable.SnackBar_sb_width, MATCH_PARENT); int minWidth = a.getDimensionPixelSize(R.styleable.SnackBar_sb_minWidth, 0); int maxWidth = a.getDimensionPixelSize(R.styleable.SnackBar_sb_maxWidth, 0); value = a.peekValue(R.styleable.SnackBar_sb_height); if (value != null && value.type == TypedValue.TYPE_INT_DEC) mHeight = a.getInteger(R.styleable.SnackBar_sb_height, WRAP_CONTENT); else mHeight = a.getDimensionPixelSize(R.styleable.SnackBar_sb_height, WRAP_CONTENT); int minHeight = a.getDimensionPixelSize(R.styleable.SnackBar_sb_minHeight, 0); int maxHeight = a.getDimensionPixelSize(R.styleable.SnackBar_sb_maxHeight, 0); mMarginStart = a.getDimensionPixelSize(R.styleable.SnackBar_sb_marginStart, 0); mMarginBottom = a.getDimensionPixelSize(R.styleable.SnackBar_sb_marginBottom, 0); int textSize = a.getDimensionPixelSize(R.styleable.SnackBar_sb_textSize, 0); boolean hasTextColor = a.hasValue(R.styleable.SnackBar_sb_textColor); int textColor = hasTextColor ? a.getColor(R.styleable.SnackBar_sb_textColor, 0xFFFFFFFF) : 0; int textAppearance = a.getResourceId(R.styleable.SnackBar_sb_textAppearance, 0); String text = a.getString(R.styleable.SnackBar_sb_text); boolean singleLine = a.getBoolean(R.styleable.SnackBar_sb_singleLine, true); int maxLines = a.getInteger(R.styleable.SnackBar_sb_maxLines, 0); int lines = a.getInteger(R.styleable.SnackBar_sb_lines, 0); int ellipsize = a.getInteger(R.styleable.SnackBar_sb_ellipsize, 0); int actionTextSize = a.getDimensionPixelSize(R.styleable.SnackBar_sb_actionTextSize, 0); ColorStateList actionTextColor; value = a.peekValue(R.styleable.SnackBar_sb_actionTextColor); if (value != null && value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) actionTextColor = ColorStateList.valueOf(a.getColor(R.styleable.SnackBar_sb_actionTextColor, 0xFF000000)); else actionTextColor = a.getColorStateList(R.styleable.SnackBar_sb_actionTextColor); int actionTextAppearance = a.getResourceId(R.styleable.SnackBar_sb_actionTextAppearance, 0); String actionText = a.getString(R.styleable.SnackBar_sb_actionText); int actionRipple = a.getResourceId(R.styleable.SnackBar_sb_actionRipple, 0); int duration = a.getInteger(R.styleable.SnackBar_sb_duration, -1); mInAnimationId = a.getResourceId(R.styleable.SnackBar_sb_inAnimation, 0); mOutAnimationId = a.getResourceId(R.styleable.SnackBar_sb_outAnimation, 0); mRemoveOnDismiss = a.getBoolean(R.styleable.SnackBar_sb_removeOnDismiss, true); a.recycle(); backgroundColor(backgroundColor).backgroundRadius(backgroundRadius); padding(horizontalPadding, verticalPadding); textAppearance(textAppearance); if (textSize > 0) textSize(textSize); if (hasTextColor) textColor(textColor); if (text != null) text(text); singleLine(singleLine); if (maxLines > 0) maxLines(maxLines); if (lines > 0) lines(lines); if (minWidth > 0) minWidth(minWidth); if (maxWidth > 0) maxWidth(maxWidth); if (minHeight > 0) minHeight(minHeight); if (maxHeight > 0) maxHeight(maxHeight); switch (ellipsize) { case 1: ellipsize(TruncateAt.START); break; case 2: ellipsize(TruncateAt.MIDDLE); break; case 3: ellipsize(TruncateAt.END); break; case 4: ellipsize(TruncateAt.MARQUEE); break; default: ellipsize(TruncateAt.END); break; } if (textAppearance != 0) actionTextAppearance(actionTextAppearance); if (actionTextSize > 0) actionTextSize(actionTextSize); if (actionTextColor != null) actionTextColor(actionTextColor); if (actionText != null) actionText(actionText); if (actionRipple != 0) actionRipple(actionRipple); if (duration >= 0) duration(duration); }
protected void applyStyle( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Switch, defStyleAttr, defStyleRes); for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.Switch_sw_trackSize) mTrackSize = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.Switch_sw_trackColor) mTrackColors = a.getColorStateList(attr); else if (attr == R.styleable.Switch_sw_trackCap) { int cap = a.getInteger(attr, 0); if (cap == 0) mTrackCap = Paint.Cap.BUTT; else if (cap == 1) mTrackCap = Paint.Cap.ROUND; else mTrackCap = Paint.Cap.SQUARE; } else if (attr == R.styleable.Switch_sw_thumbColor) mThumbColors = a.getColorStateList(attr); else if (attr == R.styleable.Switch_sw_thumbRadius) mThumbRadius = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.Switch_sw_thumbElevation) { mShadowSize = a.getDimensionPixelSize(attr, 0); mShadowOffset = mShadowSize / 2; } else if (attr == R.styleable.Switch_sw_animDuration) mMaxAnimDuration = a.getInt(attr, 0); else if (attr == R.styleable.Switch_android_gravity) mGravity = a.getInt(attr, 0); else if (attr == R.styleable.Switch_android_checked) setCheckedImmediately(a.getBoolean(attr, mChecked)); else if (attr == R.styleable.Switch_sw_interpolator) { int resId = a.getResourceId(R.styleable.Switch_sw_interpolator, 0); if (resId != 0) mInterpolator = AnimationUtils.loadInterpolator(context, resId); } } a.recycle(); if (mTrackSize < 0) mTrackSize = ThemeUtil.dpToPx(context, 2); if (mThumbRadius < 0) mThumbRadius = ThemeUtil.dpToPx(context, 8); if (mShadowSize < 0) { mShadowSize = ThemeUtil.dpToPx(context, 2); mShadowOffset = mShadowSize / 2; } if (mMaxAnimDuration < 0) mMaxAnimDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime); if (mInterpolator == null) mInterpolator = new DecelerateInterpolator(); if (mTrackColors == null) { int[][] states = new int[][] { new int[] {-android.R.attr.state_checked}, new int[] {android.R.attr.state_checked}, }; int[] colors = new int[] { ColorUtil.getColor(ThemeUtil.colorControlNormal(context, 0xFF000000), 0.5f), ColorUtil.getColor(ThemeUtil.colorControlActivated(context, 0xFF000000), 0.5f), }; mTrackColors = new ColorStateList(states, colors); } if (mThumbColors == null) { int[][] states = new int[][] { new int[] {-android.R.attr.state_checked}, new int[] {android.R.attr.state_checked}, }; int[] colors = new int[] { 0xFAFAFA, ThemeUtil.colorControlActivated(context, 0xFF000000), }; mThumbColors = new ColorStateList(states, colors); } mPaint.setStrokeCap(mTrackCap); buildShadow(); invalidate(); }
protected void applyStyle( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.FloatingActionButton, defStyleAttr, defStyleRes); int radius = -1; int elevation = -1; ColorStateList bgColor = null; int bgAnimDuration = -1; int iconSrc = 0; int iconLineMorphing = 0; for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.FloatingActionButton_fab_radius) radius = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_elevation) elevation = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_backgroundColor) bgColor = a.getColorStateList(attr); else if (attr == R.styleable.FloatingActionButton_fab_backgroundAnimDuration) bgAnimDuration = a.getInteger(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_iconSrc) iconSrc = a.getResourceId(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_iconLineMorphing) iconLineMorphing = a.getResourceId(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_iconSize) mIconSize = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_animDuration) mAnimDuration = a.getInteger(attr, 0); else if (attr == R.styleable.FloatingActionButton_fab_interpolator) { int resId = a.getResourceId(R.styleable.FloatingActionButton_fab_interpolator, 0); if (resId != 0) mInterpolator = AnimationUtils.loadInterpolator(context, resId); } } a.recycle(); if (mIconSize < 0) mIconSize = ThemeUtil.dpToPx(context, 24); if (mAnimDuration < 0) mAnimDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime); if (mInterpolator == null) mInterpolator = new DecelerateInterpolator(); if (mBackground == null) { if (radius < 0) radius = ThemeUtil.dpToPx(context, 28); if (elevation < 0) elevation = ThemeUtil.dpToPx(context, 4); if (bgColor == null) bgColor = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0)); if (bgAnimDuration < 0) bgAnimDuration = 0; mBackground = new OvalShadowDrawable(radius, bgColor, elevation, elevation, bgAnimDuration); mBackground.setInEditMode(isInEditMode()); mBackground.setBounds(0, 0, getWidth(), getHeight()); mBackground.setCallback(this); } else { if (radius >= 0) mBackground.setRadius(radius); if (bgColor != null) mBackground.setColor(bgColor); if (elevation >= 0) mBackground.setShadow(elevation, elevation); if (bgAnimDuration >= 0) mBackground.setAnimationDuration(bgAnimDuration); } if (iconLineMorphing != 0) setIcon(new LineMorphingDrawable.Builder(context, iconLineMorphing).build(), false); else if (iconSrc != 0) setIcon(context.getResources().getDrawable(iconSrc), false); getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes); Drawable background = getBackground(); if (background != null && background instanceof RippleDrawable) { RippleDrawable drawable = (RippleDrawable) background; drawable.setBackgroundDrawable(null); drawable.setMask( RippleDrawable.Mask.TYPE_OVAL, 0, 0, 0, 0, (int) mBackground.getPaddingLeft(), (int) mBackground.getPaddingTop(), (int) mBackground.getPaddingRight(), (int) mBackground.getPaddingBottom()); } }
public Dialog applyStyle(int resId) { Context context = getContext(); TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog); int layout_width; int layout_height; if (ThemeUtil.getType(a, R.styleable.Dialog_android_layout_width) == TypedValue.TYPE_DIMENSION) layout_width = a.getDimensionPixelSize(R.styleable.Dialog_android_layout_width, 0); else layout_width = a.getInteger( R.styleable.Dialog_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT); if (ThemeUtil.getType(a, R.styleable.Dialog_android_layout_height) == TypedValue.TYPE_DIMENSION) layout_height = a.getDimensionPixelSize(R.styleable.Dialog_android_layout_height, 0); else layout_height = a.getInteger( R.styleable.Dialog_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams(layout_width, layout_height); dimAmount(a.getFloat(R.styleable.Dialog_di_dimAmount, 0.5f)); backgroundColor( a.getColor( R.styleable.Dialog_di_backgroundColor, ThemeUtil.windowBackground(context, 0xFFFFFFFF))); maxElevation(a.getDimensionPixelOffset(R.styleable.Dialog_di_maxElevation, 0)); elevation( a.getDimensionPixelOffset(R.styleable.Dialog_di_elevation, ThemeUtil.dpToPx(context, 4))); cornerRadius( a.getDimensionPixelOffset( R.styleable.Dialog_di_cornerRadius, ThemeUtil.dpToPx(context, 2))); titleTextAppearance( a.getResourceId( R.styleable.Dialog_di_titleTextAppearance, R.style.TextAppearance_AppCompat_Title)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_titleTextColor) != TypedValue.TYPE_NULL) titleColor(a.getColor(R.styleable.Dialog_di_titleTextColor, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_actionBackground) != TypedValue.TYPE_NULL) actionBackground(a.getResourceId(R.styleable.Dialog_di_actionBackground, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_actionRipple) != TypedValue.TYPE_NULL) actionRipple(a.getResourceId(R.styleable.Dialog_di_actionRipple, 0)); actionTextAppearance( a.getResourceId( R.styleable.Dialog_di_actionTextAppearance, R.style.TextAppearance_AppCompat_Button)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_actionTextColor) != TypedValue.TYPE_NULL) actionTextColor(a.getColorStateList(R.styleable.Dialog_di_actionTextColor)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_positiveActionBackground) != TypedValue.TYPE_NULL) positiveActionBackground(a.getResourceId(R.styleable.Dialog_di_positiveActionBackground, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_positiveActionRipple) != TypedValue.TYPE_NULL) positiveActionRipple(a.getResourceId(R.styleable.Dialog_di_positiveActionRipple, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_positiveActionTextAppearance) != TypedValue.TYPE_NULL) positiveActionTextAppearance( a.getResourceId(R.styleable.Dialog_di_positiveActionTextAppearance, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_positiveActionTextColor) != TypedValue.TYPE_NULL) positiveActionTextColor(a.getColorStateList(R.styleable.Dialog_di_positiveActionTextColor)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_negativeActionBackground) != TypedValue.TYPE_NULL) negativeActionBackground(a.getResourceId(R.styleable.Dialog_di_negativeActionBackground, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_negativeActionRipple) != TypedValue.TYPE_NULL) negativeActionRipple(a.getResourceId(R.styleable.Dialog_di_negativeActionRipple, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_negativeActionTextAppearance) != TypedValue.TYPE_NULL) negativeActionTextAppearance( a.getResourceId(R.styleable.Dialog_di_negativeActionTextAppearance, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_negativeActionTextColor) != TypedValue.TYPE_NULL) negativeActionTextColor(a.getColorStateList(R.styleable.Dialog_di_negativeActionTextColor)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_neutralActionBackground) != TypedValue.TYPE_NULL) neutralActionBackground(a.getResourceId(R.styleable.Dialog_di_neutralActionBackground, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_neutralActionRipple) != TypedValue.TYPE_NULL) neutralActionRipple(a.getResourceId(R.styleable.Dialog_di_neutralActionRipple, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_neutralActionTextAppearance) != TypedValue.TYPE_NULL) neutralActionTextAppearance( a.getResourceId(R.styleable.Dialog_di_neutralActionTextAppearance, 0)); if (ThemeUtil.getType(a, R.styleable.Dialog_di_neutralActionTextColor) != TypedValue.TYPE_NULL) neutralActionTextColor(a.getColorStateList(R.styleable.Dialog_di_neutralActionTextColor)); inAnimation(a.getResourceId(R.styleable.Dialog_di_inAnimation, 0)); outAnimation(a.getResourceId(R.styleable.Dialog_di_outAnimation, 0)); dividerColor(a.getColor(R.styleable.Dialog_di_dividerColor, 0x1E000000)); dividerHeight( a.getDimensionPixelOffset( R.styleable.Dialog_di_dividerHeight, ThemeUtil.dpToPx(context, 1))); setCancelable(a.getBoolean(R.styleable.Dialog_di_cancelable, true)); setCanceledOnTouchOutside(a.getBoolean(R.styleable.Dialog_di_canceledOnTouchOutside, true)); a.recycle(); return this; }