Share My Creation Swiss Railway Station Clock

Having played with some graphics I have programed the
Swiss Railway Station Clock just for fun.

Best regards.

EDIT: New version, program starts at following runs.

EDIT;
This example is a 'prototype'.
You find a much more professional version made by alfcen here Helvetia.

EDIT: 2012.12.05
Due to the fact that the Swiss Federal Railways own all rights in design etc. Robert Brenner was asked to remove his Helvetia program from Google Play that uses the basic code shared here.
So to not violate these rights I removed the program.
Apple has used the design of this clock in their last OS and the Swiss Federal Railways asked Apple for a license agreement which was signed a few months ago.
 
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Gruezi Klaus,

Beautiful smooth clock! Your source does not really look like just for fun, much more like serious, professional work.

Just two findings:

1. After Compile and Run, the app works as advertised, however, when I restart the app, the clock pointers won't move.

2. The scale does not accommodate hi-res screens. On my 640 x 960 device the clock spans just a quarter of the screen at the top left. Perhaps the keyword "Density" will compensate for that.

I haven't tried Andrewid's Analog Clock library yet, but wouldn't this perhaps simplify your code?

Nothing that diminishes your effort.

Cheers
Robert
 

agraham

Expert
Licensed User
Longtime User
Hi Robert - see you are back after a long silence.
I haven't tried Andrewid's Analog Clock library yet, but wouldn't this perhaps simplify your code?
No as you will see when you try it. Perhaps you have missed the unique feature, beside the distinctive design, of a Swiss railway clock. The second hand actually sweeps continuously making a full revolution in 58.5 seconds then pauses for 1.5seconds at 12 o'clock. This can't be achieved with any of the standard clocks.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hallo Robert,
Schön dass Du wieder da bist :) !!!
Nice to see you back :) !!!

When I wrote the program, some weeks, ago I didn't really care about the different screen resolutions. My first goal was to 'play' with the graphics functions and especially with DrawBitmapRotated testing it only with the emulator (don't have a device yet).

But I will look further to adapt it to match the different resolutions.

Just an explanation about the specialty of the second needle. The engineer and designer Hans Hilfiker designed this clock in 1943, he worked at that time for the Swiss Federal Railways. All station clocks at that time didn't have a second needle and got a synchronisation signal every minute. Hilfiker added the second needle driven by an independant motor. The speed acuracy was not precise enough to garantie one exact revolution in one minute. His solution was to make one revolution in about 58-59 seconds, then the needle was mechanically stopped to wait for the synchronisation impulse. Then the minute needle moved 1 step and the second needle was released. The clocks in the railway stations in Switzerland are still the same.

Best regards.
 

colin9876

Active Member
Licensed User
I think the other point Robert mentioned is worth investigating, i.e. program works fine on first RUN but not subsequently?
 
Last edited:

agraham

Expert
Licensed User
Longtime User
The reason it doesn't work after a rotation or being hidden is that
B4X:
SetTime(True)
TimerSec.Enabled=True
are within the FirstTime conditional check. When the Activity is rebuilt again these are not executed so the clock stays at 12.00 and is not enabled.

Timers should be disabled on Activity_Pause and re-enabled on Activity_Resume. The reason is that they may trigger when the Activity is not actually present and cause an error.

To keep the displayed time, if not the same as the system clock, correct you need to save the time in a Process Global on Pause and reset it on Resume having added the amount of time that has elapsed. You can do this by also saving Now as well as the clock time and calculating the elapsed time using Now when you resume.
 

klaus

Expert
Licensed User
Longtime User
I checked the first problem reported by Robert.
It is fixed in the first post.
I didn't really understand the signification of the FirstTime variable.
As agraham already wrote
SetTime(True)
TimerSec.Enabled=
True
were fired only if FirstTime = True.
At the second start FirstTime = False so the clock did not start.
The screen layouts have not yet been solved.

Best regards.
 

agraham

Expert
Licensed User
Longtime User
At the second start FirstTime = False
This is a misconception. There is no "second start" unless Android kills the whole process and it needs to be restarted in which case FirstTime will be true again. Android applications don't start, run and stop as they do in Windows Mobile. They start, pause and resume but may be stopped by the OS if it wants to. You need to think about how to persist data between Pause and Resume and whether to save it more permanently in case the application is killed and needs to be reastarted the next time the user wants it.

It is important to fully understand the Android Process and activities life cycle
 

alfcen

Well-Known Member
Licensed User
Longtime User
Andrew, Klaus, thanks a lot for your warm welcome. There is much to catch up with and I might post more questions than helpful information.

You created the app with the emulator? You have the patience of an oyster, Klaus. Now I do understand why scaling was not an option.

