• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.provider
18 
19 import android.net.Uri
20 import android.provider.BaseColumns
21 
22 import com.android.deskclock.BuildConfig
23 import com.android.deskclock.provider.ClockContract.AlarmsColumns
24 import com.android.deskclock.provider.ClockContract.InstancesColumns
25 
26 /**
27  * The contract between the clock provider and desk clock. Contains
28  * definitions for the supported URIs and data columns.
29  *
30  * <h3>Overview</h3>
31  *
32  * ClockContract defines the data model of clock related information.
33  * This data is stored in a number of tables:
34  *
35  *  * The [AlarmsColumns] table holds the user created alarms
36  *  * The [InstancesColumns] table holds the current state of each
37  * alarm in the AlarmsColumn table.
38  */
39 object ClockContract {
40     /**
41      * This authority is used for writing to or querying from the clock
42      * provider.
43      */
44     @JvmField
45     val AUTHORITY: String = BuildConfig.APPLICATION_ID
46 
47     /**
48      * Constants for tables with AlarmSettings.
49      */
50     interface AlarmSettingColumns : BaseColumns {
51         companion object {
52             /**
53              * This string is used to indicate no ringtone.
54              */
55             @JvmField
56             val NO_RINGTONE_URI: Uri = Uri.EMPTY
57 
58             /**
59              * This string is used to indicate no ringtone.
60              */
61             @JvmField
62             val NO_RINGTONE: String = NO_RINGTONE_URI.toString()
63 
64             /**
65              * True if alarm should vibrate
66              *
67              * Type: BOOLEAN
68              */
69             @JvmField
70             val VIBRATE = "vibrate"
71 
72             /**
73              * Alarm label.
74              *
75              * Type: STRING
76              */
77             @JvmField
78             val LABEL = "label"
79 
80             /**
81              * Audio alert to play when alarm triggers. Null entry
82              * means use system default and entry that equal
83              * Uri.EMPTY.toString() means no ringtone.
84              *
85              * Type: STRING
86              */
87             @JvmField
88             val RINGTONE = "ringtone"
89         }
90     }
91 
92     /**
93      * Constants for the Alarms table, which contains the user created alarms.
94      */
95     interface AlarmsColumns : AlarmSettingColumns, BaseColumns {
96         companion object {
97             /**
98              * The content:// style URL for this table.
99              */
100             val CONTENT_URI: Uri = Uri.parse("content://$AUTHORITY/alarms")
101 
102             /**
103              * The content:// style URL for the alarms with instance tables, which is used to get the
104              * next firing instance and the current state of an alarm.
105              */
106             val ALARMS_WITH_INSTANCES_URI: Uri = Uri.parse("content://" + AUTHORITY +
107                     "/alarms_with_instances")
108 
109             /**
110              * Hour in 24-hour localtime 0 - 23.
111              *
112              * Type: INTEGER
113              */
114             const val HOUR = "hour"
115 
116             /**
117              * Minutes in localtime 0 - 59.
118              *
119              * Type: INTEGER
120              */
121             const val MINUTES = "minutes"
122 
123             /**
124              * Days of the week encoded as a bit set.
125              *
126              * Type: INTEGER
127              *
128              * [com.android.deskclock.data.Weekdays]
129              */
130             const val DAYS_OF_WEEK = "daysofweek"
131 
132             /**
133              * True if alarm is active.
134              *
135              * Type: BOOLEAN
136              */
137             const val ENABLED = "enabled"
138 
139             /**
140              * Determine if alarm is deleted after it has been used.
141              *
142              * Type: INTEGER
143              */
144             const val DELETE_AFTER_USE = "delete_after_use"
145         }
146     }
147 
148     /**
149      * Constants for the Instance table, which contains the state of each alarm.
150      */
151     interface InstancesColumns : AlarmSettingColumns, BaseColumns {
152         companion object {
153             /**
154              * The content:// style URL for this table.
155              */
156             val CONTENT_URI: Uri = Uri.parse("content://$AUTHORITY/instances")
157 
158             /**
159              * Alarm state when to show no notification.
160              *
161              * Can transitions to:
162              * LOW_NOTIFICATION_STATE
163              */
164             const val SILENT_STATE = 0
165 
166             /**
167              * Alarm state to show low priority alarm notification.
168              *
169              * Can transitions to:
170              * HIDE_NOTIFICATION_STATE
171              * HIGH_NOTIFICATION_STATE
172              * DISMISSED_STATE
173              */
174             const val LOW_NOTIFICATION_STATE = 1
175 
176             /**
177              * Alarm state to hide low priority alarm notification.
178              *
179              * Can transitions to:
180              * HIGH_NOTIFICATION_STATE
181              */
182             const val HIDE_NOTIFICATION_STATE = 2
183 
184             /**
185              * Alarm state to show high priority alarm notification.
186              *
187              * Can transitions to:
188              * DISMISSED_STATE
189              * FIRED_STATE
190              */
191             const val HIGH_NOTIFICATION_STATE = 3
192 
193             /**
194              * Alarm state when alarm is in snooze.
195              *
196              * Can transitions to:
197              * DISMISSED_STATE
198              * FIRED_STATE
199              */
200             const val SNOOZE_STATE = 4
201 
202             /**
203              * Alarm state when alarm is being fired.
204              *
205              * Can transitions to:
206              * DISMISSED_STATE
207              * SNOOZED_STATE
208              * MISSED_STATE
209              */
210             const val FIRED_STATE = 5
211 
212             /**
213              * Alarm state when alarm has been missed.
214              *
215              * Can transitions to:
216              * DISMISSED_STATE
217              */
218             const val MISSED_STATE = 6
219 
220             /**
221              * Alarm state when alarm is done.
222              */
223             const val DISMISSED_STATE = 7
224 
225             /**
226              * Alarm state when alarm has been dismissed before its intended firing time.
227              */
228             const val PREDISMISSED_STATE = 8
229 
230             /**
231              * Alarm year.
232              *
233              * Type: INTEGER
234              */
235             const val YEAR = "year"
236 
237             /**
238              * Alarm month in year.
239              *
240              * Type: INTEGER
241              */
242             const val MONTH = "month"
243 
244             /**
245              * Alarm day in month.
246              *
247              * Type: INTEGER
248              */
249             const val DAY = "day"
250 
251             /**
252              * Alarm hour in 24-hour localtime 0 - 23.
253              *
254              * Type: INTEGER
255              */
256             const val HOUR = "hour"
257 
258             /**
259              * Alarm minutes in localtime 0 - 59
260              *
261              * Type: INTEGER
262              */
263             const val MINUTES = "minutes"
264 
265             /**
266              * Foreign key to Alarms table
267              *
268              * Type: INTEGER (long)
269              */
270             const val ALARM_ID = "alarm_id"
271 
272             /**
273              * Alarm state
274              *
275              * Type: INTEGER
276              */
277             const val ALARM_STATE = "alarm_state"
278         }
279     }
280 }