Bug with headset (double and triple click) on Android Oreo solved
This commit is contained in:
parent
ddf00ab488
commit
872b23628d
3 changed files with 23 additions and 5 deletions
|
|
@ -41,6 +41,8 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
|
||||
private static final int DOUBLE_CLICK = 400;
|
||||
|
||||
private static final int MULTIPLE_CLICK = 150;
|
||||
|
||||
private static WakeLock mWakeLock = null;
|
||||
private static int mClickCounter = 0;
|
||||
private static long mLastClickTime = 0;
|
||||
|
|
@ -89,6 +91,16 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
}
|
||||
}
|
||||
|
||||
static int clicks;
|
||||
static long multipleClickStart;
|
||||
|
||||
static Runnable resetMultipleClick = () -> {
|
||||
multipleClickStart = 0;
|
||||
clicks = 0;
|
||||
};
|
||||
|
||||
static Handler timeMultipleClick;
|
||||
|
||||
public static boolean handleIntent(final Context context, final Intent intent) {
|
||||
final String intentAction = intent.getAction();
|
||||
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
|
||||
|
|
@ -108,6 +120,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
break;
|
||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||
//On Android Oreo it always call this
|
||||
command = MusicService.ACTION_TOGGLE_PAUSE;
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||
|
|
@ -133,13 +146,18 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
|
||||
// The service may or may not be running, but we need to send it
|
||||
// a command.
|
||||
if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
|
||||
int keycodeToCompare = KeyEvent.KEYCODE_HEADSETHOOK;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
keycodeToCompare = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
|
||||
}
|
||||
if (keycode == keycodeToCompare) {
|
||||
if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
|
||||
mClickCounter = 0;
|
||||
}
|
||||
|
||||
mClickCounter++;
|
||||
if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter);
|
||||
if (DEBUG)
|
||||
Log.v(TAG, "Got headset click, count = " + mClickCounter);
|
||||
mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);
|
||||
|
||||
Message msg = mHandler.obtainMessage(
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ buildscript {
|
|||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
classpath 'com.android.tools.build:gradle:3.1.0-alpha05'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,6 +1,6 @@
|
|||
#Sun Dec 10 13:25:20 CET 2017
|
||||
#Fri Dec 22 10:41:21 CET 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-4.4-20171031235950+0000-all.zip
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue