Implement NetworkRequestDialog architecture
Bug: 117399926 Test: RunSettingsRoboTests Change-Id: Ibf0a62a84bc3de080e4537ba084b0ff9a5e0e9a9
This commit is contained in:
44
res/layout/network_request_dialog_title.xml
Normal file
44
res/layout/network_request_dialog_title.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingEnd="?android:attr/dialogPreferredPadding"
|
||||
android:orientation="horizontal"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/network_request_title_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="16dip"
|
||||
android:layout_weight="1"
|
||||
android:textSize="18sp"
|
||||
android:gravity="center_vertical"
|
||||
style="@style/info_label"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/network_request_title_progress"
|
||||
style="?android:attr/progressBarStyleSmallTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="16dip"
|
||||
android:minWidth="32dp"
|
||||
android:text="@string/progress_scanning"/>
|
||||
</LinearLayout>
|
@@ -10269,7 +10269,9 @@
|
||||
<!-- See less items in contextual homepage [CHAR LIMIT=30]-->
|
||||
<string name="see_less">See less</string>
|
||||
|
||||
<!-- Summary for connected devices count in connected device slice. [CHAR LIMIT=NONE] -->
|
||||
<!-- Title for Network connection request Dialog [CHAR LIMIT=30] -->
|
||||
<string name="network_connection_request_dialog_title">Choose device</string>
|
||||
|
||||
<plurals name="show_connected_devices">
|
||||
<item quantity="one"><xliff:g id="number_device_count">%1$d</xliff:g> device connected</item>
|
||||
<item quantity="other"><xliff:g id="number_device_count">%1$d</xliff:g> devices connected</item>
|
||||
|
117
src/com/android/settings/wifi/NetworkRequestDialogFragment.java
Normal file
117
src/com/android/settings/wifi/NetworkRequestDialogFragment.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
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.wifi.AccessPoint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkRequestDialogFragment extends InstrumentedDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
|
||||
private List<AccessPoint> mAccessPointList;
|
||||
|
||||
public static NetworkRequestDialogFragment newInstance(int uid, String packageName) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("uid", uid);
|
||||
args.putString("packageName", packageName);
|
||||
NetworkRequestDialogFragment dialogFragment = new NetworkRequestDialogFragment();
|
||||
dialogFragment.setArguments(args);
|
||||
return dialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Context context = getContext();
|
||||
|
||||
// Prepares title.
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View customTitle = inflater.inflate(R.layout.network_request_dialog_title, null);
|
||||
|
||||
TextView title = customTitle.findViewById(R.id.network_request_title_text);
|
||||
title.setText(R.string.network_connection_request_dialog_title);
|
||||
ProgressBar progressBar = customTitle.findViewById(R.id.network_request_title_progress);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
// Prepares adapter.
|
||||
AccessPointAdapter adapter = new AccessPointAdapter(context,
|
||||
R.layout.preference_access_point, getAccessPointList());
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||
.setCustomTitle(customTitle)
|
||||
.setAdapter(adapter, this)
|
||||
.setPositiveButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
List<AccessPoint> getAccessPointList() {
|
||||
// Initials list for adapter, in case of display crashing.
|
||||
if (mAccessPointList == null) {
|
||||
mAccessPointList = new ArrayList<>();
|
||||
}
|
||||
return mAccessPointList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.WIFI_SCANNING_NEEDED_DIALOG;
|
||||
}
|
||||
|
||||
private class AccessPointAdapter extends ArrayAdapter<AccessPoint> {
|
||||
|
||||
private final int mResourceId;
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public AccessPointAdapter(Context context, int resourceId, List<AccessPoint> objects) {
|
||||
super(context, resourceId, objects);
|
||||
mResourceId = resourceId;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
if (view == null) {
|
||||
view = mInflater.inflate(mResourceId, parent, false);
|
||||
}
|
||||
|
||||
// TODO: Sets correct information to list item.
|
||||
final View divider = view.findViewById(com.android.settingslib.R.id.two_target_divider);
|
||||
divider.setVisibility(View.GONE);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.widget.Button;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {SettingsShadowResourcesImpl.class, ShadowAlertDialogCompat.class})
|
||||
public class NetworkRequestDialogFragmentTest {
|
||||
|
||||
private FragmentActivity mActivity;
|
||||
private NetworkRequestDialogFragment networkRequestDialogFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
networkRequestDialogFragment = spy(NetworkRequestDialogFragment.newInstance(-1, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_shouldShowTheDialog() {
|
||||
networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), null);
|
||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(alertDialog).isNotNull();
|
||||
assertThat(alertDialog.isShowing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickPositiveButton_shouldCloseTheDialog() {
|
||||
networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), null);
|
||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(alertDialog.isShowing()).isTrue();
|
||||
|
||||
Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
assertThat(positiveButton).isNotNull();
|
||||
|
||||
positiveButton.performClick();
|
||||
assertThat(alertDialog.isShowing()).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user