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