Loading res/layout/wifi_add_network_view.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2018 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <include android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/add_network_button_bar" android:layout_alignParentTop="true" layout="@layout/wifi_dialog"/> <include android:id="@+id/add_network_button_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" layout="@*android:layout/alert_dialog_button_bar_material"/> </RelativeLayout> No newline at end of file res/values/themes.xml +0 −17 Original line number Diff line number Diff line Loading @@ -174,21 +174,4 @@ <item name="android:windowLightStatusBar">true</item> </style> <!--TODO(b/111875856) This theme will be useless, when we add real activity/fragment to handle the full screen for WifiDialog --> <style name="Theme.Settings.WifiDialogFullScreen" parent="Theme.AppCompat.DayNight.NoActionBar"> <!-- Color names copied from frameworks/base/core/res/res/values/themes_device_defaults.xml --> <item name="colorPrimary">@*android:color/primary_device_default_settings_light</item> <item name="colorPrimaryDark">@*android:color/primary_dark_device_default_settings_light</item> <item name="colorAccent">@*android:color/accent_device_default_light</item> <!-- Add white nav bar with divider that matches material --> <item name="android:navigationBarDividerColor">@color/ripple_material_light</item> <item name="android:navigationBarColor">@android:color/white</item> <item name="android:windowLightNavigationBar">true</item> <item name="android:windowLightStatusBar">true</item> <!-- For AndroidX AlertDialog --> <item name="alertDialogTheme">@style/Theme.AlertDialog</item> </style> </resources> src/com/android/settings/wifi/AddNetworkFragment.java 0 → 100644 +159 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.wifi; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import androidx.annotation.VisibleForTesting; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase, View.OnClickListener { final static String WIFI_CONFIG_KEY = "wifi_config_key"; @VisibleForTesting final static int SUBMIT_BUTTON_ID = android.R.id.button1; @VisibleForTesting final static int CANCEL_BUTTON_ID = android.R.id.button2; private WifiConfigController mUIController; private Button mSubmitBtn; private Button mCancelBtn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public int getMetricsCategory() { return MetricsEvent.SETTINGS_WIFI_ADD_NETWORK; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.wifi_add_network_view, container, false); mSubmitBtn = rootView.findViewById(SUBMIT_BUTTON_ID); mCancelBtn = rootView.findViewById(CANCEL_BUTTON_ID); mSubmitBtn.setOnClickListener(this); mCancelBtn.setOnClickListener(this); mUIController = new WifiConfigController(this, rootView, null, getMode()); return rootView; } @Override public void onViewStateRestored(Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); mUIController.updatePassword(); } @Override public void onClick(View view) { switch (view.getId()) { case SUBMIT_BUTTON_ID: handleSubmitAction(); break; case CANCEL_BUTTON_ID: handleCancelAction(); break; } } @Override public int getMode() { return WifiConfigUiBase.MODE_CONNECT; } @Override public WifiConfigController getController() { return mUIController; } @Override public void dispatchSubmit() { handleSubmitAction(); } @Override public void setTitle(int id) { getActivity().setTitle(id); } @Override public void setTitle(CharSequence title) { getActivity().setTitle(title); } @Override public void setSubmitButton(CharSequence text) { mSubmitBtn.setText(text); } @Override public void setCancelButton(CharSequence text) { mCancelBtn.setText(text); } @Override public void setForgetButton(CharSequence text) { // AddNetwork doesn't need forget button. } @Override public Button getSubmitButton() { return mSubmitBtn; } @Override public Button getCancelButton() { return mCancelBtn; } @Override public Button getForgetButton() { // AddNetwork doesn't need forget button. return null; } @VisibleForTesting void handleSubmitAction() { final Intent intent = new Intent(); final Activity activity = getActivity(); intent.putExtra(WIFI_CONFIG_KEY, mUIController.getConfig()); activity.setResult(Activity.RESULT_OK, intent); activity.finish(); } @VisibleForTesting void handleCancelAction() { final Activity activity = getActivity(); activity.setResult(Activity.RESULT_CANCELED); activity.finish(); } } src/com/android/settings/wifi/WifiDialog.java +0 −8 Original line number Diff line number Diff line Loading @@ -50,14 +50,6 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase, private WifiConfigController mController; private boolean mHideSubmitButton; // TODO(b/111875856) WifiDialog should not mimic full screen UI. /** Creates a WifiDialog with fullscreen style. It displays in fullscreen mode. */ public static WifiDialog createFullscreen(Context context, WifiDialogListener listener, AccessPoint accessPoint, int mode) { return new WifiDialog(context, listener, accessPoint, mode, R.style.Theme_Settings_WifiDialogFullScreen, false /* hideSubmitButton */); } /** * Creates a WifiDialog with no additional style. It displays as a dialog above the current * view. Loading src/com/android/settings/wifi/WifiSettings.java +44 −18 Original line number Diff line number Diff line Loading @@ -100,6 +100,9 @@ public class WifiSettings extends RestrictedSettingsFragment public static final int WIFI_DIALOG_ID = 1; private static final int WRITE_NFC_DIALOG_ID = 6; @VisibleForTesting static final int ADD_NETWORK_REQUEST = 2; // Instance state keys private static final String SAVE_DIALOG_MODE = "dialog_mode"; private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state"; Loading Loading @@ -416,6 +419,12 @@ public class WifiSettings extends RestrictedSettingsFragment public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Only handle request comes from AddNetworkFragment if (requestCode == ADD_NETWORK_REQUEST) { handleAddNetworkRequest(resultCode, data); return; } final boolean formerlyRestricted = mIsRestricted; mIsRestricted = isUiRestricted(); if (formerlyRestricted && !mIsRestricted Loading Loading @@ -590,13 +599,8 @@ public class WifiSettings extends RestrictedSettingsFragment public Dialog onCreateDialog(int dialogId) { switch (dialogId) { case WIFI_DIALOG_ID: if (mDlgAccessPoint == null && mAccessPointSavedState == null) { // add new network mDialog = WifiDialog .createFullscreen(getActivity(), this, mDlgAccessPoint, mDialogMode); } else { // modify network if (mDlgAccessPoint == null) { if (mDlgAccessPoint == null && mAccessPointSavedState != null) { // restore AP from save state mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState); // Reset the saved access point data Loading @@ -604,8 +608,6 @@ public class WifiSettings extends RestrictedSettingsFragment } mDialog = WifiDialog .createModal(getActivity(), this, mDlgAccessPoint, mDialogMode); } mSelectedAccessPoint = mDlgAccessPoint; return mDialog; case WRITE_NFC_DIALOG_ID: Loading Loading @@ -928,6 +930,15 @@ public class WifiSettings extends RestrictedSettingsFragment } } private void launchAddNetworkFragment() { new SubSettingLauncher(getContext()) .setTitleRes(R.string.wifi_add_network) .setDestination(AddNetworkFragment.class.getName()) .setSourceMetricsCategory(getMetricsCategory()) .setResultListener(this, ADD_NETWORK_REQUEST) .launch(); } private void launchNetworkDetailsFragment(ConnectedAccessPointPreference pref) { new SubSettingLauncher(getContext()) .setTitleRes(R.string.pref_title_network_details) Loading Loading @@ -1096,14 +1107,29 @@ public class WifiSettings extends RestrictedSettingsFragment mWifiManager.connect(networkId, mConnectListener); } @VisibleForTesting void handleAddNetworkRequest(int result, Intent data) { if(result == Activity.RESULT_OK) { handleAddNetworkSubmitEvent(data); } mWifiTracker.resumeScanning(); } private void handleAddNetworkSubmitEvent(Intent data) { final WifiConfiguration wifiConfiguration = data.getParcelableExtra( AddNetworkFragment.WIFI_CONFIG_KEY); if (wifiConfiguration != null) { mWifiManager.save(wifiConfiguration, mSaveListener); } } /** * Called when "add network" button is pressed. */ /* package */ void onAddNetworkPressed() { mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_ADD_NETWORK); private void onAddNetworkPressed() { // No exact access point is selected. mSelectedAccessPoint = null; showDialog(null, WifiConfigUiBase.MODE_CONNECT); launchAddNetworkFragment(); } @Override Loading Loading
res/layout/wifi_add_network_view.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2018 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <include android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/add_network_button_bar" android:layout_alignParentTop="true" layout="@layout/wifi_dialog"/> <include android:id="@+id/add_network_button_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" layout="@*android:layout/alert_dialog_button_bar_material"/> </RelativeLayout> No newline at end of file
res/values/themes.xml +0 −17 Original line number Diff line number Diff line Loading @@ -174,21 +174,4 @@ <item name="android:windowLightStatusBar">true</item> </style> <!--TODO(b/111875856) This theme will be useless, when we add real activity/fragment to handle the full screen for WifiDialog --> <style name="Theme.Settings.WifiDialogFullScreen" parent="Theme.AppCompat.DayNight.NoActionBar"> <!-- Color names copied from frameworks/base/core/res/res/values/themes_device_defaults.xml --> <item name="colorPrimary">@*android:color/primary_device_default_settings_light</item> <item name="colorPrimaryDark">@*android:color/primary_dark_device_default_settings_light</item> <item name="colorAccent">@*android:color/accent_device_default_light</item> <!-- Add white nav bar with divider that matches material --> <item name="android:navigationBarDividerColor">@color/ripple_material_light</item> <item name="android:navigationBarColor">@android:color/white</item> <item name="android:windowLightNavigationBar">true</item> <item name="android:windowLightStatusBar">true</item> <!-- For AndroidX AlertDialog --> <item name="alertDialogTheme">@style/Theme.AlertDialog</item> </style> </resources>
src/com/android/settings/wifi/AddNetworkFragment.java 0 → 100644 +159 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.wifi; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import androidx.annotation.VisibleForTesting; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase, View.OnClickListener { final static String WIFI_CONFIG_KEY = "wifi_config_key"; @VisibleForTesting final static int SUBMIT_BUTTON_ID = android.R.id.button1; @VisibleForTesting final static int CANCEL_BUTTON_ID = android.R.id.button2; private WifiConfigController mUIController; private Button mSubmitBtn; private Button mCancelBtn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public int getMetricsCategory() { return MetricsEvent.SETTINGS_WIFI_ADD_NETWORK; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.wifi_add_network_view, container, false); mSubmitBtn = rootView.findViewById(SUBMIT_BUTTON_ID); mCancelBtn = rootView.findViewById(CANCEL_BUTTON_ID); mSubmitBtn.setOnClickListener(this); mCancelBtn.setOnClickListener(this); mUIController = new WifiConfigController(this, rootView, null, getMode()); return rootView; } @Override public void onViewStateRestored(Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); mUIController.updatePassword(); } @Override public void onClick(View view) { switch (view.getId()) { case SUBMIT_BUTTON_ID: handleSubmitAction(); break; case CANCEL_BUTTON_ID: handleCancelAction(); break; } } @Override public int getMode() { return WifiConfigUiBase.MODE_CONNECT; } @Override public WifiConfigController getController() { return mUIController; } @Override public void dispatchSubmit() { handleSubmitAction(); } @Override public void setTitle(int id) { getActivity().setTitle(id); } @Override public void setTitle(CharSequence title) { getActivity().setTitle(title); } @Override public void setSubmitButton(CharSequence text) { mSubmitBtn.setText(text); } @Override public void setCancelButton(CharSequence text) { mCancelBtn.setText(text); } @Override public void setForgetButton(CharSequence text) { // AddNetwork doesn't need forget button. } @Override public Button getSubmitButton() { return mSubmitBtn; } @Override public Button getCancelButton() { return mCancelBtn; } @Override public Button getForgetButton() { // AddNetwork doesn't need forget button. return null; } @VisibleForTesting void handleSubmitAction() { final Intent intent = new Intent(); final Activity activity = getActivity(); intent.putExtra(WIFI_CONFIG_KEY, mUIController.getConfig()); activity.setResult(Activity.RESULT_OK, intent); activity.finish(); } @VisibleForTesting void handleCancelAction() { final Activity activity = getActivity(); activity.setResult(Activity.RESULT_CANCELED); activity.finish(); } }
src/com/android/settings/wifi/WifiDialog.java +0 −8 Original line number Diff line number Diff line Loading @@ -50,14 +50,6 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase, private WifiConfigController mController; private boolean mHideSubmitButton; // TODO(b/111875856) WifiDialog should not mimic full screen UI. /** Creates a WifiDialog with fullscreen style. It displays in fullscreen mode. */ public static WifiDialog createFullscreen(Context context, WifiDialogListener listener, AccessPoint accessPoint, int mode) { return new WifiDialog(context, listener, accessPoint, mode, R.style.Theme_Settings_WifiDialogFullScreen, false /* hideSubmitButton */); } /** * Creates a WifiDialog with no additional style. It displays as a dialog above the current * view. Loading
src/com/android/settings/wifi/WifiSettings.java +44 −18 Original line number Diff line number Diff line Loading @@ -100,6 +100,9 @@ public class WifiSettings extends RestrictedSettingsFragment public static final int WIFI_DIALOG_ID = 1; private static final int WRITE_NFC_DIALOG_ID = 6; @VisibleForTesting static final int ADD_NETWORK_REQUEST = 2; // Instance state keys private static final String SAVE_DIALOG_MODE = "dialog_mode"; private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state"; Loading Loading @@ -416,6 +419,12 @@ public class WifiSettings extends RestrictedSettingsFragment public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Only handle request comes from AddNetworkFragment if (requestCode == ADD_NETWORK_REQUEST) { handleAddNetworkRequest(resultCode, data); return; } final boolean formerlyRestricted = mIsRestricted; mIsRestricted = isUiRestricted(); if (formerlyRestricted && !mIsRestricted Loading Loading @@ -590,13 +599,8 @@ public class WifiSettings extends RestrictedSettingsFragment public Dialog onCreateDialog(int dialogId) { switch (dialogId) { case WIFI_DIALOG_ID: if (mDlgAccessPoint == null && mAccessPointSavedState == null) { // add new network mDialog = WifiDialog .createFullscreen(getActivity(), this, mDlgAccessPoint, mDialogMode); } else { // modify network if (mDlgAccessPoint == null) { if (mDlgAccessPoint == null && mAccessPointSavedState != null) { // restore AP from save state mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState); // Reset the saved access point data Loading @@ -604,8 +608,6 @@ public class WifiSettings extends RestrictedSettingsFragment } mDialog = WifiDialog .createModal(getActivity(), this, mDlgAccessPoint, mDialogMode); } mSelectedAccessPoint = mDlgAccessPoint; return mDialog; case WRITE_NFC_DIALOG_ID: Loading Loading @@ -928,6 +930,15 @@ public class WifiSettings extends RestrictedSettingsFragment } } private void launchAddNetworkFragment() { new SubSettingLauncher(getContext()) .setTitleRes(R.string.wifi_add_network) .setDestination(AddNetworkFragment.class.getName()) .setSourceMetricsCategory(getMetricsCategory()) .setResultListener(this, ADD_NETWORK_REQUEST) .launch(); } private void launchNetworkDetailsFragment(ConnectedAccessPointPreference pref) { new SubSettingLauncher(getContext()) .setTitleRes(R.string.pref_title_network_details) Loading Loading @@ -1096,14 +1107,29 @@ public class WifiSettings extends RestrictedSettingsFragment mWifiManager.connect(networkId, mConnectListener); } @VisibleForTesting void handleAddNetworkRequest(int result, Intent data) { if(result == Activity.RESULT_OK) { handleAddNetworkSubmitEvent(data); } mWifiTracker.resumeScanning(); } private void handleAddNetworkSubmitEvent(Intent data) { final WifiConfiguration wifiConfiguration = data.getParcelableExtra( AddNetworkFragment.WIFI_CONFIG_KEY); if (wifiConfiguration != null) { mWifiManager.save(wifiConfiguration, mSaveListener); } } /** * Called when "add network" button is pressed. */ /* package */ void onAddNetworkPressed() { mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_ADD_NETWORK); private void onAddNetworkPressed() { // No exact access point is selected. mSelectedAccessPoint = null; showDialog(null, WifiConfigUiBase.MODE_CONNECT); launchAddNetworkFragment(); } @Override Loading