From 538881e18323a0c983bd8809f8c3b1cdeeeab8a6 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Wed, 25 May 2011 18:23:38 -0700 Subject: Touch pad UX improvements. Fade the pointer spot when swiping or performing a freeform gesture. Support configuring the gesture mode in the device IDC file. Added workaround for devices that report individual finger movements one at a time instead of all at once. Bug: 4124987 Change-Id: I44628b00382ad59306e4ec5c4717d69cc6fbebb8 --- services/input/PointerController.cpp | 56 ++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'services/input/PointerController.cpp') diff --git a/services/input/PointerController.cpp b/services/input/PointerController.cpp index ffef72057703..eecb76fa4bab 100644 --- a/services/input/PointerController.cpp +++ b/services/input/PointerController.cpp @@ -69,10 +69,10 @@ PointerController::PointerController(const sp& mLocked.inactivityTimeout = INACTIVITY_TIMEOUT_NORMAL; - mLocked.pointerIsFading = true; // keep the pointer initially faded + mLocked.pointerFadeDirection = 0; mLocked.pointerX = 0; mLocked.pointerY = 0; - mLocked.pointerAlpha = 0.0f; + mLocked.pointerAlpha = 0.0f; // pointer is initially faded mLocked.pointerSprite = mSpriteController->createSprite(); mLocked.pointerIconChanged = false; @@ -191,23 +191,37 @@ void PointerController::getPosition(float* outX, float* outY) const { *outY = mLocked.pointerY; } -void PointerController::fade() { +void PointerController::fade(Transition transition) { AutoMutex _l(mLock); - sendImmediateInactivityTimeoutLocked(); + // Remove the inactivity timeout, since we are fading now. + removeInactivityTimeoutLocked(); + + // Start fading. + if (transition == TRANSITION_IMMEDIATE) { + mLocked.pointerFadeDirection = 0; + mLocked.pointerAlpha = 0.0f; + updatePointerLocked(); + } else { + mLocked.pointerFadeDirection = -1; + startAnimationLocked(); + } } -void PointerController::unfade() { +void PointerController::unfade(Transition transition) { AutoMutex _l(mLock); // Always reset the inactivity timer. resetInactivityTimeoutLocked(); - // Unfade immediately if needed. - if (mLocked.pointerIsFading) { - mLocked.pointerIsFading = false; + // Start unfading. + if (transition == TRANSITION_IMMEDIATE) { + mLocked.pointerFadeDirection = 0; mLocked.pointerAlpha = 1.0f; updatePointerLocked(); + } else { + mLocked.pointerFadeDirection = 1; + startAnimationLocked(); } } @@ -401,10 +415,20 @@ void PointerController::doAnimate() { nsecs_t frameDelay = systemTime(SYSTEM_TIME_MONOTONIC) - mLocked.animationTime; // Animate pointer fade. - if (mLocked.pointerIsFading) { + if (mLocked.pointerFadeDirection < 0) { mLocked.pointerAlpha -= float(frameDelay) / POINTER_FADE_DURATION; - if (mLocked.pointerAlpha <= 0) { - mLocked.pointerAlpha = 0; + if (mLocked.pointerAlpha <= 0.0f) { + mLocked.pointerAlpha = 0.0f; + mLocked.pointerFadeDirection = 0; + } else { + keepAnimating = true; + } + updatePointerLocked(); + } else if (mLocked.pointerFadeDirection > 0) { + mLocked.pointerAlpha += float(frameDelay) / POINTER_FADE_DURATION; + if (mLocked.pointerAlpha >= 1.0f) { + mLocked.pointerAlpha = 1.0f; + mLocked.pointerFadeDirection = 0; } else { keepAnimating = true; } @@ -432,12 +456,7 @@ void PointerController::doAnimate() { } void PointerController::doInactivityTimeout() { - AutoMutex _l(mLock); - - if (!mLocked.pointerIsFading) { - mLocked.pointerIsFading = true; - startAnimationLocked(); - } + fade(TRANSITION_GRADUAL); } void PointerController::startAnimationLocked() { @@ -456,9 +475,8 @@ void PointerController::resetInactivityTimeoutLocked() { mLooper->sendMessageDelayed(timeout, mHandler, MSG_INACTIVITY_TIMEOUT); } -void PointerController::sendImmediateInactivityTimeoutLocked() { +void PointerController::removeInactivityTimeoutLocked() { mLooper->removeMessages(mHandler, MSG_INACTIVITY_TIMEOUT); - mLooper->sendMessage(mHandler, MSG_INACTIVITY_TIMEOUT); } void PointerController::updatePointerLocked() { -- cgit v1.2.3-59-g8ed1b