Permalink
Browse files

Incorporated a patch from baruchs which allows lockscreen music contr…

…ols to play/pause ANY music app that responds to the intents (pandora, listen, etc)
  • Loading branch information...
1 parent 55710a1 commit 0be3df4b706fe1ff11c5bc49ae917d52e7ec40f0 @kmobs kmobs committed Jul 22, 2010
Showing with 18 additions and 12 deletions.
  1. +18 −12 phone/com/android/internal/policy/impl/LockScreen.java
@@ -272,9 +272,7 @@ public void onClick(View v) {
mPlayIcon.setVisibility(View.GONE);
mRewindIcon.setVisibility(View.VISIBLE);
mForwardIcon.setVisibility(View.VISIBLE);
- Intent intent;
- intent = new Intent("com.android.music.musicservicecommand.togglepause");
- getContext().sendBroadcast(intent);
+ sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
}
}
});
@@ -288,28 +286,22 @@ public void onClick(View v) {
mPauseIcon.setVisibility(View.GONE);
mRewindIcon.setVisibility(View.GONE);
mForwardIcon.setVisibility(View.GONE);
- Intent intent;
- intent = new Intent("com.android.music.musicservicecommand.togglepause");
- getContext().sendBroadcast(intent);
+ sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
}
}
});
mRewindIcon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mCallback.pokeWakelock();
- Intent intent;
- intent = new Intent("com.android.music.musicservicecommand.previous");
- getContext().sendBroadcast(intent);
+ sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
}
});
mForwardIcon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mCallback.pokeWakelock();
- Intent intent;
- intent = new Intent("com.android.music.musicservicecommand.next");
- getContext().sendBroadcast(intent);
+ sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_NEXT);
}
});
@@ -539,6 +531,20 @@ private void refreshMusicStatus() {
}
}
+ private void sendMediaButtonEvent(int code) {
+ long eventtime = SystemClock.uptimeMillis();
+
+ Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
+ KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
+ downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
+ getContext().sendOrderedBroadcast(downIntent, null);
+
+ Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
+ KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, code, 0);
+ upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
+ getContext().sendOrderedBroadcast(upIntent, null);
+ }
+
/** {@inheritDoc} */
public void onTimeChanged() {
refreshTimeAndDateDisplay();

0 comments on commit 0be3df4

Please sign in to comment.