Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2017 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 android.preference2.cts;
     18 
     19 import android.content.Context;
     20 import android.preference.CheckBoxPreference;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 
     25 /**
     26  * Preference wrapper designed to help to verify whether the preference is recycled by logging calls
     27  * of {@link #getView(View, ViewGroup)}
     28  */
     29 public class RecycleCheckPreference extends CheckBoxPreference {
     30 
     31     /**
     32      * How many times was the {@link #getView(View, ViewGroup)} method called during the lifetime.
     33      */
     34     int getViewCalledCnt;
     35 
     36     /**
     37      * Whether the convert view param was null during the last call of
     38      * {@link #getView(View, ViewGroup)}
     39      */
     40     boolean wasConvertViewNullInLastCall;
     41 
     42 
     43     public RecycleCheckPreference(Context context, AttributeSet attrs,
     44             int defStyleAttr) {
     45         super(context, attrs, defStyleAttr);
     46     }
     47 
     48     public RecycleCheckPreference(Context context, AttributeSet attrs, int defStyleAttr,
     49             int defStyleRes) {
     50         super(context, attrs, defStyleAttr, defStyleRes);
     51     }
     52 
     53     public RecycleCheckPreference(Context context, AttributeSet attrs) {
     54         super(context, attrs);
     55     }
     56 
     57     public RecycleCheckPreference(Context context) {
     58         super(context);
     59     }
     60 
     61     @Override
     62     public View getView(View convertView, ViewGroup parent) {
     63         getViewCalledCnt++;
     64         wasConvertViewNullInLastCall = convertView == null;
     65 
     66         return super.getView(convertView, parent);
     67     }
     68 }
     69