From 22870ceb3107f8264dc26c17f38fc55ae49c480a Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Tue, 24 Aug 2021 01:18:55 +0300 Subject: [PATCH] Settings: Network setup UI changes for SUW Change-Id: Ic8e97b78f19e59fe108c7c3304dfe7e7f49020a9 Signed-off-by: Mohammad Hasan Keramat J --- AndroidManifest.xml | 12 ++++ res/drawable/ic_network_setup.xml | 26 +++++++ .../network/NetworkProviderSettings.java | 56 ++++++++++++++-- .../network/NetworkSetupActivity.java | 67 +++++++++++++++++++ 4 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 res/drawable/ic_network_setup.xml create mode 100644 src/com/android/settings/network/NetworkSetupActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b963ff8e6a7..89011a56f89 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -436,6 +436,18 @@ android:value="true" /> + + + + + + + + + + + + + diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java index ae2cfbc1a35..7a93a17ad3c 100644 --- a/src/com/android/settings/network/NetworkProviderSettings.java +++ b/src/com/android/settings/network/NetworkProviderSettings.java @@ -44,10 +44,12 @@ import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.Toast; import androidx.annotation.Nullable; @@ -94,6 +96,9 @@ import com.android.wifitrackerlib.WifiEntry.ConnectCallback; import com.android.wifitrackerlib.WifiPickerTracker; +import com.google.android.setupcompat.util.WizardManagerHelper; +import com.google.android.setupdesign.GlifPreferenceLayout; + import java.util.List; import java.util.Optional; @@ -167,6 +172,8 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment // Enable the Next button when a Wi-Fi network is connected. private boolean mEnableNextOnConnection; + private boolean mIsInSetupWizard; + // This string extra specifies a network to open the connect dialog on, so the user can enter // network credentials. This is used by quick settings for secured networks, among other // things. @@ -271,6 +278,16 @@ public void onViewCreated(View view, Bundle savedInstanceState) { return; } + if (mIsInSetupWizard) { + GlifPreferenceLayout layout = (GlifPreferenceLayout) view; + layout.setDividerInsets(Integer.MAX_VALUE, 0); + + layout.setIcon(getContext().getDrawable(R.drawable.ic_network_setup)); + layout.setHeaderText(R.string.provider_internet_settings); + + return; + } + setPinnedHeaderView(R.layout.progress_header); setProgressBarVisible(false); @@ -303,6 +320,9 @@ public void onCreate(Bundle icicle) { mIsRestricted = isUiRestricted(); mIsAdmin = isAdminUser(); + + final Intent intent = this.getIntent(); + mIsInSetupWizard = WizardManagerHelper.isAnySetupWizard(intent); } private boolean isAdminUser() { @@ -311,6 +331,17 @@ private boolean isAdminUser() { return userManager.isAdminUser(); } + @Override + public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, + Bundle savedInstanceState) { + if (mIsInSetupWizard) { + GlifPreferenceLayout layout = (GlifPreferenceLayout) parent; + return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); + } else { + return super.onCreateRecyclerView(inflater, parent, savedInstanceState); + } + } + private void addPreferences() { addPreferencesFromResource(R.xml.network_provider_settings); @@ -436,7 +467,12 @@ public void onFailure(int reason) { } } }; - setHasOptionsMenu(true); + if (mIsInSetupWizard) { + mConfigureWifiSettingsPreference.setVisible(false); + mDataUsagePreference.setVisible(false); + } else { + setHasOptionsMenu(true); + } if (savedInstanceState != null) { mDialogMode = savedInstanceState.getInt(SAVE_DIALOG_MODE); @@ -981,7 +1017,9 @@ protected void updateWifiEntryPreferences() { if (mClickedConnect) { mClickedConnect = false; - scrollToPreference(connectedWifiPreferenceCategory); + if (!mIsInSetupWizard) { + scrollToPreference(connectedWifiPreferenceCategory); + } } } } else { @@ -1107,10 +1145,12 @@ private void removeWifiEntryPreference() { @VisibleForTesting void setAdditionalSettingsSummaries() { - mConfigureWifiSettingsPreference.setSummary(getString( - isWifiWakeupEnabled() - ? R.string.wifi_configure_settings_preference_summary_wakeup_on - : R.string.wifi_configure_settings_preference_summary_wakeup_off)); + if (!mIsInSetupWizard) { + mConfigureWifiSettingsPreference.setSummary(getString( + isWifiWakeupEnabled() + ? R.string.wifi_configure_settings_preference_summary_wakeup_on + : R.string.wifi_configure_settings_preference_summary_wakeup_off)); + } final int numSavedNetworks = mWifiPickerTracker == null ? 0 : mWifiPickerTracker.getNumSavedNetworks(); @@ -1159,7 +1199,9 @@ private boolean isWifiWakeupEnabled() { } protected void setProgressBarVisible(boolean visible) { - showPinnedHeader(visible); + if (!mIsInSetupWizard) { + showPinnedHeader(visible); + } } @VisibleForTesting diff --git a/src/com/android/settings/network/NetworkSetupActivity.java b/src/com/android/settings/network/NetworkSetupActivity.java new file mode 100644 index 00000000000..80290ed0091 --- /dev/null +++ b/src/com/android/settings/network/NetworkSetupActivity.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2021 The LineageOS 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.network; + +import android.content.Intent; +import android.content.res.Resources; + +import androidx.preference.PreferenceFragmentCompat; + +import com.android.settings.ButtonBarHandler; +import com.android.settings.network.NetworkProviderSettings; +import com.android.settings.R; +import com.android.settings.SettingsActivity; +import com.android.settings.SetupWizardUtils; +import com.android.settings.wifi.p2p.WifiP2pSettings; +import com.android.settings.wifi.savedaccesspoints2.SavedAccessPointsWifiSettings2; + +public class NetworkSetupActivity extends SettingsActivity implements ButtonBarHandler { + + @Override + public Intent getIntent() { + Intent modIntent = new Intent(super.getIntent()); + if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) { + modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getNetworkProviderSettingsClass().getName()); + modIntent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, + R.string.provider_internet_settings); + } + return modIntent; + } + + @Override + protected boolean isValidFragment(String fragmentName) { + final boolean isSavedAccessPointsWifiSettings = + SavedAccessPointsWifiSettings2.class.getName().equals(fragmentName); + + if (NetworkProviderSettings.class.getName().equals(fragmentName) + || WifiP2pSettings.class.getName().equals(fragmentName) + || isSavedAccessPointsWifiSettings) { + return true; + } + return false; + } + + /* package */ Class getNetworkProviderSettingsClass() { + return NetworkProviderSettings.class; + } + + @Override + protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { + final int new_resid = SetupWizardUtils.getTheme(this, getIntent()); + super.onApplyThemeResource(theme, new_resid, first); + } +}