Ejemplo n.º 1
0
  @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();
  }
Ejemplo n.º 2
0
  @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.DatePicker, defStyleAttr, defStyleRes);

    String familyName = null;
    int style = -1;

    int padding = -1;
    int paddingLeft = -1;
    int paddingRight = -1;
    int paddingTop = -1;
    int paddingBottom = -1;
    boolean paddingDefined = false;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
      int attr = a.getIndex(i);

      if (attr == R.styleable.DatePicker_dp_dayTextSize)
        mTextSize = a.getDimensionPixelSize(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_textColor) mTextColor = a.getColor(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_textHighlightColor)
        mTextHighlightColor = a.getColor(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_textLabelColor)
        mTextLabelColor = a.getColor(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_textDisableColor)
        mTextDisableColor = a.getColor(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_selectionColor)
        mSelectionColor = a.getColor(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_animDuration)
        mAnimDuration = a.getInteger(attr, 0);
      else if (attr == R.styleable.DatePicker_dp_inInterpolator)
        mInInterpolator = AnimationUtils.loadInterpolator(context, a.getResourceId(attr, 0));
      else if (attr == R.styleable.DatePicker_dp_outInterpolator)
        mOutInterpolator = AnimationUtils.loadInterpolator(context, a.getResourceId(attr, 0));
      else if (attr == R.styleable.DatePicker_dp_fontFamily) familyName = a.getString(attr);
      else if (attr == R.styleable.DatePicker_dp_textStyle) style = a.getInteger(attr, 0);
      else if (attr == R.styleable.DatePicker_android_padding) {
        padding = a.getDimensionPixelSize(attr, 0);
        paddingDefined = true;
      } else if (attr == R.styleable.DatePicker_android_paddingLeft) {
        paddingLeft = a.getDimensionPixelSize(attr, 0);
        paddingDefined = true;
      } else if (attr == R.styleable.DatePicker_android_paddingTop) {
        paddingTop = a.getDimensionPixelSize(attr, 0);
        paddingDefined = true;
      } else if (attr == R.styleable.DatePicker_android_paddingRight) {
        paddingRight = a.getDimensionPixelSize(attr, 0);
        paddingDefined = true;
      } else if (attr == R.styleable.DatePicker_android_paddingBottom) {
        paddingBottom = a.getDimensionPixelSize(attr, 0);
        paddingDefined = true;
      }
    }

    if (mTextSize < 0)
      mTextSize =
          context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_caption_material);

    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);

    a.recycle();

    if (paddingDefined) {
      if (padding >= 0) setContentPadding(padding, padding, padding, padding);

      if (paddingLeft >= 0) mPaddingLeft = paddingLeft;

      if (paddingTop >= 0) mPaddingTop = paddingTop;

      if (paddingRight >= 0) mPaddingRight = paddingRight;

      if (paddingBottom >= 0) mPaddingBottom = paddingBottom;
    }

    requestLayout();
    mAdapter.notifyDataSetInvalidated();
  }