]> www.average.org Git - WhereAmI.git/blobdiff - src/org/average/whereami/WhereAmI.java
tweak layout
[WhereAmI.git] / src / org / average / whereami / WhereAmI.java
index 20812aa04ecabf6fcedc3d8f0ad87bc22307de7e..0f193cd71d3a13d8047f3ee6108c165ac034e45a 100644 (file)
@@ -15,7 +15,17 @@ import android.widget.TextView;
 
 public class WhereAmI extends Activity
 {
-    private TextView tv, tvt, tvd;
+    private class UpdateTarget {
+        public TextView tv;
+        public Integer updater; // will be the function/object
+        public UpdateTarget(TextView tv, Integer updater) {
+           this.tv = tv;
+           this.updater = updater;
+        }
+    }
+    private UpdateTarget[] ut;
+
+    private TextView tvt, tvd, tvs;
     private Resources res;
     private String[] month;
     private String[] wday;
@@ -32,9 +42,13 @@ public class WhereAmI extends Activity
         res = getResources();
         month = res.getStringArray(R.array.month);
         wday = res.getStringArray(R.array.wday);
-        tv = (TextView)findViewById(R.id.location);
         tvt = (TextView)findViewById(R.id.time);
         tvd = (TextView)findViewById(R.id.date);
+        tvs = (TextView)findViewById(R.id.timestamp);
+       ut = new UpdateTarget[] {
+            new UpdateTarget((TextView)findViewById(R.id.location),  1),
+            new UpdateTarget((TextView)findViewById(R.id.phonecall), 2)
+        };
         Log.v("WhereAmI", "created UI, about to start update task");
        updateClock.run();
        updateCal.run();
@@ -79,29 +93,33 @@ public class WhereAmI extends Activity
     private Runnable updateInfo = new Runnable () {
         public void run() {
             Log.v("updateInfo", "starting");
-            tv.setText(R.string.updating);
-            new TimedUpdateTask().execute(5); // for delayed execution
+            for (int i = 0; i < ut.length; i++) {
+                ut[i].tv.setText(R.string.updating);
+                new TimedUpdateTask().execute(ut[i]);
+            }
             mHandler.postDelayed(this, 10000);
         }
     };
 
-    private class TimedUpdateTask extends AsyncTask<Integer, Void, String> {
+    private class TimedUpdateTask extends AsyncTask<UpdateTarget, Void, String> {
+        private UpdateTarget ut;
        @Override
-        protected String doInBackground(Integer... howlong) {
+        protected String doInBackground(UpdateTarget... whereto) {
             Log.v("TimedUpdateTask", "starting");
-            try {
-                Thread.sleep(1000 * howlong[0]);
-            } catch (InterruptedException e) {
-                Log.e("TimedUpdateTask", "sleep interrupted");
-            }
+            ut = whereto[0];
+            SystemClock.sleep(5000); // real job do be done here
             Log.v("TimedUpdateTask", "about to return");
-            return (Integer.toString(howlong[0]) + " seconds passed");
+            return "5 seconds passed";
         }
     
        @Override
         protected void onPostExecute(String str) {
             Log.v("TimedUpdateTask", "callback executing");
-            tv.setText(R.string.failure);
+            ut.tv.setText(str);
+            Time tm = new Time();
+            tm.setToNow();
+            tvs.setText(R.string.lasttry);
+            tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
         }
     }
 }