• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
32         PasswordEditTextPreference {
33 
34     private String mNetworkName;
35 
NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)36     public NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs,
37             int defStyleAttr, int defStyleRes) {
38         super(context, attrs, defStyleAttr, defStyleRes);
39     }
40 
NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs, int defStyle)41     public NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs,
42             int defStyle) {
43         super(context, attrs, defStyle);
44     }
45 
NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs)46     public NetworkNameRestrictedPasswordEditTextPreference(Context context, AttributeSet attrs) {
47         super(context, attrs);
48     }
49 
NetworkNameRestrictedPasswordEditTextPreference(Context context)50     public NetworkNameRestrictedPasswordEditTextPreference(Context context) {
51         super(context);
52     }
53 
54     /** Sets the network name. */
setNetworkName(String name)55     public void setNetworkName(String name) {
56         mNetworkName = name;
57     }
58 
59     @Override
onClick()60     protected void onClick() {
61         if (TextUtils.isEmpty(mNetworkName)) {
62             Toast.makeText(getContext(), R.string.wifi_no_network_name, Toast.LENGTH_SHORT).show();
63             return;
64         }
65 
66         super.onClick();
67     }
68 }
69