android live wallpaper rescaling

Well, um, all I can say is “Welcome to the real world.” You get your screen dimensions passed to you via onSurfaceChanged, and yes, it is your job to figure out how to scale everything based on this data. That’s why they pay us the big bucks. 🙂
You will want to make sure your resources are large enough to fit the biggest display you intend to support, so you will always be shrinking things (which distorts much less than expanding things).

Suggest starting with “best practices for screen independence” here: http://developer.android.com/guide/practices/screens_support.html

Additional comments in re your request for more help…

  1. You cannot (necessarily) scale your artwork just using the width, because you need to support multiple aspect ratios. If the screen proportions do not match your artwork, you must decide if you want to distort your artwork, leave blank spaces, etc.
  2. I’m not sure how to interpret your trouble passing around the screen dimensions. Most of us put all of our active code within a single engine class, so our methods can share data via private variables. For example, in the Cube wallpaper in the SDK, onSurfaceChanged() sets mCenterX for later use in drawCube(). I suggest beginning with a similar, simple approach.
  3. Handling scrolling takes some “intelligence” and a careful assessment of the data you receive via onOffsetsChanged(). xStep indicates how many screens your launcher supports. Normally xStep will be 0.25, indicating 5 screens (i.e. xOffset = 0, 0.25, 0.5, 0.75, or 1) but it can be any value from 0 to 1; 0.5 would indicate 3 screens. xPixels gives you an indication of how much the launcher “wants” you to shift your imagery based on the screen you’re on; normally you should respect this. On my phone, the launcher “desires” a virtual wallpaper with twice the pixels of the physical screen, so each scroll is supposed to shift things only one quarter of one screen’s pixels. All this, and more, is documented in http://developer.android.com/reference/android/app/WallpaperManager.html
    This is not “easy” coding–apps are easier than wallpaper. 🙂

Good luck…George

P.S. I’ll throw in one more thing: somewhere along the line you might want to retrieve the “desired minimum width” of the wallpaper desired by the launcher, so you can explicitly understand the virtualization implicit in xPixels. For example, in my engine constructor, I have

mContext = getApplicationContext();
mWM = WallpaperManager.getInstance(mContext);
mDW = mWM.getDesiredMinimumWidth();

My device has 320 pixel width; I get mDW = 640; as I scroll from screen to screen, xPixels changes by 80 each time…because four scrolls (across five screens) is supposed to double the amount of revealed artwork (this effect is called “parallax scrolling”). The rightmost section has xPixels equals 0; the center (of five) sections has xPixels = -160, etc.

Leave a Comment