2

I would known how can I retrieve the height of a the title bar from an android LiveWallpaper?

I know how do it from an activity : Height of statusbar?:

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); 

But from the WallpaperService.Engine, I don't know how access to getWindow().

Thanks.

Community
  • 1
  • 1
PiR
  • 175
  • 9

1 Answers1

0

I don't see a way to find a getWindow() directly from a Service. As a workaround you could create a transparent activity the just gets the bar height and finishes itself. You can start this activity when you create your engine service for the first time. It is not the ideal, but should work fine.

Rodrigo Dias
  • 412
  • 4
  • 13
  • It is not really beautiful but it works. Just a remarque: the code should not be directly in the onCreate methode of the transparent activity but in a Runable called with a little delay (I choose one seconde for be sure). If not return 0 for status and title bar. – PiR Oct 08 '12 at 15:19
  • Hmm interesting.. did you try to call it on onResume instead of using the Runnable? – Rodrigo Dias Oct 08 '12 at 19:18
  • In onResume without delay I have same problem than in onCreate method. I had found the delay trick [here](http://stackoverflow.com/questions/3407256/height-of-status-bar-in-android#comment11135530_4832438) – PiR Oct 09 '12 at 07:46