From b795dcbcd19dfe94d9eb8b083e97b33147712682 Mon Sep 17 00:00:00 2001 From: cosmohsieh Date: Thu, 14 Mar 2019 18:29:55 +0800 Subject: [PATCH] [Network Connection] Implement new UI changing 1. Change title to multi-lines display 2. Add "SingleSpecifiedSSID" mode, will have connect button 3. Don't pop error dialog, if there is connection failure. Let user retry. 4. Hide progress icon if list item exists Bug: 128586511 Test: atest NetworkRequestDialogFragmentTest Change-Id: Icc560e4882fbcd941574e44690a27d5082a7c4c7 --- res/layout/network_request_dialog_title.xml | 4 +- .../wifi/NetworkRequestDialogFragment.java | 84 +++++++++++++++++-- .../NetworkRequestDialogFragmentTest.java | 46 +++++----- 3 files changed, 96 insertions(+), 38 deletions(-) diff --git a/res/layout/network_request_dialog_title.xml b/res/layout/network_request_dialog_title.xml index f643e0f5c5a..b61a7db4d23 100644 --- a/res/layout/network_request_dialog_title.xml +++ b/res/layout/network_request_dialog_title.xml @@ -25,14 +25,12 @@ mAccessPointList; private FilterWifiTracker mFilterWifiTracker; private AccessPointAdapter mDialogAdapter; private NetworkRequestUserSelectionCallback mUserSelectionCallback; + private boolean mIsSpecifiedSsid; + private boolean mWaitingConnectCallback; public static NetworkRequestDialogFragment newInstance() { NetworkRequestDialogFragment dialogFragment = new NetworkRequestDialogFragment(); @@ -104,6 +108,11 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp final TextView title = customTitle.findViewById(R.id.network_request_title_text); title.setText(getTitle()); + final Intent intent = getActivity().getIntent(); + if (intent != null) { + mIsSpecifiedSsid = intent.getBooleanExtra(EXTRA_IS_SPECIFIED_SSID, false); + } + final ProgressBar progressBar = customTitle.findViewById( R.id.network_request_title_progress); progressBar.setVisibility(View.VISIBLE); @@ -115,10 +124,13 @@ 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()) + .setNegativeButton(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 */); + if (mIsSpecifiedSsid) { + builder.setPositiveButton(R.string.wifi_connect, null /* OnClickListener */); + } // Clicking list item is to connect wifi ap. final AlertDialog dialog = builder.create(); @@ -136,8 +148,19 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp notifyAdapterRefresh(); neutralBtn.setVisibility(View.GONE); }); - }); + // Replace Positive onClickListener to avoid closing dialog + if (mIsSpecifiedSsid) { + final Button positiveBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE); + positiveBtn.setOnClickListener(v -> { + // When clicking connect button, should connect to the first and the only one + // list item. + this.onClick(dialog, 0 /* position */); + }); + // Disable button in first, and enable it after there are some accesspoints in list. + positiveBtn.setEnabled(false); + } + }); return dialog; } @@ -184,6 +207,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp if (wifiConfig != null) { mUserSelectionCallback.select(wifiConfig); + + mWaitingConnectCallback = true; + updateConnectButton(false); } } } @@ -223,7 +249,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } - private void showNeutralButton() { + private void showAllButton() { final AlertDialog alertDialog = (AlertDialog) getDialog(); if (alertDialog == null) { return; @@ -235,6 +261,35 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } + private void updateConnectButton(boolean enabled) { + // The button is only showed in single SSID mode. + if (!mIsSpecifiedSsid) { + return; + } + + final AlertDialog alertDialog = (AlertDialog) getDialog(); + if (alertDialog == null) { + return; + } + + final Button positiveBtn = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); + if (positiveBtn != null) { + positiveBtn.setEnabled(enabled); + } + } + + private void hideProgressIcon() { + final AlertDialog alertDialog = (AlertDialog) getDialog(); + if (alertDialog == null) { + return; + } + + final View progress = alertDialog.findViewById(R.id.network_request_title_progress); + if (progress != null) { + progress.setVisibility(View.GONE); + } + } + @Override public void onResume() { super.onResume(); @@ -403,7 +458,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp @Override public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) { - stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.ABORT); + // Do nothing when selection is failed, let user could try again easily. + mWaitingConnectCallback = false; + updateConnectButton(true); } private final class FilterWifiTracker { @@ -427,10 +484,6 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp mAccessPointKeys.add(key); } } - - if (mShowLimitedItem && (mAccessPointKeys.size() > MAX_NUMBER_LIST_ITEM)) { - showNeutralButton(); - } } /** @@ -457,6 +510,21 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } + // Update related UI buttons + if (mShowLimitedItem && (count >= MAX_NUMBER_LIST_ITEM)) { + showAllButton(); + } + if (count > 0) { + hideProgressIcon(); + } + // Enable connect button if there is Accesspoint item, except for the situation that + // user click but connected status doesn't come back yet. + if (count < 0) { + updateConnectButton(false); + } else if (!mWaitingConnectCallback) { + updateConnectButton(true); + } + return result; } diff --git a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java index 21b68f216f2..d2403b942a1 100644 --- a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java +++ b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java @@ -106,12 +106,12 @@ public class NetworkRequestDialogFragmentTest { } @Test - public void clickPositiveButton_shouldCloseTheDialog() { + public void clickNegativeButton_shouldCloseTheDialog() { networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), null); AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(alertDialog.isShowing()).isTrue(); - Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); + Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE); assertThat(positiveButton).isNotNull(); positiveButton.performClick(); @@ -185,26 +185,6 @@ public class NetworkRequestDialogFragmentTest { verify(spyActivity).finish(); } - @Test - public void updateAccessPointList_onUserSelectionConnectFailure_shouldCallAbortDialog() { - FakeNetworkRequestDialogFragment fakeFragment = new FakeNetworkRequestDialogFragment(); - FakeNetworkRequestDialogFragment spyFakeFragment = spy(fakeFragment); - List accessPointList = createAccessPointList(); - when(spyFakeFragment.getAccessPointList()).thenReturn(accessPointList); - spyFakeFragment.show(mActivity.getSupportFragmentManager(), null); - - AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); - assertThat(alertDialog.isShowing()).isTrue(); - - // Test if config would update list. - WifiConfiguration config = new WifiConfiguration(); - config.SSID = "Test AP 3"; - fakeFragment.onUserSelectionConnectFailure(config); - - assertThat(fakeFragment.bCalledStopAndPop).isTrue(); - assertThat(fakeFragment.errorType).isEqualTo(ERROR_DIALOG_TYPE.ABORT); - } - @Test public void onUserSelectionCallbackRegistration_onClick_shouldCallSelect() { // Assert. @@ -267,19 +247,27 @@ public class NetworkRequestDialogFragmentTest { Bundle bundle = new Bundle(); bundle.putString(KEY_SSID, "Test AP 1"); - bundle.putInt(KEY_SECURITY, 1); + bundle.putInt(KEY_SECURITY, 1 /* WEP */); accessPointList.add(new AccessPoint(mContext, bundle)); bundle.putString(KEY_SSID, "Test AP 2"); - bundle.putInt(KEY_SECURITY, 1); + bundle.putInt(KEY_SECURITY, 1 /* WEP */); accessPointList.add(new AccessPoint(mContext, bundle)); bundle.putString(KEY_SSID, "Test AP 3"); - bundle.putInt(KEY_SECURITY, 2); + bundle.putInt(KEY_SECURITY, 1 /* WEP */); accessPointList.add(new AccessPoint(mContext, bundle)); bundle.putString(KEY_SSID, "Test AP 4"); - bundle.putInt(KEY_SECURITY, 0); + bundle.putInt(KEY_SECURITY, 0 /* NONE */); + accessPointList.add(new AccessPoint(mContext, bundle)); + + bundle.putString(KEY_SSID, "Test AP 5"); + bundle.putInt(KEY_SECURITY, 1 /* WEP */); + accessPointList.add(new AccessPoint(mContext, bundle)); + + bundle.putString(KEY_SSID, "Test AP 6"); + bundle.putInt(KEY_SECURITY, 1 /* WEP */); accessPointList.add(new AccessPoint(mContext, bundle)); return accessPointList; @@ -300,9 +288,13 @@ public class NetworkRequestDialogFragmentTest { networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), /* tag */ null); final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); + + List accessPointList = createAccessPointList(); + when(mWifiTracker.getAccessPoints()).thenReturn(accessPointList); + final String SSID_AP = "Test AP "; final List scanResults = new ArrayList<>(); - for (int i = 0; i < 6 ; i ++) { + for (int i = 0; i < 7 ; i ++) { ScanResult scanResult = new ScanResult(); scanResult.SSID = SSID_AP + i; scanResult.capabilities = "WEP";