Share My Creation SCalculator

This is my first real application with B4A, and for sure it is not well optimized and does not use the new capabilities of this SW, but it works.

It was written while thinking of my purchased device which is 7'' (and will only be here in two weeks :(), and the layout is too crowded for smaller devices - my appologies.
It has a layout for landscape but I didn't bother to save the calculations while rotating it.

I attach a user manual which describes a similar calculator in B4PPC, the layout is different but not the functionality.

I do want to get comments on the programming and to learn from them.

Edit: updated to ver. 2 - immune to rotation and with less bugs...
Edit: Version 2.3, It has a Macro (recording and playing of series of operations) and some more functions, but complex calculations were removed. Added VScalculator that fits phones showing vertical display, with operation manual. The functionality is the same in both applications.
Edit: ver 2.4 added. It uses beta 4.0 and the additions are borders and some animations.
 

Attachments

  • VS_operation.zip
    6.9 KB · Views: 616
  • Vscreen.png
    Vscreen.png
    83.2 KB · Views: 5,559
  • scalculator2.3.png
    scalculator2.3.png
    123.2 KB · Views: 749
  • VScalculator2.3.zip
    85.8 KB · Views: 679
  • VScalculator2.4.zip
    86.1 KB · Views: 779
  • Scalculator2.3.zip
    97.1 KB · Views: 622
Last edited:

dlfallen

Active Member
Licensed User
Longtime User
David, thanks for sharing this - it could be quite useful.

There is a bug in the conversion code. Converting 50 from F to C returns minus 17.778 (which is -32*(5/9)), and converting anything from C to F returns 32. Obviously the conversion program is using 0 for Disp(1). I changed Disp(1) to Rdisplay.Text in the calculation code and it returned (of course) the correct conversions.

A smaller issue: When first run, clicking on the large red C button at the top does not give focus to the Rdisplay box. Once used, the focus is given when the C button is clicked.
 

derez

Expert
Licensed User
Longtime User
Thanks for testing !
The display boxes, although I use edittext, are not meant to input numbers using keyboard, only by the buttons.
Thats why the focus is not relevant. Also when using buttons to input the data, disp(1) is getting the correct number and the conversions work fine. When you input 50 by keyboard it was still 0 for the program hence the result is -17...
 
Last edited:

dlfallen

Active Member
Licensed User
Longtime User
Thanks for the explanation, it was not obvious to me.

When I click on the EditText box the virtual keyboard pops up which suggests to the user that it's use is appropriate for input - an assumption that is reinforced when the keypresses appear in the EditText box. Perhaps you could inhibit the virtual keyboard from becoming active (or else support multiple input modes).

Thanks again for sharing this nifty program!
 

derez

Expert
Licensed User
Longtime User
Good idea !
I updated the file in the first post after changing the input type of the edittext views to NONE.
 

klaus

Expert
Licensed User
Longtime User
Even if you set the input type by NONE you still can enter characters (in the emulator, I don't have a device yet).
I would suggest you to replace the EditText views to Label views with Alpha=255 and a background color and rounded corners.

The Top value of the +/- button is wrong by 4 pixels.

You could also join all the AX button events to one single event by setting in the designer the Event Name parameter to a unique name for example btnA and name the subroutine Sub btnA_Click. Like:
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]btnA_Click[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Send [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]View[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New] Send=[/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sender[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] i=Send.Tag[/SIZE][/FONT]
 
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]'If ssound_flag = 1 Then Sound("Tick.wav")[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] input_flag = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] input_mode_handler([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New] NDisplay(i)[/FONT][/SIZE]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

And setting the Tag parameter to the numeric value of the buttons.

Best regards.
 

derez

Expert
Licensed User
Longtime User
Thank you Klaus, nice solution for the A buttons.
For the edittext - It works with the labels but doesn't look as good, so I'll keep it like it is.
I tried to disable the edittext, and it does not accept keystrokes anymore but it is colored by grey stripes so this is not possible.

I added Mediaplayer to sound the ticks but it sound them in a batch of 3 to 5 instead of one by one, so this is disabled. I'll try again with a real device.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I find that with Labels it doesn't look that bad.

I agree with you that with labels the text is too much on the left, so I added 2 empty characters at the beginnung of the text to the display.

Best regards.
 

Attachments

  • SCalcLabels.jpg
    SCalcLabels.jpg
    40.4 KB · Views: 491
  • SCalcEditText.jpg
    SCalcEditText.jpg
    43.4 KB · Views: 393

Cableguy

Expert
Licensed User
Longtime User
Thank you Klaus, nice solution for the A buttons.
For the edittext - It works with the labels but doesn't look as good, so I'll keep it like it is.
I tried to disable the edittext, and it does not accept keystrokes anymore but it is colored by grey stripes so this is not possible.

I added Mediaplayer to sound the ticks but it sound them in a batch of 3 to 5 instead of one by one, so this is disabled. I'll try again with a real device.

I can assure you that this is an emulator issue, on a device ut only "ticks" once, I had the same "glitch" with my soon to release pairs game...on the emulator it always have a time lag, and sounds in batches of 3...
 

derez

Expert
Licensed User
Longtime User
I can assure you that this is an emulator issue
Thanks Cableguy, this is good news :)

I find that with Labels it doesn't look that bad
Klaus, what I meant is that the background of the edittext is as if it is in a deeper level than the panel. So I copied this as a bitmap and used it for the label.
now I had to add the space in front but it is not simple because adding two blanks converts the content to a string and it affects the calculator operation, for example - the numbers do not show the dot and additional zero after it.
Is there a way to add these blanks as part of the properties of the label (like it does with text alignment) ?

Maybe it should be addressed to Erel as a bug. Erel - Please correct it or add the functionality !

The first post is updated with sound functionality.
 

Attachments

  • et.jpg
    et.jpg
    9.8 KB · Views: 331
Last edited:

derez

Expert
Licensed User
Longtime User
When writing text into labels, the text starts very close to the left edge of the label, unlike edittext which is about two characters to the right.
The result is that it doesn't look good in the calculator, and just adding blanks is not simple in this case.
 

derez

Expert
Licensed User
Longtime User
Changing the alignment to center works but it is not what I want.

See the attachment, the top display is a Label, below is edittext.
 

Attachments

  • label.jpg
    label.jpg
    39.7 KB · Views: 358

derez

Expert
Licensed User
Longtime User
Ver 2

Version 2 uploaded to the first post, immune to rotation and with less bugs...
 

derez

Expert
Licensed User
Longtime User
Version 2.3, It has a Macro (recording and playing of series of operations) and some more functions, but complex calculations were removed. Added VScalculator that fits phones showing vertical display, with operation manual. The functionality is the same in both applications.
 
Last edited:

Roger Daley

Well-Known Member
Licensed User
Longtime User
Derez you've done it again, looks really impressive.
I haven't had much time to look in detail, but as I have been trying to figure out how to "Macro record" for a couple of days I will be looking at your code with great interest. Always a great education.

It installed on an S5 OK but the emulator didn't it size very well. See attached jpg, sorry to be the messenger of bad news.
I will try it on a note3 tomorrow.

Thanks again for uploading the code.
Regards Roger
 

Attachments

  • VSCalc.jpg
    VSCalc.jpg
    44 KB · Views: 292

derez

Expert
Licensed User
Longtime User
It installed on an S5 OK but the emulator didn't it size very well
Strange, look what I have in S5 emulator:

Anyway the problem is only with the text size, try to play with cf variable in line 40 in size module to get it right, I'll check it on several devices tomorrow.
Can you write the device screen size and density ? I'm using Genymotion's emulator with 1920/1080.
Note 3 show the same correct image , even when I change the display size from 1920/1080 to 1280/800.
Edit: I made a change in size so it works better with small screens but not less than 240/400. Loaded to first post.
 

Attachments

  • upload_2014-12-1_21-56-49.png
    upload_2014-12-1_21-56-49.png
    60.1 KB · Views: 299
Last edited:

Roger Daley

Well-Known Member
Licensed User
Longtime User
The emulator is the default B4A out of the box. Details attached.
I had a similar problem and after playing around found the code in "Interim Calculator" posted on Test my app! somehow fixed the problem for all views by adjusting only the labels text size.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Portrait")
    Dim LBLcharwidth As Int
    Dim LBLTextScale As Double
    Canvas1.Initialize(Activity)   
    LBLcharwidth = Canvas1.MeasureStringWidth("9", Typeface.DEFAULT, lblABS.TextSize)
    LBLTextScale = (lblABS.Width / LBLcharwidth) / 5.625   
   
    ' Add-in to set padding on all views to zero and reset text size in Labels.
    For Each v As View In Activity.GetAllViewsRecursive
        If v Is Button Then
             Dim jo As JavaObject = v
             jo.RunMethod("setPadding", Array As Object(0, 0, 0, 0))
        End If
       If v Is EditText Then
             Dim jo As JavaObject = v
             jo.RunMethod("setPadding", Array As Object(0, 0, 0, 0))
       End If
       If v Is Label Then
             Dim jo As JavaObject = v
             jo.RunMethod("setPadding", Array As Object(0, 0, 0, 0))
             Dim lbl As Label = v
             Dim LBLTemp As Int
             LBLTemp = lbl.TextSize * LBLTextScale
             lbl.TextSize = LBLTemp
       End If
    Next
 

Attachments

  • Emulator1.jpg
    Emulator1.jpg
    176.1 KB · Views: 358

derez

Expert
Licensed User
Longtime User
Roger, you checked with 320/480 and I believe the real device is 1080/1920, but I have corrected the problem for small devices and it is in the first post.
For such a device the screen looks like the attached picture. It require a small decrease in the textsize of the red and yellow buttons on top, but I don't think anyone has such a small device so I don't bother to change.
 

Attachments

  • small.png
    small.png
    37.7 KB · Views: 294
Last edited:
Top