Showing posts with label Timer. Show all posts
Showing posts with label Timer. Show all posts

Wednesday, February 13, 2013

Talking Exposure Timer

Is simple talking count-down timer for Android. As title says purpose of it is to help taking pictures where long exposure is required and one can’t look at watch, for example in astrophotography. That is also main reason why user interface is black and red. So, according to my intentions primary users should be people who are doing astrophotography and manual tracking or barn door tracking.
User interface is simple and we got frequency of announcements and duration spinners at the top, start and cancel buttons in the middle and info text at the bottom. If text to speech engine fails to initialize, start button is disabled and appropriate info is displayed. If text to speech engine initializes it will use default language for phone. Cancel is not immediate but is applied on first delayed post, during next announcement of remaining time.
To use it select how frequently you want announcements and how long exposure should be, after delay of 10 seconds, common for DSLR cameras in remote shutter BULB mode, it starts talking and counting down. While count down lasts, application obtains wake lock, screen will go dim but will not go to “sleep”. It is compiled for and tested on Android 2.2 device LG-P500.
Signed APK is available for download from here https://docs.google.com/file/d/0B0cIChfVrJ7WbkhISE5ZdGdSdmM/edit?usp=sharing, download, copy to SD card and open in file manager to install.
Eclipse project is here https://docs.google.com/file/d/0B0cIChfVrJ7WaS1oRl9lTUJUNmc/edit?usp=sharing, download, import in Eclipse and build.


Sunday, February 10, 2013

Timer, not it is Handler.postDelayed

In previous post http://grumpyoldprogrammer.blogspot.com/2013/02/text-to-speech.html I managed to init TTS. Now with talkative Android I can go and implement countdown timer. Whole story with SoundPool and TTS was about I need tool to count for me exposure while I am doing manual tracking. Only that I won’t use Timer or CountDownTimer but ordinary Handler. I leave whole code from TTS how it is and change button onClick listener and add couple of variables. Those are new class variables:

private int counter = 60;
private Handler timer;
boolean timerRunning = false;
private Runnable timerTask = new Runnable() {
    public void run() {
        myTTS.speak(Integer.toString(counter), TextToSpeech.QUEUE_FLUSH, null);
        if (counter > 1) {
            counter-=5;
            timer.postDelayed(timerTask, 5000);
        } else {
            counter = 60;
            timerRunning = false;
        }
    }
};


For more elaborate application I would make counter and delay adjustable but now I like it simple. Don’t forget to create instance of Handler. Now new onClick method:

public void onClick(View v) {
    if (!timerRunning) {
        timerRunning = true;
        timer.post(timerTask);
    }
}


If we do not have active cycle, onClick will start new one. Runnable.run will ask TTS to read counter and decrease it for 5 what matches the second parameter in postDelayed and finally reposts self again using Handler. When counter is 0 we reset it back to 60 and clear flag so that onClick listener can be used again. On emulator execution of 60 seconds countdown takes about 60.3 seconds, so it is not very precise but also not unusable.