Home | History | Annotate | Download | only in picker
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.tv.settings.widget.picker;
     18 
     19 import android.content.res.Resources;
     20 
     21 import com.android.tv.settings.R;
     22 
     23 import java.text.DateFormatSymbols;
     24 
     25 /**
     26  * Picker related constants
     27  */
     28 public class PickerConstants {
     29 
     30     public static class Date {
     31         public final String[] months;
     32         public final String[] days31;
     33         public final String dateSeparator;
     34 
     35         private Date(Resources resources) {
     36             months = new DateFormatSymbols().getShortMonths();
     37             days31 = createStringIntArrays(31, false, 2);
     38             dateSeparator = resources.getString(R.string.date_separator);
     39         }
     40     }
     41 
     42     public static class Time {
     43         public final String[] hours12;
     44         public final String[] hours24;
     45         public final String[] minutes;
     46         public final String[] ampm;
     47         public final String timeSeparator;
     48 
     49         private Time(Resources resources) {
     50             hours12 = createStringIntArrays(12, false, 2);
     51             hours24 = createStringIntArrays(23, true, 2);
     52             minutes = createStringIntArrays(59, true, 2);
     53             ampm = resources.getStringArray(R.array.ampm);
     54             timeSeparator = resources.getString(R.string.time_separator);
     55         }
     56     }
     57 
     58     private PickerConstants() {}
     59 
     60     private static String[] createStringIntArrays(int lastNumber, boolean startAtZero, int minLen) {
     61         int range = startAtZero ? (lastNumber + 1) : lastNumber;
     62         String format = "%0" + minLen + "d";
     63         String[] array = new String[range];
     64         for (int i = 0; i < range; i++) {
     65             if (minLen > 0) {
     66                 array[i] = String.format(format, startAtZero ? i : (i + 1));
     67             } else {
     68                 array[i] = String.valueOf(startAtZero ? i : (i + 1));
     69             }
     70         }
     71         return array;
     72     }
     73 
     74     public static PickerConstants.Date getDateInstance(Resources resources) {
     75         return new Date(resources);
     76     }
     77 
     78     public static PickerConstants.Time getTimeInstance(Resources resources) {
     79         return new Time(resources);
     80     }
     81 }
     82