SCalculator

derez

Expert
Licensed User
Longtime User
Attached is my first "real" application for Android.
I took SCalculator as the first to work on because it doesn't need any libraries or hardware (like GPS, WiFi etc.) since I have only an emulator to work on.

The code is converted from a B4PPC with many patches and is not optimized at all. I'm sure there will be many improvements (like using sender) in the future as I learn more.

Please check how it runs on real machines and tell me. Also I'd love comments on how to improve it.

The attached manual is from the B4PPC version but it is 95% valid here as well.

Edit: updated to b4a version V090.03
 

Attachments

  • landscape.jpg
    landscape.jpg
    63.4 KB · Views: 217
  • portrait.jpg
    portrait.jpg
    66.6 KB · Views: 255
  • Scalculator.zip
    14.3 KB · Views: 206
Last edited:

agraham

Expert
Licensed User
Longtime User
Nicely done but I'm afraid the UI needs a rethink as the buttons are a bit too small to be used on a phone with a capacitive screen which needs finger presses. As you cannot use a sylus it is dificult to hit the correct button. There needs to be no more than five buttons across the screen in portrait mode for it to be usable. See the layout used here Brain Overspill. It is just about reliably usable on my phone.

@Erel.
Is there a timeout in the Designer? I cannot use the emulator to look at the layout file of this application as the Designer keeps disconnecting, I assume because it takes so long to load the layout. I can't reproduce it at will but at times the phone also disconnects after loading the layout. If the phone does stay connected then the Designer works fine with good performance.

On occasion the Designer on the emulator does does display the the layout even though the IDE is disconnected. Then a few minutes later the Designer on the emulator spontaneously closes itself. Is this meant to happen? Is it an exception on a socket killing the app?
 

moster67

Expert
Licensed User
Longtime User
@derez

I tried it on my HTC HD2 (480x800) in portrait and landscape mode. The layout scales and fits perfectly. I have big fingers but I was still able to click on the buttons without any major difficulty but I do believe we are at maximum levels here. :)

Perhaps, as Andrew suggested, it would be better to use the layout-scheme as in the RealCalc-application where the button "Shift" is being used to toggle the function of a button which in that case can have two separate functions. In this way you need less buttons and you can make the other buttons slightly bigger.

In any case, your application was running smooth. It took a second or two to load but it was acceptable. The change from portrait to landscape (and vice versa) was speedy as well.

Well done! I guess we will see it on the Marketplace soon. :)
 
Last edited:

derez

Expert
Licensed User
Longtime User
Thanks !
I agree with Andrew's remark about the size, I actually was thinking about a 7'' device so this size should be OK. Of course for the small phones it is too small.

Erel
I have the same problem with disconnecting when using an emulator of 800x480 instead of 480x320, can't get it to enable design. At one time I had a 240 dpi 800x480 and saw that moving a button by code using (number)dip didn't move the button to the right place. I guess I'll have to wait till I'll be able to run such emulator again.
edit: now it happens with the small emulator also. I guess its time to go to sleep...
 
Last edited:

derez

Expert
Licensed User
Longtime User
The disconnections happen to me when I use emulator ver. 2.2 (8), it doesn't happen with 2.1 emulator.

But when I use a 800x480 emulator, no matter if it is 160 or 240 dpi, the display is on the top left of the screen (Erel you wrote that it should automatically adjust) :confused: the layouts are for 320x480 and 480x320 only.
Moster67 wrote
I tried it on my HTC HD2 (480x800) in portrait and landscape mode. The layout scales and fits perfectly
So is it an emulator problem ?

If I have to create another layout (800x480), is there an easy way to put the views in the right place by some code (like multiplying the positions and size by a factor) but how do I code the layout ?

The dip addition to a number seems a very good idea, but the designer does not accept it in the position and size windows, so how is it to be used ? only by restating each view's numbers by code ?

Sorry for this flood of thoughts and questions, but this riddle troubles me...
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The disconnections that happen when loading a large layout file will be fixed in the next update.

I've checked the scaling and it works fine. See this image for example:

scale_example.png


The emulator dimensions are 800x480, scale = 1.5 (240 dpi). The layout scale is 1. So all values should be adjusted by a factor of 1.5.
The width and height are not relevant at this stage.

Button1 is part of the layout and you can see that its left property is 240. Still is appears at the center of the screen. The actual position is set to 240 * 1.5 = 360.

The large button without text is added programatically.
B4X:
Activity.AddView(b, 0dip, 0dip, 270dip, 270dip)
Again the values are automatically scaled because I used the 'dip' unit.
So 270dip is converted to 405 on this device and therefore it takes half of the screen. Without 'dip' it would have taken only a quarter of the screen.
 

agraham

Expert
Licensed User
Longtime User
But when I use a 800x480 emulator, no matter if it is 160 or 240 dpi, the display is on the top left of the screen (Erel you wrote that it should automatically adjust)
I had trouble understanding this because I was thinking it was more complicated than it actually is. The screen size is not used when scaling - it is only used to select the layout that best matches the current screen size and orientation.

Once a layout is selected the control sizes and positions specified in the layout file are adjusted according to both the Scale of the device screen (from GetDeviceLayoutValues) and the Scale stored in the layout. The factor used to adjust then is calculated as ActualDeviceScale/StoredLayoutScale and the values in the layout file are multiplied by this factor.
 

derez

Expert
Licensed User
Longtime User
I don't know what caused the problems that I mentioned, the size and position problem has disappeared when started again the avd manager and the IDE.

Disconnects are only when using 2.2 .
 
D

Deleted member 103

Guest
Hi derez,

I've tested your application on my HTC-Desire, running it very well, only the keys are slightly too small. Do you know why some keys are not displayed properly?

Ciao,
Filippo
 

derez

Expert
Licensed User
Longtime User
can you name the problems you see ? Its hard to see in the photo. Do I see some circles on the buttons ?

Anyway - it is far from a final product, I just wanted to see if I can translate a b4ppc application to android. I already included some improvements, like increasing the font size of the numbers and moving the message box up when not using complex numbers, but set it aside as I want to work on the GPS.
 
Last edited:

Cor

Active Member
Licensed User
Longtime User
PI_number and E_number must be replaced by cPi and ce

from version 90.03

grCor
 
D

Deleted member 103

Guest
Hi derez,

the problem is not the circles but the letters, they are not shown completely. The circles I've created yourself using Windows-Paint.
 

derez

Expert
Licensed User
Longtime User
I had to play with the size of the button and the font size, on my emulator it shows the whole letter but may be some keys still need more matching.
You can simply reduce the fontsize just to check if this is the reason.
 
Top