]> average.org Git - WhereAmI.git/commitdiff
time & date display; final layout
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 26 Jan 2012 12:38:48 +0000 (16:38 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 26 Jan 2012 12:38:48 +0000 (16:38 +0400)
res/layout/main.xml
res/values/strings.xml
src/org/average/whereami/WhereAmI.java

index 58c56a2043d09593fbb308c3d3cad62606aea905..f78b7468230d8ae869fc984ebc60ad6f8ed29b11 100644 (file)
@@ -1,17 +1,84 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
     android:background="#ffffffff"
 >
+  <LinearLayout
+    android:orientation="horizontal"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_weight="1"
+  >
+    <TextView
+      android:id="@+id/time"
+      android:layout_width="wrap_content" 
+      android:layout_height="match_parent" 
+      android:layout_weight="2"
+      android:gravity="center"
+      android:textColor="#ff000000"
+      android:textSize="48sp"
+    />
+    <View
+      android:layout_width="3dp"
+      android:layout_height="match_parent"
+      android:background="#ff000000"
+    />
+    <TextView
+      android:id="@+id/date"
+      android:layout_width="wrap_content" 
+      android:layout_height="match_parent" 
+      android:layout_weight="5"
+      android:gravity="center"
+      android:textColor="#ff000000"
+      android:textSize="24sp"
+    />
+  </LinearLayout>
+  <View
+    android:layout_width="match_parent"
+    android:layout_height="3dp"
+    android:background="#ff000000"
+  />
+  <TextView
+    android:id="@+id/location"
+    android:layout_width="match_parent" 
+    android:layout_height="match_parent" 
+    android:gravity="center"
+    android:layout_weight="1"
+    android:textColor="#ff000000"
+    android:textSize="24sp"
+    android:text="location"
+  />
+  <View
+    android:layout_width="match_parent"
+    android:layout_height="3dp"
+    android:background="#ff000000"
+  />
+  <TextView
+    android:id="@+id/phonecall"
+    android:layout_width="match_parent" 
+    android:layout_height="match_parent" 
+    android:gravity="center"
+    android:layout_weight="1"
+    android:textColor="#ff000000"
+    android:textSize="24sp"
+    android:text="phonecall"
+  />
+  <View
+    android:layout_width="match_parent"
+    android:layout_height="3dp"
+    android:background="#ff000000"
+  />
   <TextView
-    android:id="@+id/tv"
-    android:layout_width="fill_parent" 
-    android:layout_height="wrap_content" 
+    android:id="@+id/timestamp"
+    android:layout_width="match_parent" 
+    android:layout_height="match_parent" 
     android:gravity="center"
     android:layout_weight="1"
     android:textColor="#ff000000"
+    android:textSize="24sp"
+    android:text="timestamp"
   />
 </LinearLayout>
 
index 09882c2a58a7210637087cbf11a8eeee6d5a082c..e141891a4de960ec790d713dc94fe66d826c26c8 100644 (file)
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <string name="app_name">WhereAmI</string>
-    <string name="greet">Где это я?!</string>
+    <string name="updating">Обновление...</string>
+    <string name="failure">Неудача</string>
     <string-array name="month">
         <item>января</item>
         <item>февраля</item>
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);
         }
     }
 }