diff --git a/res/values/strings.xml b/res/values/strings.xml index 7eb8efefc4b..8df95dbd9e2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10560,6 +10560,8 @@ Something came up. The application has cancelled the request to choose a device. Connection successful + + Show all diff --git a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java index d1df7f0d6f4..ba29e3abab4 100644 --- a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java +++ b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java @@ -37,6 +37,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; +import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -69,8 +70,12 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp /** Message sent to us to stop scanning wifi and pop up timeout dialog. */ private static final int MESSAGE_STOP_SCAN_WIFI_LIST = 0; - /** Spec defines there should be 5 wifi ap on the list at most. */ + /** + * Spec defines there should be 5 wifi ap on the list at most or just show all if {@code + * mShowLimitedItem} is false. + */ private static final int MAX_NUMBER_LIST_ITEM = 5; + private boolean mShowLimitedItem = true; /** Delayed time to stop scanning wifi. */ private static final int DELAY_TIME_STOP_SCAN_MS = 30 * 1000; @@ -110,13 +115,29 @@ 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) -> getActivity().finish()); + .setPositiveButton(R.string.cancel, (dialog, which) -> getActivity().finish()) + // Do nothings, will replace the onClickListener to avoid auto closing dialog. + .setNeutralButton(R.string.network_connection_request_dialog_showall, + null /* OnClickListener */); // Clicking list item is to connect wifi ap. final AlertDialog dialog = builder.create(); dialog.getListView() .setOnItemClickListener( (parent, view, position, id) -> this.onClick(dialog, position)); + + dialog.setOnShowListener((dialogInterface) -> { + // Replace NeutralButton onClickListener to avoid closing dialog + final Button neutralBtn = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); + neutralBtn.setVisibility(View.GONE); + neutralBtn.setOnClickListener(v -> { + mShowLimitedItem = false; + renewAccessPointList(null /* List */); + notifyAdapterRefresh(); + neutralBtn.setVisibility(View.GONE); + }); + }); + return dialog; } @@ -202,6 +223,18 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } + private void showNeutralButton() { + final AlertDialog alertDialog = (AlertDialog) getDialog(); + if (alertDialog == null) { + return; + } + + final Button neutralBtn = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); + if (neutralBtn != null) { + neutralBtn.setVisibility(View.VISIBLE); + } + } + @Override public void onResume() { super.onResume(); @@ -394,6 +427,10 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp mAccessPointKeys.add(key); } } + + if (mShowLimitedItem && (mAccessPointKeys.size() > MAX_NUMBER_LIST_ITEM)) { + showNeutralButton(); + } } /** @@ -414,7 +451,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp count++; // Limits how many count of items could show. - if (count >= MAX_NUMBER_LIST_ITEM) { + if (mShowLimitedItem && count >= MAX_NUMBER_LIST_ITEM) { break; } } diff --git a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java index 0286d07d074..21b68f216f2 100644 --- a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java +++ b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java @@ -33,6 +33,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.NetworkRequestUserSelectionCallback; import android.os.Bundle; +import android.view.View; import android.widget.Button; import android.widget.TextView; @@ -264,20 +265,77 @@ public class NetworkRequestDialogFragmentTest { private List createAccessPointList() { List accessPointList = spy(new ArrayList<>()); Bundle bundle = new Bundle(); + bundle.putString(KEY_SSID, "Test AP 1"); bundle.putInt(KEY_SECURITY, 1); accessPointList.add(new AccessPoint(mContext, bundle)); + bundle.putString(KEY_SSID, "Test AP 2"); bundle.putInt(KEY_SECURITY, 1); accessPointList.add(new AccessPoint(mContext, bundle)); + bundle.putString(KEY_SSID, "Test AP 3"); bundle.putInt(KEY_SECURITY, 2); - AccessPoint clickedAccessPoint = new AccessPoint(mContext, bundle); - accessPointList.add(clickedAccessPoint); + accessPointList.add(new AccessPoint(mContext, bundle)); + bundle.putString(KEY_SSID, "Test AP 4"); bundle.putInt(KEY_SECURITY, 0); accessPointList.add(new AccessPoint(mContext, bundle)); return accessPointList; } + + @Test + public void display_shouldNotShowNeutralButton() { + networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), /* tag */ null); + final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); + + final Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); + assertThat(button).isNotNull(); + assertThat(button.getVisibility()).isEqualTo(View.GONE); + } + + @Test + public void onMatchManyResult_showNeutralButton() { + networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), /* tag */ null); + final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); + + final String SSID_AP = "Test AP "; + final List scanResults = new ArrayList<>(); + for (int i = 0; i < 6 ; i ++) { + ScanResult scanResult = new ScanResult(); + scanResult.SSID = SSID_AP + i; + scanResult.capabilities = "WEP"; + scanResults.add(scanResult); + } + networkRequestDialogFragment.onMatch(scanResults); + + final Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); + assertThat(button).isNotNull(); + assertThat(button.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void clickNeutralButton_hideNeutralButton() { + // Assert + networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), /* tag */ null); + final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); + + final String SSID_AP = "Test AP "; + final List scanResults = new ArrayList<>(); + for (int i = 0; i < 6 ; i ++) { + ScanResult scanResult = new ScanResult(); + scanResult.SSID = SSID_AP + i; + scanResult.capabilities = "WEP"; + scanResults.add(scanResult); + } + networkRequestDialogFragment.onMatch(scanResults); + + // Action + final Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); + button.performClick(); + + // Check + assertThat(button.getVisibility()).isEqualTo(View.GONE); + } }