Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working PAUSEPLAY/FORWARD/REVERSE hardware keys integration #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
android:resource="@xml/app_widget_remote"
/>
</receiver>
<receiver android:name=".business.receiver.RemoteControlReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>

<provider android:name=".business.provider.HostProvider" android:authorities="org.xbmc.android.provider.remote" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2005-2011 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC Remote; see the file license. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/

package org.xbmc.android.remote.business.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;

import org.xbmc.android.remote.business.Command;
import org.xbmc.android.remote.business.ManagerFactory;
import org.xbmc.android.remote.presentation.controller.RemoteController;
import org.xbmc.api.business.IEventClientManager;
import org.xbmc.api.business.INotifiableManager;
import org.xbmc.api.presentation.INotifiableController;
import org.xbmc.eventclient.ButtonCodes;

/**
* @author John Pulford
*/
public class RemoteControlReceiver extends BroadcastReceiver implements INotifiableController {

@Override
public void onReceive(Context context, Intent intent) {
IEventClientManager mEventClientManager = ManagerFactory.getEventClientManager(this);

if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
String keyPressAction = "";
KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE == event.getKeyCode()) {
// Handle key press.
keyPressAction = ButtonCodes.REMOTE_PLAY;
}
if (KeyEvent.KEYCODE_MEDIA_PREVIOUS == event.getKeyCode()) {
// Handle key press.
keyPressAction = ButtonCodes.REMOTE_REVERSE;
}
if (KeyEvent.KEYCODE_MEDIA_NEXT == event.getKeyCode()) {
// Handle key press.
keyPressAction = ButtonCodes.REMOTE_FORWARD;
}
if (keyPressAction.length() > 0) {
mEventClientManager.sendButton("R1", keyPressAction, false, true, true, (short)0, (byte)0);
}
}
}


// Not convinced these methods need to do anything in this instance
// but someone with a longer history with the project may have a better idea.
@Override
public void onWrongConnectionState(int state, INotifiableManager manager, Command<?> source) {

}

@Override
public void onError(Exception e) {

}

@Override
public void onMessage(String message) {

}

@Override
public void runOnUI(Runnable action) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.xbmc.android.remote.business.CacheManager;
import org.xbmc.android.remote.business.ManagerFactory;
import org.xbmc.android.remote.business.receiver.AndroidBroadcastReceiver;
import org.xbmc.android.remote.business.receiver.RemoteControlReceiver;
import org.xbmc.android.remote.presentation.controller.HomeController;
import org.xbmc.android.remote.presentation.controller.HomeController.ProgressThread;
import org.xbmc.android.remote.presentation.notification.NowPlayingNotificationManager;
Expand All @@ -38,10 +39,13 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.IntentFilter;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -85,7 +89,8 @@ public class HomeActivity extends Activity {

private ProgressThread mProgressThread;
private ProgressDialog mProgressDialog;


private AudioManager mAudioManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -121,8 +126,15 @@ public void onClick(View v) {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);

//Register Receivers
registerReceiver(new AndroidBroadcastReceiver(), filter);

//Register for hardware media keys, if possible.
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (Build.VERSION.SDK_INT >= 8) {
// Start listening for button presses
mAudioManager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), RemoteControlReceiver.class.getName()));
}
}


Expand Down Expand Up @@ -262,7 +274,14 @@ protected void onPause() {
mConfigurationManager.onActivityPause();
mEventClientManager.setController(null);
}


@Override
protected void onDestroy() {
if (Build.VERSION.SDK_INT >= 8) {
// Stop listening for button presses
mAudioManager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), RemoteControlReceiver.class.getName()));
}
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Expand Down