@Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   switch (keyCode) {
     case KeyEvent.KEYCODE_VOLUME_UP:
       mEventClientManager.sendButton(
           "R1", ButtonCodes.REMOTE_VOLUME_PLUS, false, true, true, (short) 0, (byte) 0);
       return true;
     case KeyEvent.KEYCODE_VOLUME_DOWN:
       mEventClientManager.sendButton(
           "R1", ButtonCodes.REMOTE_VOLUME_MINUS, false, true, true, (short) 0, (byte) 0);
       return true;
   }
   return super.onKeyDown(keyCode, event);
 }
  private void mute() {

    try {
      event.sendButton("R1", ButtonCodes.REMOTE_MUTE, false, true, true, (short) 0, (byte) 0);
    } catch (IOException e) {
      e.printStackTrace();
    }
    control.getVolume(
        new DataResponse<Integer>() {
          @Override
          public void run() {
            removeBusyMessage();
            if (initialVolume != value) {
              // it worked, we muted xbmc through the eventserver
              msg.setText(R.string.setup_wizard_final_message);
              try {
                event.sendButton(
                    "R1", ButtonCodes.REMOTE_MUTE, false, true, true, (short) 0, (byte) 0);
              } catch (IOException e) {
                e.printStackTrace();
              }
              setCanFinish(true);
            } else {
              // we couldn't mute xbmc through the eventserver, so display some help.
              retry.setVisibility(View.VISIBLE);
              msg.setText(R.string.setup_wizard_muting_failed);
            }
          }
        },
        getContext());
  }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   IEventClientManager client = ManagerFactory.getEventClientManager(mMovieDetailsController);
   switch (keyCode) {
     case KeyEvent.KEYCODE_VOLUME_UP:
       client.sendButton(
           "R1", ButtonCodes.REMOTE_VOLUME_PLUS, false, true, true, (short) 0, (byte) 0);
       return true;
     case KeyEvent.KEYCODE_VOLUME_DOWN:
       client.sendButton(
           "R1", ButtonCodes.REMOTE_VOLUME_MINUS, false, true, true, (short) 0, (byte) 0);
       return true;
   }
   client.setController(null);
   boolean handled = (mKeyTracker != null) ? mKeyTracker.doKeyDown(keyCode, event) : false;
   return handled || super.onKeyDown(keyCode, event);
 }
 public void onActivityResume(Activity activity) {
   super.onActivityResume(activity);
   ConnectionFactory.getNowPlayingPoller(activity.getApplicationContext())
       .subscribe(mNowPlayingHandler);
   if (mEventClient != null) {
     mEventClient.setController(this);
   }
   if (mMusicManager != null) {
     mMusicManager.setController(this);
   }
   if (mControlManager != null) {
     mControlManager.setController(this);
   }
 }
 public void onActivityPause() {
   ConnectionFactory.getNowPlayingPoller(mActivity.getApplicationContext())
       .unSubscribe(mNowPlayingHandler);
   if (mMusicManager != null) {
     mMusicManager.setController(null);
     mMusicManager.postActivity();
   }
   if (mControlManager != null) {
     mControlManager.setController(null);
   }
   if (mEventClient != null) {
     mEventClient.setController(null);
   }
   super.onActivityPause();
 }