1 /* 2 * Copyright (C) 2022 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.settings.regionalpreferences; 18 19 import android.content.Context; 20 import android.provider.Settings; 21 22 import androidx.core.text.util.LocalePreferences; 23 24 import com.android.settings.R; 25 import com.android.settings.core.BasePreferenceController; 26 27 import java.util.Locale; 28 29 /** A controller for the entry of First Day of Week's page */ 30 public class FirstDayOfWeekController extends BasePreferenceController { 31 private static final String TAG = FirstDayOfWeekController.class.getSimpleName(); 32 FirstDayOfWeekController(Context context, String preferenceKey)33 public FirstDayOfWeekController(Context context, String preferenceKey) { 34 super(context, preferenceKey); 35 } 36 37 /** 38 * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the 39 * Setting should be shown or disabled in Settings. Further, it can be used to produce 40 * appropriate error / warning Slice in the case of unavailability. 41 * </p> 42 * The status is used for the convenience methods: {@link #isAvailable()}, {@link 43 * #isSupported()} 44 * </p> 45 * The inherited class doesn't need to check work profile if android:forWork="true" is set in 46 * preference xml. 47 */ 48 @Override getAvailabilityStatus()49 public int getAvailabilityStatus() { 50 return AVAILABLE; 51 } 52 53 @Override getSummary()54 public CharSequence getSummary() { 55 String record = Settings.System.getString( 56 mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES); 57 String result = ""; 58 if (record != null) { 59 result = LocalePreferences.getFirstDayOfWeek(Locale.forLanguageTag(record), false); 60 } 61 62 if (result.isEmpty()) { 63 result = LocalePreferences.getFirstDayOfWeek(false); 64 } 65 return result.isEmpty() 66 ? mContext.getString(R.string.default_string_of_regional_preference) 67 : RegionalPreferencesDataUtils.dayConverter(mContext, result); 68 } 69 } 70