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 android.support.v14.preference.PreferenceFragment;
20 
21 import com.android.internal.logging.MetricsLogger;
22 
23 /**
24  * Instrumented preference fragment that logs visibility state.
25  */
26 public abstract class InstrumentedPreferenceFragment extends PreferenceFragment {
27     /**
28      * Declare the view of this category.
29      *
30      * Categories are defined in {@link com.android.internal.logging.MetricsProto.MetricsEvent}
31      * or if there is no relevant existing category you may define one in
32      * {@link com.android.settings.InstrumentedFragment}.
33      */
getMetricsCategory()34     protected abstract int getMetricsCategory();
35 
36     @Override
onResume()37     public void onResume() {
38         super.onResume();
39         MetricsLogger.visible(getActivity(), getMetricsCategory());
40     }
41 
42     @Override
onPause()43     public void onPause() {
44         super.onPause();
45         MetricsLogger.hidden(getActivity(), getMetricsCategory());
46     }
47 }
48