Loading res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -12882,4 +12882,7 @@ <!-- Authority of the content provider that support methods restartPhoneProcess and restartRild. Will be overlaid by OEM.--> <string name="reset_telephony_stack_content_provider_authority" translatable="false"></string> <!--Text for Stylus Pointer Icon preference --> <string name="show_stylus_pointer_icon">Show pointer while hovering</string> </resources> src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +35 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.hardware.input.InputSettings; import android.os.Process; import android.os.UserHandle; import android.os.UserManager; Loading Loading @@ -73,6 +74,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem static final String KEY_IGNORE_BUTTON = "ignore_button"; @VisibleForTesting static final String KEY_DEFAULT_NOTES = "default_notes"; @VisibleForTesting static final String KEY_SHOW_STYLUS_POINTER_ICON = "show_stylus_pointer_icon"; private static final String TAG = "StylusDevicesController"; Loading Loading @@ -181,6 +184,26 @@ public class StylusDevicesController extends AbstractPreferenceController implem return pref; } @Nullable private SwitchPreferenceCompat createShowStylusPointerIconPreference( SwitchPreferenceCompat preference) { if (!mContext.getResources() .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon)) { // If the config is not enabled, no need to show the preference to user return null; } SwitchPreferenceCompat pref = preference == null ? new SwitchPreferenceCompat(mContext) : preference; pref.setKey(KEY_SHOW_STYLUS_POINTER_ICON); pref.setTitle(mContext.getString(R.string.show_stylus_pointer_icon)); pref.setIcon(R.drawable.ic_stylus); pref.setOnPreferenceClickListener(this); pref.setChecked(Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, InputSettings.DEFAULT_STYLUS_POINTER_ICON_ENABLED) == 1); return pref; } @Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); Loading Loading @@ -213,6 +236,11 @@ public class StylusDevicesController extends AbstractPreferenceController implem Secure.STYLUS_BUTTONS_ENABLED, ((TwoStatePreference) preference).isChecked() ? 0 : 1); break; case KEY_SHOW_STYLUS_POINTER_ICON: Settings.Secure.putInt(mContext.getContentResolver(), Secure.STYLUS_POINTER_ICON_ENABLED, ((SwitchPreferenceCompat) preference).isChecked() ? 1 : 0); break; } return true; } Loading Loading @@ -268,6 +296,13 @@ public class StylusDevicesController extends AbstractPreferenceController implem if (buttonPref == null) { mPreferencesContainer.addPreference(createButtonPressPreference()); } SwitchPreferenceCompat currShowStylusPointerIconPref = mPreferencesContainer .findPreference(KEY_SHOW_STYLUS_POINTER_ICON); Preference showStylusPointerIconPref = createShowStylusPointerIconPreference(currShowStylusPointerIconPref); if (currShowStylusPointerIconPref == null && showStylusPointerIconPref != null) { mPreferencesContainer.addPreference(showStylusPointerIconPref); } } private boolean currentInputMethodSupportsHandwriting() { Loading tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +46 −2 Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ public class StylusDevicesControllerTest { showScreen(controller); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(4); } @Test Loading Loading @@ -249,11 +249,12 @@ public class StylusDevicesControllerTest { @Test public void btStylusInputDevice_showsAllPreferences() { showScreen(mController); Preference defaultNotesPref = mPreferenceContainer.getPreference(0); Preference handwritingPref = mPreferenceContainer.getPreference(1); Preference buttonPref = mPreferenceContainer.getPreference(2); Preference stylusPointerIconPref = mPreferenceContainer.getPreference(3); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); assertThat(defaultNotesPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_default_notes_app)); assertThat(defaultNotesPref.isVisible()).isTrue(); Loading @@ -263,6 +264,9 @@ public class StylusDevicesControllerTest { assertThat(buttonPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_ignore_button)); assertThat(buttonPref.isVisible()).isTrue(); assertThat(stylusPointerIconPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.show_stylus_pointer_icon)); assertThat(stylusPointerIconPref.isVisible()).isTrue(); } @Test Loading Loading @@ -551,6 +555,46 @@ public class StylusDevicesControllerTest { Secure.STYLUS_BUTTONS_ENABLED, -1)).isEqualTo(1); } @Test public void stylusPointerIconPreference_checkedWhenFlagTrue() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 1); showScreen(mController); SwitchPreferenceCompat stylusPointerIconPref = (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); assertThat(stylusPointerIconPref.isChecked()).isEqualTo(true); } @Test public void stylusPointerIconPreference_uncheckedWhenFlagFalse() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 0); showScreen(mController); SwitchPreferenceCompat stylusPointerIconPref = (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); assertThat(stylusPointerIconPref.isChecked()).isEqualTo(false); } @Test public void stylusPointerIconPreference_updatesFlagOnClick() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 0); showScreen(mController); SwitchPreferenceCompat stylusPointerIconPref = (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); stylusPointerIconPref.performClick(); assertThat(stylusPointerIconPref.isChecked()).isEqualTo(true); assertThat(Settings.Secure.getInt(mContext.getContentResolver(), Secure.STYLUS_POINTER_ICON_ENABLED, -1)).isEqualTo(1); } private void showScreen(StylusDevicesController controller) { controller.displayPreference(mScreen); } Loading Loading
res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -12882,4 +12882,7 @@ <!-- Authority of the content provider that support methods restartPhoneProcess and restartRild. Will be overlaid by OEM.--> <string name="reset_telephony_stack_content_provider_authority" translatable="false"></string> <!--Text for Stylus Pointer Icon preference --> <string name="show_stylus_pointer_icon">Show pointer while hovering</string> </resources>
src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +35 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.hardware.input.InputSettings; import android.os.Process; import android.os.UserHandle; import android.os.UserManager; Loading Loading @@ -73,6 +74,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem static final String KEY_IGNORE_BUTTON = "ignore_button"; @VisibleForTesting static final String KEY_DEFAULT_NOTES = "default_notes"; @VisibleForTesting static final String KEY_SHOW_STYLUS_POINTER_ICON = "show_stylus_pointer_icon"; private static final String TAG = "StylusDevicesController"; Loading Loading @@ -181,6 +184,26 @@ public class StylusDevicesController extends AbstractPreferenceController implem return pref; } @Nullable private SwitchPreferenceCompat createShowStylusPointerIconPreference( SwitchPreferenceCompat preference) { if (!mContext.getResources() .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon)) { // If the config is not enabled, no need to show the preference to user return null; } SwitchPreferenceCompat pref = preference == null ? new SwitchPreferenceCompat(mContext) : preference; pref.setKey(KEY_SHOW_STYLUS_POINTER_ICON); pref.setTitle(mContext.getString(R.string.show_stylus_pointer_icon)); pref.setIcon(R.drawable.ic_stylus); pref.setOnPreferenceClickListener(this); pref.setChecked(Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, InputSettings.DEFAULT_STYLUS_POINTER_ICON_ENABLED) == 1); return pref; } @Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); Loading Loading @@ -213,6 +236,11 @@ public class StylusDevicesController extends AbstractPreferenceController implem Secure.STYLUS_BUTTONS_ENABLED, ((TwoStatePreference) preference).isChecked() ? 0 : 1); break; case KEY_SHOW_STYLUS_POINTER_ICON: Settings.Secure.putInt(mContext.getContentResolver(), Secure.STYLUS_POINTER_ICON_ENABLED, ((SwitchPreferenceCompat) preference).isChecked() ? 1 : 0); break; } return true; } Loading Loading @@ -268,6 +296,13 @@ public class StylusDevicesController extends AbstractPreferenceController implem if (buttonPref == null) { mPreferencesContainer.addPreference(createButtonPressPreference()); } SwitchPreferenceCompat currShowStylusPointerIconPref = mPreferencesContainer .findPreference(KEY_SHOW_STYLUS_POINTER_ICON); Preference showStylusPointerIconPref = createShowStylusPointerIconPreference(currShowStylusPointerIconPref); if (currShowStylusPointerIconPref == null && showStylusPointerIconPref != null) { mPreferencesContainer.addPreference(showStylusPointerIconPref); } } private boolean currentInputMethodSupportsHandwriting() { Loading
tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +46 −2 Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ public class StylusDevicesControllerTest { showScreen(controller); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(4); } @Test Loading Loading @@ -249,11 +249,12 @@ public class StylusDevicesControllerTest { @Test public void btStylusInputDevice_showsAllPreferences() { showScreen(mController); Preference defaultNotesPref = mPreferenceContainer.getPreference(0); Preference handwritingPref = mPreferenceContainer.getPreference(1); Preference buttonPref = mPreferenceContainer.getPreference(2); Preference stylusPointerIconPref = mPreferenceContainer.getPreference(3); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); assertThat(defaultNotesPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_default_notes_app)); assertThat(defaultNotesPref.isVisible()).isTrue(); Loading @@ -263,6 +264,9 @@ public class StylusDevicesControllerTest { assertThat(buttonPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_ignore_button)); assertThat(buttonPref.isVisible()).isTrue(); assertThat(stylusPointerIconPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.show_stylus_pointer_icon)); assertThat(stylusPointerIconPref.isVisible()).isTrue(); } @Test Loading Loading @@ -551,6 +555,46 @@ public class StylusDevicesControllerTest { Secure.STYLUS_BUTTONS_ENABLED, -1)).isEqualTo(1); } @Test public void stylusPointerIconPreference_checkedWhenFlagTrue() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 1); showScreen(mController); SwitchPreferenceCompat stylusPointerIconPref = (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); assertThat(stylusPointerIconPref.isChecked()).isEqualTo(true); } @Test public void stylusPointerIconPreference_uncheckedWhenFlagFalse() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 0); showScreen(mController); SwitchPreferenceCompat stylusPointerIconPref = (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); assertThat(stylusPointerIconPref.isChecked()).isEqualTo(false); } @Test public void stylusPointerIconPreference_updatesFlagOnClick() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 0); showScreen(mController); SwitchPreferenceCompat stylusPointerIconPref = (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); stylusPointerIconPref.performClick(); assertThat(stylusPointerIconPref.isChecked()).isEqualTo(true); assertThat(Settings.Secure.getInt(mContext.getContentResolver(), Secure.STYLUS_POINTER_ICON_ENABLED, -1)).isEqualTo(1); } private void showScreen(StylusDevicesController controller) { controller.displayPreference(mScreen); } Loading