1 package org.average.whereami;
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.os.AsyncTask;
6 import android.os.Handler;
7 import android.os.SystemClock;
8 import android.util.Log;
9 import android.view.View;
10 import android.view.Window;
11 import android.view.WindowManager;
12 import android.widget.TextView;
14 public class WhereAmI extends Activity
18 /** Called when the activity is first created. */
20 public void onCreate(Bundle savedInstanceState)
22 super.onCreate(savedInstanceState);
23 requestWindowFeature(Window.FEATURE_NO_TITLE);
24 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
25 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
26 setContentView(R.layout.main);
27 tv = (TextView)findViewById(R.id.tv);
28 Log.v("WhereAmI", "created UI, about to start update task");
29 mHandler.postDelayed(updateClock, 2000);
30 Log.v("WhereAmI", "created UI, update task created");
33 private Handler mHandler = new Handler();
35 private Runnable updateClock = new Runnable () {
37 long millis = System.currentTimeMillis();
38 Log.v("updateClock", "executing");
39 // new TimedUpdateTask().execute(5); // for delayed execution
40 tv.setText(Long.toString(millis));
41 mHandler.postDelayed(this, 2000);
45 private class TimedUpdateTask extends AsyncTask<Integer, Void, String> {
47 protected String doInBackground(Integer... howlong) {
48 Log.v("TimedUpdateTask", "starting");
50 Thread.sleep(1000 * howlong[0]);
51 } catch (InterruptedException e) {
52 Log.e("TimedUpdateTask", "sleep interrupted");
54 Log.v("TimedUpdateTask", "about to return");
55 return (Integer.toString(howlong[0]) + " seconds passed");
59 protected void onPostExecute(String str) {
60 Log.v("TimedUpdateTask", "callback executing");