Android Tutorial [Newbie sample] Simple Timer Up & Down, Counter Up & Down.

drachmad

Member
Licensed User
This is only a simple example for newbie to learn Wheel algorithm.
For fully blown of wheels, see ClsWheel v 1.4 by Klaus.
There is no intention to make it an advance Stopwatch & Timer!
Advance Stopwatch and Timer apk can be download free from the web.

Demonstrate:
Using scrollview in a Wheel object (simplified).
Manipulate the scrollview native methods/properties using reflection.
Enable/disable scrollview from scrolling manually.
Use "smoothScrollTo" to simulate scrolling programmatically.
Trick: to look like scrolling continuously from bottom/top.
Displaying many variation of one class at once.
Non-modal dialog does not stop timer in Stopwatch/Timer while running.
Entry a new title
Displaying the lap result
or while displaying maximum object allowed.

The last position when going to sleep is save in variables in a service.
If accidentally the back button is pressed, the last postion can be recovered except the lap data.
If it is considered the data is critical, change the algotithm to save it in a file.
Like Statemanager but simpler.
Note: if using the TimeCounter.zip - Don't let stopwatch/timer running in the main activity if not used, it drains the battery although in sleep mode.
ClsActionBar 1.42 for the menu.

Sleep orange -> in sleep mode
Sleep green -> in keep awake
LongClick at the del button to delete.

Library used:
Reflection v 2.40 for Wheel simulation.
Phone v.2.10 for WakeState
IME v.1.05 for automatic hiding the keyboard

TimeCounter.zip - using phw.PartialLock
TimeCounterTD.zip - using TimeDifference (phw.PartialLock not used) see #3

Designed & Tested on Tab 7"
 

Attachments

Last edited:

drachmad

Member
Licensed User
Update to save the position

The last position when going to sleep or back button is pressed is save in variables in a service.
Can be in sleep mode or keep awake.

I apologize, there is still bug in the timer when sleeping.
If connected to the PC it is working correctly, but in stand alone the timer slow down.

Above bug already corrected. Added phw.PartialLock.
Better use reminder for long running timer (simple-task-reminder)
 
Last edited:

drachmad

Member
Licensed User
Update save method

In sleep mode the timer is turned off.
phw.PartialLock is not used.
On wake up the display is get from the last save value + time difference
I did not test for the precision! In my opinion there should be a delay.
 
Last edited:

merlin2049er

Well-Known Member
Licensed User
Cool, got to check this timer out. Can you use it to just display the minutes? I'd love to be able to stick a small up-counter in my app.
 

djveleno

Active Member
Licensed User
Hi dear, with Samsung Galaxy S3 the number into wheel counter are too large respect emulator (perfect), there is a method to change the sizes of numbers?
Thanks for all.
 
Top