Home | History | Annotate | Download | only in logging
      1 /*
      2  * Copyright (C) 2016 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.contacts.common.logging;
     17 
     18 import android.app.Activity;
     19 import android.app.Fragment;
     20 import android.text.TextUtils;
     21 
     22 import com.android.contacts.common.logging.ScreenEvent.ScreenType;
     23 import com.android.contacts.commonbind.ObjectFactory;
     24 import com.android.contacts.commonbind.analytics.AnalyticsUtil;
     25 
     26 /**
     27  * Logs analytics events.
     28  */
     29 public abstract class Logger {
     30     public static final String TAG = "Logger";
     31 
     32     private static Logger getInstance() {
     33         return ObjectFactory.getLogger();
     34     }
     35 
     36     /**
     37      * Logs an event indicating that a screen was displayed.
     38      *
     39      * @param screenType integer identifier of the displayed screen
     40      * @param activity Parent activity of the displayed screen.
     41      */
     42     public static void logScreenView(Activity activity, int screenType) {
     43         logScreenView(activity, screenType, ScreenType.UNKNOWN);
     44     }
     45 
     46     /**
     47      * @param previousScreenType integer identifier of the displayed screen the user came from.
     48      */
     49     public static void logScreenView(Activity activity, int screenType, int previousScreenType) {
     50         final Logger logger = getInstance();
     51         if (logger != null) {
     52             logger.logScreenViewImpl(screenType, previousScreenType);
     53         }
     54         // We prepend the friendly screen name with "From" and use it as the tag to indicate the
     55         // screen where the user was previously when they initiated the screen view being logged
     56         String tag = ScreenType.getFriendlyName(previousScreenType);
     57         if (!TextUtils.isEmpty(tag)) {
     58             tag = "From" + tag;
     59         }
     60         AnalyticsUtil.sendScreenView(/* fragmentName */ (String) null, activity, tag);
     61     }
     62 
     63     /**
     64      * Logs the results of a user search for a particular contact.
     65      */
     66     public static void logSearchEvent(SearchState searchState) {
     67         final Logger logger = getInstance();
     68          if (logger != null) {
     69             logger.logSearchEventImpl(searchState);
     70         }
     71     }
     72 
     73     public abstract void logScreenViewImpl(int screenType, int previousScreenType);
     74     public abstract void logSearchEventImpl(SearchState searchState);
     75 }
     76