1 /* 2 * Copyright (C) 2019 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; 18 19 import android.content.Context; 20 import android.text.TextUtils; 21 import android.util.AttributeSet; 22 import android.widget.Toast; 23 24 import com.android.car.settings.R; 25 import com.android.car.settings.common.PasswordEditTextPreference; 26 27 /** 28 * Custom {@link PasswordEditTextPreference} which doesn't open the password dialog unless the 29 * network name is provided. 30 */ 31 public class NetworkNameRestrictedPasswordEditTextPreference extends PasswordEditTextPreference { 32 33 private String mNetworkName; 34 NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)35 public NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs, 36 int defStyleAttr, int defStyleRes) { 37 super(context, attrs, defStyleAttr, defStyleRes); 38 } 39 NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs, int defStyle)40 public NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs, 41 int defStyle) { 42 super(context, attrs, defStyle); 43 } 44 NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs)45 public NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs) { 46 super(context, attrs); 47 } 48 NetworkNameRestrictedPasswordEditTextPreference(Context context)49 public NetworkNameRestrictedPasswordEditTextPreference(Context context) { 50 super(context); 51 } 52 53 /** Sets the network name. */ setNetworkName(String name)54 public void setNetworkName(String name) { 55 mNetworkName = name; 56 } 57 58 @Override onClick()59 protected void onClick() { 60 if (TextUtils.isEmpty(mNetworkName)) { 61 Toast.makeText(getContext(), R.string.wifi_no_network_name, Toast.LENGTH_SHORT).show(); 62 return; 63 } 64 65 super.onClick(); 66 } 67 } 68