コード例 #1
0
  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);

    mSelectionColor = ThemeUtil.colorPrimary(context, 0xFF000000);

    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);
  }
コード例 #2
0
    public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
      TypedArray a =
          context.obtainStyledAttributes(
              attrs, R.styleable.CheckBoxDrawable, defStyleAttr, defStyleRes);

      width(
          a.getDimensionPixelSize(
              R.styleable.CheckBoxDrawable_cbd_width, ThemeUtil.dpToPx(context, 32)));
      height(
          a.getDimensionPixelSize(
              R.styleable.CheckBoxDrawable_cbd_height, ThemeUtil.dpToPx(context, 32)));
      boxSize(
          a.getDimensionPixelSize(
              R.styleable.CheckBoxDrawable_cbd_boxSize, ThemeUtil.dpToPx(context, 18)));
      cornerRadius(
          a.getDimensionPixelSize(
              R.styleable.CheckBoxDrawable_cbd_cornerRadius, ThemeUtil.dpToPx(context, 2)));
      strokeSize(
          a.getDimensionPixelSize(
              R.styleable.CheckBoxDrawable_cbd_strokeSize, ThemeUtil.dpToPx(context, 2)));
      strokeColor(a.getColorStateList(R.styleable.CheckBoxDrawable_cbd_strokeColor));
      tickColor(a.getColor(R.styleable.CheckBoxDrawable_cbd_tickColor, 0xFFFFFFFF));
      animDuration(
          a.getInt(
              R.styleable.CheckBoxDrawable_cbd_animDuration,
              context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));

      a.recycle();

      if (mStrokeColor == null) {
        int[][] states =
            new int[][] {
              new int[] {-android.R.attr.state_checked}, new int[] {android.R.attr.state_checked},
            };
        int[] colors =
            new int[] {
              ThemeUtil.colorControlNormal(context, 0xFF000000),
              ThemeUtil.colorControlActivated(context, 0xFF000000),
            };
        strokeColor(new ColorStateList(states, colors));
      }
    }