/** * Calculate the degrees within the circle that corresponds to the specified coordinates, if * the coordinates are within the range that will trigger a selection. * @param pointX The x coordinate. * @param pointY The y coordinate. * @param forceLegal Force the selection to be legal, regardless of how far the coordinates are * from the actual numbers. * @param isInnerCircle If the selection may be in the inner circle, pass in a size-1 boolean * array here, inside which the value will be true if the selection is in the inner circle, * and false if in the outer circle. * @return Degrees from 0 to 360, if the selection was within the legal range. -1 if not. */ private int getDegreesFromCoords(float pointX, float pointY, boolean forceLegal, final Boolean[] isInnerCircle) { int currentItem = getCurrentItemShowing(); if (currentItem == HOUR_INDEX) { return mHourRadialSelectorView.getDegreesFromCoords( pointX, pointY, forceLegal, isInnerCircle); } else if (currentItem == MINUTE_INDEX) { return mMinuteRadialSelectorView.getDegreesFromCoords( pointX, pointY, forceLegal, isInnerCircle); } else { return -1; } }
if (index == MINUTE_INDEX) { anims[0] = mHourRadialTextsView.getDisappearAnimator(); anims[1] = mHourRadialSelectorView.getDisappearAnimator(); anims[2] = mMinuteRadialTextsView.getReappearAnimator(); anims[3] = mMinuteRadialSelectorView.getReappearAnimator(); } else if (index == HOUR_INDEX){ anims[0] = mHourRadialTextsView.getReappearAnimator(); anims[1] = mHourRadialSelectorView.getReappearAnimator(); anims[2] = mMinuteRadialTextsView.getDisappearAnimator(); anims[3] = mMinuteRadialSelectorView.getDisappearAnimator(); int minuteAlpha = (index == MINUTE_INDEX) ? 255 : 0; mHourRadialTextsView.setAlpha(hourAlpha); mHourRadialSelectorView.setAlpha(hourAlpha); mMinuteRadialTextsView.setAlpha(minuteAlpha); mMinuteRadialSelectorView.setAlpha(minuteAlpha);
/** * Set either the hour or the minute. Will set the internal value, and set the selection. */ private void setItem(int index, int value) { if (index == HOUR_INDEX) { setValueForItem(HOUR_INDEX, value); int hourDegrees = (value % 12) * HOUR_VALUE_TO_DEGREES_STEP_SIZE; mHourRadialSelectorView.setSelection(hourDegrees, isHourInnerCircle(value), false); mHourRadialSelectorView.invalidate(); } else if (index == MINUTE_INDEX) { setValueForItem(MINUTE_INDEX, value); int minuteDegrees = value * MINUTE_VALUE_TO_DEGREES_STEP_SIZE; mMinuteRadialSelectorView.setSelection(minuteDegrees, false, false); mMinuteRadialSelectorView.invalidate(); } }
@Override public void onDraw(Canvas canvas) { int viewWidth = getWidth(); if (viewWidth == 0 || !mIsInitialized) { return; mXCenter = getWidth() / 2; mYCenter = getHeight() / 2; mCircleRadius = (int) (Math.min(mXCenter, mYCenter) * mCircleRadiusMultiplier); innerRadiusSelection = equals(mNumbersRadiusMultiplier, Float.parseFloat(getResources().getString(R.string.numbers_radius_multiplier_inner))); if (constraintsAreMet(innerRadiusSelection, mSelectionDegrees)){ canvas.drawCircle(pointX, pointY, mSelectionRadius, mPaint); if (constraintsAreMet(innerRadiusSelection, mSelectionDegrees)){ canvas.drawCircle(pointX, pointY, (mSelectionRadius * 2 / 7), mPaint); if (constraintsAreMet(innerRadiusSelection, mSelectionDegrees)){ canvas.drawLine(mXCenter, mYCenter, pointX, pointY, mPaint);
if (mMinHour <= value && value <= mMaxHour) { mCurrentHoursOfDay = value; mMinuteRadialSelectorView.setSelectedHour(mCurrentHoursOfDay); mMinuteRadialSelectorView.invalidate(); mMinuteRadialTextsView.setSelectedHour(mCurrentHoursOfDay); mMinuteRadialTextsView.invalidate();
@Override public void onAnimationUpdate(ValueAnimator animation) { RadialSelectorView.this.invalidate(); } }
addView(mMinuteRadialTextsView); mHourRadialSelectorView = new RadialSelectorView(context); addView(mHourRadialSelectorView); mMinuteRadialSelectorView = new RadialSelectorView(context); addView(mMinuteRadialSelectorView);
setValueForItem(MINUTE_INDEX, initialMinutes); int hourDegrees = (initialHoursOfDay % 12) * HOUR_VALUE_TO_DEGREES_STEP_SIZE; mHourRadialSelectorView.initialize(context, mHideAmPm, is24HourMode, true, hourDegrees, isHourInnerCircle(initialHoursOfDay)); int minuteDegrees = initialMinutes * MINUTE_VALUE_TO_DEGREES_STEP_SIZE; mMinuteRadialSelectorView.initialize(context, mHideAmPm, false, false, minuteDegrees, false);
mInvalidateUpdateListener = new InvalidateUpdateListener(); setSelection(selectionDegrees, isInnerCircle, false); mIsInitialized = true;
stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE; radialSelectorView.setSelection(degrees, isInnerCircle, forceDrawDot); radialSelectorView.invalidate();
@Override public void onAnimationUpdate(ValueAnimator animation) { RadialSelectorView.this.invalidate(); } }
addView(mMinuteRadialTextsView); mHourRadialSelectorView = new RadialSelectorView(context); addView(mHourRadialSelectorView); mMinuteRadialSelectorView = new RadialSelectorView(context); addView(mMinuteRadialSelectorView);
setValueForItem(MINUTE_INDEX, initialMinutes); int hourDegrees = (initialHoursOfDay % 12) * HOUR_VALUE_TO_DEGREES_STEP_SIZE; mHourRadialSelectorView.initialize(context, mHideAmPm, is24HourMode, true, hourDegrees, isHourInnerCircle(initialHoursOfDay), mMinHour, mMaxHour, mMinMinute, mMaxMinute); int minuteDegrees = initialMinutes * MINUTE_VALUE_TO_DEGREES_STEP_SIZE; mMinuteRadialSelectorView.initialize(context, mHideAmPm, false, false, minuteDegrees, false, minHour, maxHour, minMinute, maxMinute);
mInvalidateUpdateListener = new InvalidateUpdateListener(); setSelection(selectionDegrees, isInnerCircle, false); mIsInitialized = true;
if (index == MINUTE_INDEX) { anims[0] = mHourRadialTextsView.getDisappearAnimator(); anims[1] = mHourRadialSelectorView.getDisappearAnimator(); anims[2] = mMinuteRadialTextsView.getReappearAnimator(); anims[3] = mMinuteRadialSelectorView.getReappearAnimator(); } else if (index == HOUR_INDEX){ anims[0] = mHourRadialTextsView.getReappearAnimator(); anims[1] = mHourRadialSelectorView.getReappearAnimator(); anims[2] = mMinuteRadialTextsView.getDisappearAnimator(); anims[3] = mMinuteRadialSelectorView.getDisappearAnimator(); int minuteAlpha = (index == MINUTE_INDEX) ? 255 : 0; mHourRadialTextsView.setAlpha(hourAlpha); mHourRadialSelectorView.setAlpha(hourAlpha); mMinuteRadialTextsView.setAlpha(minuteAlpha); mMinuteRadialSelectorView.setAlpha(minuteAlpha);
/** * Set either the hour or the minute. Will set the internal value, and set the selection. */ private void setItem(int index, int value) { if (index == HOUR_INDEX) { setValueForItem(HOUR_INDEX, value); int hourDegrees = (value % 12) * HOUR_VALUE_TO_DEGREES_STEP_SIZE; mHourRadialSelectorView.setSelection(hourDegrees, isHourInnerCircle(value), false); mHourRadialSelectorView.invalidate(); } else if (index == MINUTE_INDEX) { setValueForItem(MINUTE_INDEX, value); int minuteDegrees = value * MINUTE_VALUE_TO_DEGREES_STEP_SIZE; mMinuteRadialSelectorView.setSelection(minuteDegrees, false, false); mMinuteRadialSelectorView.invalidate(); } }
/** * Calculate the degrees within the circle that corresponds to the specified coordinates, if * the coordinates are within the range that will trigger a selection. * @param pointX The x coordinate. * @param pointY The y coordinate. * @param forceLegal Force the selection to be legal, regardless of how far the coordinates are * from the actual numbers. * @param isInnerCircle If the selection may be in the inner circle, pass in a size-1 boolean * array here, inside which the value will be true if the selection is in the inner circle, * and false if in the outer circle. * @return Degrees from 0 to 360, if the selection was within the legal range. -1 if not. */ private int getDegreesFromCoords(float pointX, float pointY, boolean forceLegal, final Boolean[] isInnerCircle) { int currentItem = getCurrentItemShowing(); if (currentItem == HOUR_INDEX) { return mHourRadialSelectorView.getDegreesFromCoords( pointX, pointY, forceLegal, isInnerCircle); } else if (currentItem == MINUTE_INDEX) { return mMinuteRadialSelectorView.getDegreesFromCoords( pointX, pointY, forceLegal, isInnerCircle); } else { return -1; } }
stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE; radialSelectorView.setSelection(degrees, isInnerCircle, forceDrawDot); radialSelectorView.invalidate();