Skip to content

Commit

Permalink
Settings: Network setup UI changes for SUW
Browse files Browse the repository at this point in the history
Change-Id: Ic8e97b78f19e59fe108c7c3304dfe7e7f49020a9
Signed-off-by: Mohammad Hasan Keramat J <[email protected]>
  • Loading branch information
mikeNG authored and electrikjesus committed Jan 29, 2024
1 parent da2bb47 commit 22870ce
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 7 deletions.
12 changes: 12 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,18 @@
android:value="true" />
</activity>

<activity
android:name=".network.NetworkSetupActivity"
android:theme="@style/GlifV3Theme.Light"
android:exported="true">
<intent-filter android:priority="1">
<action android:name="android.settings.NETWORK_PROVIDER_SETUP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>

<activity
android:name=".wifi.WifiPickerActivity"
android:permission="android.permission.CHANGE_WIFI_STATE"
Expand Down
26 changes: 26 additions & 0 deletions res/drawable/ic_network_setup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="?android:attr/colorPrimary"
android:pathData="M12,2A8,8 0 0,0 4,10C4,14.03 7,17.42 11,17.93V19H10A1,1 0 0,0 9,20H2V22H9A1,1 0 0,0 10,23H14A1,1 0 0,0 15,22H22V20H15A1,1 0 0,0 14,19H13V17.93C17,17.43 20,14.03 20,10A8,8 0 0,0 12,2M12,4C12,4 12.74,5.28 13.26,7H10.74C11.26,5.28 12,4 12,4M9.77,4.43C9.5,4.93 9.09,5.84 8.74,7H6.81C7.5,5.84 8.5,4.93 9.77,4.43M14.23,4.44C15.5,4.94 16.5,5.84 17.19,7H15.26C14.91,5.84 14.5,4.93 14.23,4.44M6.09,9H8.32C8.28,9.33 8.25,9.66 8.25,10C8.25,10.34 8.28,10.67 8.32,11H6.09C6.03,10.67 6,10.34 6,10C6,9.66 6.03,9.33 6.09,9M10.32,9H13.68C13.72,9.33 13.75,9.66 13.75,10C13.75,10.34 13.72,10.67 13.68,11H10.32C10.28,10.67 10.25,10.34 10.25,10C10.25,9.66 10.28,9.33 10.32,9M15.68,9H17.91C17.97,9.33 18,9.66 18,10C18,10.34 17.97,10.67 17.91,11H15.68C15.72,10.67 15.75,10.34 15.75,10C15.75,9.66 15.72,9.33 15.68,9M6.81,13H8.74C9.09,14.16 9.5,15.07 9.77,15.56C8.5,15.06 7.5,14.16 6.81,13M10.74,13H13.26C12.74,14.72 12,16 12,16C12,16 11.26,14.72 10.74,13M15.26,13H17.19C16.5,14.16 15.5,15.07 14.23,15.57C14.5,15.07 14.91,14.16 15.26,13Z" />
</vector>
56 changes: 49 additions & 7 deletions src/com/android/settings/network/NetworkProviderSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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() {
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -981,7 +1017,9 @@ protected void updateWifiEntryPreferences() {

if (mClickedConnect) {
mClickedConnect = false;
scrollToPreference(connectedWifiPreferenceCategory);
if (!mIsInSetupWizard) {
scrollToPreference(connectedWifiPreferenceCategory);
}
}
}
} else {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1159,7 +1199,9 @@ private boolean isWifiWakeupEnabled() {
}

protected void setProgressBarVisible(boolean visible) {
showPinnedHeader(visible);
if (!mIsInSetupWizard) {
showPinnedHeader(visible);
}
}

@VisibleForTesting
Expand Down
67 changes: 67 additions & 0 deletions src/com/android/settings/network/NetworkSetupActivity.java
Original file line number Diff line number Diff line change
@@ -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<? extends PreferenceFragmentCompat> 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);
}
}

0 comments on commit 22870ce

Please sign in to comment.