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.data; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.provider.Settings; 22 23 import com.android.deskclock.R; 24 import com.android.deskclock.data.DataModel.CitySort; 25 import com.android.deskclock.data.DataModel.ClockStyle; 26 27 import java.util.TimeZone; 28 29 /** 30 * All settings data is accessed via this model. 31 */ 32 final class SettingsModel { 33 34 private final Context mContext; 35 36 /** The uri of the default ringtone to use for timers until the user explicitly chooses one. */ 37 private Uri mDefaultTimerRingtoneUri; 38 39 SettingsModel(Context context) { 40 mContext = context; 41 42 // Set the user's default home timezone if one has not yet been chosen. 43 SettingsDAO.setDefaultHomeTimeZone(mContext, TimeZone.getDefault()); 44 } 45 46 CitySort getCitySort() { 47 return SettingsDAO.getCitySort(mContext); 48 } 49 50 void toggleCitySort() { 51 SettingsDAO.toggleCitySort(mContext); 52 } 53 54 TimeZone getHomeTimeZone() { 55 return SettingsDAO.getHomeTimeZone(mContext); 56 } 57 58 ClockStyle getClockStyle() { 59 return SettingsDAO.getClockStyle(mContext); 60 } 61 62 ClockStyle getScreensaverClockStyle() { 63 return SettingsDAO.getScreensaverClockStyle(mContext); 64 } 65 66 boolean getShowHomeClock() { 67 if (!SettingsDAO.getAutoShowHomeClock(mContext)) { 68 return false; 69 } 70 71 // Show the home clock if the current time and home time differ. 72 // (By using UTC offset for this comparison the various DST rules are considered) 73 final TimeZone homeTimeZone = SettingsDAO.getHomeTimeZone(mContext); 74 final long now = System.currentTimeMillis(); 75 return homeTimeZone.getOffset(now) != TimeZone.getDefault().getOffset(now); 76 } 77 78 Uri getDefaultTimerRingtoneUri() { 79 if (mDefaultTimerRingtoneUri == null) { 80 final String packageName = mContext.getPackageName(); 81 final int resId = R.raw.timer_expire; 82 final String uriString = String.format("android.resource://%s/%d", packageName, resId); 83 mDefaultTimerRingtoneUri = Uri.parse(uriString); 84 } 85 86 return mDefaultTimerRingtoneUri; 87 } 88 89 Uri getTimerRingtoneUri() { 90 return SettingsDAO.getTimerRingtoneUri(mContext, getDefaultTimerRingtoneUri()); 91 } 92 93 Uri getDefaultAlarmRingtoneUri() { 94 return SettingsDAO.getDefaultAlarmRingtoneUri(mContext, 95 Settings.System.DEFAULT_ALARM_ALERT_URI); 96 } 97 98 void setDefaultAlarmRingtoneUri(Uri uri) { 99 SettingsDAO.setDefaultAlarmRingtoneUri(mContext, uri); 100 } 101 }