Android - Live Wallpaper offset clipping
Asked Answered
N

2

6

I am writing a live wallpaper for android. To test my basic code was working I drew a rectangle in the top left-hand cornor of the screen:

canvas.drawRect(0f,0f,50f,50f,paint);

Half of the rectangle was underneath the bar at the top of the home screen.alt text

I tried to take into account pixel offsets using:

public void onOffsetsChanged(float xOffset, float yOffset,
            float xOffsetStep, float yOffsetStep, int xPixelOffset,
            int yPixelOffset)

...

  canvas.drawRect(0f+xPixelOffset,0f+yPixelOffset,50f+xPixelOffset,50f+yPixelOffset
  ,paint);

But the rectangle is still drawn underneath the bar. How do find where the bar ends so I can draw below it?

Cheers,

Pete

Neilneila answered 18/8, 2010 at 15:39 Comment(1)
possible duplicate of Height of statusbar?Handclasp
C
9

This SO answer seems to provide a way to get the height of the status bar: Height of statusbar? I copied the code below - originally answered by Jorgesys.

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;

   Log.i("*** Jorgesys :: ", "StatusBar Height= " + StatusBarHeight + " , TitleBar Height = " + TitleBarHeight); 

Hope it helps.

Civet answered 23/8, 2010 at 0:51 Comment(3)
Maybe I've glossed over something, but I can't find out how to call getWindow() from within the Live Wallpaper. WallpaperService and WallpaperService.Engine don't have a getWindow() method. You can easily use getWindow() in an Activity but a Live Wallpaper is based off of the Service class. Can anybody explain?Straightedge
Nice answer we got the height,Now in some phones/tabs status bar is below and in some its on top how we know the position of status barDemurrage
@RenjithKN you should ask a new questionCivet
G
3

Have you checked if an offset is set (guess your offset variables are zero)? I would draw under the bar, too, because there are some home-screen apps which can blend out the bar and you will than have a blank area.

I also guess that the offset you use is only used if you slide to other screens...

Gruff answered 18/8, 2010 at 15:48 Comment(2)
I just checked and they are both 0. Us there another way to get the height of the home screen bar?Neilneila
In a normal application you can get the difference between the device screen size and the view size, so you can calculate the height of each bar. Don't know if that works for wallpapers.Gruff

© 2022 - 2024 — McMap. All rights reserved.