Some developers are using touch events instead of system onOffsetsChanged() to work with TouchWiz. I think, currently the only better way is using the hybrid event system, which will work in such way:
1) Always assume that onOffsetsChanged() message is not sent correctly (make boolean property defaulting to false).
2) This means that you should implement onTouch() method to make the proper imitation of onOffsetsChanged(). Listen to onTouch() only if the boolean property is still false.
3) When onOffsetsChanged() is called, check the xOffset param. If it's neither 0.0f nor 0.5f, then change the boolean property to true and listen only to onOffsetsChanged().
Code will be sth like:
public class myEngine extends WallpaperService.Engine {
private boolean offsetChangedWorking = false;
public void onOffsetsChanged (float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
if (offsetChangedWorking == false && xOffset != 0.0f && xOffset != 0.5f) {
offsetChangedWorking = true;
}
if (offsetChangedWorking == true) {
// Do sth here
}
}
public void onTouchEvent(MotionEvent paramMotionEvent) {
if (offsetChangedWorking == false) {
// Do sth else here
}
}
}
This code is only an illustration. Note, that comparing floats with == is not correct, but it might work in this case.
Also, it looks like Samsung Parallax LWPs are working the same way. If you have a device with TouchWiz and some other properly working launcher (which sends onOffsetsChanged() normally), you can try it by yourself:
1) Set parallax LWP on TouchWiz first (important!) and see that it depends only on onTouchEvent()
2) Change the launcher to the other one. See that LWP now depends on onOffsetsChanged()
3) Change the launcher to TouchWiz again and see that swiping doesn't work for this LWP anymore.
So what i recommend to add is on every onResume() event change the boolean offsetChangedWorking to false again. This should prevent such bugs with launcher changes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…