@Override public void onClick(View v) { CircleCheckedTextView child = (CircleCheckedTextView)v; child.setChecked(!child.isChecked()); } };
@Override public View getView(int position, View convertView, ViewGroup parent) { CircleCheckedTextView v = (CircleCheckedTextView)convertView; if(v == null){ v = new CircleCheckedTextView(getContext()); v.setGravity(Gravity.CENTER); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) v.setTextAlignment(TEXT_ALIGNMENT_CENTER); v.setMinHeight(mItemRealHeight); v.setMaxHeight(mItemRealHeight); v.setAnimDuration(mAnimDuration); v.setInterpolator(mInInterpolator, mOutInterpolator); v.setBackgroundColor(mSelectionColor); v.setTypeface(mTypeface); v.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); v.setTextColor(new ColorStateList(STATES, mTextColors)); v.setOnClickListener(this); } int year = (Integer)getItem(position); v.setTag(year); v.setText(String.format(YEAR_FORMAT, year)); v.setCheckedImmediately(year == mCurYear); return v; } }
@Override public void onCheckedChanged(CircleCheckedTextView view, boolean checked) { onDaySelectionChanged((Integer)view.getTag(), checked); } };
public void setSelected(int dayOfWeek, boolean selected, boolean immediately){ int index = dayOfWeek >= mFirstDayOfWeek ? (dayOfWeek - mFirstDayOfWeek) : (dayOfWeek + 7 - mFirstDayOfWeek); CircleCheckedTextView view = (CircleCheckedTextView)getChildAt(index); if(immediately) view.setCheckedImmediately(selected); else view.setChecked(selected); }
}; mAmView.setBackgroundColor(mTimePicker.getSelectionColor()); mAmView.setAnimDuration(mTimePicker.getAnimDuration()); mAmView.setInterpolator(mTimePicker.getInInterpolator(), mTimePicker.getOutInterpolator()); mAmView.setTypeface(mTimePicker.getTypeface()); mAmView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTimePicker.getTextSize()); mAmView.setTextColor(new ColorStateList(states, colors)); mAmView.setText(am); mPmView.setBackgroundColor(mTimePicker.getSelectionColor()); mPmView.setAnimDuration(mTimePicker.getAnimDuration()); mPmView.setInterpolator(mTimePicker.getInInterpolator(), mTimePicker.getOutInterpolator()); mPmView.setTypeface(mTimePicker.getTypeface()); mPmView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTimePicker.getTextSize()); mPmView.setTextColor(new ColorStateList(states, colors)); mPmView.setText(pm); mMidday = mIsAm ? mAmView.getText().toString() : mPmView.getText().toString();
public TimePickerLayout(Context context) { super(context); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextAlign(Paint.Align.LEFT); mHeaderBackground = new Path(); mRect = new RectF(); mAmView = new CircleCheckedTextView(context); mPmView = new CircleCheckedTextView(context); mTimePicker = new TimePicker(context); mTimePicker.setPadding(mContentPadding, mContentPadding, mContentPadding, mContentPadding); mTimePicker.setOnTimeChangedListener(this); mAmView.setGravity(Gravity.CENTER); mPmView.setGravity(Gravity.CENTER); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){ mAmView.setTextAlignment(TEXT_ALIGNMENT_CENTER); mPmView.setTextAlignment(TEXT_ALIGNMENT_CENTER); } mAmView.setCheckedImmediately(mIsAm); mPmView.setCheckedImmediately(!mIsAm); mAmView.setOnClickListener(this); mPmView.setOnClickListener(this); addView(mTimePicker); addView(mAmView); addView(mPmView); setWillNotDraw(false); mCheckBoxSize = ThemeUtil.dpToPx(context, 48); mHeaderHeight = ThemeUtil.dpToPx(context, 120); mTextTimeSize = context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_headline_material); }
private void setAm(boolean am, boolean animation){ if(mTimePicker.is24Hour()) return; if(mIsAm != am){ int oldHour = getHour(); mIsAm = am; if(animation) { mAmView.setChecked(mIsAm); mPmView.setChecked(!mIsAm); } else{ mAmView.setCheckedImmediately(mIsAm); mPmView.setCheckedImmediately(!mIsAm); } mMidday = mIsAm ? mAmView.getText().toString() : mPmView.getText().toString(); invalidate(0, 0, mHeaderRealWidth, mHeaderRealHeight); if(mOnTimeChangedListener != null) mOnTimeChangedListener.onTimeChanged(oldHour, getMinute(), getHour(), getMinute()); } }
protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ setGravity(Gravity.CENTER); setPadding(0, 0, 0, 0); mBackground = new CircleDrawable(); mBackground.setInEditMode(isInEditMode()); mBackground.setAnimEnable(false); ViewUtil.setBackground(this, mBackground); mBackground.setAnimEnable(true); }
public void setCheckedImmediately(boolean checked){ mBackground.setAnimEnable(false); setChecked(checked); mBackground.setAnimEnable(true); }
public boolean isSelected(int dayOfWeek){ int index = dayOfWeek >= mFirstDayOfWeek ? (dayOfWeek - mFirstDayOfWeek) : (dayOfWeek + 7 - mFirstDayOfWeek); CircleCheckedTextView view = (CircleCheckedTextView)getChildAt(index); return view.isChecked(); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { mPaint.setTextSize(mOriginalTextSize); float baseWidth = mPaint.measureText(BASE_TEXT); float realWidth = getChildAt(0).getMeasuredWidth() - mHorizontalPadding; if(realWidth < baseWidth){ float textSize = mOriginalTextSize * realWidth / baseWidth; for(int i = 0; i < getChildCount(); i++) ((CircleCheckedTextView)getChildAt(i)).setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } }
private void updateBackgroundColor(int[] state){ int color = mBackgroundColors.getColorForState(state, mBackgroundColors.getDefaultColor()); if(mCurrentBackgroundColor != color){ mCurrentBackgroundColor = color; for(int i = 0; i < getChildCount(); i++){ CircleCheckedTextView child = (CircleCheckedTextView)getChildAt(i); child.setBackgroundColor(color); } invalidate(); } }
public CircleCheckedTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs, defStyleAttr, 0); }
public void clearSelection(boolean immediately){ for(int i = 0; i < getChildCount(); i++) if(immediately) ((CircleCheckedTextView)getChildAt(i)).setCheckedImmediately(false); else ((CircleCheckedTextView)getChildAt(i)).setChecked(false); }
public void setYear(int year){ if(mCurYear != year){ int old = mCurYear; mCurYear = year; CircleCheckedTextView child = (CircleCheckedTextView) YearPicker.this.getChildAt(positionOfYear(old) - YearPicker.this.getFirstVisiblePosition()); if(child != null) child.setChecked(false); child = (CircleCheckedTextView) YearPicker.this.getChildAt(positionOfYear(mCurYear) - YearPicker.this.getFirstVisiblePosition()); if(child != null) child.setChecked(true); if(mOnYearChangedListener != null) mOnYearChangedListener.onYearChanged(old, mCurYear); } }
@Override public void setChecked(boolean checked) { boolean oldCheck = isChecked(); if(oldCheck != checked) { super.setChecked(checked); if(mCheckedChangeListener != null) mCheckedChangeListener.onCheckedChanged(this, checked); } }
public CircleCheckedTextView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs, 0, 0); }
public CircleCheckedTextView(Context context) { super(context); init(context, null, 0, 0); }