Question

I have the following snippet of code extending GLWallpaperService in an app:

    @Override
    public void onOffsetsChanged(float xOffset, float yOffset,
            float xStep, float yStep, int xPixels, int yPixels) {
    super.onOffsetsChanged(xOffset,yOffset,xStep,yStep,xPixels,yPixels);
    VideoLiveWallpaper.xStep = xStep;
    VideoLiveWallpaper.yStep = yStep;
    Log.w("General", "xStep: " + xStep);
    Log.w("General", "yStep: " + yStep);

When I run this my understanding is that xstep should return a value between 0 and 1, essentially allowing me to determine the number of screens by dividing the xstep value by 1. However, every time I run this on my Sony Xperia Ion the xstep is returned as -1. I have five homescreens setup so this is not just a default for a single homescreen.

I have tried searching Google but did not see anyone else who seems to be having the same problem. Is this a bug in my particular phone? Is there a better way to determine the number of homescreens and how much a wallpaper should scroll as they move?

Was it helpful?

Solution

I never did find the reason why this occurs, but I did find another piece of code that addresses the issue. Here is the relevant portion, in case it helps anyone else:

 if (xStep <= 0.0f && VideoLiveWallpaper.xStep == 0) {
      xStep = xOffset / 2; // originator didn't set step size, assume we're halfway

It seems to work as long as the home screen (middle screen) is up when the wallpaper starts. That's not perfect, but it works better than my method of assuming 5 screens (xStep = 0.25) in all cases when it's zero...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top