• 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.events
18 
19 import androidx.annotation.StringRes
20 
21 import com.android.deskclock.R
22 import com.android.deskclock.controller.Controller
23 
24 /**
25  * This thin layer over [Controller.sendEvent] eases the API usage.
26  */
27 object Events {
28     /** Extra describing the entity responsible for the action being performed.  */
29     const val EXTRA_EVENT_LABEL = "com.android.deskclock.extra.EVENT_LABEL"
30 
31     /**
32      * Tracks an alarm event.
33      *
34      * @param action resource id of event action
35      * @param label resource id of event label
36      */
37     @JvmStatic
sendAlarmEventnull38     fun sendAlarmEvent(@StringRes action: Int, @StringRes label: Int) {
39         sendEvent(R.string.category_alarm, action, label)
40     }
41 
42     /**
43      * Tracks a clock event.
44      *
45      * @param action resource id of event action
46      * @param label resource id of event label
47      */
48     @JvmStatic
sendClockEventnull49     fun sendClockEvent(@StringRes action: Int, @StringRes label: Int) {
50         sendEvent(R.string.category_clock, action, label)
51     }
52 
53     /**
54      * Tracks a timer event.
55      *
56      * @param action resource id of event action
57      * @param label resource id of event label
58      */
59     @JvmStatic
sendTimerEventnull60     fun sendTimerEvent(@StringRes action: Int, @StringRes label: Int) {
61         sendEvent(R.string.category_timer, action, label)
62     }
63 
64     /**
65      * Tracks a stopwatch event.
66      *
67      * @param action resource id of event action
68      * @param label resource id of event label
69      */
70     @JvmStatic
sendStopwatchEventnull71     fun sendStopwatchEvent(@StringRes action: Int, @StringRes label: Int) {
72         sendEvent(R.string.category_stopwatch, action, label)
73     }
74 
75     /**
76      * Tracks a screensaver event.
77      *
78      * @param action resource id of event action
79      * @param label resource id of event label
80      */
81     @JvmStatic
sendScreensaverEventnull82     fun sendScreensaverEvent(@StringRes action: Int, @StringRes label: Int) {
83         sendEvent(R.string.category_screensaver, action, label)
84     }
85 
86     /**
87      * Tracks an event. Events have a category, action, label and value. This
88      * method can be used to track events such as button presses or other user
89      * interactions with your application (value is not used in this app).
90      *
91      * @param category resource id of event category
92      * @param action resource id of event action
93      * @param label resource id of event label
94      */
95     @JvmStatic
sendEventnull96     fun sendEvent(@StringRes category: Int, @StringRes action: Int, @StringRes label: Int) {
97         Controller.getController().sendEvent(category, action, label)
98     }
99 }