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.events; 18 19 import android.support.annotation.StringRes; 20 21 import com.android.deskclock.R; 22 23 import java.util.ArrayList; 24 import java.util.Collection; 25 26 public final class Events { 27 28 private static final Collection<EventTracker> sEventTrackers = new ArrayList<>(); 29 addEventTracker(EventTracker eventTracker)30 public static void addEventTracker(EventTracker eventTracker) { 31 sEventTrackers.add(eventTracker); 32 } 33 removeEventTracker(EventTracker eventTracker)34 public static void removeEventTracker(EventTracker eventTracker) { 35 sEventTrackers.remove(eventTracker); 36 } 37 38 /** 39 * Tracks an alarm event. 40 * 41 * @param action resource id of event action 42 * @param label resource id of event label 43 */ sendAlarmEvent(@tringRes int action, @StringRes int label)44 public static void sendAlarmEvent(@StringRes int action, @StringRes int label) { 45 sendEvent(R.string.category_alarm, action, label); 46 } 47 48 /** 49 * Tracks a clock event. 50 * 51 * @param action resource id of event action 52 * @param label resource id of event label 53 */ sendClockEvent(@tringRes int action, @StringRes int label)54 public static void sendClockEvent(@StringRes int action, @StringRes int label) { 55 sendEvent(R.string.category_clock, action, label); 56 } 57 58 /** 59 * Tracks an timer event. 60 * 61 * @param action resource id of event action 62 * @param label resource id of event label 63 */ sendTimerEvent(@tringRes int action, @StringRes int label)64 public static void sendTimerEvent(@StringRes int action, @StringRes int label) { 65 sendEvent(R.string.category_timer, action, label); 66 } 67 68 /** 69 * Tracks an stopwatch event. 70 * 71 * @param action resource id of event action 72 * @param label resource id of event label 73 */ sendStopwatchEvent(@tringRes int action, @StringRes int label)74 public static void sendStopwatchEvent(@StringRes int action, @StringRes int label) { 75 sendEvent(R.string.category_stopwatch, action, label); 76 } 77 78 /** 79 * Tracks an event. Events have a category, action, label and value. This 80 * method can be used to track events such as button presses or other user 81 * interactions with your application (value is not used in this app). 82 * 83 * @param category resource id of event category 84 * @param action resource id of event action 85 * @param label resource id of event label 86 */ sendEvent(@tringRes int category, @StringRes int action, @StringRes int label)87 public static void sendEvent(@StringRes int category, @StringRes int action, 88 @StringRes int label) { 89 for (EventTracker eventTracker : sEventTrackers) { 90 eventTracker.sendEvent(category, action, label); 91 } 92 } 93 94 /** 95 * Tracks an event. Events have a category, action, label and value. This 96 * method can be used to track events such as button presses or other user 97 * interactions with your application (value is not used in this app). 98 * 99 * @param category the event category 100 * @param action the event action 101 * @param label the event label 102 */ sendEvent(String category, String action, String label)103 public static void sendEvent(String category, String action, String label) { 104 if (category != null && action != null) { 105 for (EventTracker eventTracker : sEventTrackers) { 106 eventTracker.sendEvent(category, action, label); 107 } 108 } 109 } 110 111 /** 112 * Tracks entering a view with a new app screen name. 113 * 114 * @param screenName the new app screen name 115 */ sendView(String screenName)116 public static void sendView(String screenName) { 117 for (EventTracker eventTracker : sEventTrackers) { 118 eventTracker.sendView(screenName); 119 } 120 } 121 }