waleedAhmad1 / google-glass-api

Automatically exported from code.google.com/p/google-glass-api
0 stars 0 forks source link

WakeLock obstruction touchInputs (onGenericMotionEvent not fired after wakelock on) #630

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Here is the sample code

// ----
public GestureDetector mGestureDetector;
private PowerManager.WakeLock wl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");

    mGestureDetector = createGestureDetector(this);
}

@Override
protected void onResume() {
    super.onResume();
    wl.acquire();    // <--- problem is here !!!!
    }

    private GestureDetector createGestureDetector(Context context) {
    GestureDetector gestureDetector = new GestureDetector(context);
    gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            // .....
            return false;
        }

    });
    return gestureDetector;
}

@Override
public boolean onGenericMotionEvent(MotionEvent event) {  // <--- Not fired 
after wakelock on...
    if (mGestureDetector != null) {
        return mGestureDetector.onMotionEvent(event);  
    }
    return false;
}

// ----

If you comment out the wl.acquire();, everything got normal.
but after wakelock. the gestureDetector cannot receive gestures anymore.

Testing ok in XE12-16 but fail in XE22.

What is the expected output? What do you see instead?

Touches and gestures can be captured no matter what wakelock status.

What version of the product are you using? On what operating system?

XE22

Please provide any additional information below.

Original issue reported on code.google.com by j796160...@gmail.com on 5 Nov 2014 at 2:40

GoogleCodeExporter commented 8 years ago
Hello,

Have you tried using the FLAG_KEEP_SCREEN_ON method instead?
  https://developer.android.com/training/scheduling/wakelock.html

This should be easier than acquiring a wakelock and is used in our samples.

Best,
Alain

Original comment by ala...@google.com on 6 Nov 2014 at 12:45

GoogleCodeExporter commented 8 years ago
 I think it is temporally solved my problem.
I wonder if this script is deprecated so do this bug appears?

Original comment by j796160...@gmail.com on 9 Nov 2014 at 4:32

GoogleCodeExporter commented 8 years ago
Hello,

The solution I provided is actually the recommended way to keep the screen on. 
It is also mentioned in the Android docs as the wake lock flag is being 
deprecated.

Best,
Alain

Original comment by ala...@google.com on 10 Nov 2014 at 4:18