Search in sources :

Example 41 with DateFormatSymbols

use of java.text.DateFormatSymbols in project HoloEverywhere by Prototik.

the class TimePickerDialog method onCreateView.

@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);
    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 = (Button) 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.
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.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);
        mAmPmTextView.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 = "--";
    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;
}
Also used : ArrayList(java.util.ArrayList) TextView(org.holoeverywhere.widget.TextView) View(android.view.View) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) DateFormatSymbols(java.text.DateFormatSymbols) TextView(org.holoeverywhere.widget.TextView) Resources(android.content.res.Resources)

Example 42 with DateFormatSymbols

use of java.text.DateFormatSymbols in project Japid by branaway.

the class JapidDateFormat method parsePattern.

// Parse the pattern
// -----------------------------------------------------------------------
/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a <code>List</code> of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 */
protected List parsePattern() {
    DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    List rules = new ArrayList();
    String[] ERAs = symbols.getEras();
    String[] months = symbols.getMonths();
    String[] shortMonths = symbols.getShortMonths();
    String[] weekdays = symbols.getWeekdays();
    String[] shortWeekdays = symbols.getShortWeekdays();
    String[] AmPmStrings = symbols.getAmPmStrings();
    int length = mPattern.length();
    int[] indexRef = new int[1];
    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        String token = parseToken(mPattern, indexRef);
        i = indexRef[0];
        int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }
        Rule rule;
        char c = token.charAt(0);
        switch(c) {
            case // era designator (text)
            'G':
                rule = new TextField(Calendar.ERA, ERAs);
                break;
            case // year (number)
            'y':
                if (tokenLen >= 4) {
                    rule = selectNumberRule(Calendar.YEAR, tokenLen);
                } else {
                    rule = TwoDigitYearField.INSTANCE;
                }
                break;
            case // month in year (text and number)
            'M':
                if (tokenLen >= 4) {
                    rule = new TextField(Calendar.MONTH, months);
                } else if (tokenLen == 3) {
                    rule = new TextField(Calendar.MONTH, shortMonths);
                } else if (tokenLen == 2) {
                    rule = TwoDigitMonthField.INSTANCE;
                } else {
                    rule = UnpaddedMonthField.INSTANCE;
                }
                break;
            case // day in month (number)
            'd':
                rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
                break;
            case // hour in am/pm (number, 1..12)
            'h':
                rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
                break;
            case // hour in day (number, 0..23)
            'H':
                rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
                break;
            case // minute in hour (number)
            'm':
                rule = selectNumberRule(Calendar.MINUTE, tokenLen);
                break;
            case // second in minute (number)
            's':
                rule = selectNumberRule(Calendar.SECOND, tokenLen);
                break;
            case // millisecond (number)
            'S':
                rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
                break;
            case // day in week (text)
            'E':
                rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
                break;
            case // day in year (number)
            'D':
                rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
                break;
            case // day of week in month (number)
            'F':
                rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
                break;
            case // week in year (number)
            'w':
                rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
                break;
            case // week in month (number)
            'W':
                rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
                break;
            case // am/pm marker (text)
            'a':
                rule = new TextField(Calendar.AM_PM, AmPmStrings);
                break;
            case // hour in day (1..24)
            'k':
                rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
                break;
            case // hour in am/pm (0..11)
            'K':
                rule = selectNumberRule(Calendar.HOUR, tokenLen);
                break;
            case // time zone (text)
            'z':
                if (tokenLen >= 4) {
                    rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
                } else {
                    rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
                }
                break;
            case // time zone (value)
            'Z':
                if (tokenLen == 1) {
                    rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
                } else {
                    rule = TimeZoneNumberRule.INSTANCE_COLON;
                }
                break;
            case // literal text
            '\'':
                String sub = token.substring(1);
                if (sub.length() == 1) {
                    rule = new CharacterLiteral(sub.charAt(0));
                } else {
                    rule = new StringLiteral(sub);
                }
                break;
            default:
                throw new IllegalArgumentException("Illegal pattern component: " + token);
        }
        rules.add(rule);
    }
    return rules;
}
Also used : ArrayList(java.util.ArrayList) DateFormatSymbols(java.text.DateFormatSymbols) ArrayList(java.util.ArrayList) List(java.util.List)

Example 43 with DateFormatSymbols

use of java.text.DateFormatSymbols in project j2objc by google.

the class DateFormatSymbolsTest method test_setLocalPatternCharsLjava_lang_String.

public void test_setLocalPatternCharsLjava_lang_String() {
    String patternChars = "GyMZZkHmsSEHHFwWahKz";
    dfs.setLocalPatternChars(patternChars);
    assertEquals(patternChars, dfs.getLocalPatternChars());
    try {
        // Regression for HARMONY-466
        new DateFormatSymbols().setLocalPatternChars(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols)

Example 44 with DateFormatSymbols

use of java.text.DateFormatSymbols in project j2objc by google.

the class DateFormatSymbolsTest method test_equalsLjava_lang_Object.

/**
 * @tests java.text.DateFormatSymbols#equals(java.lang.Object)
 */
public void test_equalsLjava_lang_Object() {
    // Test for method boolean
    // java.text.DateFormatSymbols.equals(java.lang.Object)
    assertTrue("Equal object returned true", dfs.equals(dfs.clone()));
    dfs.setLocalPatternChars("KKKKKKKKK");
    assertTrue("Un-Equal objects returned false", !dfs.equals(new DateFormatSymbols()));
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols)

Example 45 with DateFormatSymbols

use of java.text.DateFormatSymbols in project j2objc by google.

the class DateFormatSymbolsTest method test_getInstanceLjava_util_Locale.

public void test_getInstanceLjava_util_Locale() {
    try {
        DateFormatSymbols.getInstance(null);
        fail();
    } catch (NullPointerException expected) {
    }
    assertEquals(new DateFormatSymbols(Locale.GERMANY), DateFormatSymbols.getInstance(Locale.GERMANY));
    Locale locale = new Locale("not exist language", "not exist country");
    DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
    assertEquals(DateFormatSymbols.getInstance(Locale.ROOT), symbols);
}
Also used : Locale(java.util.Locale) DateFormatSymbols(java.text.DateFormatSymbols)

Aggregations

DateFormatSymbols (java.text.DateFormatSymbols)140 SimpleDateFormat (java.text.SimpleDateFormat)38 Date (java.util.Date)26 ArrayList (java.util.ArrayList)23 Locale (java.util.Locale)21 Resources (android.content.res.Resources)15 View (android.view.View)14 TextView (android.widget.TextView)12 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)9 List (java.util.List)8 OnClickListener (android.view.View.OnClickListener)7 Test (org.junit.Test)7 Typeface (android.graphics.Typeface)6 RelativeLayout (android.widget.RelativeLayout)6 LayoutParams (android.app.ActionBar.LayoutParams)5 IOException (java.io.IOException)5 TypedArray (android.content.res.TypedArray)4 AdapterView (android.widget.AdapterView)4 Button (android.widget.Button)4