sreichholf / dreamDroid

DreamDroid is an open-source enigma2 client for android based devices.
https://dreamdroid.org
GNU General Public License v3.0
106 stars 43 forks source link

HW-Volume Buttons should control the dreambox volume #18

Closed sreichholf closed 13 years ago

sreichholf commented 13 years ago

HW-Volume Buttons should/could be used to control the dreambox volume. This should be optional.

xylo commented 13 years ago

I don't know how to attach patches to issues. Therefore I just paste it here. The patch allows to control the volume via hardware volume buttons in every activity.

Index: src/net/reichholf/dreamdroid/abstivities/AbstractHttpListActivity.java
===================================================================
--- src/net/reichholf/dreamdroid/abstivities/AbstractHttpListActivity.java  (revision 49ab431f4acfddc94d6f184e5990e07684b1ab0e)
+++ src/net/reichholf/dreamdroid/abstivities/AbstractHttpListActivity.java  (revision )
@@ -14,9 +14,11 @@
 import net.reichholf.dreamdroid.activities.MainActivity;
 import net.reichholf.dreamdroid.helpers.ExtendedHashMap;
 import net.reichholf.dreamdroid.helpers.SimpleHttpClient;
+import net.reichholf.dreamdroid.helpers.enigma2.Remote;
 import net.reichholf.dreamdroid.helpers.enigma2.SimpleResult;
 import net.reichholf.dreamdroid.helpers.enigma2.requesthandler.ListRequestHandler;
 import net.reichholf.dreamdroid.helpers.enigma2.requesthandler.SimpleResultRequestHandler;
+import net.reichholf.dreamdroid.helpers.enigma2.requesthandler.impl.RemoteCommandRequestHandler;
 import net.reichholf.dreamdroid.helpers.enigma2.requesthandler.impl.ZapRequestHandler;

 import org.apache.http.NameValuePair;
@@ -276,16 +278,6 @@
    /*
     * (non-Javadoc)
     * 
-    * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
-    */
-   @Override
-   public boolean onKeyDown(int keyCode, KeyEvent event) {
-       return super.onKeyDown(keyCode, event);
-   }
-
-   /*
-    * (non-Javadoc)
-    * 
     * @see android.app.Activity#onRetainNonConfigurationInstance()
     */
    @Override
@@ -506,4 +498,41 @@
        Toast toast = Toast.makeText(this, toastText, Toast.LENGTH_LONG);
        toast.show();
    }
+
+   @Override
+   public boolean onKeyDown(int keyCode, KeyEvent event) {
+       switch (keyCode) {
+           case KeyEvent.KEYCODE_VOLUME_UP:
+               onButtonClicked(Remote.KEY_VOLP, false);
+               return true;
+
+           case KeyEvent.KEYCODE_VOLUME_DOWN:
+               onButtonClicked(Remote.KEY_VOLM, false);
+               return true;
-}
+       }
+
+       return super.onKeyDown(keyCode, event);
+   }
+
+   @Override
+   public boolean onKeyUp(int keyCode, KeyEvent event) {
+       return keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || super.onKeyUp(keyCode, event);
+   }
+
+   /**
+    * Called after a Button has been clicked
+    *
+    * @param id
+    *            The id of the item
+    * @param longClick
+    *            If true the item has been long-clicked
+    */
+   private void onButtonClicked(int id, boolean longClick) {
+       ArrayList params = new ArrayList();
+       params.add(new BasicNameValuePair("command", new Integer(id).toString()));
+       if (longClick) {
+           params.add(new BasicNameValuePair("type", Remote.CLICK_TYPE_LONG));
+       }
+       execSimpleResultTask(new RemoteCommandRequestHandler(), params);
+   }
+}
Index: AndroidManifest.xml
===================================================================
--- AndroidManifest.xml (revision 49ab431f4acfddc94d6f184e5990e07684b1ab0e)
+++ AndroidManifest.xml (revision )
@@ -3,7 +3,7 @@
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.reichholf.dreamdroid" 
    android:installLocation="auto" 
-   android:versionName="0.9.5.1" android:versionCode="76">
+   android:versionName="0.9.5.2" android:versionCode="77">

     params = new ArrayList();
+       params.add(new BasicNameValuePair("command", new Integer(id).toString()));
+       if (longClick) {
+           params.add(new BasicNameValuePair("type", Remote.CLICK_TYPE_LONG));
+       }
+       execSimpleResultTask(new RemoteCommandRequestHandler(), params);
+   }
+}
sreichholf commented 13 years ago

HI, the diff seems to get a little "fucked up" when simply pasting. Could you send it to me via email? -> stephan.reichholf -at- gmail.com

The prettiest way would be to push the changes to your dreamDroid fork (I've seen you forked it) and make a "pull" request. I could then merg your changes into my repo.

sreichholf commented 13 years ago

merged and improved.