private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker, defStyleAttr, defStyleRes); mTextSize = a.getDimensionPixelSize( R.styleable.DatePicker_dp_dayTextSize, context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_caption_material)); mTextColor = a.getColor(R.styleable.DatePicker_dp_textColor, 0xFF000000); mTextHighlightColor = a.getColor(R.styleable.DatePicker_dp_textHighlightColor, 0xFFFFFFFF); mTextLabelColor = a.getColor(R.styleable.DatePicker_dp_textLabelColor, 0xFF767676); mTextDisableColor = a.getColor(R.styleable.DatePicker_dp_textDisableColor, 0xFF767676); mSelectionColor = a.getColor( R.styleable.DatePicker_dp_selectionColor, ThemeUtil.colorPrimary(context, 0xFF000000)); mAnimDuration = a.getInteger( R.styleable.DatePicker_dp_animDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)); int resId = a.getResourceId(R.styleable.DatePicker_dp_inInterpolator, 0); if (resId != 0) mInInterpolator = AnimationUtils.loadInterpolator(context, resId); else mInInterpolator = new DecelerateInterpolator(); resId = a.getResourceId(R.styleable.DatePicker_dp_outInterpolator, 0); if (resId != 0) mOutInterpolator = AnimationUtils.loadInterpolator(context, resId); else mOutInterpolator = new DecelerateInterpolator(); String familyName = a.getString(R.styleable.DatePicker_dp_fontFamily); int style = a.getInteger(R.styleable.DatePicker_dp_textStyle, Typeface.NORMAL); mTypeface = TypefaceUtil.load(context, familyName, style); int padding = a.getDimensionPixelSize(R.styleable.DatePicker_android_padding, -1); if (padding >= 0) setContentPadding(padding, padding, padding, padding); mPaddingLeft = a.getDimensionPixelSize(R.styleable.DatePicker_android_paddingLeft, mPaddingLeft); mPaddingTop = a.getDimensionPixelSize(R.styleable.DatePicker_android_paddingTop, mPaddingTop); mPaddingRight = a.getDimensionPixelSize(R.styleable.DatePicker_android_paddingRight, mPaddingRight); mPaddingBottom = a.getDimensionPixelSize(R.styleable.DatePicker_android_paddingBottom, mPaddingBottom); a.recycle(); }
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { setWillNotDraw(false); setSelector(BlankDrawable.getInstance()); setCacheColorHint(0); setDivider(null); setItemsCanFocus(true); setFastScrollEnabled(false); setVerticalScrollBarEnabled(false); setOnScrollListener(this); setFadingEdgeLength(0); setFrictionIfSupported(ViewConfiguration.getScrollFriction() * mFriction); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); mPaint.setTextAlign(Paint.Align.CENTER); mDayPadding = ThemeUtil.dpToPx(context, 4); mCalendar = Calendar.getInstance(); mFirstDayOfWeek = mCalendar.getFirstDayOfWeek(); int index = mCalendar.get(Calendar.DAY_OF_WEEK) - 1; DateFormat format = new SimpleDateFormat( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ? "EEEEE" : "E"); for (int i = 0; i < 7; i++) { mLabels[index] = format.format(mCalendar.getTime()); index = (index + 1) % 7; mCalendar.add(Calendar.DAY_OF_MONTH, 1); } mAdapter = new MonthAdapter(); setAdapter(mAdapter); applyStyle(context, attrs, defStyleAttr, defStyleRes); }