OSDN Git Service

am 31d519fe: (-s ours) am 66b5a58a: Merge "Fix init order so we have something to...
[android-x86/packages-apps-Settings.git] / src / com / android / settings / wifi / WifiDialog.java
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 com.android.settings.R;
20 import com.android.settingslib.wifi.AccessPoint;
21
22 import android.app.AlertDialog;
23 import android.content.Context;
24 import android.content.DialogInterface;
25 import android.os.Bundle;
26 import android.view.View;
27 import android.widget.Button;
28
29 class WifiDialog extends AlertDialog implements WifiConfigUiBase {
30     static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
31     static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
32
33     private final boolean mEdit;
34     private final boolean mModify;
35     private final DialogInterface.OnClickListener mListener;
36     private final AccessPoint mAccessPoint;
37
38     private View mView;
39     private WifiConfigController mController;
40     private boolean mHideSubmitButton;
41     private boolean mHideForgetButton;
42
43     public WifiDialog(Context context, DialogInterface.OnClickListener listener,
44             AccessPoint accessPoint, boolean edit, boolean modify,
45             boolean hideSubmitButton, boolean hideForgetButton) {
46         this(context, listener, accessPoint, edit, modify);
47         mHideSubmitButton = hideSubmitButton;
48         mHideForgetButton = hideForgetButton;
49     }
50
51     public WifiDialog(Context context, DialogInterface.OnClickListener listener,
52             AccessPoint accessPoint, boolean edit, boolean modify) {
53         super(context);
54         mEdit = edit;
55         mModify = modify;
56         mListener = listener;
57         mAccessPoint = accessPoint;
58         mHideSubmitButton = false;
59         mHideForgetButton = false;
60     }
61
62     @Override
63     public WifiConfigController getController() {
64         return mController;
65     }
66
67     @Override
68     protected void onCreate(Bundle savedInstanceState) {
69         mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
70         setView(mView);
71         setInverseBackgroundForced(true);
72         mController = new WifiConfigController(this, mView, mAccessPoint, mEdit, mModify);
73         super.onCreate(savedInstanceState);
74
75         if (mHideSubmitButton) {
76             mController.hideSubmitButton();
77         } else {
78             /* During creation, the submit button can be unavailable to determine
79              * visibility. Right after creation, update button visibility */
80             mController.enableSubmitIfAppropriate();
81         }
82
83         if (mHideForgetButton) {
84             mController.hideForgetButton();
85         }
86     }
87
88     public void onRestoreInstanceState(Bundle savedInstanceState) {
89             super.onRestoreInstanceState(savedInstanceState);
90             mController.updatePassword();
91     }
92
93     @Override
94     public boolean isEdit() {
95         return mEdit;
96     }
97
98     @Override
99     public Button getSubmitButton() {
100         return getButton(BUTTON_SUBMIT);
101     }
102
103     @Override
104     public Button getForgetButton() {
105         return getButton(BUTTON_FORGET);
106     }
107
108     @Override
109     public Button getCancelButton() {
110         return getButton(BUTTON_NEGATIVE);
111     }
112
113     @Override
114     public void setSubmitButton(CharSequence text) {
115         setButton(BUTTON_SUBMIT, text, mListener);
116     }
117
118     @Override
119     public void setForgetButton(CharSequence text) {
120         setButton(BUTTON_FORGET, text, mListener);
121     }
122
123     @Override
124     public void setCancelButton(CharSequence text) {
125         setButton(BUTTON_NEGATIVE, text, mListener);
126     }
127 }