/* package */ void setTheme(Context context, boolean themeDark) { mCircleView.setTheme(context, themeDark); mAmPmCirclesView.setTheme(context, themeDark); mHourRadialTextsView.setTheme(context, themeDark); mMinuteRadialTextsView.setTheme(context, themeDark); mHourRadialSelectorView.setTheme(context, themeDark); mMinuteRadialSelectorView.setTheme(context, themeDark); }
/** * Initialize the Layout with starting values. * * @param context * @param initialHoursOfDay * @param initialMinutes * @param is24HourMode */ public void initialize( Context context, HapticFeedbackController hapticFeedbackController, int initialHoursOfDay, int initialMinutes, boolean is24HourMode) { if (mTimeInitialized) { Log.e(TAG, "Time has already been initialized."); return; } mHapticFeedbackController = hapticFeedbackController; mIs24HourMode = is24HourMode; mHideAmPm = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager) ? true : mIs24HourMode; // Initialize the circle and AM/PM circles if applicable. mCircleView.initialize(context, mHideAmPm); mCircleView.invalidate(); if (!mHideAmPm) { mAmPmCirclesView.initialize(context, initialHoursOfDay < 12 ? AM : PM); mAmPmCirclesView.invalidate(); } // Initialize the hours and minutes numbers. Resources res = context.getResources(); int[] hours = {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; int[] hours_24 = {0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; int[] minutes = {0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55}; String[] hoursTexts = new String[12]; String[] innerHoursTexts = new String[12]; String[] minutesTexts = new String[12]; for (int i = 0; i < 12; i++) { hoursTexts[i] = is24HourMode ? String.format("%02d", hours_24[i]) : String.format("%d", hours[i]); innerHoursTexts[i] = String.format("%d", hours[i]); minutesTexts[i] = String.format("%02d", minutes[i]); } mHourRadialTextsView.initialize( res, hoursTexts, (is24HourMode ? innerHoursTexts : null), mHideAmPm, true); mHourRadialTextsView.invalidate(); mMinuteRadialTextsView.initialize(res, minutesTexts, null, mHideAmPm, false); mMinuteRadialTextsView.invalidate(); // Initialize the currently-selected hour and minute. setValueForItem(HOUR_INDEX, initialHoursOfDay); 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); mTimeInitialized = true; }
/** * Set either minutes or hours as showing. * * @param animate True to animate the transition, false to show with no animation. */ public void setCurrentItemShowing(int index, boolean animate) { if (index != HOUR_INDEX && index != MINUTE_INDEX) { Log.e(TAG, "TimePicker does not support view at index " + index); return; } int lastIndex = getCurrentItemShowing(); mCurrentItemShowing = index; if (animate && (index != lastIndex)) { List<ObjectAnimator> anims = new ArrayList<ObjectAnimator>(); if (index == MINUTE_INDEX) { anims.addAll(mHourRadialTextsView.getDisappearAnimator()); anims.addAll(mHourRadialSelectorView.getDisappearAnimator()); anims.addAll(mMinuteRadialTextsView.getReappearAnimator()); anims.addAll(mMinuteRadialSelectorView.getReappearAnimator()); } else if (index == HOUR_INDEX) { anims.addAll(mHourRadialTextsView.getReappearAnimator()); anims.addAll(mHourRadialSelectorView.getReappearAnimator()); anims.addAll(mMinuteRadialTextsView.getDisappearAnimator()); anims.addAll(mMinuteRadialSelectorView.getDisappearAnimator()); } if (mTransition != null && mTransition.isRunning()) { mTransition.end(); } mTransition = new AnimatorSet(); mTransition.playTogether(anims.toArray(new ObjectAnimator[anims.size()])); mTransition.start(); } else { int hourAlpha = (index == HOUR_INDEX) ? 255 : 0; int minuteAlpha = (index == MINUTE_INDEX) ? 255 : 0; Log.i( TAG, "set current item showing, no animate, hour alpha:" + hourAlpha + ", min alpha:" + minuteAlpha); ViewHelper.setAlpha(mHourRadialTextsView, hourAlpha); ViewHelper.setAlpha(mHourRadialSelectorView, hourAlpha); ViewHelper.setAlpha(mMinuteRadialTextsView, minuteAlpha); ViewHelper.setAlpha(mMinuteRadialSelectorView, minuteAlpha); } }
/** * Set either minutes or hours as showing. * * @param animate True to animate the transition, false to show with no animation. */ public void setCurrentItemShowing(int index, boolean animate) { if (index != HOUR_INDEX && index != MINUTE_INDEX) { Log.e(TAG, "TimePicker does not support view at index " + index); return; } int lastIndex = getCurrentItemShowing(); mCurrentItemShowing = index; if (animate && (index != lastIndex)) { ObjectAnimator[] anims = new ObjectAnimator[4]; 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(); } if (mTransition != null && mTransition.isRunning()) { mTransition.end(); } mTransition = new AnimatorSet(); mTransition.playTogether(anims); mTransition.start(); } else { int hourAlpha = (index == HOUR_INDEX) ? 255 : 0; int minuteAlpha = (index == MINUTE_INDEX) ? 255 : 0; mHourRadialTextsView.setAlpha(hourAlpha); mHourRadialSelectorView.setAlpha(hourAlpha); mMinuteRadialTextsView.setAlpha(minuteAlpha); mMinuteRadialSelectorView.setAlpha(minuteAlpha); } }