Java Code Examples for android.text.format.DateFormat#getDateFormatOrder()

The following examples show how to use android.text.format.DateFormat#getDateFormatOrder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatePicker.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
/**
 * Reorders the spinners according to the date format that is
 * explicitly set by the user and if no such is set fall back
 * to the current locale's default format.
 */
private void reorderSpinners() {
    mSpinners.removeAllViews();
    // We use numeric spinners for year and day, but textual months. Ask icu4c what
    // order the user's locale uses for that combination. http://b/7207103.
    char[] order = DateFormat.getDateFormatOrder(mContext);
    final int spinnerCount = order.length;
    for (int i = 0; i < spinnerCount; i++) {
        switch (order[i]) {
            case 'd':
                mSpinners.addView(mDaySpinner);
                setImeOptions(mDaySpinner, spinnerCount, i);
                break;
            case 'M':
                mSpinners.addView(mMonthSpinner);
                setImeOptions(mMonthSpinner, spinnerCount, i);
                break;
            case 'y':
                mSpinners.addView(mYearSpinner);
                setImeOptions(mYearSpinner, spinnerCount, i);
                break;
            default:
                throw new IllegalArgumentException(Arrays.toString(order));
        }
    }
}
 
Example 2
Source File: DateFormatFix.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
public static char[] getDateFormatOrder(Context context, Locale locale, String skeleton) {
    //char[] order = ICU.getDateFormatOrder(pattern);
   /* if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return DateFormat.getDateFormatOrder(context);
        //return android.icu.text.DateFormat.getInstanceForSkeleton(skeleton, locale);
    }*/
    // FIXME String pattern = getBestDateTimePattern(context, locale, skeleton);
    // FIXME check this ICU.getDateFormatOrder(pattern);
    return DateFormat.getDateFormatOrder(context);
}
 
Example 3
Source File: TwoFieldDatePicker.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Reorder the date picker spinners to match the order suggested by the locale.
 * Assumes that the order of month and year in the locale is also the right order
 * for the spinner columns.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void reorderSpinners() {
    boolean posInserted = false;
    boolean yearInserted = false;

    LinearLayout pickers = (LinearLayout) findViewById(R.id.pickers);

    pickers.removeView(mPositionInYearSpinner);
    pickers.removeView(mYearSpinner);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // logic duplicated from android.widget.DatePicker
        String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "yyyyMMMdd");

        for (int i = 0; i < pattern.length(); ++i) {
            char ch = pattern.charAt(i);
            if (ch == '\'') {
                i = pattern.indexOf('\'', i + 1);
                if (i == -1) {
                    throw new IllegalArgumentException("Bad quoting in " + pattern);
                }
            } else if ((ch == 'M' || ch == 'L') && !posInserted) {
                pickers.addView(mPositionInYearSpinner);
                posInserted = true;
            } else if (ch == 'y' && !yearInserted) {
                pickers.addView(mYearSpinner);
                yearInserted = true;
            }
        }
    } else {
        // This method was used to order android.widget.DatePicker
        // fields in JB prior to the availability of
        // getBestDateTimePattern.
        char[] order = DateFormat.getDateFormatOrder(getContext());
        for (int i = 0; i < order.length; ++i) {
            if (order[i] == 'M') {
                pickers.addView(mPositionInYearSpinner);
                posInserted = true;
            } else if (order[i] == 'y') {
                pickers.addView(mYearSpinner);
                yearInserted = true;
            }
        }
    }

    if (!posInserted) pickers.addView(mPositionInYearSpinner);
    if (!yearInserted) pickers.addView(mYearSpinner);
}
 
Example 4
Source File: CustomDatePicker.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void reorderPickers(String[] months) {
    java.text.DateFormat format;
    String order;

    /*
     * If the user is in a locale where the medium date format is
     * still numeric (Japanese and Czech, for example), respect
     * the date format order setting.  Otherwise, use the order
     * that the locale says is appropriate for a spelled-out date.
     */

    if (months[0].startsWith("1")) {
        format = DateFormat.getDateFormat(getContext());
    } else {
        format = DateFormat.getMediumDateFormat(getContext());
    }

    if (format instanceof SimpleDateFormat) {
        order = ((SimpleDateFormat) format).toPattern();
    } else {
        // Shouldn't happen, but just in case.
        order = new String(DateFormat.getDateFormatOrder(getContext()));
    }

    /* Remove the 3 pickers from their parent and then add them back in the
     * required order.
     */
    LinearLayout parent = (LinearLayout) findViewById(R.id.parent);
    parent.removeAllViews();

    boolean quoted = false;
    boolean didDay = false, didMonth = false, didYear = false;

    for (int i = 0; i < order.length(); i++) {
        char c = order.charAt(i);

        if (c == '\'') {
            quoted = !quoted;
        }

        if (!quoted) {
            if (c == DATE && !didDay) {
                parent.addView(mDayPicker);
                didDay = true;
            } else if ((c == MONTH || c == 'L') && !didMonth) {
                parent.addView(mMonthPicker);
                didMonth = true;
            } else if (c == YEAR && !didYear) {
                parent.addView(mYearPicker);
                didYear = true;
            }
        }
    }

    // Shouldn't happen, but just in case.
    if (!didMonth) {
        parent.addView(mMonthPicker);
    }
    if (!didDay) {
        parent.addView(mDayPicker);
    }
    if (!didYear) {
        parent.addView(mYearPicker);
    }
}