frameworks/base
Revision | cbefcdf6db80341d78a01b6d4770beba47fd18ff (tree) |
---|---|
Zeit | 2016-10-09 21:46:31 |
Autor | Steve Kondik <shade@chem...> |
Commiter | Steve Kondik |
input: Add option to toggle pointer icon when using stylus
* The visible pointer icon when hovering or drawing with the stylus is
Change-Id: I26ba2ca8b92511799033759ca85c36f4ba2b7833
@@ -212,6 +212,7 @@ public class InputManagerService extends IInputManager.Stub | ||
212 | 212 | InputChannel fromChannel, InputChannel toChannel); |
213 | 213 | private static native void nativeSetPointerSpeed(long ptr, int speed); |
214 | 214 | private static native void nativeSetShowTouches(long ptr, boolean enabled); |
215 | + private static native void nativeSetStylusIconEnabled(long ptr, boolean enabled); | |
215 | 216 | private static native void nativeSetVolumeKeysRotation(long ptr, int mode); |
216 | 217 | private static native void nativeSetInteractive(long ptr, boolean interactive); |
217 | 218 | private static native void nativeReloadCalibration(long ptr); |
@@ -325,6 +326,7 @@ public class InputManagerService extends IInputManager.Stub | ||
325 | 326 | registerPointerSpeedSettingObserver(); |
326 | 327 | registerShowTouchesSettingObserver(); |
327 | 328 | registerAccessibilityLargePointerSettingObserver(); |
329 | + registerStylusIconEnabledSettingObserver(); | |
328 | 330 | registerVolumeKeysRotationSettingObserver(); |
329 | 331 | |
330 | 332 | mContext.registerReceiver(new BroadcastReceiver() { |
@@ -333,6 +335,7 @@ public class InputManagerService extends IInputManager.Stub | ||
333 | 335 | updatePointerSpeedFromSettings(); |
334 | 336 | updateShowTouchesFromSettings(); |
335 | 337 | updateAccessibilityLargePointerFromSettings(); |
338 | + updateStylusIconEnabledFromSettings(); | |
336 | 339 | updateVolumeKeysRotationFromSettings(); |
337 | 340 | } |
338 | 341 | }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); |
@@ -340,6 +343,7 @@ public class InputManagerService extends IInputManager.Stub | ||
340 | 343 | updatePointerSpeedFromSettings(); |
341 | 344 | updateShowTouchesFromSettings(); |
342 | 345 | updateAccessibilityLargePointerFromSettings(); |
346 | + updateStylusIconEnabledFromSettings(); | |
343 | 347 | updateVolumeKeysRotationFromSettings(); |
344 | 348 | } |
345 | 349 |
@@ -1667,6 +1671,32 @@ public class InputManagerService extends IInputManager.Stub | ||
1667 | 1671 | return result; |
1668 | 1672 | } |
1669 | 1673 | |
1674 | + public void updateStylusIconEnabledFromSettings() { | |
1675 | + int enabled = getStylusIconEnabled(0); | |
1676 | + nativeSetStylusIconEnabled(mPtr, enabled != 0); | |
1677 | + } | |
1678 | + | |
1679 | + public void registerStylusIconEnabledSettingObserver() { | |
1680 | + mContext.getContentResolver().registerContentObserver( | |
1681 | + CMSettings.System.getUriFor(CMSettings.System.STYLUS_ICON_ENABLED), false, | |
1682 | + new ContentObserver(mHandler) { | |
1683 | + @Override | |
1684 | + public void onChange(boolean selfChange) { | |
1685 | + updateStylusIconEnabledFromSettings(); | |
1686 | + } | |
1687 | + }); | |
1688 | + } | |
1689 | + | |
1690 | + private int getStylusIconEnabled(int defaultValue) { | |
1691 | + int result = defaultValue; | |
1692 | + try { | |
1693 | + result = CMSettings.System.getInt(mContext.getContentResolver(), | |
1694 | + CMSettings.System.STYLUS_ICON_ENABLED); | |
1695 | + } catch (CMSettings.CMSettingNotFoundException snfe) { | |
1696 | + } | |
1697 | + return result; | |
1698 | + } | |
1699 | + | |
1670 | 1700 | public void updateVolumeKeysRotationFromSettings() { |
1671 | 1701 | int mode = getVolumeKeysRotationSetting(0); |
1672 | 1702 | nativeSetVolumeKeysRotation(mPtr, mode); |
@@ -202,6 +202,7 @@ public: | ||
202 | 202 | void setSystemUiVisibility(int32_t visibility); |
203 | 203 | void setPointerSpeed(int32_t speed); |
204 | 204 | void setShowTouches(bool enabled); |
205 | + void setStylusIconEnabled(bool enabled); | |
205 | 206 | void setVolumeKeysRotation(int mode); |
206 | 207 | void setInteractive(bool interactive); |
207 | 208 | void reloadCalibration(); |
@@ -277,6 +278,9 @@ private: | ||
277 | 278 | // Show touches feature enable/disable. |
278 | 279 | bool showTouches; |
279 | 280 | |
281 | + // Show icon when stylus is used | |
282 | + bool stylusIconEnabled; | |
283 | + | |
280 | 284 | // Volume keys rotation mode (0 - off, 1 - phone, 2 - tablet) |
281 | 285 | int32_t volumeKeysRotationMode; |
282 | 286 |
@@ -316,6 +320,7 @@ NativeInputManager::NativeInputManager(jobject contextObj, | ||
316 | 320 | mLocked.pointerSpeed = 0; |
317 | 321 | mLocked.pointerGesturesEnabled = true; |
318 | 322 | mLocked.showTouches = false; |
323 | + mLocked.stylusIconEnabled = false; | |
319 | 324 | mLocked.volumeKeysRotationMode = 0; |
320 | 325 | } |
321 | 326 | mInteractive = true; |
@@ -464,6 +469,7 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon | ||
464 | 469 | outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled; |
465 | 470 | |
466 | 471 | outConfig->showTouches = mLocked.showTouches; |
472 | + outConfig->stylusIconEnabled = mLocked.stylusIconEnabled; | |
467 | 473 | outConfig->volumeKeysRotationMode = mLocked.volumeKeysRotationMode; |
468 | 474 | |
469 | 475 | outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport); |
@@ -773,6 +779,22 @@ void NativeInputManager::setShowTouches(bool enabled) { | ||
773 | 779 | InputReaderConfiguration::CHANGE_SHOW_TOUCHES); |
774 | 780 | } |
775 | 781 | |
782 | +void NativeInputManager::setStylusIconEnabled(bool enabled) { | |
783 | + { // acquire lock | |
784 | + AutoMutex _l(mLock); | |
785 | + | |
786 | + if (mLocked.stylusIconEnabled == enabled) { | |
787 | + return; | |
788 | + } | |
789 | + | |
790 | + ALOGI("Setting stylus icon enabled to %s.", enabled ? "enabled" : "disabled"); | |
791 | + mLocked.stylusIconEnabled = enabled; | |
792 | + } // release lock | |
793 | + | |
794 | + mInputManager->getReader()->requestRefreshConfiguration( | |
795 | + InputReaderConfiguration::CHANGE_STYLUS_ICON_ENABLED); | |
796 | +} | |
797 | + | |
776 | 798 | void NativeInputManager::setVolumeKeysRotation(int mode) { |
777 | 799 | { // acquire lock |
778 | 800 | AutoMutex _l(mLock); |
@@ -1394,6 +1416,13 @@ static void nativeSetShowTouches(JNIEnv* /* env */, | ||
1394 | 1416 | im->setShowTouches(enabled); |
1395 | 1417 | } |
1396 | 1418 | |
1419 | +static void nativeSetStylusIconEnabled(JNIEnv* env, | |
1420 | + jclass clazz, jlong ptr, jboolean enabled) { | |
1421 | + NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); | |
1422 | + | |
1423 | + im->setStylusIconEnabled(enabled); | |
1424 | +} | |
1425 | + | |
1397 | 1426 | static void nativeSetVolumeKeysRotation(JNIEnv* env, |
1398 | 1427 | jclass clazz, jlong ptr, int mode) { |
1399 | 1428 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
@@ -1544,6 +1573,8 @@ static const JNINativeMethod gInputManagerMethods[] = { | ||
1544 | 1573 | (void*) nativeSetPointerSpeed }, |
1545 | 1574 | { "nativeSetShowTouches", "(JZ)V", |
1546 | 1575 | (void*) nativeSetShowTouches }, |
1576 | + { "nativeSetStylusIconEnabled", "(JZ)V", | |
1577 | + (void*) nativeSetStylusIconEnabled }, | |
1547 | 1578 | { "nativeSetVolumeKeysRotation", "(JI)V", |
1548 | 1579 | (void*) nativeSetVolumeKeysRotation }, |
1549 | 1580 | { "nativeSetInteractive", "(JZ)V", |