[XPOSED] HTC Motion Media Gestures

Sivat

Member
Jun 11, 2016
48
26
0
Hey everyone. I got sick of not having double tap to wake enabled when using the asop lockscreen and created this xposed module to fix that and change all of the other functions to control media.

After you install double check the motion launch settings are on by going into settings -> Display, gestures & buttons -> Motion Launch gestures.

Swiping up will pull google play music up (I use this in conjunction with quick access which lets it draw over the lock screen)
Swiping Down is play/pause music
Swiping Right is next
Swiping left is previous
Double tap is wake device

I was originally going to try and do more with this, but I'm gonna shift focus to modifying the kernel to see if it's possible to add even more custom gestures. However if you run into any issues let me know and I'll try to figure out what's going on.

Here's the source code, do what you want:
Code:
        import android.content.Context;
        import android.content.Intent;
        import android.os.PowerManager;
        import android.view.KeyEvent;
        import java.lang.Object;
        import de.robv.android.xposed.IXposedHookLoadPackage;
        import de.robv.android.xposed.XC_MethodHook;
        import de.robv.android.xposed.XposedBridge;
        import de.robv.android.xposed.XposedHelpers;
        import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
        import de.robv.android.xposed.XC_MethodReplacement;

public class XposedMod implements IXposedHookLoadPackage {
    Context context;
    XC_MethodHook.MethodHookParam temp;
    @Override
    public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("com.htc.sense.easyaccessservice"))
            return;
        Class<?> EasyAction =
                XposedHelpers.findClass("com.htc.sense.easyaccessservice.easy.sense81.EasySensorAction81", lpparam.classLoader);

        XposedHelpers.findAndHookMethod(EasyAction, "triggerMotionAction", int.class, new XC_MethodReplacement() {
            @Override
            protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
                XposedBridge.log("BEFORE EXECUTE!");
                temp = param;
                context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
                int gesture = (Integer) param.args[0];
                XposedBridge.log(String.format("%1$d",gesture));
                performAction(gesture, context);
                param.setResult(null);
                return null;
            }
        });
    }
    private void performAction(int action, Context context) {
        switch(action){
            case GestureType.SWIPE_LEFT:
                sendMediaButton(context, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
                XposedHelpers.callMethod(temp.thisObject, "doOnResetAction");
                XposedBridge.log("LEFT");
                break;
            case GestureType.SWIPE_RIGHT:
                sendMediaButton(context, KeyEvent.KEYCODE_MEDIA_NEXT);
                XposedHelpers.callMethod(temp.thisObject, "doOnResetAction");
                XposedBridge.log("RIGHT");
                break;
            case GestureType.CAMERA_ACTION:
                sendMediaButton(context, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
                    XposedHelpers.callMethod(temp.thisObject, "doOnResetAction");
                break;
            case GestureType.SWIPE_UP:
                Context ctx=context;
                try {
                    Intent i = ctx.getPackageManager().getLaunchIntentForPackage("com.google.android.music");
                    ctx.startActivity(i);
                } catch (Exception e) {
                    XposedBridge.log(e);
                }
                wakeUpDevice();
                break;
            case GestureType.DOUBLE_TAP_ACTION:
                wakeUpDevice();
                break;
            default: break;
        }
    }
    private void wakeUpDevice() {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
        wakeLock.acquire();
        wakeLock.release();
        XposedBridge.log("WTFISGOINGON");
    }

    private void sendMediaButton(Context context, int keyCode) {
        KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
        context.sendOrderedBroadcast(intent, null);
        keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
        intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
        context.sendOrderedBroadcast(intent, null);
    }

    public class GestureType {
        public static final int SWIPE_LEFT = 3;
        public static final int SWIPE_RIGHT = 2;
        public static final int SWIPE_UP = 1;
        public static final int CAMERA_ACTION = 6;
        public static final int DOUBLE_TAP_ACTION = 5;
    }
}
 

Attachments

Last edited:

merlin21

Senior Member
Jul 19, 2010
1,176
701
0
Cool, thanks for sharing. Is there any module out there that let us put our own commands to shortcuts - as example, open torch or xda app when swiping on screen up while phone is off?

That would be insane!
 

jhadsfi

Senior Member
Jul 30, 2016
549
150
0
Hi. Thanks for this. Could you please also make vibration feedback and flip to mute for calls to work with Google dialler?
 

Sivat

Member
Jun 11, 2016
48
26
0
This mod working with Play Music app only?
It will only launch the play music app by swiping up, but it should control any media player.


EDIT:

To anyone asking for features, i'm not gonna be adding them. I upgraded to Nougat and I'm probably not gonna be using xposed anymore considering the big reason why I did was for android n-ify and a few other things that are now just built into the system.
 
Last edited:
  • Like
Reactions: dawebbreb

efato

Senior Member
Nov 21, 2010
118
30
0
Istanbul
It will only launch the play music app by swiping up, but it should control any media player.


EDIT:

To anyone asking for features, i'm not gonna be adding them. I upgraded to Nougat and I'm probably not gonna be using xposed anymore considering the big reason why I did was for android n-ify and a few other things that are now just built into the system.
I know you are done with xposed territory but I have a question. Is there a way to make this work with magisk? I'm on nougat and there is no xposed yet for nougat.. Not a request, just a question. Thank you.