B4A Library Clock-View

A "partial" wrap for this Github Project. When I have some more time available I will try to add some more features.

Posting:
1. The B4A sample project (b4aClock.zip)
2. LibRes.zip - extract it and copy the LibRes folder with its contents to be on the same folder level as that of the /Objects and /Files folders of the B4A project.
3. The Java code (library and wrapper) - change it to your liking....
4. B4A lib files (ClockLibFiles.zip). Extract the jar and xml and copy them to your additional libs folder.

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

#AdditionalRes: ..\LibRes
#AdditionalJar: com.android.support:support-v4

#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 cv1 As ClockView
    Private cv2 As ClockView
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")
    
    cv1.BorderColor = Colors.LightGray
    cv1.ShowBorder = True
    
    cv1.ShowSecondsNeedle = True
    cv1.ShowSecondsProgress = True
    cv1.SecondsNeedleColor = Colors.Magenta
    cv1.SecondsProgressColor = Colors.Magenta
    
    cv1.ShowMinutesValues = True
    cv1.ShowMinutesProgress = True
    cv1.MinutesNeedleColor = Colors.Cyan
    cv1.MinutesProgressColor = Colors.Yellow   
    
    cv1.ShowHoursValues = True
    cv1.HoursValuesColor = Colors.Red
    cv1.HoursProgressColor = Colors.Yellow
    cv1.HoursNeedleColor = Colors.Red
    
    cv1.ShowCenter = True
    cv1.CenterOuterColor = Colors.White
    cv1.CenterInnerColor = Colors.Green

    
    cv1.ShowDegrees = True
    cv1.DegreesColor = Colors.Cyan
    
    'this can be cv1.DISPOSITION_ALTERNATE, cv1.DISPOSITION_REGULAR
    cv1.ClockValueDisposition = cv1.DISPOSITION_ALTERNATE
    
    'this can be cv1.DEGREE_TYPE_CIRCLE, cv1.DEGREE_TYPE_LINE, cv1.DEGREE_TYPE_SQUARE
    cv1.ClockDegreesType = cv1.DEGREE_TYPE_CIRCLE
    
    ' this can be cv1.DEGREE_STEP_QUARTER, cv1.DEGREE_STEP_FULL, or cv1.DEGREE_STEP_TWELVE
    cv1.ClockDegreeStep = cv1.DEGREE_STEP_FULL
    

    '2nd clock
    cv2.BorderColor = Colors.Yellow
    cv2.ShowBorder = True
    
    cv2.ShowSecondsNeedle = True
    cv2.ShowSecondsProgress = True
    cv2.SecondsNeedleColor = Colors.Blue
    cv2.SecondsProgressColor = Colors.Blue
    
    cv2.ShowMinutesValues = True
    cv2.ShowMinutesProgress = True
    cv2.MinutesNeedleColor = Colors.Cyan
    cv2.MinutesProgressColor = Colors.White
    
    cv2.ShowHoursValues = True
    cv2.HoursValuesColor = Colors.Yellow
    cv2.HoursProgressColor = Colors.Red
    cv2.HoursNeedleColor = Colors.Yellow
    
    cv2.ShowCenter = True
    cv2.CenterOuterColor = Colors.Green
    cv2.CenterInnerColor = Colors.White

    
    cv2.ShowDegrees = True
    cv2.DegreesColor = Colors.Red
    
    'this can be cv2.DISPOSITION_ALTERNATE, cv2.DISPOSITION_REGULAR
    cv2.ClockValueDisposition = cv2.DISPOSITION_REGULAR
    
    'this can be cv2.DEGREE_TYPE_CIRCLE, cv2.DEGREE_TYPE_LINE, cv2.DEGREE_TYPE_SQUARE
    cv2.ClockDegreesType = cv2.DEGREE_TYPE_LINE
    
    ' this can be cv2.DEGREE_STEP_QUARTER, cv2.DEGREE_STEP_FULL, or cv2.DEGREE_STEP_TWELVE
    cv2.ClockDegreeStep = cv2.DEGREE_STEP_QUARTER

    
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub






