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
17package com.android.settings.wifi;
18
19import com.android.settings.R;
20
21import android.app.AlertDialog;
22import android.content.Context;
23import android.content.DialogInterface;
24import android.os.Bundle;
25import android.view.View;
26import android.widget.Button;
27
28class WifiDialog extends AlertDialog implements WifiConfigUiBase {
29    static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
30    static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
31
32    private final boolean mEdit;
33    private final DialogInterface.OnClickListener mListener;
34    private final AccessPoint mAccessPoint;
35
36    private View mView;
37    private WifiConfigController mController;
38
39    public WifiDialog(Context context, DialogInterface.OnClickListener listener,
40            AccessPoint accessPoint, boolean edit) {
41        super(context, R.style.Theme_WifiDialog);
42        mEdit = edit;
43        mListener = listener;
44        mAccessPoint = accessPoint;
45    }
46
47    @Override
48    public WifiConfigController getController() {
49        return mController;
50    }
51
52    @Override
53    protected void onCreate(Bundle savedInstanceState) {
54        mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
55        setView(mView);
56        setInverseBackgroundForced(true);
57        mController = new WifiConfigController(this, mView, mAccessPoint, mEdit);
58        super.onCreate(savedInstanceState);
59        /* During creation, the submit button can be unavailable to determine
60         * visibility. Right after creation, update button visibility */
61        mController.enableSubmitIfAppropriate();
62    }
63
64    @Override
65    public boolean isEdit() {
66        return mEdit;
67    }
68
69    @Override
70    public Button getSubmitButton() {
71        return getButton(BUTTON_SUBMIT);
72    }
73
74    @Override
75    public Button getForgetButton() {
76        return getButton(BUTTON_FORGET);
77    }
78
79    @Override
80    public Button getCancelButton() {
81        return getButton(BUTTON_NEGATIVE);
82    }
83
84    @Override
85    public void setSubmitButton(CharSequence text) {
86        setButton(BUTTON_SUBMIT, text, mListener);
87    }
88
89    @Override
90    public void setForgetButton(CharSequence text) {
91        setButton(BUTTON_FORGET, text, mListener);
92    }
93
94    @Override
95    public void setCancelButton(CharSequence text) {
96        setButton(BUTTON_NEGATIVE, text, mListener);
97    }
98}
99