Remove the dependency on InputMethodSettings
InputMethodUtils.InputMethodSetting is a quite complicated inernal class of InputMethodUtils and PhysicalKeyboardFragment's depending on it just for getting/setting SHOW_IME_WITH_HARD_KEYBOARD is overkill. With this CL, PhysicalKeyboardFragment just uses Secure Settings APIs directly. There should be no user-visible behavior change. Bug: 77730201 Test: Manually verified as follows: 1. Open system settings. 2. Tap "System" -> "Languages & input" -> "Physical keyboard" 3. Make sure "Show virtual keyboard" is unchecked 4. Make sure the following command shows 0 adb shell settings get secure show_ime_with_hard_keyboard 5. Check "Show virtual keyboard" 6. Make sure the following command shows 1 adb shell settings get secure show_ime_with_hard_keyboard 7. Run the following command adb shell settings put secure show_ime_with_hard_keyboard 0 8. Make sure "Show virtual keyboard" is chenged to unchecked Change-Id: I956da5dad27313d6edf141f2320bb0a7954fbbea
This commit is contained in:
@@ -38,7 +38,6 @@ import android.support.v7.preference.PreferenceScreen;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
|
|
||||||
import com.android.internal.inputmethod.InputMethodUtils;
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -52,7 +51,6 @@ import com.android.settingslib.utils.ThreadUtils;
|
|||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -73,8 +71,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
private PreferenceCategory mKeyboardAssistanceCategory;
|
private PreferenceCategory mKeyboardAssistanceCategory;
|
||||||
@NonNull
|
@NonNull
|
||||||
private SwitchPreference mShowVirtualKeyboardSwitch;
|
private SwitchPreference mShowVirtualKeyboardSwitch;
|
||||||
@NonNull
|
|
||||||
private InputMethodUtils.InputMethodSettings mSettings;
|
|
||||||
|
|
||||||
private Intent mIntentWaitingForResult;
|
private Intent mIntentWaitingForResult;
|
||||||
|
|
||||||
@@ -83,13 +79,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
Activity activity = Preconditions.checkNotNull(getActivity());
|
Activity activity = Preconditions.checkNotNull(getActivity());
|
||||||
addPreferencesFromResource(R.xml.physical_keyboard_settings);
|
addPreferencesFromResource(R.xml.physical_keyboard_settings);
|
||||||
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
|
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
|
||||||
mSettings = new InputMethodUtils.InputMethodSettings(
|
|
||||||
activity.getResources(),
|
|
||||||
getContentResolver(),
|
|
||||||
new HashMap<>(),
|
|
||||||
new ArrayList<>(),
|
|
||||||
UserHandle.myUserId(),
|
|
||||||
false /* copyOnWrite */);
|
|
||||||
mKeyboardAssistanceCategory = Preconditions.checkNotNull(
|
mKeyboardAssistanceCategory = Preconditions.checkNotNull(
|
||||||
(PreferenceCategory) findPreference(KEYBOARD_ASSISTANCE_CATEGORY));
|
(PreferenceCategory) findPreference(KEYBOARD_ASSISTANCE_CATEGORY));
|
||||||
mShowVirtualKeyboardSwitch = Preconditions.checkNotNull(
|
mShowVirtualKeyboardSwitch = Preconditions.checkNotNull(
|
||||||
@@ -210,7 +199,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateShowVirtualKeyboardSwitch() {
|
private void updateShowVirtualKeyboardSwitch() {
|
||||||
mShowVirtualKeyboardSwitch.setChecked(mSettings.isShowImeWithHardKeyboardEnabled());
|
mShowVirtualKeyboardSwitch.setChecked(
|
||||||
|
Secure.getInt(getContentResolver(), Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleKeyboardShortcutsMenu() {
|
private void toggleKeyboardShortcutsMenu() {
|
||||||
@@ -218,12 +208,10 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final OnPreferenceChangeListener mShowVirtualKeyboardSwitchPreferenceChangeListener =
|
private final OnPreferenceChangeListener mShowVirtualKeyboardSwitchPreferenceChangeListener =
|
||||||
new OnPreferenceChangeListener() {
|
(preference, newValue) -> {
|
||||||
@Override
|
Secure.putInt(getContentResolver(), Secure.SHOW_IME_WITH_HARD_KEYBOARD,
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
((Boolean) newValue) ? 1 : 0);
|
||||||
mSettings.setShowImeWithHardKeyboard((Boolean) newValue);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private final ContentObserver mContentObserver = new ContentObserver(new Handler(true)) {
|
private final ContentObserver mContentObserver = new ContentObserver(new Handler(true)) {
|
||||||
|
Reference in New Issue
Block a user