B4A Library Digital Clock

Discussion in 'Additional libraries, classes and official updates' started by Johan Schoeman, Mar 30, 2019.

Similar threads

B4A Tutorial [java] Custom View with Designer Support (Java library)
B4A Library Clock-View
B4A Library ChatMessageView
B4A Library [B4X] SNTP class
B4A Library CameraKit
  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    A simple wrap for this Github project

    Sure you will figure it out. Posting:
    1. B4A sample project
    2. B4A library files (jar and xml - copy them to your additional library folder
    3. The java code (amended project and wrapper) - change it to your licking.

    Touch the clock to change the colors

    Sample B4A Code:
    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: DigitalClock
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #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.

    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 dc1 As DigitalClock
    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")
        
    Dim clkclr() As Int = Array As Int (Colors.Yellow, Colors.Green, Colors.Magenta, Colors.Cyan, Colors.Red)
        dc1.ClockColors = clkclr
        dc1.SelectedColorIndex = 
    0
        dc1.ClockTextColor = 
    Colors.White

    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub dc1_clock_touched(newcolor As Int)
        
    Log("newcolor = " & newcolor)
    End Sub
    1.png

    Library as it is at present:
    DigitalClock
    Author:
    Github: Damian Borecki, Wrapped by: Johan Schoeman
    Version: 1
    • DigitalClock
      Events:
      • clock_touched (newcolor As Int)
      Methods:
      • DesignerCreateView (base As anywheresoftware.b4a.objects.PanelWrapper, lw As anywheresoftware.b4a.objects.LabelWrapper, props As anywheresoftware.b4a.objects.collections.Map) As void
      • IsInitialized As boolean
      • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String) As void
      • BringToFront As void
      • SetLayout (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
      • SendToBack As void
      • SetVisibleAnimated (arg0 As int, arg1 As boolean) As void
      • RemoveView As void
      • Invalidate3 (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
      • Invalidate2 (arg0 As android.graphics.Rect) As void
      • SetColorAnimated (arg0 As int, arg1 As int, arg2 As int) As void
      • SetBackgroundImageNew (arg0 As android.graphics.Bitmap) As anywheresoftware.b4a.objects.drawable.BitmapDrawable
      • Invalidate As void
      • SetLayoutAnimated (arg0 As int, arg1 As int, arg2 As int, arg3 As int, arg4 As int) As void
      • RequestFocus As boolean
      Properties:
      • ClockTextColor As int [write only]
      • Left As int
      • Background As android.graphics.drawable.Drawable
      • Parent As java.lang.Object [read only]
      • Color As int [write only]
      • Enabled As boolean
      • ClockColors As int[] [write only]
      • Top As int
      • Visible As boolean
      • SelectedColorIndex As int [write only]
      • Padding As int[]
      • Height As int
      • Tag As java.lang.Object
      • Width As int
     

    Attached Files:

  2. rboeck

    rboeck Well-Known Member Licensed User

    I have problems with the integrated digital.ttf font - i get a java runtime exception: Font asset not found digital.ttf
    I see the font in the files folder, i get warning #15 - file digital.ttf is not used.
    i tried to load the font before it is used in loadlayout, but i find no way to help digital clock to use this font.
    Second question: is any kind of localisation integrated or to i have to change the java source for it?
    Thanks!
     
  3. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Have added a method so that you can set the TypeFace from within B4A
    Lib should show as V1.01. Download and copy attached jar and xml to your additional libs folder

    Code:
    Dim myfont As Typeface = Typeface.LoadFromAssets("digital.ttf")
       
    dc1.ClockTypeFace = myfont
    For second question - this is some of the code in the original project:
    Code:
    private int[] getDateTime(){

            //get date & time
            Calendar calendar = Calendar.getInstance(Locale.getDefault());
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
            int ss = calendar.get(Calendar.SECOND);
            int mm = calendar.get(Calendar.MINUTE);
            int hh = calendar.get(Calendar.HOUR_OF_DAY);

            int[] values = {year,month,day,day_of_week, hh, mm, ss 
    };
            return values;

        }

        private String getDayOfWeek(int day_of_week){
            switch(day_of_week){
                case Calendar.MONDAY:
                    return "MON";
                case Calendar.TUESDAY:
                    return "TUE";
                case Calendar.WEDNESDAY:
                    return "WED";
                case Calendar.THURSDAY:
                    return "THU";
                case Calendar.FRIDAY:
                    return "FRI";
                case Calendar.SATURDAY:
                    return "SAT";
                case Calendar.SUNDAY:
                    return "SUN";
            }

            return null;

        }
     

    Attached Files:

  4. rboeck

    rboeck Well-Known Member Licensed User

    Thanks for your work; i think my problems raised from the fact, that i wanted to implement this clock element in an kiosk mode app. Your demo is working now; when in try to use exactly the same code inside my kiosk mode tryout i get:
    So i think i have to remove the changes, that i made for kiosk mode on my mobile and try it further. If i find the source of the problem i will inform you further.
    Thanks!
     
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