Loading src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +7 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.provider.Settings.Secure; import android.text.TextUtils; import android.util.Log; import android.view.InputDevice; import android.view.KeyEvent; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; Loading Loading @@ -107,6 +108,12 @@ public class StylusDevicesController extends AbstractPreferenceController implem return null; } boolean doesStylusSupportTailButton = mInputDevice.hasKeys( KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL)[0]; if (!doesStylusSupportTailButton) { return null; } Preference pref = preference == null ? new Preference(mContext) : preference; pref.setKey(KEY_DEFAULT_NOTES); pref.setTitle(mContext.getString(R.string.stylus_default_notes_app)); Loading tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.connecteddevice.stylus; import static android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; Loading Loading @@ -139,6 +141,8 @@ public class StylusDevicesControllerTest { .setSources(InputDevice.SOURCE_STYLUS) .build()); when(mInputDevice.getBluetoothAddress()).thenReturn("SOME:ADDRESS"); when(mInputDevice.hasKeys(KEYCODE_STYLUS_BUTTON_TAIL)).thenReturn( new boolean[]{true}); mController = new StylusDevicesController(mContext, mInputDevice, null, mLifecycle); } Loading Loading @@ -220,6 +224,28 @@ public class StylusDevicesControllerTest { assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); } @Test public void usiStylusInputDevice_doesntSupportTailButton_tailButtonPreferenceNotShown() { when(mInputDevice.hasKeys(KEYCODE_STYLUS_BUTTON_TAIL)).thenReturn(new boolean[]{false}); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); StylusDevicesController controller = new StylusDevicesController( mContext, mInputDevice, mCachedBluetoothDevice, mLifecycle ); showScreen(controller); Preference handwritingPref = mPreferenceContainer.getPreference(0); Preference buttonPref = mPreferenceContainer.getPreference(1); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(2); assertThat(handwritingPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_textfield_handwriting)); assertThat(handwritingPref.isVisible()).isTrue(); assertThat(buttonPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_ignore_button)); assertThat(buttonPref.isVisible()).isTrue(); } @Test public void btStylusInputDevice_showsAllPreferences() { showScreen(mController); Loading Loading
src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +7 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.provider.Settings.Secure; import android.text.TextUtils; import android.util.Log; import android.view.InputDevice; import android.view.KeyEvent; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; Loading Loading @@ -107,6 +108,12 @@ public class StylusDevicesController extends AbstractPreferenceController implem return null; } boolean doesStylusSupportTailButton = mInputDevice.hasKeys( KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL)[0]; if (!doesStylusSupportTailButton) { return null; } Preference pref = preference == null ? new Preference(mContext) : preference; pref.setKey(KEY_DEFAULT_NOTES); pref.setTitle(mContext.getString(R.string.stylus_default_notes_app)); Loading
tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.connecteddevice.stylus; import static android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; Loading Loading @@ -139,6 +141,8 @@ public class StylusDevicesControllerTest { .setSources(InputDevice.SOURCE_STYLUS) .build()); when(mInputDevice.getBluetoothAddress()).thenReturn("SOME:ADDRESS"); when(mInputDevice.hasKeys(KEYCODE_STYLUS_BUTTON_TAIL)).thenReturn( new boolean[]{true}); mController = new StylusDevicesController(mContext, mInputDevice, null, mLifecycle); } Loading Loading @@ -220,6 +224,28 @@ public class StylusDevicesControllerTest { assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); } @Test public void usiStylusInputDevice_doesntSupportTailButton_tailButtonPreferenceNotShown() { when(mInputDevice.hasKeys(KEYCODE_STYLUS_BUTTON_TAIL)).thenReturn(new boolean[]{false}); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); StylusDevicesController controller = new StylusDevicesController( mContext, mInputDevice, mCachedBluetoothDevice, mLifecycle ); showScreen(controller); Preference handwritingPref = mPreferenceContainer.getPreference(0); Preference buttonPref = mPreferenceContainer.getPreference(1); assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(2); assertThat(handwritingPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_textfield_handwriting)); assertThat(handwritingPref.isVisible()).isTrue(); assertThat(buttonPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_ignore_button)); assertThat(buttonPref.isVisible()).isTrue(); } @Test public void btStylusInputDevice_showsAllPreferences() { showScreen(mController); Loading