Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please take a look at my code:</p> <pre><code> public class PonyWallpaper extends AnimationWallpaper { /*some code here*/ class PonyEngine extends AnimationEngine { /*some code here as well*/ @Override public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.v("orientation changed", "w: "+width + " h: " + height + " width desired: " + this.getDesiredMinimumWidth() + " height desired: " + this.getDesiredMinimumHeight()); </code></pre> <p>with AnimationEngine declared as</p> <pre><code>protected abstract class AnimationEngine extends android.service.wallpaper.WallpaperService.Engine </code></pre> <p>The output when switching to portrait from landscape:</p> <blockquote> <p>orientation changed(352): w: 800 h: 480 width desired: 960 height desired: 800</p> </blockquote> <p>The output when switching to landscape from portrait: </p> <blockquote> <p>orientation changed(352): w: 480 h: 800 width desired: 960 height desired: 800</p> </blockquote> <p>As you can see, method onSurfaceChanged of the android.service.wallpaper.WallpaperService.Engine class is called every time an orientation gets changed. </p> <p>From what i've noticed, </p> <blockquote> <p>this.getDesiredMinimumWidth()</p> </blockquote> <p>and </p> <blockquote> <p>this.getDesiredMinimumHeight()</p> </blockquote> <p>don't change and are maximum possible values of width and height. </p> <p>My solution was: </p> <ul> <li>to pass width, desired width, height and desired height to a method of my drawer object;</li> <li>to call drawObject() - like methods with a coordinates ranging from 0.0 to 1.0;</li> <li>to scale those values inside drawer object to logical coordinates described by desired width and desired height;</li> <li>to set an offset of a real x coordinates judging by xPixelOffset passed by </li> </ul> <blockquote> <p>onOffsetsChanged</p> </blockquote> <p>method of </p> <blockquote> <p>android.service.wallpaper.WallpaperService.Engine</p> </blockquote> <ul> <li>to set an offeset of a real y coordinates judging by difference of a real height and desired height.</li> </ul> <p>I hope that will help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload