B4A Library TabDigit

Discussion in 'Additional libraries, classes and official updates' started by Johan Schoeman, Dec 8, 2016.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    A warp for this Github Project. I hope I have the code right in the B4A sample project....running a real time clock with the tab digits.

    Note the files in the /Objects/res/values folder of the B4A project. Make sure they are set to READ ONLY before you run the B4A project

    1.png

    Library:
    TabDigit
    Author:
    Github: Xenione, Wrapped by: Johan Schoeman
    Version: 1
    • TabDigit
      Fields:
      • ba As BA
      Methods:
      • BringToFront
      • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
      • Initialize (EventName As String)
      • Invalidate
      • Invalidate2 (arg0 As Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • RemoveView
      • RequestFocus As Boolean
      • SendToBack
      • SetBackgroundImage (arg0 As Bitmap)
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
      • elapsedTime (elapsedTime As Float)
      • start
      Properties:
      • Background As Drawable
      • BackgroundColor As Int [write only]
      • Char As Int [write only]
      • Chars() As Char [write only]
        Sets chars that are going to be displayed.
        Note: <b>That only one digit is allow per character.</b>
      • Color As Int [write only]
      • CornerSize As Int [write only]
      • DividerColor As Int [write only]
      • Enabled As Boolean
      • Height As Int
      • Left As Int
      • Padding As Int [write only]
      • Parent As Object [read only]
      • Tag As Object
      • TextColor As Int [write only]
      • TextSize As Int [write only]
      • Top As Int
      • Visible As Boolean
      • Width As Int

    Sample Code:
    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: b4aTabDigit
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: landscape
        
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim t As Timer

    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.


        
    Private tdsec1 As TabDigit
        
    Private tdsec10 As TabDigit
        
    Private tdmin1 As TabDigit
        
    Private tdmin10 As TabDigit
        
    Private tdhr1 As TabDigit
        
    Private tdhr10 As TabDigit
       
        
    Dim prevsec1 As Int
        
    Dim prevsec10 As Int
        
    Dim prevmin1 As Int
        
    Dim prevmin10 As Int
        
    Dim prevhr1 As Int
        
    Dim prevhr10 As Int       
       

    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("main")
        t.Initialize(
    "t"10)
       
        tdsec1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdsec10.Chars = 
    Array As Char("0""1""2""3""4""5")
        tdmin1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdmin10.Chars = 
    Array As Char("0""1""2""3""4""5")
        tdhr1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdhr10.Chars = 
    Array As Char("0""1""2")
       
        
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
        
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
        
    Dim second As Int = DateTime.GetSecond(DateTime.Now)
       
       
        tdsec1.Char = second 
    Mod 10
        tdsec10.Char = second - (second 
    Mod 10)
        tdsec1.TextSize = 
    250
        tdsec1.DividerColor = 
    Colors.Red
        tdsec1.Padding = 
    20
        tdsec1.TextColor = 
    Colors.Cyan
        tdsec1.BackgroundColor = 
    Colors.Gray
        prevsec1 = second 
    Mod 10
       
       
        tdsec10.Char = (second - (second 
    Mod 10))/10
        tdsec10.TextSize = 
    250
        tdsec10.DividerColor = 
    Colors.Red
        tdsec10.Padding = 
    20
        tdsec10.TextColor = 
    Colors.Cyan
        tdsec10.BackgroundColor = 
    Colors.Gray
        prevsec10 = (second - (second 
    Mod 10))/10    
       
        tdmin1.Char = minute 
    Mod 10
        tdmin10.Char = minute - (minute 
    Mod 10)
        tdmin1.TextSize = 
    250
        tdmin1.DividerColor = 
    Colors.Red
        tdmin1.Padding = 
    20
        tdmin1.TextColor = 
    Colors.Blue
        tdmin1.BackgroundColor = 
    Colors.white
        prevmin1 = minute 
    Mod 10
       

        tdmin10.Char = (minute - (minute 
    Mod 10))/10
        tdmin10.TextSize = 
    250
        tdmin10.DividerColor = 
    Colors.Red
        tdmin10.Padding = 
    20
        tdmin10.TextColor = 
    Colors.Blue
        tdmin10.BackgroundColor = 
    Colors.white   
        prevmin10 = (minute - (minute 
    Mod 10))/10        
       
        tdhr1.Char = hour 
    Mod 10
        tdhr10.Char = hour - (hour 
    Mod 10)
        tdhr1.TextSize = 
    250
        tdhr1.DividerColor = 
    Colors.Red
        tdhr1.Padding = 
    20
        tdhr1.TextColor = 
    Colors.Yellow
        tdhr1.BackgroundColor = 
    Colors.LightGray
        prevhr1 = hour 
    Mod 10
       
        tdhr10.Char = (hour - (hour 
    Mod 10))/10
        tdhr10.TextSize = 
    250
        tdhr10.DividerColor = 
    Colors.Red
        tdhr10.Padding = 
    20
        tdhr10.TextColor = 
    Colors.Yellow
        tdhr10.BackgroundColor = 
    Colors.LightGray
        prevhr10 = (hour - (hour 
    Mod 10))/10            
       
       
       

    End Sub

    Sub Activity_Resume
       
        t.Enabled = 
    True

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
       
        t.Enabled = 
    False

    End Sub

    Sub t_tick
       
        
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
        
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
        
    Dim second As Int = DateTime.GetSecond(DateTime.Now)
       
       
        
    If prevsec1 <> second Mod 10 Then
            tdsec1.start
            prevsec1 = second 
    Mod 10
        
    End If 

        
    If prevsec10 <> (second - (second Mod 10))/10 Then
            tdsec10.start
            prevsec10 = (second - (second 
    Mod 10))/10
        
    End If
       


        
    If prevmin1 <> minute Mod 10 Then
            tdmin1.start
            prevmin1 = minute 
    Mod 10
        
    End If 

        
    If prevmin10 <> (minute - (minute Mod 10))/10 Then
            tdmin10.start
            prevmin10 = (minute - (minute 
    Mod 10))/10
        
    End If   
       
       
       
        
    If prevhr1 <> hour Mod 10 Then
            tdhr1.start
            prevhr1 = hour 
    Mod 10
        
    End If 

        
    If prevhr10 <> (hour - (hour Mod 10))/10 Then
            tdhr10.start
            prevhr10 = (hour - (hour 
    Mod 10))/10
        
    End If       

       
    End Sub
     

    Attached Files:

  2. MarcoRome

    MarcoRome Expert Licensed User

    Good work Johan ...good work ;)
     
    Johan Schoeman likes this.
  3. Daniel-White

    Daniel-White Active Member Licensed User

    Nice one:D
     
    Johan Schoeman likes this.
  4. Widget

    Widget Well-Known Member Licensed User

    Does it also make the click and flip sounds of the leaf (number) falling down?
    Or is that for version 2? ;)
     
  5. Rantor777

    Rantor777 Member Licensed User

  6. Mashiane

    Mashiane Expert Licensed User

    Johan Schoeman likes this.
  7. Johan Schoeman

    Johan Schoeman Expert Licensed User

    This adds a "click" sound to it every time the "seconds" changes. No changes to the library. All done with inline Java code. You need to enable the JavaObject library in the B4A IDE Libraries Tab.

    Sample code:
    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: b4aTabDigit
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: landscape
        
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim t As Timer
       
        
    Dim nativeMe As JavaObject

    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.


        
    Private tdsec1 As TabDigit
        
    Private tdsec10 As TabDigit
        
    Private tdmin1 As TabDigit
        
    Private tdmin10 As TabDigit
        
    Private tdhr1 As TabDigit
        
    Private tdhr10 As TabDigit
       
        
    Dim prevsec1 As Int
        
    Dim prevsec10 As Int
        
    Dim prevmin1 As Int
        
    Dim prevmin10 As Int
        
    Dim prevhr1 As Int
        
    Dim prevhr10 As Int       
       

    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("main")
        nativeMe.InitializeContext
        t.Initialize(
    "t"10)
       
        tdsec1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdsec10.Chars = 
    Array As Char("0""1""2""3""4""5")
        tdmin1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdmin10.Chars = 
    Array As Char("0""1""2""3""4""5")
        tdhr1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdhr10.Chars = 
    Array As Char("0""1""2")
       
        
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
        
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
        
    Dim second As Int = DateTime.GetSecond(DateTime.Now)
       
       
        tdsec1.Char = second 
    Mod 10
        tdsec10.Char = second - (second 
    Mod 10)
        tdsec1.TextSize = 
    125
        tdsec1.DividerColor = 
    Colors.Red
        tdsec1.Padding = 
    20
        tdsec1.TextColor = 
    Colors.Cyan
        tdsec1.BackgroundColor = 
    Colors.Gray
        prevsec1 = second 
    Mod 10
       
       
        tdsec10.Char = (second - (second 
    Mod 10))/10
        tdsec10.TextSize = 
    125
        tdsec10.DividerColor = 
    Colors.Red
        tdsec10.Padding = 
    20
        tdsec10.TextColor = 
    Colors.Cyan
        tdsec10.BackgroundColor = 
    Colors.Gray
        prevsec10 = (second - (second 
    Mod 10))/10    
       
        tdmin1.Char = minute 
    Mod 10
        tdmin10.Char = minute - (minute 
    Mod 10)
        tdmin1.TextSize = 
    125
        tdmin1.DividerColor = 
    Colors.Red
        tdmin1.Padding = 
    20
        tdmin1.TextColor = 
    Colors.Blue
        tdmin1.BackgroundColor = 
    Colors.white
        prevmin1 = minute 
    Mod 10
       

        tdmin10.Char = (minute - (minute 
    Mod 10))/10
        tdmin10.TextSize = 
    125
        tdmin10.DividerColor = 
    Colors.Red
        tdmin10.Padding = 
    20
        tdmin10.TextColor = 
    Colors.Blue
        tdmin10.BackgroundColor = 
    Colors.white   
        prevmin10 = (minute - (minute 
    Mod 10))/10        
       
        tdhr1.Char = hour 
    Mod 10
        tdhr10.Char = hour - (hour 
    Mod 10)
        tdhr1.TextSize = 
    125
        tdhr1.DividerColor = 
    Colors.Red
        tdhr1.Padding = 
    20
        tdhr1.TextColor = 
    Colors.Yellow
        tdhr1.BackgroundColor = 
    Colors.LightGray
        prevhr1 = hour 
    Mod 10
       
        tdhr10.Char = (hour - (hour 
    Mod 10))/10
        tdhr10.TextSize = 
    125
        tdhr10.DividerColor = 
    Colors.Red
        tdhr10.Padding = 
    20
        tdhr10.TextColor = 
    Colors.Yellow
        tdhr10.BackgroundColor = 
    Colors.LightGray
        prevhr10 = (hour - (hour 
    Mod 10))/10            
       
       
       

    End Sub

    Sub Activity_Resume
       
        t.Enabled = 
    True

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
       
        t.Enabled = 
    False

    End Sub

    Sub t_tick
       

        
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
        
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
        
    Dim second As Int = DateTime.GetSecond(DateTime.Now)
       
       
        
    If prevsec1 <> second Mod 10 Then
            tdsec1.start
            nativeMe.RunMethod(
    "playTone"Null)
            prevsec1 = second 
    Mod 10
        
    End If 

        
    If prevsec10 <> (second - (second Mod 10))/10 Then
            tdsec10.start
            prevsec10 = (second - (second 
    Mod 10))/10
        
    End If
       


        
    If prevmin1 <> minute Mod 10 Then
            tdmin1.start
            prevmin1 = minute 
    Mod 10
        
    End If 

        
    If prevmin10 <> (minute - (minute Mod 10))/10 Then
            tdmin10.start
            prevmin10 = (minute - (minute 
    Mod 10))/10
        
    End If   
       
       
       
        
    If prevhr1 <> hour Mod 10 Then
            tdhr1.start
            prevhr1 = hour 
    Mod 10
        
    End If 

        
    If prevhr10 <> (hour - (hour Mod 10))/10 Then
            tdhr10.start
            prevhr10 = (hour - (hour 
    Mod 10))/10
        
    End If       

       
    End Sub

    #if Java

    import android.media.ToneGenerator;
    import android.media.AudioManager;
    import android.content.Context;
    import android.view.SoundEffectConstants;

    public void playTone() {
        AudioManager audioManager = (AudioManager) BA.applicationContext.getSystemService(Context.AUDIO_SERVICE);
        audioManager.playSoundEffect(SoundEffectConstants.CLICK);

    }

    #End If
     

    Attached Files:

    inakigarm, MarcoRome and Rantor777 like this.
  8. Rantor777

    Rantor777 Member Licensed User

    Perfect, was waiting for this! +100 ;)
     
  9. Rantor777

    Rantor777 Member Licensed User

  10. coslad

    coslad Well-Known Member Licensed User

    HI

    is it possible to use custom bitmap for the digit ?
     
  11. DonManfred

    DonManfred Expert Licensed User

    Based on the java code it is using a canvas which draw the Numbers.
     
    Johan Schoeman likes this.
  12. coslad

    coslad Well-Known Member Licensed User

  13. coslad

    coslad Well-Known Member Licensed User

    Hi

    i solved ! There was a script into design layout
     
    Johan Schoeman likes this.
  14. Pen & Papyrus

    Pen & Papyrus New Member Licensed User

  15. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Should be possible once I have added some code to the wrapper. Will do so sometime this week.
     
  16. Pen & Papyrus

    Pen & Papyrus New Member Licensed User

    That will be great! :)
     
    Johan Schoeman likes this.
  17. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Try with the attached library files (note that they are called TabDigitNew in the libs tab of the B4A IDE). Had to re-wrap the original github project as the project has changed quite a lot since I have first wrapped it. It can now change direction (but needs at least 500ms for animation to complete).

    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: b4aTabDigit
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: portrait
        
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim t As Timer
        
        
    Dim nativeMe As JavaObject

    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.


        
    Private tdsec1 As TabDigitNew
        
    Private tdsec10 As TabDigitNew
        
    Private tdmin1 As TabDigitNew
        
    Private tdmin10 As TabDigitNew
        
    Private tdhr1 As TabDigitNew
        
    Private tdhr10 As TabDigitNew
        
        
    Dim prevsec1 As Int
        
    Dim prevsec10 As Int
        
    Dim prevmin1 As Int
        
    Dim prevmin10 As Int
        
    Dim prevhr1 As Int
        
    Dim prevhr10 As Int   
        
        
    Dim aw As Int
        
    Dim ah As Int   
        
        
    Dim sec1direction, sec10direction, min1direction, min10direction, hr1direction, hr10direction As Boolean = False
            

    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("main")
        nativeMe.InitializeContext
        t.Initialize(
    "t"10)
        
        tdsec1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdsec10.Chars = 
    Array As Char("0""1""2""3""4""5")
        tdmin1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdmin10.Chars = 
    Array As Char("0""1""2""3""4""5")
        tdhr1.Chars = 
    Array As Char("0""1""2""3""4""5""6""7""8""9")
        tdhr10.Chars = 
    Array As Char("0""1""2")
        
        
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
        
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
        
    Dim second As Int = DateTime.GetSecond(DateTime.Now)
        
        
        tdsec1.Char = second 
    Mod 10
        tdsec10.Char = second - (second 
    Mod 10)
        tdsec1.TextSize = 
    100
        tdsec1.DividerColor = 
    Colors.Red
        tdsec1.Padding = 
    30
        tdsec1.TextColor = 
    Colors.Cyan
        tdsec1.BackgroundColor = 
    Colors.Gray
        prevsec1 = second 
    Mod 10
        
        
        tdsec10.Char = (second - (second 
    Mod 10))/10
        tdsec10.TextSize = 
    100
        tdsec10.DividerColor = 
    Colors.Red
        tdsec10.Padding = 
    30
        tdsec10.TextColor = 
    Colors.Cyan
        tdsec10.BackgroundColor = 
    Colors.Gray
        prevsec10 = (second - (second 
    Mod 10))/10     
        
        tdmin1.Char = minute 
    Mod 10
        tdmin10.Char = minute - (minute 
    Mod 10)
        tdmin1.TextSize = 
    100
        tdmin1.DividerColor = 
    Colors.Red
        tdmin1.Padding = 
    30
        tdmin1.TextColor = 
    Colors.Blue
        tdmin1.BackgroundColor = 
    Colors.white
        prevmin1 = minute 
    Mod 10
        

        tdmin10.Char = (minute - (minute 
    Mod 10))/10
        tdmin10.TextSize = 
    100
        tdmin10.DividerColor = 
    Colors.Red
        tdmin10.Padding = 
    30
        tdmin10.TextColor = 
    Colors.Blue
        tdmin10.BackgroundColor = 
    Colors.white   
        prevmin10 = (minute - (minute 
    Mod 10))/10         
        
        tdhr1.Char = hour 
    Mod 10
        tdhr10.Char = hour - (hour 
    Mod 10)
        tdhr1.TextSize = 
    100
        tdhr1.DividerColor = 
    Colors.Red
        tdhr1.Padding = 
    30
        tdhr1.TextColor = 
    Colors.Yellow
        tdhr1.BackgroundColor = 
    Colors.LightGray
        prevhr1 = hour 
    Mod 10
        
        tdhr10.Char = (hour - (hour 
    Mod 10))/10
        tdhr10.TextSize = 
    100
        tdhr10.DividerColor = 
    Colors.Red
        tdhr10.Padding = 
    30
        tdhr10.TextColor = 
    Colors.Yellow
        tdhr10.BackgroundColor = 
    Colors.LightGray
        prevhr10 = (hour - (hour 
    Mod 10))/10             
        
        
        

    End Sub

    Sub Activity_Resume
        
        t.Enabled = 
    True

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        
        t.Enabled = 
    False

    End Sub

    Sub t_tick
        

        
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
        
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
        
    Dim second As Int = DateTime.GetSecond(DateTime.Now)
        
        
        
    If prevsec1 <> second Mod 10 Then
            sec1direction = 
    Not(sec1direction)
            tdsec1.ChangeDirection = sec1direction
            tdsec1.start
            prevsec1 = second 
    Mod 10
        
    End If 

        
    If prevsec10 <> (second - (second Mod 10))/10 Then
            sec10direction = 
    Not(sec10direction)
            tdsec10.ChangeDirection = sec10direction
            tdsec10.start
            prevsec10 = (second - (second 
    Mod 10))/10
        
    End If
        


        
    If prevmin1 <> minute Mod 10 Then
            min1direction = 
    Not(min1direction)
            tdmin1.ChangeDirection = min1direction
            tdmin1.start
            prevmin1 = minute 
    Mod 10
        
    End If 

        
    If prevmin10 <> (minute - (minute Mod 10))/10 Then
            min10direction = 
    Not(min10direction)
            tdmin10.ChangeDirection = min10direction
            tdmin10.start
            prevmin10 = (minute - (minute 
    Mod 10))/10
        
    End If   
        
        
        
        
    If prevhr1 <> hour Mod 10 Then
            hr1direction = 
    Not(hr1direction)
            tdhr1.ChangeDirection = hr1direction
            tdhr1.start
            prevhr1 = hour 
    Mod 10
        
    End If 

        
    If prevhr10 <> (hour - (hour Mod 10))/10 Then
            hr10direction = 
    Not(hr10direction)
            tdhr10.ChangeDirection = hr10direction
            tdhr10.start
            prevhr10 = (hour - (hour 
    Mod 10))/10
        
    End If       

        
    End Sub
     

    Attached Files:

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice