• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.settings.wifi;
18 
19 import android.content.Context;
20 import android.view.View;
21 
22 import androidx.annotation.DrawableRes;
23 import androidx.fragment.app.Fragment;
24 import androidx.preference.PreferenceViewHolder;
25 
26 import com.android.settings.R;
27 import com.android.settingslib.wifi.AccessPoint;
28 
29 /**
30  * An AP preference for the currently connected AP
31  */
32 public class ConnectedAccessPointPreference extends LongPressAccessPointPreference implements
33         View.OnClickListener {
34 
35     private OnGearClickListener mOnGearClickListener;
36     private boolean mIsCaptivePortal;
37 
ConnectedAccessPointPreference(AccessPoint accessPoint, Context context, UserBadgeCache cache, @DrawableRes int iconResId, boolean forSavedNetworks, Fragment fragment)38     public ConnectedAccessPointPreference(AccessPoint accessPoint, Context context,
39             UserBadgeCache cache, @DrawableRes int iconResId, boolean forSavedNetworks,
40             Fragment fragment) {
41         super(accessPoint, context, cache, forSavedNetworks, iconResId, fragment);
42     }
43 
44     @Override
getWidgetLayoutResourceId()45     protected int getWidgetLayoutResourceId() {
46         return R.layout.preference_widget_gear_optional_background;
47     }
48 
49     @Override
refresh()50     public void refresh() {
51         super.refresh();
52 
53         setShowDivider(mIsCaptivePortal);
54         if (mIsCaptivePortal) {
55             setSummary(R.string.wifi_tap_to_sign_in);
56         }
57     }
58 
setOnGearClickListener(OnGearClickListener l)59     public void setOnGearClickListener(OnGearClickListener l) {
60         mOnGearClickListener = l;
61         notifyChanged();
62     }
63 
64     @Override
onBindViewHolder(PreferenceViewHolder holder)65     public void onBindViewHolder(PreferenceViewHolder holder) {
66         super.onBindViewHolder(holder);
67 
68         final View gear = holder.findViewById(R.id.settings_button);
69         gear.setOnClickListener(this);
70 
71         final View gearNoBg = holder.findViewById(R.id.settings_button_no_background);
72         gearNoBg.setVisibility(mIsCaptivePortal ? View.INVISIBLE : View.VISIBLE);
73         gear.setVisibility(mIsCaptivePortal ? View.VISIBLE : View.INVISIBLE);
74     }
75 
76     @Override
onClick(View v)77     public void onClick(View v) {
78         if (v.getId() == R.id.settings_button) {
79             if (mOnGearClickListener != null) {
80                 mOnGearClickListener.onGearClick(this);
81             }
82         }
83     }
84 
setCaptivePortal(boolean isCaptivePortal)85     public void setCaptivePortal(boolean isCaptivePortal) {
86         if (mIsCaptivePortal != isCaptivePortal) {
87             mIsCaptivePortal = isCaptivePortal;
88             refresh();
89         }
90     }
91 
92     public interface OnGearClickListener {
onGearClick(ConnectedAccessPointPreference p)93         void onGearClick(ConnectedAccessPointPreference p);
94     }
95 
96 }
97