We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 530d84f9 authored by Mike Sheldon's avatar Mike Sheldon

Support bluetooth media controls in Libre Droid

parent 6d9ad9e9
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fm.libre.droid"
android:versionCode="1"
android:versionName="1.0">
android:versionCode="2"
android:versionName="1.1">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".LibreDroid"
android:label="@string/app_name"
......
......@@ -47,6 +47,10 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreProtocolPNames;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
......@@ -57,6 +61,7 @@ import android.media.MediaPlayer.OnCompletionListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
......@@ -84,6 +89,7 @@ public class LibreDroid extends Activity implements OnBufferingUpdateListener, O
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.registerReceiver(new MediaButtonReceiver(), new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
setContentView(R.layout.main);
this.mp = new MediaPlayer();
......@@ -434,4 +440,32 @@ public class LibreDroid extends Activity implements OnBufferingUpdateListener, O
}
}
private class MediaButtonReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
KeyEvent ev = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
if (ev.getAction() == KeyEvent.ACTION_UP) {
// Only perform the action on keydown/multiple
return;
}
switch(ev.getKeyCode()) {
case KeyEvent.KEYCODE_MEDIA_NEXT:
LibreDroid.this.next();
this.abortBroadcast();
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
LibreDroid.this.prev();
this.abortBroadcast();
break;
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
LibreDroid.this.togglePause();
this.abortBroadcast();
break;
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment