Detect gestures without blocking other apps

好久不见. 提交于 2019-12-24 19:20:47

问题


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);
            }
        }
    }
}

}

来源:https://stackoverflow.com/questions/43830532/detect-gestures-without-blocking-other-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!