• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.app.AlertDialog;
20 import android.content.Context;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 import android.view.View;
24 import android.widget.Button;
25 
26 import com.android.settings.R;
27 import com.android.settingslib.RestrictedLockUtils;
28 import com.android.settingslib.wifi.AccessPoint;
29 
30 class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener {
31 
32     public interface WifiDialogListener {
onForget(WifiDialog dialog)33         void onForget(WifiDialog dialog);
onSubmit(WifiDialog dialog)34         void onSubmit(WifiDialog dialog);
35     }
36 
37     private static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
38     private static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
39 
40     private final int mMode;
41     private final WifiDialogListener mListener;
42     private final AccessPoint mAccessPoint;
43 
44     private View mView;
45     private WifiConfigController mController;
46     private boolean mHideSubmitButton;
47 
WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint, int mode, boolean hideSubmitButton)48     public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
49             int mode, boolean hideSubmitButton) {
50         this(context, listener, accessPoint, mode);
51         mHideSubmitButton = hideSubmitButton;
52     }
53 
WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint, int mode)54     public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
55             int mode) {
56         super(context);
57         mMode = mode;
58         mListener = listener;
59         mAccessPoint = accessPoint;
60         mHideSubmitButton = false;
61     }
62 
63     @Override
getController()64     public WifiConfigController getController() {
65         return mController;
66     }
67 
68     @Override
onCreate(Bundle savedInstanceState)69     protected void onCreate(Bundle savedInstanceState) {
70         mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
71         setView(mView);
72         setInverseBackgroundForced(true);
73         mController = new WifiConfigController(this, mView, mAccessPoint, mMode);
74         super.onCreate(savedInstanceState);
75 
76         if (mHideSubmitButton) {
77             mController.hideSubmitButton();
78         } else {
79             /* During creation, the submit button can be unavailable to determine
80              * visibility. Right after creation, update button visibility */
81             mController.enableSubmitIfAppropriate();
82         }
83 
84         if (mAccessPoint == null) {
85             mController.hideForgetButton();
86         }
87     }
88 
onRestoreInstanceState(Bundle savedInstanceState)89     public void onRestoreInstanceState(Bundle savedInstanceState) {
90             super.onRestoreInstanceState(savedInstanceState);
91             mController.updatePassword();
92     }
93 
94     @Override
dispatchSubmit()95     public void dispatchSubmit() {
96         if (mListener != null) {
97             mListener.onSubmit(this);
98         }
99         dismiss();
100     }
101 
102     @Override
onClick(DialogInterface dialogInterface, int id)103     public void onClick(DialogInterface dialogInterface, int id) {
104         if (mListener != null) {
105             switch (id) {
106                 case BUTTON_SUBMIT:
107                     mListener.onSubmit(this);
108                     break;
109                 case BUTTON_FORGET:
110                     if (WifiSettings.isEditabilityLockedDown(
111                             getContext(), mAccessPoint.getConfig())) {
112                         RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
113                                 RestrictedLockUtils.getDeviceOwner(getContext()));
114                         return;
115                     }
116                     mListener.onForget(this);
117                     break;
118             }
119         }
120     }
121 
122     @Override
getMode()123     public int getMode() {
124         return mMode;
125     }
126 
127     @Override
getSubmitButton()128     public Button getSubmitButton() {
129         return getButton(BUTTON_SUBMIT);
130     }
131 
132     @Override
getForgetButton()133     public Button getForgetButton() {
134         return getButton(BUTTON_FORGET);
135     }
136 
137     @Override
getCancelButton()138     public Button getCancelButton() {
139         return getButton(BUTTON_NEGATIVE);
140     }
141 
142     @Override
setSubmitButton(CharSequence text)143     public void setSubmitButton(CharSequence text) {
144         setButton(BUTTON_SUBMIT, text, this);
145     }
146 
147     @Override
setForgetButton(CharSequence text)148     public void setForgetButton(CharSequence text) {
149         setButton(BUTTON_FORGET, text, this);
150     }
151 
152     @Override
setCancelButton(CharSequence text)153     public void setCancelButton(CharSequence text) {
154         setButton(BUTTON_NEGATIVE, text, this);
155     }
156 }
157