OSDN Git Service

Use event time to detect long press in MediaButtonIntentReceiver.
authorMike Lockwood <lockwood@android.com>
Wed, 3 Jun 2009 00:26:44 +0000 (17:26 -0700)
committerMike Lockwood <lockwood@android.com>
Wed, 3 Jun 2009 00:26:44 +0000 (17:26 -0700)
This should help avoid false positives in the Party Shuffle feature
when the system is very slow.

Signed-off-by: Mike Lockwood <lockwood@android.com>
src/com/android/music/MediaButtonIntentReceiver.java

index 96c29cd..5840721 100644 (file)
@@ -102,20 +102,16 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
 
             if (command != null) {
                 if (action == KeyEvent.ACTION_DOWN) {
-                    if (!mDown) {
-                        // only if this isn't a repeat event
-                        
-                        if (MediaPlaybackService.CMDTOGGLEPAUSE.equals(command)) {
-                            // We're not using the original time of the event as the
-                            // base here, because in some cases it can take more than
-                            // one second for us to receive the event, in which case
-                            // we would go immediately to auto shuffle mode, even if
-                            // the user didn't long press.
-                            mHandler.sendMessageDelayed(
-                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context),
-                                    LONG_PRESS_DELAY);
+                    if (mDown) {
+                        if (MediaPlaybackService.CMDTOGGLEPAUSE.equals(command)
+                                && mLastClickTime != 0 
+                                && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
+                            mHandler.sendMessage(
+                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context));
                         }
-                        
+                    } else {
+                        // if this isn't a repeat event
+
                         // The service may or may not be running, but we need to send it
                         // a command.
                         Intent i = new Intent(context, MediaPlaybackService.class);