How can I make my AppWidget automatically fill the width of the home screen?

982 views Asked by At

I am working on a widget. On the typical phone, I would prefer it to be 4x2, filling the width of the home screen. However, on some larger phones (i.e. Samsung Galaxy Mega), the launcher has 5 cells' width. I am trying to find the best way to automatically change my widget provider to be a 5x3, based on the launcher cell dimensions.

Currently, we have two providers: a 4x2 and a 5x3. Since we only want to show one (4x2) on normal-size phones (they don't support 5x3), we do a runtime check when the widget is added to check if the device model matches one of the models with a 5-cell wide launcher. We then disable the other widget provider component. However, this isn't ideal, as the 5x3 will show up temporarily in the app drawer and cause the launcher to force close if the user tries to add it.

Any thoughts on how to work around this? I realize I most likely won't be able to read exactly the cell-width size, as there are tons of launchers, and there isn't an API to check. However, I think we would all agree that there must be something better than keeping a static list of devices that have a 5-cell screen (not to mention people with custom launchers can set a range of widths).

I have thought briefly on using the resource folder qualifiers (sw720dp, etc.) ...but that still doesn't solve the issue of determining what the user's launcher's width in cells is.

Thanks for the help, Drew

P.S. I also realize that a similar question was asked here: Appwidget Maximum Width that fits all screen sizes with no comments or answers. Any input would be much appreciated.

1

There are 1 answers

1
CommonsWare On

Any thoughts on how to work around this?

Allow your app widget to be resizeable, so users who want it to fill the home screen width can elect to do so.