package org.smblott.intentradio;

import android.os.AsyncTask;
import java.lang.Thread;

public abstract class Later extends AsyncTask<Integer, Void, Void>
{
   private static final int default_seconds = 120;
   private int seconds = default_seconds;
   private int then;

   Later(int secs)
   {
      super();
      seconds = 0 < secs ? secs : default_seconds;
      then = Counter.now();
   }

   Later()
      { this(default_seconds); }

   public abstract void later();

   protected Void doInBackground(Integer... args)
   {
      try { Thread.sleep(seconds * 1000); }
      catch ( Exception e ) { }
      return null;
   }

   protected void onPostExecute(Void ignored)
   {
      if ( ! isCancelled() && Counter.still(then) )
         later();
   }

   public AsyncTask<Integer,Void,Void> start()
      { return executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
}

@@ -266,16 +266,134 @@
  then;%0A%0A
+   // secs %3C  0: execute immediately%0A   // secs == 0: delay for default_seconds%0A   // otherwise: delay for secs%0A   //%0A
    Later
@@ -433,35 +433,40 @@
     
+if ( 
 sec
-ond
 s =
+=
  0 
-%3C secs ?
+)%0A        
  secs 
-:
+=
  def
@@ -479,16 +479,38 @@
 econds;%0A
+      seconds = secs;%0A
       th
@@ -680,16 +680,35 @@
    try %7B
+ if ( 0 %3C seconds )
  Thread.

Extend Later() API.