Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3eab6a9 authored by govenliu's avatar govenliu
Browse files

[Wi-Fi] Hide SoftKeyboard temporary when user tap the advanced button.

When tapping on the advanced button during configuring a network, some items in the expanded list are covered by IME keyboard, which may cause user to ignore them accidently.

To improve it, hide the IME temporary to let user can see most of them.

Bug: 78441374
Test: Use ShadowInputMethodManager to check if the keyboard is hide or not after tapping on the advance button.
Change-Id: I0677d96febc90c66d1cf6f98555bbb436a654660
parent 31c7ac10
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.net.wifi.WifiEnterpriseConfig.Eap;
import android.net.wifi.WifiEnterpriseConfig.Phase2;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.os.UserManager;
import android.security.Credentials;
import android.security.KeyStore;
@@ -48,6 +49,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
@@ -60,8 +62,6 @@ import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.VisibleForTesting;

import com.android.settings.ProxySelector;
import com.android.settings.R;
import com.android.settings.wifi.details.WifiPrivacyPreferenceController;
@@ -76,6 +76,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

import androidx.annotation.VisibleForTesting;

/**
 * The class for allowing UIs like {@link WifiDialog} and {@link WifiConfigUiBase} to
 * share the logic for controlling buttons, text fields, etc.
@@ -1490,6 +1492,9 @@ public class WifiConfigController implements TextWatcher,
            if (isChecked) {
                toggleVisibility = View.VISIBLE;
                stringID = R.string.wifi_advanced_toggle_description_expanded;

                // Hide the SoftKeyboard temporary to let user can see most of the expanded items.
                hideSoftKeyboard(mView.getWindowToken());
            } else {
                toggleVisibility = View.GONE;
                stringID = R.string.wifi_advanced_toggle_description_collapsed;
@@ -1688,4 +1693,10 @@ public class WifiConfigController implements TextWatcher,
        }
        return accessibleEntries;
    }

    private void hideSoftKeyboard(IBinder windowToken) {
        final InputMethodManager inputMethodManager = mContext.getSystemService(
                InputMethodManager.class);
        inputMethodManager.hideSoftInputFromWindow(windowToken, 0 /* flags */);
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ import android.security.KeyStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;

@@ -51,7 +53,9 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowInputMethodManager;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowConnectivityManager.class)
@@ -509,4 +513,17 @@ public class WifiConfigControllerTest {
        final int selectedItemPosition = eapMethodSpinner.getSelectedItemPosition();
        assertThat(eapMethodSpinner.getSelectedItem().toString()).isEqualTo("TLS");
    }

    @Test
    public void checkImeStatus_whenAdvancedToggled_shouldBeHide() {
        final InputMethodManager inputMethodManager = mContext
                .getSystemService(InputMethodManager.class);
        final ShadowInputMethodManager shadowImm = Shadows.shadowOf(inputMethodManager);
        final CheckBox advButton = mView.findViewById(R.id.wifi_advanced_togglebox);

        inputMethodManager.showSoftInput(null /* view */, 0 /* flags */);
        advButton.performClick();

        assertThat(shadowImm.isSoftInputVisible()).isFalse();
    }
}