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 17 package com.android.settings; 18 19 import com.android.internal.logging.MetricsLogger; 20 21 import android.os.Bundle; 22 import android.support.v14.preference.PreferenceFragment; 23 24 /** 25 * Instrumented fragment that logs visibility state. 26 */ 27 public abstract class InstrumentedFragment extends PreferenceFragment { 28 // Declare new temporary categories here, starting after this value. 29 public static final int UNDECLARED = 100000; 30 31 // Used by PreferenceActivity for the dummy fragment it adds, no useful data here. 32 public static final int PREFERENCE_ACTIVITY_FRAGMENT = UNDECLARED + 1; 33 34 /** 35 * Declare the view of this category. 36 * 37 * Categories are defined in {@link com.android.internal.logging.MetricsProto.MetricsEvent} 38 * or if there is no relevant existing category you may define one in 39 * {@link com.android.settings.InstrumentedFragment}. 40 */ getMetricsCategory()41 protected abstract int getMetricsCategory(); 42 43 @Override onCreatePreferences(Bundle savedInstanceState, String rootKey)44 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 45 } 46 47 @Override onResume()48 public void onResume() { 49 super.onResume(); 50 MetricsLogger.visible(getActivity(), getMetricsCategory()); 51 } 52 53 @Override onPause()54 public void onPause() { 55 super.onPause(); 56 MetricsLogger.hidden(getActivity(), getMetricsCategory()); 57 } 58 } 59