2014년 11월 28일 금요일

Help Test the API4 Code in App Inventor.


Please help us test the API4 code. 
http://api4test.appinventor.mit.edu has just been updated to the latest release. It now also has the ability to set the width and height of objects as a percentage of their parent. This is useful in cases where you do not know the actual screen density and dimensions of the target device.

The source code for the test code is on my "api4jis" branch in my GitHub fork (jisqyv/appinventor-sources).

--
Nice start!

Here's a bug:

- create an app with a single button, set the screen to center the component horizontally, and set the button to center the text in the button.    Make the background of the button red.   Make the button width 20% of the screen width.

Look fine.
Now rotate the phone so the button is along the long side of the phone.   Looks great:  The button width expands.

Now rotate phone again.  The button and the red background are correct, but it leaves an extra block rectangle to the right of the red.

PS: I also found a more serious bug, but I can't reproduce it.  I'll work on that.

Shall we set up a google form for people to report  things?

--
Another bug:

Start wit an empty project.
Add a horizontal arrangement.  Make it's width 50%.

Place a label in the horizontal arrangement.  Make its background color red.

Change the label width from automatic to 20%

Rotate the screen and check the label width in both orientations.  It is the same in both orientations.
I played around more and am getting funny results, but I haven't done a careful protocol.   I'll do more later.

Also, if you try to set the label width to 200%, the error alert says:
The value must be a number greater than or equal to 0

--
Great enhancement.

I had a thought about the extra block WidthPercentage
Instead of adding the extra WidthPercent block it's possible to do this with the just Canvas.Width block and adding a new built-in maths block  % as shown below which I did earlier today


The reason I would do it like this is when using the coordinate system on Canvas component for drawing circles, lines, etc you'll need extra set of block. Using the maths percent block I have created means you could use the same block to draw a circle for instance and either use the maths percent number or just a number. Below is an example of what I mean

drawing a circle on the canvas using pixels (centrally on a canvas 320px by 480px)
drawing the same circle using the number percent block (centrally on the canvas)
This is only a thought which I have partially implemented already myself.

--
That percentage block needs a bit more thought, but it's nice idea.  

--
Thanks. The problem I am dealing with is that throughout the code lengths are represented by an integer. In the pre-API4 code, a positive value is a pixel count. -1 and -2 are special and indicate AUTOMATIC and FILL_PARENT. In the API4 code, positive values are now density independent pixels (aka "dp"s). In order to represent a percentage value, and still use a simple integer, I added a hack where the range -1100 through -1000 represent percentages (where -1100 is 100% and -1000 is 0%). These values are never returned (when you read the width or height of a component you will get the currently computed "dp" value). The WidthPercent and HeightPercent blocks simple convert their input into this range, thus hiding this ugliness from the App Inventor Programmer.

Actually, now that I think about it, You *can* input -1100 through -1000 via the normal Height and Width setters and the right thing will happen. So I guess we can create a percent block that just takes its input and moves it to this range. Hmmm. That might actually result in App Inventor code that looks cleaner. On the other hand, if people take the value of a percent block (my kind) they might be mystified by the weird negative values!

--

I was able to reproduce this one. Looks like a Android problem. I'm looking into how to get around it. I believe if I can trigger a complete screen redraw on rotation, that will deal with it...

--

Great.   Let me know when you've got a new version and then I'll do more testing.

--

댓글 없음:

댓글 쓰기