andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

[ClockApps] - Countdown Timer and Stopwatch


 
       anddev.org - Android Development Community | Android Tutorials | Index -> Promote your Android Application
Author Message
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Sun Nov 23, 2008 1:07 am    Post subject: [ClockApps] - Countdown Timer and Stopwatch Reply with quote

Promoting my application, please let me know what you think.

Applications > Tools > Clock Apps.

I'm willing to show source if anyone is interested.



clockapps3.png
 Description:
Settings.
 Filesize:  31 KB
 Viewed:  7204 Time(s)

clockapps3.png



clockapps4.png
 Description:
Timer stopped, buttons enabled, hour column hidden.
 Filesize:  37.25 KB
 Viewed:  7204 Time(s)

clockapps4.png



clockapps2.png
 Description:
Stopwatch done, laps showing.
 Filesize:  27.81 KB
 Viewed:  7204 Time(s)

clockapps2.png



clockapps.png
 Description:
Timer running, buttons disabled, hour column showing.
 Filesize:  32.49 KB
 Viewed:  7204 Time(s)

clockapps.png




Last edited by noamwolf on Sun Dec 07, 2008 2:27 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
MrSnowflake
Moderator
Moderator


Joined: 16 Feb 2008
Posts: 1437
Location: Flanders, Belgium

PostPosted: Sun Nov 23, 2008 1:15 pm    Post subject: Reply with quote

Nice, there are always situations where you need such timers Smile.

How did you implement the shake to reset? Is running with it also shaking? (could I get your shake to reset code, maybe?)
Back to top
View user's profile Send private message
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Sun Nov 23, 2008 4:24 pm    Post subject: Reply with quote

So the shake to reset is actually kinda fragile at this moment. The threshold i set is kind of iffy and I intend to add it to the pref menu (as in, choose the shake to reset threshold: Light shake, just shake, hard shake).

Anyway the code is based off of the API's OS example for sensors, I pretty much copied it from there (I'm not on my dev box right now but I would be happy to send you the exact code if you still want it).

HTH
Back to top
View user's profile Send private message Visit poster's website
MrSnowflake
Moderator
Moderator


Joined: 16 Feb 2008
Posts: 1437
Location: Flanders, Belgium

PostPosted: Sun Nov 23, 2008 4:43 pm    Post subject: Reply with quote

Yeah, I'd like to see it.
Back to top
View user's profile Send private message
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Sun Nov 23, 2008 4:47 pm    Post subject: Reply with quote

Heres my listner, notice the threshold, the higher it is the lighter you have to shake the device.

Again this is not the best solution, but it works for now.

Also, remember that you have to register this listener.

Java:

private SensorListener sensorListener = new SensorListener() {
    public float accelerometer_shake_threshold = 50000;
    static final int ACCELEROMETER_FLOAT_TO_INT = 1024;

    public void onAccuracyChanged(int sensor, int accuracy) {
    }

    public void onSensorChanged(int sensor, float[] values) {
      synchronized (this) {
        if (sensor == SensorManager.SENSOR_ACCELEROMETER) {

          int ax = (int) (ACCELEROMETER_FLOAT_TO_INT * values[0]);
          int ay = (int) (ACCELEROMETER_FLOAT_TO_INT * values[1]);
          int az = (int) (ACCELEROMETER_FLOAT_TO_INT * values[2]);

          int len2 = (ax * ax + ay * ay + az * az) / 1000;

          if (len2 < accelerometer_shake_threshold) {
            clockAppsReset();
          }      
      }
    }

  };


Any comments/feedback would be greatly appreciated.
Back to top
View user's profile Send private message Visit poster's website
MrSnowflake
Moderator
Moderator


Joined: 16 Feb 2008
Posts: 1437
Location: Flanders, Belgium

PostPosted: Sun Nov 23, 2008 5:49 pm    Post subject: Reply with quote

Your code register a looong acceleration in 1 direction too as a shake, doesn't it?
Back to top
View user's profile Send private message
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Sun Nov 23, 2008 5:54 pm    Post subject: Reply with quote

Not sure I understand what you're asking. You can shake in any direction.
Back to top
View user's profile Send private message Visit poster's website
MrSnowflake
Moderator
Moderator


Joined: 16 Feb 2008
Posts: 1437
Location: Flanders, Belgium

PostPosted: Sun Nov 23, 2008 5:59 pm    Post subject: Reply with quote

But if you keep accelerating in 1 direction, it will also register as a shake, won't it?
Back to top
View user's profile Send private message
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Sun Nov 23, 2008 6:08 pm    Post subject: Reply with quote

ah i see what you're saying. Yes, probably. Any suggestions on how to fix it?
Back to top
View user's profile Send private message Visit poster's website
MrSnowflake
Moderator
Moderator


Joined: 16 Feb 2008
Posts: 1437
Location: Flanders, Belgium

PostPosted: Sun Nov 23, 2008 6:20 pm    Post subject: Reply with quote

No, that's why I wanted your code Very Happy
Back to top
View user's profile Send private message
infotechsailor
Once Poster
Once Poster


Joined: 02 Dec 2008
Posts: 1

PostPosted: Tue Dec 02, 2008 4:54 am    Post subject: Re: [ClockApps] - Countdown Timer and Stopwatch Reply with quote

noamwolf wrote:
Promoting my application, please let me know what you think.

Applications > Tools > Clock Apps.

I'm willing to show source if anyone is interested.



I'm interested in this code... I'm a Java and Android n00b... but I would like to implement a simple countdown timer in my application that can be set by the user the stop/started.

If you would like to help me with my app... I would appreciate it... just a learning experience for my first app...

Thanks!

--Josh B.
Back to top
View user's profile Send private message
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Tue Dec 02, 2008 6:09 am    Post subject: Reply with quote

Sure, i would be glad to help. Start off by looking at CountDownTimer http://code.google.com/android/reference/android/os/CountDownTimer.html

Try to figure it out, then if you have a specific question feel free to email me.
Back to top
View user's profile Send private message Visit poster's website
noamwolf
Junior Developer
Junior Developer


Joined: 23 Nov 2008
Posts: 13

PostPosted: Sat Dec 06, 2008 5:13 pm    Post subject: Version 1.0.16 is out Reply with quote

I put out an update that fixes some bugs that have been reported. Check it out and please rate and write a review Wink

Thanks!
Back to top
View user's profile Send private message Visit poster's website
wolfmankurd
Freshman
Freshman


Joined: 02 Jan 2010
Posts: 4

PostPosted: Sat Jan 02, 2010 11:26 pm    Post subject: Reply with quote

noamwolf wrote:
ah i see what you're saying. Yes, probably. Any suggestions on how to fix it?


This is dependant on a large absolute acceleration? A shake would have an overall movement of zero. So maybe checking for +ve acceleration followed by -ve acceleration, I don't know how this would be implemented. Cause I'm a n00b.
Back to top
View user's profile Send private message
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Promote your Android Application All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.