Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 862a29b2 authored by Danesh Mondegarian's avatar Danesh Mondegarian
Browse files

GestureInput : Allow doubletap/longpress configuration

Allows devices to specify pending intents for double tap and
long press events.

Change-Id: I7e7cc2f9f96a01d8f6232e5cf0e19832fdfd5359
parent 4dd3f322
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
package android.service.gesture;

import android.app.PendingIntent;

/** @hide */
interface IGestureService {

    /**
     * Register a listener for gesture sensor input. Gesture sensor input
     * is then converted into input events for system consumption.
     */
    void setOnLongPressPendingIntent(in PendingIntent pendingIntent);
    void setOnDoubleClickPendingIntent(in PendingIntent pendingIntent);

}
+29 −15
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@
 */
package com.android.server.gesture;

import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
import android.hardware.input.InputManager;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Slog;
import android.view.Display;
import android.view.GestureDetector;
@@ -30,13 +30,10 @@ import android.view.IInputFilter;
import android.view.IInputFilterHost;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.ViewConfiguration;
import android.view.WindowManager;

import java.io.PrintWriter;

/**
@@ -57,6 +54,8 @@ public class GestureInputFilter implements IInputFilter, GestureDetector.OnGestu
    private float mGesturePadWidth, mGesturePadHeight;
    private int mTouchSlop, mOrientation;
    private Context mContext;
    private PendingIntent mLongPressPendingIntent;
    private PendingIntent mDoubleClickPendingIntent;

    public GestureInputFilter(Context context) {
        mInputManager = InputManager.getInstance();
@@ -285,9 +284,13 @@ public class GestureInputFilter implements IInputFilter, GestureDetector.OnGestu

    @Override
    public void onLongPress(MotionEvent e) {
        Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
        mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
                null, null, null, 0, null, null);
        if (mLongPressPendingIntent != null) {
            try {
                mLongPressPendingIntent.send();
            } catch (CanceledException e1) {
                e1.printStackTrace();
            }
        }
    }

    @Override
@@ -303,17 +306,28 @@ public class GestureInputFilter implements IInputFilter, GestureDetector.OnGestu

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        long now = SystemClock.uptimeMillis();
        sendInputEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN,
                KeyEvent.KEYCODE_CAMERA, 0, 0,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
        sendInputEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP,KeyEvent.KEYCODE_CAMERA,
                0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
        if (mDoubleClickPendingIntent != null) {
            try {
                mDoubleClickPendingIntent.send();
                return true;
            } catch (CanceledException e1) {
                e1.printStackTrace();
            }
        }

        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        return false;
    }

    public void setOnLongPressPendingIntent(PendingIntent pendingIntent) {
        mLongPressPendingIntent = pendingIntent;
    }

    public void setOnDoubleClickPendingIntent(PendingIntent pendingIntent) {
        mDoubleClickPendingIntent = pendingIntent;
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.server.gesture;

import android.Manifest;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
@@ -51,4 +52,12 @@ public class GestureService extends IGestureService.Stub {
        mInputFilter = new GestureInputFilter(mContext);
        mInputManager.registerSecondaryInputFilter(mInputFilter);
    }

    public void setOnLongPressPendingIntent(PendingIntent pendingIntent) {
        mInputFilter.setOnLongPressPendingIntent(pendingIntent);
    }

    public void setOnDoubleClickPendingIntent(PendingIntent pendingIntent) {
        mInputFilter.setOnDoubleClickPendingIntent(pendingIntent);
    }
}