At first, I also stumbled helplessly over the FirstTime flag. We need to get used to the way the Android handles its processes. A big THANKS to Andrew for posting a comprehensive explanation.

Anyway, I successfully modified your code as Andrew suggested. It's really lovely now! Would make a most attractive gadget for the desktop screen, however, I believe this reqires Eclipse(?).

For a good reason the Swiss are the best in clock making :)

By the way, do you know ad hoc how to get an app into landscape mode? I compiled with Orientation set the Both, but without effect after turning the device. The device sensors are in good mood, though.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
By the way, do you know ad hoc how to get an app into landscape mode? I compiled with Orientation set the Both, but without effect after turning the device. The device sensors are in good mood, though.
By default the device should change the orientation when it is turn. The user can disable this effect in the device settings (don't remember where exactly).
 

agraham

Expert
Licensed User
Longtime User
Would make a most attractive gadget for the desktop screen, however, I believe this reqires Eclipse(?).
At the moment, however Erel indicates that widgets may be coming in the future. It's very early days for Basic4android - there's lots more to come

By the way, do you know ad hoc how to get an app into landscape mode? I compiled with Orientation set the Both, but without effect after turning the device.
It should just happen, even if you don't have an explicit landscape layout Basic4Android just tries with what it has got even if the result is bad.
 

alfcen

Well-Known Member
Licensed User
Longtime User
Erel, Andrew
I found the setting in the device. Works perfectly. Thanks so much!!!
 

copiloto

Member
Licensed User
Longtime User
Klaus,

I'm making a clock like yours, but I'm having too much problems with needles design. In your example, I have edited seconds needle using "paint" program from Win, only have coloured it, save changes and... now this needle go deleting all the matrix, deleting some parts of the other needles...

Please, how do you paint needles so that they can be one near other without deleting some parts?

Best regards.
 

klaus

Expert
Licensed User
Longtime User
The first points are:
1) The center of the needles must be the center of the bitmap.
2) All pixels other than the needle pixels must be transparent, png file !
As explained in the Beginner's Guide chapter 14.2.1 Drawing rotating bitmaps / Rotating needle.

Then there are different possibilities:
1) Like in the Swiss Railway Station Clock
- All bitmaps are redrawn each second directly onto the Activity.
- The clock bitmap and all needle bitmaps.
Instead of drawing onto the Activity you could also draw onto a Panel and show or hide this one according to your needs.

2) Use panels.
- one for the background, transparent or not, it could also be the Activity.
- one transparent panel for the hour needle
- one transparent panel for the minute needle
- one transparent panel for the second needle
and update the different panels when needed.
Update means erasing the current needle and draw the new one.

As updating 'only' every second is not that often, the first version works well. But depending on what you want to do in the mean time the second solution could be more efficient, but a little bit more complicated, need to differentiate the moments when updating the minutes and hours needles.

If you allow screen orientation change you need to manage the time during the orientaion change and update the needles in the new orientation.

Best regards.
 
Last edited:

copiloto

Member
Licensed User
Longtime User
From your post:

"2) All pixels other than the needle pixels must be transparent, png file !"

I think that is my mistake. Didn't know that posibility of .png files... I have been trying to find an option into Paint (Windows) without sucess. So, reading by internet, have discovered it's not possible using Paint... Yet, this type of archives seems to be able to make using Gimp (linux), so, I'll have to investigate Gimp program..


Thanks Klaus.

Best regards.
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi copiloto,
Perhaps in the past you or your friends have bought a scanner or a printer with a companion CD containing PhotoShop LE. This is just fine for working with transparent layers and save the work as (transparent) PNG.
I have prepared a ZIP with some transparent compass needles and clock hands and send you a PM with the download link, shortly.

Hallo Klaus,
You wrote, you are using panels for clock hands. I am using labels believing that they require less system resources than panels (or imageviews). Is that correct or doesn't it make any noticable difference?
 

alfcen

Well-Known Member
Licensed User
Longtime User
Thanks for your fast reply, Erel.
No difference... that's speaks for B4A :icon_clap:
 

copiloto

Member
Licensed User
Longtime User
Alfcen,

Thank you very much for your help&files. By the way, to paint the clock circle, I'm using a little trick I've invented to avoid aliasing largely which doesn't slow (working in background and after using activity.invalidate) graphic speed:

for a=0 to 360 step 0.5 (or less, depends of circle size)
canvas1.drawLine(centerx+radius*sin(a*cpi/180),centery+radius*cos(a*cpi/180,centerx+(radius+1)*sin(a*cpi/180),centery+(radius+1)*cos(a*cpi/180),...)
next

If circle is wider than 1, then first draw a circle of wished wide and after, I draw the routine above by the external and internal side.

Best regards.
 

Similar Threads

Top