Clock
Version:
1
  • ClockView
    Fields:
    • DEGREE_TYPE_SQUARE As int
    • DISPOSITION_ALTERNATE As int
    • DEGREE_TYPE_CIRCLE As int
    • DEGREE_STEP_TWELVE As int
    • DISPOSITION_REGULAR As int
    • DEGREE_TYPE_LINE As int
    • DEGREE_STEP_QUARTER As int
    • DEGREE_STEP_FULL 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:
    • ShowSecondsProgress As boolean [write only]
    • Left As int
    • ClockValueStep As int [write only]
    • Parent As java.lang.Object [read only]
    • BorderColor As int [write only]
    • SecondsProgressFactor As float [write only]
    • HoursNeedleColor As int [write only]
    • ShowCenter As boolean [write only]
    • ClockDegreeStep As int [write only]
    • SecondsNeedleColor As int [write only]
    • HoursProgressColor As int [write only]
    • Visible As boolean
    • Padding As int[]
    • Height As int
    • ShowSecondsNeedle As boolean [write only]
    • Width As int
    • ShowBorder As boolean [write only]
    • HoursValuesColor As int [write only]
    • ClockValueDisposition As int [write only]
    • DegreesColor As int [write only]
    • Background As android.graphics.drawable.Drawable
    • ShowHoursProgress As boolean [write only]
    • Color As int [write only]
    • MinutesNeedleColor As int [write only]
    • MinutesValuesFactor As float [write only]
    • Enabled As boolean
    • CenterOuterColor As int [write only]
    • CenterInnerColor As int [write only]
    • ClockDegreesType As int [write only]
    • Top As int
    • MinutesProgressFactor As float [write only]
    • ShowMinutesValues As boolean [write only]
    • MinutesProgressColor As int [write only]
    • ShowHoursValues As boolean [write only]
    • Tag As java.lang.Object
    • ShowMinutesProgress As boolean [write only]
    • ClockBackground As int [write only]
    • SecondsProgressColor As int [write only]
    • ClockType As int [write only]
    • ShowDegrees As boolean [write only]

1.png
 

Attachments

  • LibRes.zip
    109.4 KB · Views: 139
  • ClockLibFiles.zip
    31.1 KB · Views: 137
  • b4aClock.zip
    9.5 KB · Views: 124
  • TheJavaCode.zip
    20.7 KB · Views: 114

Albert Kallal

Active Member
Licensed User
I do put the lib res here:
1609091428795.png

So I tried again. It DOES compile. First things first - the APK posted DOES work!


So lib res is being found. And original post DOES compile.

However, your last build post now spits out above (during the compile). (but I noticed you commented out these two lines:
B4X:
'#AdditionalRes: ..\libres
'#AdditionalJar: com.android.support:support-v4

(perhaps due to testing you by accident left above commented out)

If I include the Jar - it does compile.
If I un-commment addtonalRes, it now does NOT compile. I get this:

B4X:
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    Error
res\values\attrs.xml:7: error: Attribute "clock_type" already defined with incompatible format.
..\libres\values\attrs.xml:7: Original attribute defined here.
res\values\attrs.xml:38: error: Attribute "clock_value_type" already defined with incompatible format.
..\libres\values\attrs.xml:39: Original attribute defined here.
res\values\attrs.xml:44: error: Attribute "clock_value_disposition" already defined with incompatible format.
..\libres\values\attrs.xml:44: Original attribute defined here.
res\values\attrs.xml:49: error: Attribute "clock_value_step" already defined with incompatible format.
..\libres\values\attrs.xml:48: Original attribute defined here.

I should also point out that anytime I include or comment out the additional jar (or res), then I do a clean project - if you don't, then the last time you compile - the files stick around and you not notice your changes.


But the APK does run fine. If I comment out (thus include) the additional jar, then again it does compile. But now commenting out (include the res), then it does not compile - and we see attributes of clock_value seeming to be already defined.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Last edited:
Top