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: 144
  • ClockLibFiles.zip
    31.1 KB · Views: 140
  • b4aClock.zip
    9.5 KB · Views: 128
  • TheJavaCode.zip
    20.7 KB · Views: 121

Johan Schoeman

Expert
Licensed User
B4A Version: 10.2
Java Version: 11
Parsing code. (0.01s)
Building folders structure. (0.01s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: ..\libres font
....maybe because you are using Java 11 and I am using Java 8
 

Johan Schoeman

Expert
Licensed User
I switched to java 8, the same error still there
Can you try to download and install this APK and see if it works?


It is the APK that were created when I compiled the B4A project (in the Objects folder of the B4A project)
 

Albert Kallal

Active Member
Licensed User
You don't have to do anything with the Java code. Only posted it in case someone wants to modify the library and recompile it into a new jar and xml. Have just tested it again on my device and all working fine.

Ah, very good (this is what I assumed - and it is beyond the call of duty to have included that Java code). (I feel much better - since that is exaclty what I assumed. But I also assumed that I was to modify that code to make this work.

What is inside your Files folder?

I not added or changed what the sample has. I see only the view "main.bal" layout (view) file.

I see/have this:
1608500288949.png

And inside of Files, there is as noted the main.bal layout:

1608500407109.png


I don't have anything else in that folder.

As I noted, the project does build. But we error out on 37 - this line:

B4X:
    Activity.LoadLayout("main")

And the error is as per above screen shot:
eg:

1608500536126.png


So, I was assuming that I had to modify the source to make this work.

I am using jdk-11.0.1. , build tools points to 30.0.2 (these are to my knowledge the defalults out of the box for B4A).

So, at least I am now on the right track. It obviously a build version/configuration issue in regards to my version of B4A.

I try pointing B4A to a previous version of the build tools, and see if that works.

(appreciate your follow-up). So, based on information so far, with the sample, as long as it compiles, sees the LibRes folder correctly (it does), then this should run.

Current libraries shows only 2 references:

1608501082274.png


So, as long as I grasp the idea here (I did not realize) that the given sample should run, then obviously work on my end to try some earlier versions of the SDK would be in order.

I honestly feed bad - since your instructions were clear - I just had to be 100% sure I should not need to modify this sample to run. S

Now that this assuming is clear, then I think this road comes down to trying a few different SDK's - I give this a try and see what happens.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 

Albert Kallal

Active Member
Licensed User
B4A 10.2
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>

Ok, manifest is this:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

It compiles - upon run I get this:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 34 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at JHS.Clock.main._activity_create(main.java:391)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at JHS.Clock.main.afterFirstLayout(main.java:105)
    at JHS.Clock.main.access$000(main.java:17)
    at JHS.Clock.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 18 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/res/ResourcesCompat;
    at com.arbelkilani.clock.Clock.init(Clock.java:217)
    at com.arbelkilani.clock.Clock.<init>(Clock.java:147)
    at clockviewwrapper.clockviewWrapper._initialize(clockviewWrapper.java:92)
    ... 21 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.res.ResourcesCompat" on path: DexPathList[[zip file "/data/app/JHS.Clock-PpRbu-9ogfWms7r8gkPQmg==/base.apk"],nativeLibraryDirectories=[/data/app/JHS.Clock-PpRbu-9ogfWms7r8gkPQmg==/lib/x86_64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 24 more
** Activity (main) Resume **

Looking at above? it looks like it can't find/resolve the external lib:
B4X:
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/res/ResourcesCompat;
    at com.arbelkilani.clock.Clock.init(Clock.java:217)

R
Albert
 

Johan Schoeman

Expert
Licensed User
Attached is the zipped B4A project (note that I have added the jar and xml to the /Files folder. Cut them (jar and xml) from this folder and paste them in your additional library folder). Have also attached LibRes.zip. Extract folder LibRes (with its contents) and copy the folder (LibRes) to be the same folder level of the B4A project's /Files and /Objects folders.
 

Attachments

  • LibRes.zip
    109.4 KB · Views: 58
  • b4aClock.zip
    188.3 KB · Views: 54

amidgeha

Active Member
Licensed User
B4A Version: 10.2
Java Version: 11
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: ..\libres font
 

Johan Schoeman

Expert
Licensed User
B4A Version: 10.2
Java Version: 11
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: ..\libres font
B4X:
B4A Version: 10.2
Java Version: 8
Parsing code.    (0.01s)
Building folders structure.    (0.02s)
Compiling code.    (0.11s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.73s)
Compiling generated Java code.    (3.14s)
Convert byte code - optimized dex.    (5.01s)
Packaging files.    (1.04s)
Copying libraries resources    (0.01s)
Signing package file (debug key).    (1.43s)
ZipAlign file.    (0.09s)
Installing file to device.    (5.91s)
    Device serial: RF8M70NF4RL
Completed successfully.
 

Johan Schoeman

Expert
Licensed User
B4X:
B4A Version: 10.2
Java Version: 8
Parsing code.    (0.01s)
Building folders structure.    (0.02s)
Compiling code.    (0.11s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.73s)
Compiling generated Java code.    (3.14s)
Convert byte code - optimized dex.    (5.01s)
Packaging files.    (1.04s)
Copying libraries resources    (0.01s)
Signing package file (debug key).    (1.43s)
ZipAlign file.    (0.09s)
Installing file to device.    (5.91s)
    Device serial: RF8M70NF4RL
Completed successfully.
Give 5 minutes - we will try a different approach.....
 

Johan Schoeman

Expert
Licensed User
B4A Version: 10.2
Java Version: 11
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: ..\libres font
See if this will compile correctly:
1. I have done away with the LibRes folder - the "font" and "values" folders are now in the B4A project's /Objects/res folder
2. When you have downloaded the attached B4A project and "unzipped" it you need to make sure that the properties of the files in the "font" and "values" foldes are set to READ ONLY before you compile the B4A project - else they will be deleted when you compile the B4A project

Let's try it and see is it works...
 

Attachments

  • b4aClock.zip
    297.3 KB · Views: 50

amidgeha

Active Member
Licensed User
B4A Version: 10.2
Java Version: 11
Parsing code. (0.01s)
Building folders structure. (0.01s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: res font

The font and values are read only and not deleted after compilation
 

Johan Schoeman

Expert
Licensed User
B4A Version: 10.2
Java Version: 11
Parsing code. (0.01s)
Building folders structure. (0.01s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: res font

The font and values are read only and not deleted after compilation

:( .....no idea....is it Java 11 (you) vs Java 8 (me) that is messing us around?
 

amidgeha

Active Member
Licensed User
:( .....no idea....is it Java 11 (you) vs Java 8 (me) that is messing us around?
I Switched to Java8
B4A Version: 10.2
Java Version: 8
Parsing code. (0.01s)
Building folders structure. (0.04s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: res font
 

Johan Schoeman

Expert
Licensed User
I Switched to Java8
B4A Version: 10.2
Java Version: 8
Parsing code. (0.01s)
Building folders structure. (0.04s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
invalid resource directory name: res font
Something very strange going on here....I now get the same error after all the "messing around"....after I moved it to the /Object/res folder and then back to the LibRes folder...

B4X:
B4A Version: 10.2
Java Version: 8
Parsing code.    (0.00s)
Building folders structure.    (0.05s)
Compiling code.    (0.06s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    Error
invalid resource directory name: ..\libres fonts
 

amidgeha

Active Member
Licensed User
Something very strange going on here....I now get the same error after all the "messing around"....after I moved it to the /Object/res folder and then back to the LibRes folder...

B4X:
B4A Version: 10.2
Java Version: 8
Parsing code.    (0.00s)
Building folders structure.    (0.05s)
Compiling code.    (0.06s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    Error
invalid resource directory name: ..\libres fonts
Sorry for the mess, like you said before @Erel should be able to help, I hope
 
Top