ScreenEvent.java revision f96bb18b904dada96002cb72d862097ae344db57
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.dialer.logging;
17
18import android.text.TextUtils;
19
20import com.android.contacts.common.dialog.ClearFrequentsDialog;
21import com.android.contacts.common.interactions.ImportExportDialogFragment;
22import com.android.dialer.calllog.CallLogFragment;
23import com.android.dialer.dialpad.DialpadFragment;
24import com.android.dialer.filterednumber.BlockedNumbersFragment;
25import com.android.dialer.list.AllContactsFragment;
26import com.android.dialer.list.BlockedListSearchFragment;
27import com.android.dialer.list.RegularSearchFragment;
28import com.android.dialer.list.SmartDialSearchFragment;
29import com.android.dialer.list.SpeedDialFragment;
30import com.android.dialer.settings.DialerSettingsActivity;
31import com.android.incallui.AnswerFragment;
32import com.android.incallui.CallCardFragment;
33import com.android.incallui.ConferenceManagerFragment;
34import com.android.incallui.InCallActivity;
35
36import java.util.HashMap;
37import java.util.Map;
38
39/**
40 * Stores constants identifying individual screens/dialogs/fragments in the application, and also
41 * provides a mapping of integer id -> screen name mappings for analytics purposes.
42 */
43public class ScreenEvent {
44    private static final Map<Integer, String> sScreenNameMap = new HashMap<>();
45
46    public static final String FRAGMENT_TAG_SEPARATOR = "#";
47
48    public static final int UNKNOWN = 0;
49
50    // The dialpad in the main Dialer activity
51    public static final int DIALPAD = 1;
52
53    // The speed dial tab in the main Dialer activity
54    public static final int SPEED_DIAL = 2;
55
56    // The recents tab in the main Dialer activity
57    public static final int CALL_LOG = 3;
58
59    // The voicemail tab in the main Dialer activity
60    public static final int VOICEMAIL_LOG = 4;
61
62    // The all contacts tab in the main Dialer activity
63    public static final int ALL_CONTACTS = 5;
64
65    // List of search results returned by typing into the search box.
66    public static final int REGULAR_SEARCH = 6;
67
68    // List of search results returned by typing into the dialpad.
69    public static final int SMART_DIAL_SEARCH = 7;
70
71    // The All and Missed call log tabs in CallLogActivity
72    public static final int CALL_LOG_FILTER = 8;
73
74    // Dialer settings screen.
75    public static final int SETTINGS = 9;
76
77    // The "Import/export contacts" dialog launched via the overflow menu.
78    public static final int IMPORT_EXPORT_CONTACTS = 10;
79
80    // The "Clear frequents" dialog launched via the overflow menu.
81    public static final int CLEAR_FREQUENTS = 11;
82
83    // The "Send feedback" dialog launched via the overflow menu.
84    public static final int SEND_FEEDBACK = 12;
85
86    // The main in call screen that displays caller details and contact photos
87    public static final int INCALL = 13;
88
89    // The screen that displays the glowpad widget (slide right to answer,
90    // slide left to dismiss).
91    public static final int INCOMING_CALL = 14;
92
93    // Conference management fragment displayed for conferences that support
94    // management of individual calls within the conference.
95    public static final int CONFERENCE_MANAGEMENT = 15;
96
97    // The dialpad displayed in-call that is used to send dtmf tones.
98    public static final int INCALL_DIALPAD = 16;
99
100    // Menu options displayed when long pressing on a call log entry.
101    public static final int CALL_LOG_CONTEXT_MENU = 17;
102
103    // Screen displayed to allow the user to see an overview of all blocked
104    // numbers.
105    public static final int BLOCKED_NUMBER_MANAGEMENT = 18;
106
107    // Screen displayed to allow the user to add a new blocked number.
108    public static final int BLOCKED_NUMBER_ADD_NUMBER = 19;
109
110    static {
111        sScreenNameMap.put(ScreenEvent.DIALPAD,
112                getScreenNameWithTag(DialpadFragment.class.getSimpleName(), "Dialer"));
113        sScreenNameMap.put(ScreenEvent.SPEED_DIAL, SpeedDialFragment.class.getSimpleName());
114        sScreenNameMap.put(ScreenEvent.CALL_LOG,
115                getScreenNameWithTag(CallLogFragment.class.getSimpleName(), "History"));
116        sScreenNameMap.put(ScreenEvent.VOICEMAIL_LOG,
117                getScreenNameWithTag(CallLogFragment.class.getSimpleName(), "Voicemail"));
118        sScreenNameMap.put(ScreenEvent.ALL_CONTACTS, AllContactsFragment.class.getSimpleName());
119        sScreenNameMap.put(ScreenEvent.REGULAR_SEARCH,
120                RegularSearchFragment.class.getSimpleName());
121        sScreenNameMap.put(ScreenEvent.SMART_DIAL_SEARCH,
122                SmartDialSearchFragment.class.getSimpleName());
123        sScreenNameMap.put(ScreenEvent.CALL_LOG_FILTER,
124                getScreenNameWithTag(CallLogFragment.class.getSimpleName(), "Filtered"));
125        sScreenNameMap.put(ScreenEvent.SETTINGS,
126                DialerSettingsActivity.class.getSimpleName());
127        sScreenNameMap.put(ScreenEvent.IMPORT_EXPORT_CONTACTS,
128                ImportExportDialogFragment.class.getSimpleName());
129        sScreenNameMap.put(ScreenEvent.CLEAR_FREQUENTS,
130                ClearFrequentsDialog.class.getSimpleName());
131        sScreenNameMap.put(ScreenEvent.SEND_FEEDBACK, "SendFeedback");
132        sScreenNameMap.put(ScreenEvent.INCALL, InCallActivity.class.getSimpleName());
133        sScreenNameMap.put(ScreenEvent.INCOMING_CALL, AnswerFragment.class.getSimpleName());
134        sScreenNameMap.put(ScreenEvent.CONFERENCE_MANAGEMENT,
135                ConferenceManagerFragment.class.getSimpleName());
136        sScreenNameMap.put(ScreenEvent.INCALL_DIALPAD,
137                getScreenNameWithTag(DialpadFragment.class.getSimpleName(), "InCall"));
138        sScreenNameMap.put(ScreenEvent.CALL_LOG_CONTEXT_MENU, "CallLogContextMenu");
139        sScreenNameMap.put(ScreenEvent.BLOCKED_NUMBER_MANAGEMENT,
140                BlockedNumbersFragment.class.getSimpleName());
141        sScreenNameMap.put(ScreenEvent.BLOCKED_NUMBER_ADD_NUMBER,
142                BlockedListSearchFragment.class.getSimpleName());
143    }
144
145    /**
146     * For a given screen type, returns the actual screen name that is used for logging/analytics
147     * purposes.
148     *
149     * @param screenType unique ID of a type of screen
150     *
151     * @return the tagged version of the screen name corresponding to the provided screenType,
152     *         or {@null} if the provided screenType is unknown.
153     */
154    public static String getScreenName(int screenType) {
155        return sScreenNameMap.get(screenType);
156    }
157
158    /**
159     * Build a tagged version of the provided screenName if the tag is non-empty.
160     *
161     * @param screenName Name of the screen.
162     * @param tag Optional tag describing the screen.
163     * @return the unchanged screenName if the tag is {@code null} or empty, the tagged version of
164     *         the screenName otherwise.
165     */
166    public static String getScreenNameWithTag(String screenName, String tag) {
167        if (TextUtils.isEmpty(tag)) {
168            return screenName;
169        }
170        return screenName + FRAGMENT_TAG_SEPARATOR + tag;
171    }
172}
173