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 package com.android.deskclock.events;
17 
18 import android.content.Context;
19 import android.support.annotation.StringRes;
20 
21 import com.android.deskclock.LogUtils;
22 
23 public final class LogEventTracker implements EventTracker {
24 
25     private static final LogUtils.Logger LOGGER = new LogUtils.Logger("Events");
26 
27     private final Context mContext;
28 
LogEventTracker(Context context)29     public LogEventTracker(Context context) {
30         mContext = context;
31     }
32 
33     @Override
sendEvent(@tringRes int category, @StringRes int action, @StringRes int label)34     public void sendEvent(@StringRes int category, @StringRes int action, @StringRes int label) {
35         if (label == 0) {
36             LOGGER.d("[%s] [%s]", safeGetString(category), safeGetString(action));
37         } else {
38             LOGGER.d("[%s] [%s] [%s]", safeGetString(category), safeGetString(action),
39                     safeGetString(label));
40         }
41     }
42 
43     /**
44      * @return Resource string represented by a given resource id, null if resId is invalid (0).
45      */
safeGetString(@tringRes int resId)46     private String safeGetString(@StringRes int resId) {
47         return resId == 0 ? null : mContext.getString(resId);
48     }
49 }
50