WifiConfigUiForSetupWizardXL.java revision c81d3768d24bfe3ff2f785426f6fd5a10da39c1a
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.Activity;
22import android.content.Context;
23import android.util.Log;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.ViewGroup;
27import android.view.inputmethod.InputMethodManager;
28import android.widget.Button;
29import android.widget.EditText;
30
31/**
32 * Shows simplified UI for configuring a wifi network. Used only in SetupWizard for XLarge
33 * screen.
34 */
35public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase {
36    private static final String TAG = "SetupWizard";
37
38    private Button mConnectButton;
39    private Button mForgetButton;
40    private Button mCancelButton;
41
42    private final Activity mActivity;
43    private View mView;
44    private WifiConfigController mController;
45    private AccessPoint mAccessPoint;
46    private boolean mEdit;
47
48    private LayoutInflater mInflater;
49
50    /**
51     * @param activity Activity which creates this object.
52     * @param parent Parent ViewGroup (typically some layout) holding a view object created by
53     * this object
54     * @param accessPoint target AccessPoint to be configured.
55     * @param edit
56     */
57    public WifiConfigUiForSetupWizardXL(
58            Activity activity, ViewGroup parent, AccessPoint accessPoint, boolean edit) {
59        mActivity = activity;
60        mConnectButton = (Button)activity.findViewById(R.id.wifi_setup_connect);
61        mForgetButton = (Button)activity.findViewById(R.id.wifi_setup_forget);
62        mCancelButton = (Button)activity.findViewById(R.id.wifi_setup_cancel);
63        mAccessPoint = accessPoint;
64        mEdit = edit;
65        mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
66
67        mView = mInflater.inflate(R.layout.wifi_config_ui_for_setup_wizard, parent, false);
68        mController = new WifiConfigController(this, mView, mAccessPoint, edit);
69        trySetFocusAndLaunchSoftInput(R.id.password);
70    }
71
72    private void trySetFocusAndLaunchSoftInput(int id) {
73        final View viewToBeFocused = mView.findViewById(id);
74        if (viewToBeFocused != null && viewToBeFocused.getVisibility() == View.VISIBLE) {
75            Log.d(TAG, "requestFocus() returned " + viewToBeFocused.requestFocus());
76            // TODO: doesn't work.
77            if (viewToBeFocused instanceof EditText) {
78                Log.d(TAG, "Focused View is EditText. We try showing the software keyboard");
79                // viewToBeFocused.performClick();
80                final InputMethodManager inputMethodManager = (InputMethodManager)
81                        mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
82                inputMethodManager.showSoftInput(viewToBeFocused, 0);
83            }
84        }
85    }
86
87    public View getView() {
88        return mView;
89    }
90
91    public AccessPoint getAccessPoint() {
92        return mAccessPoint;
93    }
94
95    @Override
96    public WifiConfigController getController() {
97        return mController;
98    }
99
100    @Override
101    public boolean isEdit() {
102        return mEdit;
103    }
104
105    @Override
106    public LayoutInflater getLayoutInflater() {
107        return mInflater;
108    }
109
110    @Override
111    public Button getSubmitButton() {
112        return mConnectButton;
113    }
114
115    @Override
116    public Button getForgetButton() {
117        return mForgetButton;
118    }
119
120    @Override
121    public Button getCancelButton() {
122        return mCancelButton;
123    }
124
125    @Override
126    public void setSubmitButton(CharSequence text) {
127        mConnectButton.setVisibility(View.VISIBLE);
128        mConnectButton.setText(text);
129
130        // test
131        mForgetButton.setVisibility(View.GONE);
132    }
133
134    @Override
135    public void setForgetButton(CharSequence text) {
136        // In XL setup screen, we won't show Forget button for simplifying the UI.
137        // mForgetButton.setVisibility(View.VISIBLE);
138        // mForgetButton.setText(text);
139    }
140
141    @Override
142    public void setCancelButton(CharSequence text) {
143        mCancelButton.setVisibility(View.VISIBLE);
144        // We don't want "cancel" label given from caller.
145        // mCancelButton.setText(text);
146    }
147
148    @Override
149    public Context getContext() {
150        return mActivity;
151    }
152
153    @Override
154    public void setTitle(int id) {
155        Log.d(TAG, "Ignoring setTitle");
156    }
157
158    @Override
159    public void setTitle(CharSequence title) {
160        Log.d(TAG, "Ignoring setTitle");
161    }
162}