1

I want to create system overlay view, which detect gestures without blocking other apps. How can i do it (apps like OmniSwipe, Easy Swipe detect gestures without blocking anything)? Below code, which blocking other apps cause of system overlay view.

package com.carxsing.anglelockscreen.GestureDetector;

public class GestureService extends Service implements 
  GestureOverlayView.OnGesturePerformedListener{

  private WindowManager windowManager;
  private GestureOverlayView GestureOverlay, GestureOverlay2;
  private GestureLibrary mGestureLib;

public GestureService() {
}

@Override public IBinder onBind(Intent intent) {
    return null;
}

@Override public void onCreate() {
    super.onCreate();
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    GestureOverlay = new GestureOverlayView(this);
    GestureOverlay2 = new GestureOverlayView(this);
    GestureOverlay.setGestureColor(00000000);
    GestureOverlay.setUncertainGestureColor(00000000);
    GestureOverlay2.setGestureColor(00000000);
    GestureOverlay2.setUncertainGestureColor(00000000);
    GestureOverlay.addOnGesturePerformedListener(this);
    GestureOverlay2.addOnGesturePerformedListener(this);
    mGestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!mGestureLib.load()) {
        mGestureLib.save();
    }
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT);
    params.height = 450;
    params.width = 75;
    params.gravity = Gravity.BOTTOM | Gravity.LEFT;
    windowManager.addView(GestureOverlay, params);
    params.height = 450;
    params.width = 75;
    params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    windowManager.addView(GestureOverlay2, params);

}

@Override
public void onDestroy() {
    super.onDestroy();
    if (GestureOverlay != null) windowManager.removeView(GestureOverlay);
    if (GestureOverlay2 != null) windowManager.removeView(GestureOverlay2);
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    ArrayList<Prediction> predictions = mGestureLib.recognize(gesture);
    if (predictions.size() > 0) {
        Prediction prediction = predictions.get(0);
        if (prediction.score > 1.0) {
            if (prediction.name.equals(Gestures.bottomleft) || prediction.name.equals(Gestures.bottomright)) {
                Intent i = new Intent(GestureService.this, LockScreenActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.putExtra("start", 1);
                startActivity(i);
            }
        }
    }
}

}

  • "apps like OmniSwipe, Easy Swipe detect gestures without blocking anything" -- if those gestures can be anywhere at any time, that's a security problem, as apps are not supposed to be able to both intercept touch events *and* allow those events to continue along to underlying windows. If those gestures have to be initiated from some "hot spot" on the screen, then they're probably just using a "chat heads"-style solution. – CommonsWare May 07 '17 at 11:30
  • @CommonsWare in these apps gestures detect from a specific place on the screen. What to do? – Anton Kurashkevich May 07 '17 at 12:13
  • I will be surprised if the gesture overlay stuff would work. You probably have to deal with the low-level touch events yourself. – CommonsWare May 07 '17 at 12:16
  • @CommonsWare what is low-levet touch events? – Anton Kurashkevich May 09 '17 at 11:58
  • `onTouchEvent()` – CommonsWare May 09 '17 at 12:02

0 Answers0