Android: onOffsetsChanged in Live WallpaperService not working

In android making live wallpaper is quite easy by using onOffsetsChanged and onTouch overridable methods. WallpaperService and WallpaperService.Engine classes have many overridable methods to make smooth and interactive wallpaper service.

There are many methods which you can use to making your wallpaper service and for more details you should refer android documentation. Here are some important overridables which should be handled in your interactive wallpaper service.

         * Called to inform you of the wallpaper becoming visible or
         * hidden.  <em>It is very important that a wallpaper only use
         * CPU while it is visible.</em>.
        public void onVisibilityChanged(boolean visible) {
         * Called as the user performs touch-screen interaction with the
         * window that is currently showing this wallpaper.  Note that the
         * events you receive here are driven by the actual application the
         * user is interacting with, so if it is slow you will get fewer
         * move events.
        public void onTouchEvent(MotionEvent event) {
         * Called to inform you of the wallpaper's offsets changing
         * within its contain, corresponding to the container's
         * call to {@link WallpaperManager#setWallpaperOffsets(IBinder, float, float)
         * WallpaperManager.setWallpaperOffsets()}.
        public void onOffsetsChanged(float xOffset, float yOffset,
                float xOffsetStep, float yOffsetStep,
                int xPixelOffset, int yPixelOffset) {

onVisibilityChanged should be handled for starting and stopping your wallpaper processing for efficient CPU use.

onTouch should be used to handle touch event in case you don?t need screen count, current home screen index or offset changed valued of screen scroll. Mean you should use touch when you wallpaper requires only touch events.

onOffsetsChanged should be used when you want to make a Live wallpaper in which you want to used scroll width, Home screen count, current screen index and next screen index etc. But use onOffsetsChanged only when it is required because onOffsetsChanged is a costly operation.

?onOffsetsChanged is a costly operation that?s why many android device makers has forbidden or block this method in their custom Home or Launchers and you wallpaper service will not work properly on these Launchers. So don?t panic when onOffsetsChanges is not working in your service.  you will get once call in onOffsetsChanged  when you wallpaper visibility is changed?

There are many free Launcher Home screen on android market place you can download and use one of them in which onOffsetsChanged is working. I used ?Apex Launcher? which is working fine.

Android wallpaperservice.Engine class has two methods to enable Touch event and offset changed in latest version of android sdk.

public void setOffsetNotificationsEnabled (boolean enabled) since api level 15

public void setTouchEventsEnabled (boolean enabled) since api level 7

Get getting home screen count you can use xOffsetStep value. As it is float value varies between 0.0 to 1.0.

so (1/xOffsetStep )+1 will give you no of home screen. And default value of  xOffsetStep is 1 in case of only one home screen.

Leave a Reply

Your email address will not be published. Required fields are marked *