1 /*
2  * Copyright (C) 2018 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.car.settings.wifi.details;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.util.AttributeSet;
22 import android.widget.TextView;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.PreferenceViewHolder;
26 
27 import com.android.car.settings.R;
28 import com.android.car.ui.preference.CarUiPreference;
29 
30 /**
31  * A Preference to be used with the Wifi Network Detail Fragment that allows a summary text to be
32  * set inside the widget resource
33  */
34 public class WifiDetailsPreference extends CarUiPreference {
35     private String mDetailText;
36 
WifiDetailsPreference(Context context, AttributeSet attributeSet)37     public WifiDetailsPreference(Context context, AttributeSet attributeSet) {
38         super(context, attributeSet);
39         setWidgetLayoutResource(R.layout.summary_preference_widget);
40         setShowChevron(false);
41     }
42 
43     @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
WifiDetailsPreference(Context context)44     WifiDetailsPreference(Context context) {
45         super(context);
46     }
47 
48     /**
49      * Sets the detail text.
50      */
setDetailText(String text)51     public void setDetailText(String text) {
52         if (TextUtils.equals(mDetailText, text)) {
53             return;
54         }
55         mDetailText = text;
56         notifyChanged();
57     }
58 
59     @Override
onBindViewHolder(PreferenceViewHolder view)60     public void onBindViewHolder(PreferenceViewHolder view) {
61         super.onBindViewHolder(view);
62         TextView textView = ((TextView) view.findViewById(R.id.widget_summary));
63         textView.setText(mDetailText);
64     }
65 
66     @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
getDetailText()67     String getDetailText() {
68         return mDetailText;
69     }
70 }
71