171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu/*
271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * Copyright (C) 2015 The Android Open Source Project
371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu *
471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * in compliance with the License. You may obtain a copy of the License at
671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu *
771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * http://www.apache.org/licenses/LICENSE-2.0
871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu *
971d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License
1071d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * or implied. See the License for the specific language governing permissions and limitations under
1271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * the License.
1371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu */
1471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
1571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gupackage android.support.v17.leanback.widget.picker;
1671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
1771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Guimport android.content.res.Resources;
1871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Guimport android.support.v17.leanback.R;
1971d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
2071d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Guimport java.text.DateFormatSymbols;
2171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Guimport java.util.Calendar;
2271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Guimport java.util.Locale;
2371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
2471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu/**
2571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu * Date/Time Picker related constants
2671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu */
2771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Guclass PickerConstant {
2871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
2971d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String[] months;
3071d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String[] days;
3171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String[] hours12;
3271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String[] hours24;
3371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String[] minutes;
3471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String[] ampm;
3571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String dateSeparator;
3671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final String timeSeparator;
3771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public final Locale locale;
3871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
3971d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public PickerConstant(Locale locale, Resources resources) {
4071d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        this.locale = locale;
4171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
4271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        months = symbols.getShortMonths();
4371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        Calendar calendar = Calendar.getInstance(locale);
4471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        days = createStringIntArrays(calendar.getMinimum(Calendar.DAY_OF_MONTH),
4571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu                calendar.getMaximum(Calendar.DAY_OF_MONTH), "%02d");
4671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        hours12 = createStringIntArrays(1, 12, "%02d");
4771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        hours24 = createStringIntArrays(0, 23, "%02d");
4871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        minutes = createStringIntArrays(0, 59, "%02d");
4971d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        ampm = symbols.getAmPmStrings();
5071d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        dateSeparator = resources.getString(R.string.lb_date_separator);
5171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        timeSeparator = resources.getString(R.string.lb_time_separator);
5271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    }
5371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
5471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
5571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    public static String[] createStringIntArrays(int firstNumber, int lastNumber, String format) {
5671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        String[] array = new String[lastNumber - firstNumber + 1];
5771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        for (int i = firstNumber; i <= lastNumber; i++) {
5871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu            if (format != null) {
5971d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu                array[i - firstNumber] = String.format(format, i);
6071d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu            } else {
6171d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu                array[i - firstNumber] = String.valueOf(i);
6271d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu            }
6371d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        }
6471d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu        return array;
6571d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu    }
6671d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
6771d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu
6871d30e1cf5514761ba8ad4bd3c8c70540d60dbd3Dake Gu}