Beta 1.60: Some findings with homescreen widgets

corwin42

Expert
Licensed User
Longtime User
Ok, I played a bit with homescreen widgets:

I have some problems with the size. I'm trying to create a 4x1 widget. The Android documentation mentions that in portrait mode a 4x1 widget should have the size 320x100. If I create such a base panel then I get a 4x2 widget. I have to reduce the size of the base panel to 75 to get a 4x1 widget (80 still gave 4x2. Didn't try all values inbetween). Is this normal? Seems a bit too low for me. Have I misunderstood something regarding the size?

If I add an ImageView without adding an Image in the designer I get the following error:
Error compiling program.
Error description: Die Zieldatei "C:\Users\stm\Dropbox\AndroDev\AHWeather\Objects\res/drawable/" ist keine Datei, sondern ein Verzeichnis.
Occurred on line: 8
rv = ConfigureHomeWidget("L4x1", "rv", 60, "AHWeather 4x1")
Word: )

Took me some time to find the problem. At least the error message should be a bit better? (Another thing was that it is not allowed to select an image with a numerical name like "10.jpg". Then the R.java can not be compiled. Don't know if this should be fixed and I think has nothing to do with the new widget possibilities)

If you want to use a homescreen widget you should disable the "Can install to external storage" option. Otherwise you don't see the widget in the list of widgets. This should be mentioned in the documentation/Tutorials.

Ok, thats for now. Otherwise: It's absolutely fun to design widgets wich B4A :sign0162:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The sizing issue is an Android issue. On this page they are saying that to go on "the safe side" you should use this formula:
(number of cells * 74) - 2

It is possible that different devices use a slightly different size for a single cell.

The points you mentioned are very important. All of them will be fixed tomorrow.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
The sizing issue is an Android issue. On this page they are saying that to go on "the safe side" you should use this formula:
(number of cells * 74) - 2

It is possible that different devices use a slightly different size for a single cell.

The sizing is really a bit strange. I now changed the dimensions of my main panel to values calculated with the suggested formula. So my widget has 294dp width and 72dp height. If I leave the panel at position 0,0 it is not centered in the "cell". I have to adjust the position of the panel to 13,14 to have it centered.

The strange thing is that some widgets I have on my homescreens are (much) higher than 72dp but they still use one cell in height.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
I begin to understand how it works.

The widget size (how many cells will be used) is based on the minWidth and minHeight attributes of the <widget>_info.xml. These values are derived from the Base Panel size.

The real size of the widget can be independent of this minimum values. That means it is possible to use another size for the Base Panel.

I have tried to use -2,-2 for the Panel size (this means "fill_parent"). Then I get a 1x1 widget. The launcher I use (Go Launcher) allows to resize widgets. I could resize the widget and the panel automatically resizes too. This is great.

What does this all mean?

To be free in designing widgets and to allow them adopt to other screen sizes (like switching between portrait and landscape) we need a possibility to change size and position of the widget elements.

My suggestions:
1. Add two parameters for minWidth and minHeight to ConfigureHomeWidget() function. Nice would be if it is possible to specify them as 4x1 etc. and B4A calculates the dp values itself with the given formula.
Example: ConfigureHomeWidget("L4x1", 4, 1, "rv", 60, "AHWeather 4x1")

2. Add a function to determine the real size of the widget container to the RemoteView object. I think this should be possible somehow?

3. Add functions to get and set position and dimension of widget elements to the RemoteView object so we can programatically set new size and position for our items on the widget.

Erel, what do you think? This shouldn't be too hard to add.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I think that it is more complicated then it may sound. Especially as the default home screen doesn't support resizing (for 2.x devices). There is a bug in this version where the first panel x and y weren't set to 0. This is however not relevant for your request.

The final version will not overwrite read-only layout files and the info file. This means that you will still be able to change the minWidth and minHeight if you want to use values other than the main panel values.

This is the first version that supports widgets. Later versions may add such features.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Ok, I understand that you don't want to do any bigger changes before the release now.

Anyway I have tried to change the <widget>_info.xml (setting minWidth and minHeight) and making the file read only. But B4A complains that it cannot write the file. If this works in the next version I think I can live with it at the moment.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
This discussion seems to have deeper implications than at first sight...For xample, anyone tried to create a widegt to a 480*600 screen? How does the formula aply in this case?
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
This discussion seems to have deeper implications than at first sight...For xample, anyone tried to create a widegt to a 480*600 screen? How does the formula aply in this case?

You mean 480x600 or 480x800?

Thats why I requested the possibility to define the minWidth and minHeight independent of the base panel size and a function to get the real widget container size and the possibility to dynamically set positions.

On a 480x800 screen (on smartphone) with a scale of 1.5 you can use the formula and for a 4x4 widget you get (4*74)-2 = 294*1.5 = 441 pixel.

So you have to specify 294 for minHeight and minWidth to get a 4x4 widget. Problem is the real size of the widget is MUCH bigger. With the current possibilities of B4A you can only create a 441x441 pixel widget but the real size of the widget will be something about 480x600. So there is much unused space in the B4A widgets and centering the base panel correctly on all devices will really be a big problem without modifying the generated xml manually.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Yes Cor, I ment 480*800, my mistake...

I believe some kind of easy tweak or formula will be made available...
I would suggest to create a new Thread on the Forum, and the users/developers that already made some widgets, would post theis finding and of Formulas used to get the widget size, and of course, the actual size they used...
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
With the current implementation you can only create widgets which have the maximum sizes calculated with the formula.

If the final version allows to set the generated xml files read only it would be possible to modify the xml to create complete new and better layouts. I hopefully will have time to test this in detail in the next three weeks.

Another thing I haven't tried yet is to add a layout variant for landscape mode.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Another thing I haven't tried yet is to add a layout variant for landscape mode.

I just tried it. Seems that B4A currently doesn't support layout variants for widgets. Only xml for the base variant is created.
 
Upvote 0
Top