time & date display; final layout
[WhereAmI.git] / src / org / average / whereami / WhereAmI.java
index f4403642a1a4b4d96380eea192e9c92f68da0a8b..20812aa04ecabf6fcedc3d8f0ad87bc22307de7e 100644 (file)
@@ -15,7 +15,7 @@ import android.widget.TextView;
 
 public class WhereAmI extends Activity
 {
-    private TextView tv;
+    private TextView tv, tvt, tvd;
     private Resources res;
     private String[] month;
     private String[] wday;
@@ -32,12 +32,13 @@ public class WhereAmI extends Activity
         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);
+        tv = (TextView)findViewById(R.id.location);
+        tvt = (TextView)findViewById(R.id.time);
+        tvd = (TextView)findViewById(R.id.date);
         Log.v("WhereAmI", "created UI, about to start update task");
-       mHandler.postDelayed(updateClock, 1000);
+       updateClock.run();
+       updateCal.run();
+       updateInfo.run();
         Log.v("WhereAmI", "created UI, update task created");
     }
 
@@ -48,23 +49,42 @@ public class WhereAmI extends Activity
             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(
+            tvt.setText(tm.format("%H:%M"));
+            tm.set(now + 60000);
+            tm.second=0;
+            long next = tm.toMillis(false);
+            mHandler.postDelayed(this, next-now+1);
+        }
+    };
+
+    private Runnable updateCal = new Runnable () {
+        public void run() {
+            long now = System.currentTimeMillis();
+            Time tm = new Time();
+            tm.set(now);
+            tvd.setText(
                        wday[tm.weekDay] +
-                       tm.format("%d ") +
+                       tm.format("\n%d ") +
                        month[tm.month] +
-                       tm.format(" %Y") +
-                       tm.format(", %H:%M%:%S"));
-            tm.second++;
+                       tm.format(" %Y"));
+            tm.set(now + 86400000);
+            tm.hour=0;
+            tm.minute=0;
+            tm.second=0;
             long next = tm.toMillis(false);
-            tv.append("\n" + Long.toString(next-now+1));
-            
-            // new TimedUpdateTask().execute(5); // for delayed execution
             mHandler.postDelayed(this, next-now+1);
         }
     };
 
+    private Runnable updateInfo = new Runnable () {
+        public void run() {
+            Log.v("updateInfo", "starting");
+            tv.setText(R.string.updating);
+            new TimedUpdateTask().execute(5); // for delayed execution
+            mHandler.postDelayed(this, 10000);
+        }
+    };
+
     private class TimedUpdateTask extends AsyncTask<Integer, Void, String> {
        @Override
         protected String doInBackground(Integer... howlong) {
@@ -81,7 +101,7 @@ public class WhereAmI extends Activity
        @Override
         protected void onPostExecute(String str) {
             Log.v("TimedUpdateTask", "callback executing");
-            tv.setText(str);
+            tv.setText(R.string.failure);
         }
     }
 }