• 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.settings.wifi;
18 
19 import android.app.ActionBar;
20 import android.app.Activity;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.Button;
29 
30 import androidx.annotation.VisibleForTesting;
31 
32 import com.android.settings.R;
33 import com.android.settings.core.InstrumentedFragment;
34 import com.android.settingslib.wifi.AccessPoint;
35 
36 /**
37  * Detail page for configuring Wi-Fi network.
38  *
39  * The AccessPoint should be saved to the argument when launching this class in order to properly
40  * render this page.
41  *
42  * Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
43  * future, please develop in {@link ConfigureWifiEntryFragment}.
44  */
45 public class ConfigureAccessPointFragment extends InstrumentedFragment implements WifiConfigUiBase {
46 
47     public static final String NETWORK_CONFIG_KEY = "network_config_key";
48 
49     private static final int SUBMIT_BUTTON_ID = android.R.id.button1;
50     private static final int CANCEL_BUTTON_ID = android.R.id.button2;
51 
52     private WifiConfigController mUiController;
53     private Button mSubmitBtn;
54     private Button mCancelBtn;
55     private AccessPoint mAccessPoint;
56 
57     @Override
onAttach(Context context)58     public void onAttach(Context context) {
59         super.onAttach(context);
60         mAccessPoint = new AccessPoint(context, getArguments());
61     }
62 
63     @Override
getMetricsCategory()64     public int getMetricsCategory() {
65         return SettingsEnums.SETTINGS_WIFI_CONFIGURE_NETWORK;
66     }
67 
68     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)69     public View onCreateView(LayoutInflater inflater, ViewGroup container,
70             Bundle savedInstanceState) {
71         final View rootView = inflater.inflate(R.layout.wifi_add_network_view,
72                 container, false /* attachToRoot */);
73 
74         final Button neutral = rootView.findViewById(android.R.id.button3);
75         if (neutral != null) {
76             neutral.setVisibility(View.GONE);
77         }
78 
79         mSubmitBtn = rootView.findViewById(SUBMIT_BUTTON_ID);
80         mCancelBtn = rootView.findViewById(CANCEL_BUTTON_ID);
81         mSubmitBtn.setOnClickListener(view -> handleSubmitAction());
82         mCancelBtn.setOnClickListener(view -> handleCancelAction());
83 
84         mUiController = new WifiConfigController(this, rootView, mAccessPoint,
85                 getMode(), false /* requestFocus */);
86 
87         /**
88          * For this add AccessPoint UI, need to remove the Home button, so set related feature as
89          * false.
90          */
91         final ActionBar actionBar = getActivity().getActionBar();
92         if (actionBar != null) {
93             actionBar.setDisplayHomeAsUpEnabled(false);
94             actionBar.setHomeButtonEnabled(false);
95             actionBar.setDisplayShowHomeEnabled(false);
96         }
97 
98         return rootView;
99     }
100 
101     @Override
onViewStateRestored(Bundle savedInstanceState)102     public void onViewStateRestored(Bundle savedInstanceState) {
103         super.onViewStateRestored(savedInstanceState);
104         mUiController.updatePassword();
105     }
106 
107     @Override
getMode()108     public int getMode() {
109         return WifiConfigUiBase.MODE_CONNECT;
110     }
111 
112     @Override
getController()113     public WifiConfigController getController() {
114         return mUiController;
115     }
116 
117     @Override
dispatchSubmit()118     public void dispatchSubmit() {
119         handleSubmitAction();
120     }
121 
122     @Override
setTitle(int id)123     public void setTitle(int id) {
124         getActivity().setTitle(id);
125     }
126 
127     @Override
setTitle(CharSequence title)128     public void setTitle(CharSequence title) {
129         getActivity().setTitle(title);
130     }
131 
132     @Override
setSubmitButton(CharSequence text)133     public void setSubmitButton(CharSequence text) {
134         mSubmitBtn.setText(text);
135     }
136 
137     @Override
setCancelButton(CharSequence text)138     public void setCancelButton(CharSequence text) {
139         mCancelBtn.setText(text);
140     }
141 
142     @Override
setForgetButton(CharSequence text)143     public void setForgetButton(CharSequence text) {
144         // AddNetwork doesn't need forget button.
145     }
146 
147     @Override
getSubmitButton()148     public Button getSubmitButton() {
149         return mSubmitBtn;
150     }
151 
152     @Override
getCancelButton()153     public Button getCancelButton() {
154         return mCancelBtn;
155     }
156 
157     @Override
getForgetButton()158     public Button getForgetButton() {
159         // AddNetwork doesn't need forget button.
160         return null;
161     }
162 
163     @VisibleForTesting
handleSubmitAction()164     void handleSubmitAction() {
165         final Intent intent = new Intent();
166         final Activity activity = getActivity();
167         intent.putExtra(NETWORK_CONFIG_KEY, mUiController.getConfig());
168         activity.setResult(Activity.RESULT_OK, intent);
169         activity.finish();
170     }
171 
172     @VisibleForTesting
handleCancelAction()173     void handleCancelAction() {
174         final Activity activity = getActivity();
175         activity.setResult(Activity.RESULT_CANCELED);
176         activity.finish();
177     }
178 }
179