Analog Clock with custom hands

bravotango

Member
Licensed User
Longtime User
I have just started with B4A and have been trying to make an analog clock with custom dial and hands. I have already created this in Eclipse but I have just run into a brick wall. The options seem so limited.

Playing with the AnalogClock example I was able to get the bitmap for the custom dial and second hand working but I see no way of doing the same with the hour and minute hands. Also the face of the standard clock persists over the custom dial.

Must confess that it is a mystery how Eclipse finds this method in the android API as it mysteriously happens in an xml file which produces hints as you type for example android:hand_minutes...... the hand_minute is one of the items that appear in a pop-up list, and I can find no reference in the SDK for hand_minute or hand_hour.

I can post the code if wanted but just tell me it's impossible guys and I will understand. Like I said it already works with Eclipse so it's not the end of the world.

Bazza
 

Attachments

  • ClockCapture.jpg
    ClockCapture.jpg
    21.2 KB · Views: 430

bravotango

Member
Licensed User
Longtime User
I told a lie. I just found a reference to the hands in a file in each of the platforms in the SDK. under data/res/values/attrs.xml and it includes the following:
<declare-styleable name="AnalogClock">
<attr name="dial" format="reference"/>
<attr name="hand_hour" format="reference"/>
<attr name="hand_minute" format="reference"/>
</declare-styleable>
 
Upvote 0

bravotango

Member
Licensed User
Longtime User
Almost but not quite!!

Managed to repeat the process for minute and hour hands and now have all hands working but still have the ugly face of the standard clock persisting. How to get rid of that is difficult.

LabelHour.Initialize("")
Activity.AddView(LabelHour,(ScnWidth-400)*.5,(ScnHeight-400)*.5,400,400)
LabelHour.BringToFront
bmpNeedleHour.Initialize(File.DirAssets,"clock_hours.png")

LabelMin.Initialize("")
Activity.AddView(LabelMin,(ScnWidth-400)*.5,(ScnHeight-400)*.5,400,400)
LabelMin.BringToFront
bmpNeedleMin.Initialize(File.DirAssets,"clock_minutes.png")

LabelSec.Initialize("")
Activity.AddView(LabelSec,(ScnWidth-400)*.5,(ScnHeight-400)*.5,400,400)
LabelSec.BringToFront
bmpNeedleSec.Initialize(File.DirAssets,"clock_seconds.png")
 
Upvote 0

bravotango

Member
Licensed User
Longtime User
Erel directed me to Klaus clock which is done completely with VB, bypassing the android clock. Klaus has already done what I was struggling with. I couldn't get rid of the standard clock dial but Klaus created his own, so this is progress. Thanks Klaus
 
Upvote 0
Top