List of usage examples for android.text.format DateFormat getBestDateTimePattern
public static String getBestDateTimePattern(Locale locale, String skeleton)
From source file:Main.java
public static String getFormattedTime(Context context, Calendar time) { String skeleton = DateFormat.is24HourFormat(context) ? "EHm" : "Ehma"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); return (String) DateFormat.format(pattern, time); }
From source file:Main.java
private static String getLocalizedPattern(String template, Locale locale) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return DateFormat.getBestDateTimePattern(locale, template); } else {//from w ww . j a v a 2 s .co m return new SimpleDateFormat(template, locale).toLocalizedPattern(); } }
From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.DayPickerView.java
public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(SUtils.createThemeWrapper(context, R.attr.sublimePickerStyle, R.style.SublimePickerStyleLight, defStyleAttr, R.style.DayPickerViewStyle), attrs); context = getContext();/*from w w w. j a v a 2 s . co m*/ mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView, defStyleAttr, R.style.DayPickerViewStyle); final int monthTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spMonthTextAppearance, R.style.SPMonthLabelTextAppearance); // verified final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spWeekDayTextAppearance, R.style.SPWeekDayLabelTextAppearance); // verified final int dayTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spDateTextAppearance, R.style.SPDayTextAppearance); final ColorStateList daySelectorColor = a.getColorStateList(R.styleable.DayPickerView_spDaySelectorColor); a.recycle(); if (Config.DEBUG) { Log.i(TAG, "MDayPickerView_spmMonthTextAppearance: " + monthTextAppearanceResId); Log.i(TAG, "MDayPickerView_spmWeekDayTextAppearance: " + dayOfWeekTextAppearanceResId); Log.i(TAG, "MDayPickerView_spmDateTextAppearance: " + dayTextAppearanceResId); } String titleFormat; final Resources res = getContext().getResources(); final Locale locale = res.getConfiguration().locale; if (SUtils.isApi_18_OrHigher()) { titleFormat = DateFormat.getBestDateTimePattern(locale, "MM"); } else { titleFormat = DateTimePatternHelper.getBestDateTimePattern(locale, DateTimePatternHelper.PATTERN_MMMMy); } mTitleFormatter = new SimpleDateFormat(titleFormat, locale); // Set up adapter. mAdapter = new DayPickerPagerAdapter(context, R.layout.date_picker_month_item, R.id.month_view, this); mAdapter.setMonthTextAppearance(monthTextAppearanceResId); mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId); mAdapter.setDayTextAppearance(dayTextAppearanceResId); mAdapter.setDaySelectorColor(daySelectorColor); final LayoutInflater inflater = LayoutInflater.from(context); int layoutIdToUse, viewPagerIdToUse; if (getTag() != null && getTag() instanceof String && getResources().getString(R.string.recurrence_end_date_picker_tag).equals(getTag())) { layoutIdToUse = R.layout.day_picker_content_redp; viewPagerIdToUse = R.id.redp_view_pager; } else { layoutIdToUse = R.layout.day_picker_content_sdp; viewPagerIdToUse = R.id.sdp_view_pager; } inflater.inflate(layoutIdToUse, this, true); OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View v) { int direction = -1; if (v == mPrevButton) { direction = -1; } else if (v == mNextButton) { direction = 1; } else if (v == tvReset) { if (mOnResetClickListener != null) mOnResetClickListener.onResetClick(); // return; } // Animation is expensive for accessibility services since it sends // lots of scroll and content change events. final boolean animate = !mAccessibilityManager.isEnabled(); // ViewPager clamps input values, so we don't need to worry // about passing invalid indices. final int nextItem = mViewPager.getCurrentItem() + direction; mViewPager.setCurrentItem(nextItem, animate); } }; mPrevButton = (TextView) findViewById(R.id.prev); mPrevButton.setOnClickListener(onClickListener); mNextButton = (TextView) findViewById(R.id.next); mNextButton.setOnClickListener(onClickListener); mPrevButton.setText(getTitle()); mNextButton.setText(getNextTitle()); tvReset = (TextView) findViewById(R.id.tv_reset); tvReset.setOnClickListener(onClickListener); ViewPager.OnPageChangeListener onPageChangedListener = new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { final float alpha = Math.abs(0.5f - positionOffset) * 2.0f; // mPrevButton.setAlpha(alpha); // mNextButton.setAlpha(alpha); } @Override public void onPageScrollStateChanged(int state) { } @Override public void onPageSelected(int position) { Log.i("TAG", "position=" + position); mOnPageClickListener.onPageSelected(position); updateButtonVisibility(position); } }; mViewPager = (DayPickerViewPager) findViewById(viewPagerIdToUse); mViewPager.setAdapter(mAdapter); mViewPager.addOnPageChangeListener(onPageChangedListener); // Proxy the month text color into the previous and next buttons. if (monthTextAppearanceResId != 0) { final TypedArray ta = context.obtainStyledAttributes(null, ATTRS_TEXT_COLOR, 0, monthTextAppearanceResId); final ColorStateList monthColor = ta.getColorStateList(0); ta.recycle(); } // Proxy selection callbacks to our own listener. mAdapter.setDaySelectionEventListener(new DayPickerPagerAdapter.DaySelectionEventListener() { @Override public boolean onDaySelected(SimpleMonthView view, Calendar day) { if (mProxyDaySelectionEventListener != null) { return mProxyDaySelectionEventListener.onDaySelected(view, day); } return true; } @Override public void onDateRangeSelectionStarted(@NonNull SelectedDate selectedDate) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDateRangeSelectionStarted(selectedDate); } } @Override public void onDateRangeSelectionEnded(@Nullable SelectedDate selectedDate) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDateRangeSelectionEnded(selectedDate); } } @Override public void onDateRangeSelectionUpdated(@NonNull SelectedDate selectedDate) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDateRangeSelectionUpdated(selectedDate); } } }); }
From source file:connect.app.com.connect.calendar.SimpleMonthView.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final Resources res = context.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.date_picker_day_selector_radius); // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); // setAccessibilityDelegate(mTouchHelper); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); final Locale locale = res.getConfiguration().locale; final String titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT); mTitleFormatter = new SimpleDateFormat(titleFormat, locale); mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale); mDayFormatter = NumberFormat.getIntegerInstance(locale); initPaints(res);/* ww w. java2s . c o m*/ }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
private void init() { mContext = getContext();// w w w. j a va2s .c o m mTouchSlopSquared = ViewConfiguration.get(mContext).getScaledTouchSlop() * ViewConfiguration.get(mContext).getScaledTouchSlop(); final Resources res = mContext.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_selector_radius); mPaddingRangeIndicator = res.getDimensionPixelSize(R.dimen.sp_month_view_range_padding); // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); final Locale locale = res.getConfiguration().locale; String titleFormat; if (SUtils.isApi_18_OrHigher()) { titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT); } else { titleFormat = DateTimePatternHelper.getBestDateTimePattern(locale, DateTimePatternHelper.PATTERN_MMMMy); } mTitleFormatter = new SimpleDateFormat(titleFormat, locale); mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale); mDayFormatter = NumberFormat.getIntegerInstance(locale); initPaints(res); }
From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java
private void init() { mContext = getContext();//from w w w. j av a2 s. c o m mTouchSlopSquared = ViewConfiguration.get(mContext).getScaledTouchSlop() * ViewConfiguration.get(mContext).getScaledTouchSlop(); final Resources res = mContext.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_selector_radius); mPaddingRangeIndicator = res.getDimensionPixelSize(R.dimen.sp_month_view_range_padding); // Set up accessibility components. // mTouchHelper = new MonthViewTouchHelper(this); // ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); final Locale locale = res.getConfiguration().locale; String titleFormat; if (SUtils.isApi_18_OrHigher()) { titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT); } else { titleFormat = DateTimePatternHelper.getBestDateTimePattern(locale, DateTimePatternHelper.PATTERN_MMMMy); } mTitleFormatter = new SimpleDateFormat(titleFormat, locale); mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale); mDayFormatter = NumberFormat.getIntegerInstance(locale); initPaints(res); }
From source file:com.customdatepicker.date.DatePickerDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Activity activity = getActivity(); activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mCurrentView = UNINITIALIZED;//from ww w. ja va2 s . c om if (savedInstanceState != null) { mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR)); mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH)); mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY)); mDefaultView = savedInstanceState.getInt(KEY_DEFAULT_VIEW); } if (Build.VERSION.SDK_INT < 18) { VERSION_2_FORMAT = new SimpleDateFormat( activity.getResources().getString(R.string.mdtp_date_v2_daymonthyear), Locale.getDefault()); } else { VERSION_2_FORMAT = new SimpleDateFormat( DateFormat.getBestDateTimePattern(Locale.getDefault(), "EEEMMMdd"), Locale.getDefault()); } VERSION_2_FORMAT.setTimeZone(getTimeZone()); }
From source file:com.mastercard.masterpasswallet.fragments.MainCardFragment.java
private void updateLastTransaction() { if (mCurrentCard != null) { updateUIForCards();/*from w w w .j a v a 2 s .c o m*/ Log.d(TAG, "updateLastTransaction card: " + mCurrentCard.getDpan()); ArrayList<TransactionRecord> transactions = WalletApplication.getInstance().mTransactionRecordHelper .getByQuery(TransactionRecordHelper.COL_CARD + "=?", new String[] { mCurrentCard.getDpan() }, null, null, TransactionRecordHelper.COL_DATE + " DESC"); if (transactions.size() > 0) { TransactionRecord latestTransaction = transactions.get(0); SimpleDateFormat sdf = new SimpleDateFormat( DateFormat.getBestDateTimePattern(Locale.US, "MM/dd/yy"), Locale.US); String formattedDate = sdf.format(latestTransaction.mDate); mTxtLastTransactionDate.setText(formattedDate); mTxtLastTransactionAmount.setVisibility(View.VISIBLE); mTxtLastTransactionAmount.setText(latestTransaction.mValue); if (!android.text.TextUtils.isEmpty(latestTransaction.mMerchant)) { mTxtLastTransactionMerchant.setVisibility(View.VISIBLE); mTxtLastTransactionMerchant.setText(latestTransaction.mMerchant); } else { mTxtLastTransactionMerchant.setVisibility(View.INVISIBLE); } } else { mTxtLastTransactionDate.setText(R.string.text_no_transactions); mTxtLastTransactionAmount.setText(""); mTxtLastTransactionAmount.setVisibility(View.GONE); mTxtLastTransactionMerchant.setVisibility(View.GONE); } } else { updateUIForNoCards(); } }
From source file:com.wizardsofm.deskclock.Utils.java
/** * Clock views can call this to refresh their date. **///from www .j av a 2 s . c om public static void updateDate(String dateSkeleton, String descriptionSkeleton, View clock) { final TextView dateDisplay = (TextView) clock.findViewById(com.wizardsofm.deskclock.R.id.date); if (dateDisplay == null) { return; } final Locale l = Locale.getDefault(); final String datePattern = DateFormat.getBestDateTimePattern(l, dateSkeleton); final String descriptionPattern = DateFormat.getBestDateTimePattern(l, descriptionSkeleton); final Date now = new Date(); dateDisplay.setText(new SimpleDateFormat(datePattern, l).format(now)); dateDisplay.setVisibility(View.VISIBLE); dateDisplay.setContentDescription(new SimpleDateFormat(descriptionPattern, l).format(now)); }
From source file:me.calebjones.spacelaunchnow.utils.Utils.java
public static SimpleDateFormat getSimpleDateFormatForUI(String pattern) { String format = DateFormat.getBestDateTimePattern(Locale.getDefault(), pattern); return new SimpleDateFormat(format, Locale.getDefault()); }