List of usage examples for java.text DateFormatSymbols DateFormatSymbols
public DateFormatSymbols()
From source file:com.zenkun.datetimepicker.time.TimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.time_picker_dialogs, container); KeyboardListener keyboardListener = new KeyboardListener(); LinearLayout ly = (LinearLayout) view.findViewById(R.id.picker_dialog); ly.setOnKeyListener(keyboardListener); Resources res = getResources(); mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); mBlue = res.getColor(R.color.blue);//from w w w . ja v a 2 s . c o m mBlack = res.getColor(R.color.numbers_text_color); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); mTimePicker.tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); mTimePicker.tryVibrate(); } }); mDoneButton = (TextView) view.findViewById(R.id.done_button); mDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { mTimePicker.tryVibrate(); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); } }); mDoneButton.setOnKeyListener(keyboardListener); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); mAmPmHitspace.setVisibility(View.GONE); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); } else { mAmPmTextView.setVisibility(View.VISIBLE); mAmPmHitspace.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mTimePicker.tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } updateAmPmDisplay(amOrPm); mTimePicker.setAmOrPm(amOrPm); } }); } mAllowAutoAdvance = true; setHour(mInitialHourOfDay, true); setMinute(mInitialMinute); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<Integer>(); } return view; }
From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialTimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.radial_time_picker_dialog, null); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener); Resources res = getResources(); mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); mBlue = res.getColor(R.color.blue);// w w w. j a v a 2 s.c om mBlack = res.getColor(R.color.numbers_text_color); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); mTimePicker.tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); mTimePicker.tryVibrate(); } }); mDoneButton = (TextView) view.findViewById(R.id.done_button); mDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { mTimePicker.tryVibrate(); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); } }); mDoneButton.setOnKeyListener(keyboardListener); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); } else { mAmPmTextView.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mTimePicker.tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } updateAmPmDisplay(amOrPm); mTimePicker.setAmOrPm(amOrPm); } }); } mAllowAutoAdvance = true; setHour(mInitialHourOfDay, true); setMinute(mInitialMinute); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<Integer>(); } return view; }
From source file:com.massivekinetics.ow.ui.views.timepicker.TimePicker.java
public TimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // initialization based on locale setCurrentLocale(Locale.getDefault()); // process style attributes //TypedArray attributesArray = context.obtainStyledAttributes( // attrs, R.styleable.TimePicker, defStyle, 0); //int layoutResourceId = attributesArray.getResourceId( // R.styleable.TimePicker_internalLayout, R.layout.time_picker); //attributesArray.recycle(); int layoutResourceId = R.layout.time_picker_holo; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(layoutResourceId, this, true); // hour/* w ww .ja v a2s .co m*/ mHourSpinner = (NumberPicker) findViewById(R.id.hour); mHourSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { public void onValueChange(NumberPicker spinner, int oldVal, int newVal) { updateInputState(); if (!is24HourView()) { if ((oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) || (oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1)) { mIsAm = !mIsAm; updateAmPmControl(); } } onTimeChanged(); } }); mHourSpinnerInput = (EditText) mHourSpinner.findViewById(R.id.np__numberpicker_input); mHourSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT); // divider (only for the new widget style) mDivider = (TextView) findViewById(R.id.divider); if (mDivider != null) { mDivider.setText(R.string.time_picker_separator); } // minute mMinuteSpinner = (NumberPicker) findViewById(R.id.minute); mMinuteSpinner.setMinValue(0); mMinuteSpinner.setMaxValue(59); mMinuteSpinner.setOnLongPressUpdateInterval(100); mMinuteSpinner.setFormatter(NumberPicker.getTwoDigitFormatter()); mMinuteSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { public void onValueChange(NumberPicker spinner, int oldVal, int newVal) { updateInputState(); int minValue = mMinuteSpinner.getMinValue(); int maxValue = mMinuteSpinner.getMaxValue(); if (oldVal == maxValue && newVal == minValue) { int newHour = mHourSpinner.getValue() + 1; if (!is24HourView() && newHour == HOURS_IN_HALF_DAY) { mIsAm = !mIsAm; updateAmPmControl(); } mHourSpinner.setValue(newHour); } else if (oldVal == minValue && newVal == maxValue) { int newHour = mHourSpinner.getValue() - 1; if (!is24HourView() && newHour == HOURS_IN_HALF_DAY - 1) { mIsAm = !mIsAm; updateAmPmControl(); } mHourSpinner.setValue(newHour); } onTimeChanged(); } }); mMinuteSpinnerInput = (EditText) mMinuteSpinner.findViewById(R.id.np__numberpicker_input); mMinuteSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT); /* Get the localized am/pm strings and use them in the spinner */ mAmPmStrings = new DateFormatSymbols().getAmPmStrings(); // am/pm View amPmView = findViewById(R.id.amPm); if (amPmView instanceof Button) { mAmPmSpinner = null; mAmPmSpinnerInput = null; mAmPmButton = (Button) amPmView; mAmPmButton.setOnClickListener(new OnClickListener() { public void onClick(View button) { button.requestFocus(); mIsAm = !mIsAm; updateAmPmControl(); onTimeChanged(); } }); } else { mAmPmButton = null; mAmPmSpinner = (NumberPicker) amPmView; mAmPmSpinner.setMinValue(0); mAmPmSpinner.setMaxValue(1); mAmPmSpinner.setDisplayedValues(mAmPmStrings); mAmPmSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { public void onValueChange(NumberPicker picker, int oldVal, int newVal) { updateInputState(); picker.requestFocus(); mIsAm = !mIsAm; updateAmPmControl(); onTimeChanged(); } }); mAmPmSpinnerInput = (EditText) mAmPmSpinner.findViewById(R.id.np__numberpicker_input); mAmPmSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_DONE); } // update controls to initial state updateHourControl(); updateAmPmControl(); setOnTimeChangedListener(NO_OP_CHANGE_LISTENER); // set to current time setCurrentHour(mTempCalendar.get(Calendar.HOUR_OF_DAY)); setCurrentMinute(mTempCalendar.get(Calendar.MINUTE)); if (!isEnabled()) { setEnabled(false); } // set the content descriptions setContentDescriptions(); // If not explicitly specified this view is important for accessibility. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) { setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); } }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
/** * Get default locale name of this day ("Monday", "Tuesday", etc.) * Based on a zeroindexed array.// w w w. j a va 2 s .com * * @return Name of day. */ public static String getDayName(int dayInWeek) { String[] weekdays = new DateFormatSymbols().getWeekdays(); switch (dayInWeek) { case 0: return weekdays[2]; case 1: return weekdays[3]; case 2: return weekdays[4]; case 3: return weekdays[5]; case 4: return weekdays[6]; case 5: return weekdays[7]; case 6: return weekdays[1]; default: assert false : "Invalid day of week: " + dayInWeek; } // This will never happen return null; }
From source file:fr.esecure.banking.PDFTransactionRapport.java
private String getMonth(int month) { return new DateFormatSymbols().getMonths()[month - 1]; }
From source file:mirko.android.datetimepicker.time.TimePickerDialogSupport.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate( mEnableClearButton ? R.layout.time_picker_dialog_clear : R.layout.time_picker_dialog, null); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener); Resources res = getResources(); mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); mBlue = res.getColor(R.color.blue);//from w ww . j av a 2 s . c o m mBlack = res.getColor(R.color.numbers_text_color); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); mTimePicker.tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); mTimePicker.tryVibrate(); } }); mDoneButton = (TextView) view.findViewById(R.id.done_button); mDoneButton.setOnClickListener(this); mDoneButton.setOnKeyListener(keyboardListener); mClearButton = (TextView) view.findViewById(R.id.clear_button); mClearButton.setOnClickListener(this); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); } else { mAmPmTextView.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mTimePicker.tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } updateAmPmDisplay(amOrPm); mTimePicker.setAmOrPm(amOrPm); } }); } mAllowAutoAdvance = true; setHour(mInitialHourOfDay, true); setMinute(mInitialMinute); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<Integer>(); } return view; }
From source file:com.siphyc.utils.Utilities.java
public static String getMonthForInt(int num) { String month = "wrong"; DateFormatSymbols dfs = new DateFormatSymbols(); String[] months = dfs.getMonths(); if (num >= 0 && num <= 11) { month = months[num];//from w w w. j ava2s.c om } return month; }
From source file:com.android.datetimepicker.time.TimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.time_picker_dialog, null); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener); Resources res = getResources(); mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); mSelectedColor = res.getColor(mThemeDark ? R.color.red : R.color.blue); mUnselectedColor = res.getColor(mThemeDark ? R.color.white : R.color.numbers_text_color); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0];//w w w.ja v a 2s. c om mPmText = amPmTexts[1]; mHapticFeedbackController = new HapticFeedbackController(getActivity()); mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), mHapticFeedbackController, mInitialHourOfDay, mInitialMinute, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); tryVibrate(); } }); mDoneButton = (TextView) view.findViewById(R.id.done_button); mDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { tryVibrate(); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); } }); mDoneButton.setOnKeyListener(keyboardListener); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); } else { mAmPmTextView.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } updateAmPmDisplay(amOrPm); mTimePicker.setAmOrPm(amOrPm); } }); } mAllowAutoAdvance = true; setHour(mInitialHourOfDay, true); setMinute(mInitialMinute); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<Integer>(); } // Set the theme at the end so that the initialize()s above don't counteract the theme. mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark); // Prepare some colors to use. int white = res.getColor(R.color.white); int circleBackground = res.getColor(R.color.circle_background); int line = res.getColor(R.color.line_background); int timeDisplay = res.getColor(R.color.numbers_text_color); ColorStateList doneTextColor = res.getColorStateList(R.color.done_text_color); int doneBackground = R.drawable.done_background_color; int darkGray = res.getColor(R.color.dark_gray); int lightGray = res.getColor(R.color.light_gray); int darkLine = res.getColor(R.color.line_dark); ColorStateList darkDoneTextColor = res.getColorStateList(R.color.done_text_color_dark); int darkDoneBackground = R.drawable.done_background_color_dark; // Set the colors for each view based on the theme. view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark ? darkGray : white); view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark ? darkGray : white); ((TextView) view.findViewById(R.id.separator)).setTextColor(mThemeDark ? white : timeDisplay); ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mThemeDark ? white : timeDisplay); view.findViewById(R.id.line).setBackgroundColor(mThemeDark ? darkLine : line); mDoneButton.setTextColor(mThemeDark ? darkDoneTextColor : doneTextColor); mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground); mDoneButton.setBackgroundResource(mThemeDark ? darkDoneBackground : doneBackground); return view; }
From source file:DateChooserPanel.java
/** * Returns a panel of buttons, each button representing a day in the month. * This is a sub-component of the DatePanel. * * @return the panel./*from w w w . jav a2 s . c o m*/ */ private JPanel getCalendarPanel() { final JPanel p = new JPanel(new GridLayout(7, 7)); final DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(); final String[] weekDays = dateFormatSymbols.getShortWeekdays(); for (int i = 0; i < this.WEEK_DAYS.length; i++) { p.add(new JLabel(weekDays[this.WEEK_DAYS[i]], SwingConstants.CENTER)); } this.buttons = new JButton[42]; for (int i = 0; i < 42; i++) { final JButton b = new JButton(""); b.setMargin(new Insets(1, 1, 1, 1)); b.setName(Integer.toString(i)); b.setFont(this.dateFont); b.setFocusPainted(false); b.setActionCommand("dateButtonClicked"); b.addActionListener(this); this.buttons[i] = b; p.add(b); } return p; }
From source file:com.philliphsu.bottomsheetpickers.time.grid.GridTimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener); if (!mThemeSetAtRuntime) { mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark); }//w ww. j a va 2 s. c om final Resources res = getResources(); final Context ctx = getActivity(); mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); mSelectedColor = getColor(ctx, android.R.color.white); mUnselectedColor = getColor(ctx, R.color.unselected_color); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; // TODO: Restore // mHapticFeedbackController = new HapticFeedbackController(getActivity()); mTimePicker = (GridPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), /*mHapticFeedbackController,*/ mInitialHourOfDay, mInitialMinute, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); tryVibrate(); } }); mDoneButton = (FloatingActionButton) view.findViewById(R.id.fab); mDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { tryVibrate(); } onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } }); mDoneButton.setOnKeyListener(keyboardListener); // TODO: setOnKeyListener? mFirstHalfDayToggle = (Button) view.findViewById(R.id.half_day_toggle_1); mFirstHalfDayToggle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryToggleHalfDay(HALF_DAY_1); } }); // TODO: setOnKeyListener? mSecondHalfDayToggle = (Button) view.findViewById(R.id.half_day_toggle_2); mSecondHalfDayToggle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryToggleHalfDay(HALF_DAY_2); } }); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); mFirstHalfDayToggle.setText(R.string.hours_00_11); mSecondHalfDayToggle.setText(R.string.hours_12_23); // We need different drawable resources for each case, not a single one that we // just tint differently, because the orientation of each one is different. final int icon1 = mThemeDark ? R.drawable.ic_half_day_1_dark_24dp : R.drawable.ic_half_day_1_24dp; final int icon2 = mThemeDark ? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp; mFirstHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(0, icon1, 0, 0); mSecondHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(0, icon2, 0, 0); } else { mAmPmTextView.setVisibility(View.VISIBLE); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == HALF_DAY_1) { amOrPm = HALF_DAY_2; } else if (amOrPm == HALF_DAY_2) { amOrPm = HALF_DAY_1; } updateHalfDay(amOrPm); mTimePicker.setHalfDay(amOrPm); } }); mFirstHalfDayToggle.setText(mAmText); mSecondHalfDayToggle.setText(mPmText); } mAllowAutoAdvance = true; setHour(mInitialHourOfDay, true); setMinute(mInitialMinute); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<Integer>(); } // Set the theme at the end so that the initialize()s above don't counteract the theme. // // If you decide to move the FAB and the half day toggles to the GridPickerLayout // class, you should remove getApplicationContext(). Otherwise, you would not // retrieve the correct accent color. mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark); // Prepare some colors to use. final int white = getColor(ctx, android.R.color.white); final int darkGray = getColor(ctx, R.color.dark_gray); final int lightGray = getColor(ctx, R.color.light_gray); final int accentColor = Utils.getThemeAccentColor(getActivity()); final int sidebarDark = getColor(ctx, R.color.sidebar_color_dark); final int sidebarLight = getColor(ctx, R.color.sidebar_color_light); // Set the whole view's background color first view.setBackgroundColor(mThemeDark ? darkGray : white); // Set the colors for each view based on the theme. view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark ? lightGray : accentColor); view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark ? lightGray : accentColor); ((TextView) view.findViewById(R.id.separator)).setTextColor(mUnselectedColor); ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mUnselectedColor); view.findViewById(R.id.sidebar).setBackgroundColor(mThemeDark ? sidebarDark : sidebarLight); // Color in normal state mDoneButton.setBackgroundTintList(ColorStateList.valueOf(accentColor)); //TODO mDoneButton.setRippleColor(); mHalfDayToggleSelectedColor = accentColor; mHalfDayToggleUnselectedColor = getColor(ctx, mThemeDark ? R.color.text_color_primary_dark : R.color.text_color_primary_light); Utils.setColorControlHighlight(mFirstHalfDayToggle, accentColor); Utils.setColorControlHighlight(mSecondHalfDayToggle, accentColor); // Update the half day at the end when the state colors have been initialized updateHalfDay(mInitialHourOfDay < 12 ? HALF_DAY_1 : HALF_DAY_2); return view; }