Determine the homescreen's appwidgets space grid size
Asked Answered
N

4

3

I have developed a re-sizable app-widget for tablets. The app-widget works nice on most devices with the majority of launchers, however there are some problems with the orientation especially on the GO-HD Launcher in portrait mode. The height of the app-widget is too big and doesn't look nice.

In order to deal with this I have created a method to allow the user to set any extra margins, in the app-widget space, he wants to make it look nice. For example he can set extra 20 pixels top margin when the device is in portrait mode and only 5 pixels when in landscape etc.

Now I am creating an activity to allow users to set the margins. I want to make a small preview area (it will be a linear layout with the same background drawable app-widget has) in order for the user to get an idea of how the app-widget will look like on the home screen with these margins. Actually I have done that but the result is far away from the reality.

So my question is:

Is there any way to get the size (or close to it) of the grid cell that launcher application using to place the app-widgets on the home screen? Please note that I am aware of the fact that not all launchers following the Android formulas for this but what I want is to get a way to calculate an approximation of it.

---- EDIT ----

In order to better understand my problem I have created a screenshot:

shot

First of all the app-widget's background is a shape xml file with no graphics or dimensions at all. It's up to Android to draw it in the available space. In my opinion this is the best GUI design (at least with the background). Now in the screen 1 you can see the widget in portrait mode in the default Android launcher, it looks very nice and it is re-sizing OK. In screen 2 and 3 you can see it in GO-HD launcher (landscape and portrait mode), in this launcher it looks pretty small in landscape mode and very big in portrait mode. I can fix this problem by letting the user adjust the margins as you can see in screen 4.

If you compare the preview (the dark area in the center of screen 4) with the original app-widget in android's default launcher you can see that there is no a good match. What I am asking is how can I present to the user a better preview (closest to the actual app-widget).

Thank you and please forgive my English

Natal answered 9/1, 2013 at 19:32 Comment(1)
Wouldn't it be simpler and more reliable to come up with a GUI design that is more flexible and can more readily accommodate different cell sizes and the like?Matisse
H
3

Have you implemented AppWidgetProvider.onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle)? All well-behaved launchers should report some metrics about your placed widget, which you can retrieve from the bundle, using code like:

int minwidth_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
int maxwidth_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
int minheight_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
int maxheight_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);

Note that there is no concept of cell here - these metrics correspond to the actual size of your widget, however many cells it takes up.

The stock launcher maps these to different orientations like so:

minwidth -> portrait width
minheight -> landscape height
maxwidth -> landscape width
maxheight -> portrait height

Any launcher that keeps the same number of rows and columns in both orientations, and that resizes the cells to fit the screen, ought to map these the same way. Be aware, assuming these relationships always hold may produce undesired results if you're embedded in a launcher that does something unusual with its widgets - placing them in only part of the screen, or using a different number of rows or columns in different orientations.

Alternately, some launchers may report the metrics of the current orientation in both min- and max- values, and simply call you again with new metrics when the orientation changes. However, if you are only interested in the current orientation, the behavior of these launchers is compatible with that of the stock launcher.

Highup answered 1/4, 2013 at 6:40 Comment(3)
There is to my knowledge no way to get these metrics on downlevel versions.Highup
Thanks for your answer, the idea to use onAppWidgetOptionsChanged in order to get the metrics has crossed my mind. However it cannot be used in my situation because I want to know the metrics for each orientation regardless of the device current settings furthermore, and most important, I want the metrics before the widget is added on the homescreen i.e. in the configuration activity. Anyway thank you very much for your time and for a very well documented answer.Natal
I don't think you're going to get any better than onAppWidgetOptionsChanged. Perhaps you could have your configuration activity start a very short timer and then finish() immediately. Then, when onAppWidgetOptionsChanged is called, or the timer expires, you can startActivity() yourself. Probably the biggest disadvantage to this approach is that the user wouldn't be able to cancel adding the widget, since it has technically already been added. But I just can't imagine how you could get any remotely-reliable metrics any other way.Highup
M
0

Is there any way to get the size (or close to it) of the grid cell that launcher application using to place the app-widgets on the home screen?

No. Each home screen developer is welcome to do what that developer wishes.

in this launcher it looks pretty small in landscape mode and very big in portrait mode

Then come up with a design that accommodates those sizes. For example, you might look to see what other app widgets do when run on that home screen.

Matisse answered 11/1, 2013 at 1:12 Comment(5)
Thank you for the answer. I am already know the first part (very well :)). As for the second I actually tried a bunch of other widgets and all the re-sizable ones have the same problems with non "standard" launchers. The non re-sizable had no issues but I need to create a re-sizable one. As for the design I really can not figure out how a different re-sizable design can address this issue. Any idea is welcome. Thanks again.Natal
@Christos: "Any idea is welcome" -- my idea is to not worry about it. By your own admission, others are experiencing the same behavior. Yet, their apps are being downloaded and, presumably, are not getting poor ratings due to the slightly irregular behavior of their app widgets when they are initially added to users' chosen home screens.Matisse
@Christos I think this is the correct answer and you should accept it. Even when it says "sorry, it isn't possible" like this.Coda
@Coda I am working on a possible solution to my problem, based on the results I will come back and either post it or accept the best answer even if it says that it isn't possible. This case is still open but thank you for your suggestion anyway.Natal
@Christos you're welcome. I will follow this question, I'm interested on what you're trying to achieveCoda
P
0

I don't know of a way to make a reliable preview, but it might help to use different margins based on orientation. You can use layout-land and layout-port to specify different layouts with different margins.

Pozzy answered 12/1, 2013 at 2:32 Comment(3)
it seems to me that you didn't read my question. This is exactly what I am doing. I am just try to create a reliable preview.Natal
Its not clear from your question that you are also using different margins for portrait/landscape layouts (only that you allow users to adjust the margins for orientation). Maybe you are doing both?Pozzy
I am sorry if my question is misleading about the margins (my English aren't so good so it may be). However is about creating a preview screen and not about the layout of the app-widget. Thanks anyway.Natal
H
0

I know it's been awhile, but I was just upvoted on my other answer so I got the chance to glance at this with fresh eyes.

I think the real answer to the original question might be to set the widget's size yourself, or maybe just the height since that seems to be the problem in the screenshots. In your layout set layout_height="@dimen/my_perfect_height" and the launcher will center it within the cell. If you need a little flexibility, you can use a few different layouts with different metrics and let the user choose between them. And of course, you'll have no problem previewing that height since you're the one setting it.

Highup answered 4/1, 2014 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.