3

I'm trying to adapt Google's CubeLiveWallpaper demo to create a parallax effect in a live wallpaper. I've removed the cube and have my own image displaying and that's great, but I've hit a wall.

My understanding is that I'm supposed to be able to use xPixels from onOffsetsChanged() to determine where to draw my bitmap on the canvas. Assuming I'm not already talking crazy, logic would dictate that xPixels would have to be a different value every time the user makes a swipe. I have proven with a log statement that this is not happening. In fact, none of the values received by onOffsetsChanged() ever change. The result is that my image does not move.

First, I'll provide the log output, then the code.

Log (copied from Dalvik Debug Monitor). Every swipe, in either direction, produces this output.

02-23 20:09:29.859: D/onOffsetsChanged(1039): xOffset (0.500000) | yOffset (0.000000) | xStep (0.000000) | yStep (0.000000) | xPixels (-160) | yPixels (0)

onOffsetsChanged

  public void onOffsetsChanged( float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels )
  {
     Log.d( "onOffsetsChanged", String.format("xOffset (%f) | yOffset (%f) | xStep (%f) | yStep (%f) | xPixels (%d) | yPixels (%d)",
            xOffset,
            yOffset,
            xStep,
            yStep,
            xPixels,
            yPixels) );

     mOffset = xPixels;  // mOffset is a member of my class
     drawFrame();
  }

I figure that including the below code is unnecessary, since the drawing operations come after mOffset is assigned in onOffsetsChanged, but seeing as how I'm the one asking for help here, I've lost all right to assume things.

drawFrame()

  void drawFrame()
  {
     final SurfaceHolder holder = getSurfaceHolder();

     Canvas c = null;

     try
     {
        c = holder.lockCanvas();

        if( c != null )
        {
           drawBackdrop( c );
        }
     }
     finally
     {
        if( c != null )
        {
           holder.unlockCanvasAndPost( c );
        }
     }

     mHandler.removeCallbacks( drawFrameRunnable );

     if( mVisible )
     {
        mHandler.postDelayed( drawFrameRunnable, 1000 / 25 );
     }
  }

drawBackdrop()

  void drawBackdrop( Canvas c )
  {
     c.save();
     c.drawColor( Color.BLACK );

     c.drawBitmap( backdropBmp,
                   mOffset,
                   0,
                   null );
     c.restore();
  }

As a final note, I'll mention that as far as I know, my phone supports scrolling wallpapers. I understand that the Galaxy S3, for example, does not (source: http://androidforums.com/samsung-galaxy-s3/586033-galaxy-s3-cheated-some-us-leaving-out-scrolling-wallpapers.html). I have downloaded several live wallpapers from the Play store and they've all successfully scrolled. I assume those developers haven't somehow jumped through a bunch of hoops to hack on the same functionality for my device. I'm using a Samsung Transform Ultra.

Thank you for your help!

Daniel Imms
  • 47,944
  • 19
  • 150
  • 166
mershal
  • 31
  • 2
  • Can you try to use another launcher like nova to check if something changes. Touchwiz has some problems to manage horizzontal scrolling. – xcesco Sep 04 '15 at 09:07

0 Answers0