1 /* 2 * Copyright (C) 2015 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.deskclock.alarms.utils; 18 19 import android.content.Context; 20 21 import com.android.deskclock.Utils; 22 import com.android.deskclock.provider.DaysOfWeek; 23 24 import java.util.Calendar; 25 26 /** 27 * Contains information about the order that days of the week are shown in the UI. 28 */ 29 public final class DayOrderUtils { 30 31 // A reference used to create mDayOrder 32 private static final int[] DAY_ORDER = { 33 Calendar.SUNDAY, 34 Calendar.MONDAY, 35 Calendar.TUESDAY, 36 Calendar.WEDNESDAY, 37 Calendar.THURSDAY, 38 Calendar.FRIDAY, 39 Calendar.SATURDAY, 40 }; 41 getDayOrder(Context context)42 public static int[] getDayOrder(Context context) { 43 // Value from preferences corresponds to Calendar.<WEEKDAY> value 44 // -1 in order to correspond to DAY_ORDER indexing 45 final int startDay = Utils.getZeroIndexedFirstDayOfWeek(context); 46 final int[] dayOrder = new int[DaysOfWeek.DAYS_IN_A_WEEK]; 47 48 for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; ++i) { 49 dayOrder[i] = DAY_ORDER[(startDay + i) % DaysOfWeek.DAYS_IN_A_WEEK]; 50 } 51 return dayOrder; 52 } 53 54 } 55