Move Contacts logging classes to ContactsCommon (2/5)
Bug 18388581
Change-Id: I4d3f224207d1a949bb18108224958ad59a513f25
diff --git a/src/com/android/contacts/common/logging/Logger.java b/src/com/android/contacts/common/logging/Logger.java
new file mode 100644
index 0000000..cb8a3f8
--- /dev/null
+++ b/src/com/android/contacts/common/logging/Logger.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.contacts.common.logging;
+
+import android.app.Activity;
+
+import com.android.contacts.commonbind.analytics.AnalyticsUtil;
+import com.android.contacts.commonbind.logging.ClearcutLoggerHelper;
+
+/**
+ * Logs analytics events.
+ */
+public abstract class Logger {
+ public static final String TAG = "Logger";
+
+ public static Logger getInstance() {
+ return ClearcutLoggerHelper.getInstance();
+ }
+
+ /**
+ * Logs an event indicating that a screen was displayed.
+ *
+ * @param screenType integer identifier of the displayed screen
+ * @param activity Parent activity of the displayed screen.
+ * @param tag Optional description of the displayed screen.
+ */
+ public static void logScreenView(int screenType, Activity activity, String tag) {
+ final Logger logger = getInstance();
+ if (logger != null) {
+ logger.logScreenViewImpl(screenType);
+ }
+
+ final String screenName = ScreenEvent.getScreenNameWithTag(
+ activity.getClass().getSimpleName(), tag);
+ AnalyticsUtil.sendScreenView(screenName, activity, tag);
+ }
+
+ public abstract void logScreenViewImpl(int screenType);
+}
diff --git a/src/com/android/contacts/common/logging/ScreenEvent.java b/src/com/android/contacts/common/logging/ScreenEvent.java
new file mode 100644
index 0000000..6d6306d
--- /dev/null
+++ b/src/com/android/contacts/common/logging/ScreenEvent.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.contacts.common.logging;
+
+import android.text.TextUtils;
+
+/**
+ * Stores constants identifying individual screens/dialogs/fragments in the application, and also
+ * provides a mapping of integer id -> screen name mappings for analytics purposes.
+ */
+public class ScreenEvent {
+ private static final String FRAGMENT_TAG_SEPARATOR = "#";
+
+ public static final int UNKNOWN = 0;
+
+ public static final int SEARCH = 1;
+
+ /**
+ * Build a tagged version of the provided screenName if the tag is non-empty.
+ *
+ * @param screenName Name of the screen.
+ * @param tag Optional tag describing the screen.
+ * @return the unchanged screenName if the tag is {@code null} or empty, the tagged version of
+ * the screenName otherwise.
+ */
+ public static String getScreenNameWithTag(String screenName, String tag) {
+ if (TextUtils.isEmpty(tag)) {
+ return screenName;
+ }
+ return screenName + FRAGMENT_TAG_SEPARATOR + tag;
+ }
+}
diff --git a/src/com/android/contacts/commonbind/logging/ClearcutLoggerHelper.java b/src/com/android/contacts/commonbind/logging/ClearcutLoggerHelper.java
new file mode 100644
index 0000000..5cc2095
--- /dev/null
+++ b/src/com/android/contacts/commonbind/logging/ClearcutLoggerHelper.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.contacts.commonbind.logging;
+
+import com.android.contacts.common.logging.Logger;
+
+/**
+ * No-op clearcut logger implementation.
+ */
+public class ClearcutLoggerHelper extends Logger {
+
+ private static ClearcutLoggerHelper sInstance;
+
+ public static ClearcutLoggerHelper getInstance() {
+ if (sInstance == null) {
+ sInstance = new ClearcutLoggerHelper();
+ }
+ return sInstance;
+ }
+
+ private ClearcutLoggerHelper() {
+ }
+
+ @Override
+ public void logScreenViewImpl(int screenType) {
+ }
+}