I'm trying to create an app that sends out a morse code by using the flash of my cell phone on android. With a timer I was able turn the flash on and off with certain intervals, but the user is unable to cancel the operation. Is there a way to implement this functionality? What class/function should I use to implement the waits between the led on/led offs?
Thanks in advance, Cédric
this is my current code to make the flash work
public void sendSOS()
{
t=new Timer();
//kort kort kort
t.schedule(new ShortFlash(),0);
t.schedule(new ShortFlash(),700);
t.schedule(new ShortFlash(),1400);
//lang lang lang
t.schedule(new LongFlash(),2400);
t.schedule(new LongFlash(),3600);
t.schedule(new LongFlash(),4800);
//kort kort kort
t.schedule(new ShortFlash(),6200);
t.schedule(new ShortFlash(),6900);
t.schedule(new ShortFlash(),7600);
}
class ShortFlash extends TimerTask
{
public void run()
{
cam=Camera.open();
Camera.Parameters params = cam.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
cam.setParameters(params);
cam.startPreview();
cam.autoFocus(new Camera.AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
android.os.SystemClock.sleep(500);
cam.stopPreview();
cam.release();
}
}
class LongFlash extends TimerTask
{
public void run()
{
cam=Camera.open();
Camera.Parameters params = cam.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
cam.setParameters(params);
cam.startPreview();
cam.autoFocus(new Camera.AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
android.os.SystemClock.sleep(1000);
cam.stopPreview();
cam.release();
}
}