Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onOffsetsChanged not called by Touchwiz

Note: since it is a question specific to Samsung, I also asked it on their developer board.

I am currently implementing a Live Wallpaper in Android and I'm listening to the onOffsetsChanged() method in my wallpaper engine to change the wallpaper when the user swipes through his homescreens. This works great on my private Galaxy Tab with a CM9 custom rom. On my company device, a stock Galaxy S3, it does not work. Somehow Touchwiz doesn't call onOffsetsChanged when the homescreen is changed.

Googling for the topic didn't yield any significant results besides the description of this app, where the dev states: "Fixed scrolling on latest TouchWiz launcher where onOffsetsChanged() doesn't get called." Now I would just contact the dev, but unfortunately it is also a Samsung app.

Does anyone know a workaround to get the current offsets without relying on onOffsetsChanged? Has anyone run into this problem in their own wallpaper? Does anyone know if this is intentional or if I can assume that future Touchwiz versions will make use of the method again?

like image 554
Thrakbad Avatar asked Jan 10 '13 12:01

Thrakbad


1 Answers

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.

like image 124
Brainman Avatar answered Oct 01 '22 04:10

Brainman