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