Loading AndroidManifest.xml +12 −0 Original line number Diff line number Diff line Loading @@ -2585,6 +2585,18 @@ </intent-filter> </activity> <activity android:name=".wifi.NetworkRequestDialogActivity" android:theme="@style/Transparent" android:excludeFromRecents="true" android:exported="true" android:permission="android.permission.NETWORK_SETTINGS"> <intent-filter> <action android:name="com.android.settings.wifi.NETWORK_REQUEST" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".sim.SimDialogActivity" android:theme="@style/Theme.AlertDialog" android:label="@string/sim_settings_title" Loading src/com/android/settings/wifi/NetworkRequestDialogActivity.java 0 → 100644 +38 −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.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; /** * When other applications request to have a wifi connection, framework will bring up this activity * to let user select which wifi ap wanna to connect. This activity is just a door for framework * call, and main functional process is at {@code NetworkRequestDialogFragment}. */ public class NetworkRequestDialogActivity extends FragmentActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final NetworkRequestDialogFragment fragment = NetworkRequestDialogFragment.newInstance(); fragment.show(getSupportFragmentManager(), "NetworkRequestDialogFragment"); } } src/com/android/settings/wifi/NetworkRequestDialogFragment.java +232 −211 Original line number Diff line number Diff line Loading @@ -28,9 +28,11 @@ import android.net.wifi.WifiManager.NetworkRequestMatchCallback; import android.os.Handler; import android.os.Message; import android.widget.BaseAdapter; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.preference.internal.PreferenceImageView; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; Loading @@ -38,11 +40,13 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ProgressBar; import android.widget.TextView; import com.android.internal.logging.nano.MetricsProto; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settingslib.Utils; import com.android.settingslib.wifi.AccessPoint; import java.util.ArrayList; import java.util.List; Loading Loading @@ -74,7 +78,8 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final TextView title = customTitle.findViewById(R.id.network_request_title_text); title.setText(R.string.network_connection_request_dialog_title); final ProgressBar progressBar = customTitle.findViewById(R.id.network_request_title_progress); final ProgressBar progressBar = customTitle.findViewById( R.id.network_request_title_progress); progressBar.setVisibility(View.VISIBLE); // Prepares adapter. Loading @@ -84,8 +89,14 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final AlertDialog.Builder builder = new AlertDialog.Builder(context) .setCustomTitle(customTitle) .setAdapter(mDialogAdapter, this) .setPositiveButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); return builder.create(); .setPositiveButton(R.string.cancel, (dialog, which) -> getActivity().finish()); // Clicking list item is to connect wifi ap. final AlertDialog dialog = builder.create(); dialog.getListView() .setOnItemClickListener( (parent, view, position, id) -> this.onClick(dialog, position)); return dialog; } @NonNull Loading Loading @@ -117,6 +128,13 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } @Override public void onCancel(@NonNull DialogInterface dialog) { super.onCancel(dialog); // Finishes activity when user clicks back key or outside of dialog. getActivity().finish(); } @Override public void onPause() { super.onPause(); Loading Loading @@ -188,7 +206,8 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp if (view == null) { view = mInflater.inflate(mResourceId, parent, false); final View divider = view.findViewById(com.android.settingslib.R.id.two_target_divider); final View divider = view.findViewById( com.android.settingslib.R.id.two_target_divider); divider.setVisibility(View.GONE); } Loading @@ -207,8 +226,10 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final PreferenceImageView imageView = view.findViewById(android.R.id.icon); final int level = accessPoint.getLevel(); if (imageView != null) { final Drawable drawable = getContext().getDrawable(Utils.getWifiIconResource(level)); drawable.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal)); final Drawable drawable = getContext().getDrawable( Utils.getWifiIconResource(level)); drawable.setTintList( Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal)); imageView.setImageDrawable(drawable); } Loading tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java 0 → 100644 +48 −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 static com.google.common.truth.Truth.assertThat; import androidx.appcompat.app.AlertDialog; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl; import com.android.settings.testutils.shadow.ShadowAlertDialogCompat; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config(shadows = { ShadowAlertDialogCompat.class, SettingsShadowResourcesImpl.class }) public class NetworkRequestDialogActivityTest { @Test public void LaunchActivity_shouldShowNetworkRequestDialog() { NetworkRequestDialogActivity activity = Robolectric .setupActivity(NetworkRequestDialogActivity.class); AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(alertDialog.isShowing()).isTrue(); } } Loading
AndroidManifest.xml +12 −0 Original line number Diff line number Diff line Loading @@ -2585,6 +2585,18 @@ </intent-filter> </activity> <activity android:name=".wifi.NetworkRequestDialogActivity" android:theme="@style/Transparent" android:excludeFromRecents="true" android:exported="true" android:permission="android.permission.NETWORK_SETTINGS"> <intent-filter> <action android:name="com.android.settings.wifi.NETWORK_REQUEST" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".sim.SimDialogActivity" android:theme="@style/Theme.AlertDialog" android:label="@string/sim_settings_title" Loading
src/com/android/settings/wifi/NetworkRequestDialogActivity.java 0 → 100644 +38 −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.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; /** * When other applications request to have a wifi connection, framework will bring up this activity * to let user select which wifi ap wanna to connect. This activity is just a door for framework * call, and main functional process is at {@code NetworkRequestDialogFragment}. */ public class NetworkRequestDialogActivity extends FragmentActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final NetworkRequestDialogFragment fragment = NetworkRequestDialogFragment.newInstance(); fragment.show(getSupportFragmentManager(), "NetworkRequestDialogFragment"); } }
src/com/android/settings/wifi/NetworkRequestDialogFragment.java +232 −211 Original line number Diff line number Diff line Loading @@ -28,9 +28,11 @@ import android.net.wifi.WifiManager.NetworkRequestMatchCallback; import android.os.Handler; import android.os.Message; import android.widget.BaseAdapter; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.preference.internal.PreferenceImageView; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; Loading @@ -38,11 +40,13 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ProgressBar; import android.widget.TextView; import com.android.internal.logging.nano.MetricsProto; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settingslib.Utils; import com.android.settingslib.wifi.AccessPoint; import java.util.ArrayList; import java.util.List; Loading Loading @@ -74,7 +78,8 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final TextView title = customTitle.findViewById(R.id.network_request_title_text); title.setText(R.string.network_connection_request_dialog_title); final ProgressBar progressBar = customTitle.findViewById(R.id.network_request_title_progress); final ProgressBar progressBar = customTitle.findViewById( R.id.network_request_title_progress); progressBar.setVisibility(View.VISIBLE); // Prepares adapter. Loading @@ -84,8 +89,14 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final AlertDialog.Builder builder = new AlertDialog.Builder(context) .setCustomTitle(customTitle) .setAdapter(mDialogAdapter, this) .setPositiveButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); return builder.create(); .setPositiveButton(R.string.cancel, (dialog, which) -> getActivity().finish()); // Clicking list item is to connect wifi ap. final AlertDialog dialog = builder.create(); dialog.getListView() .setOnItemClickListener( (parent, view, position, id) -> this.onClick(dialog, position)); return dialog; } @NonNull Loading Loading @@ -117,6 +128,13 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } @Override public void onCancel(@NonNull DialogInterface dialog) { super.onCancel(dialog); // Finishes activity when user clicks back key or outside of dialog. getActivity().finish(); } @Override public void onPause() { super.onPause(); Loading Loading @@ -188,7 +206,8 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp if (view == null) { view = mInflater.inflate(mResourceId, parent, false); final View divider = view.findViewById(com.android.settingslib.R.id.two_target_divider); final View divider = view.findViewById( com.android.settingslib.R.id.two_target_divider); divider.setVisibility(View.GONE); } Loading @@ -207,8 +226,10 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final PreferenceImageView imageView = view.findViewById(android.R.id.icon); final int level = accessPoint.getLevel(); if (imageView != null) { final Drawable drawable = getContext().getDrawable(Utils.getWifiIconResource(level)); drawable.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal)); final Drawable drawable = getContext().getDrawable( Utils.getWifiIconResource(level)); drawable.setTintList( Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal)); imageView.setImageDrawable(drawable); } Loading
tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogActivityTest.java 0 → 100644 +48 −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 static com.google.common.truth.Truth.assertThat; import androidx.appcompat.app.AlertDialog; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl; import com.android.settings.testutils.shadow.ShadowAlertDialogCompat; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config(shadows = { ShadowAlertDialogCompat.class, SettingsShadowResourcesImpl.class }) public class NetworkRequestDialogActivityTest { @Test public void LaunchActivity_shouldShowNetworkRequestDialog() { NetworkRequestDialogActivity activity = Robolectric .setupActivity(NetworkRequestDialogActivity.class); AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(alertDialog.isShowing()).isTrue(); } }