import android.os.AsyncTask;
import android.os.Handler;
import android.os.SystemClock;
+import android.content.res.Resources;
+import android.text.format.Time;
import android.util.Log;
import android.view.View;
import android.view.Window;
public class WhereAmI extends Activity
{
private TextView tv;
+ private Resources res;
+ private String[] month;
+ private String[] wday;
/** Called when the activity is first created. */
@Override
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.main);
+ res = getResources();
+ month = res.getStringArray(R.array.month);
+ wday = res.getStringArray(R.array.wday);
+ Log.v("WhereAmI","month length " + Integer.toString(month.length));
+ Log.v("WhereAmI","wday length " + Integer.toString(wday.length));
tv = (TextView)findViewById(R.id.tv);
+ tv.setText(R.string.greet);
Log.v("WhereAmI", "created UI, about to start update task");
- mHandler.postDelayed(updateClock, 2000);
+ mHandler.postDelayed(updateClock, 1000);
Log.v("WhereAmI", "created UI, update task created");
}
private Runnable updateClock = new Runnable () {
public void run() {
- long millis = System.currentTimeMillis();
- Log.v("updateClock", "executing");
+ long now = System.currentTimeMillis();
+ Time tm = new Time();
+ tm.set(now);
+ Log.v("WhereAmI", "weekday is" + Integer.toString(tm.weekDay));
+ Log.v("WhereAmI", "month is" + Integer.toString(tm.month));
+ tv.setText(
+ wday[tm.weekDay] +
+ tm.format(", %d ") +
+ month[tm.month] +
+ tm.format(" %Y") +
+ tm.format(", %H:%M%:%S"));
+ tm.second++;
+ long next = tm.toMillis(false);
+ tv.append("\n" + Long.toString(next-now+1));
+
// new TimedUpdateTask().execute(5); // for delayed execution
- tv.setText(Long.toString(millis));
- mHandler.postDelayed(this, 2000);
+ mHandler.postDelayed(this, next-now+1);
}
};