]> www.average.org Git - WhereAmI.git/commitdiff
tweak layout
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 26 Jan 2012 16:52:24 +0000 (20:52 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 26 Jan 2012 16:52:24 +0000 (20:52 +0400)
res/layout/main.xml
res/values/strings.xml
src/org/average/whereami/WhereAmI.java

index f78b7468230d8ae869fc984ebc60ad6f8ed29b11..2a604b3760cc7dcc08d796547eb7c22563091bb7 100644 (file)
@@ -8,8 +8,8 @@
   <LinearLayout
     android:orientation="horizontal"
     android:layout_width="match_parent"
   <LinearLayout
     android:orientation="horizontal"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:layout_weight="1"
+    android:layout_height="0px"
+    android:layout_weight="2"
   >
     <TextView
       android:id="@+id/time"
   >
     <TextView
       android:id="@+id/time"
@@ -27,7 +27,7 @@
     />
     <TextView
       android:id="@+id/date"
     />
     <TextView
       android:id="@+id/date"
-      android:layout_width="wrap_content
+      android:layout_width="0px
       android:layout_height="match_parent" 
       android:layout_weight="5"
       android:gravity="center"
       android:layout_height="match_parent" 
       android:layout_weight="5"
       android:gravity="center"
@@ -43,9 +43,9 @@
   <TextView
     android:id="@+id/location"
     android:layout_width="match_parent" 
   <TextView
     android:id="@+id/location"
     android:layout_width="match_parent" 
-    android:layout_height="match_parent
+    android:layout_height="0px
     android:gravity="center"
     android:gravity="center"
-    android:layout_weight="1"
+    android:layout_weight="3"
     android:textColor="#ff000000"
     android:textSize="24sp"
     android:text="location"
     android:textColor="#ff000000"
     android:textSize="24sp"
     android:text="location"
@@ -58,9 +58,9 @@
   <TextView
     android:id="@+id/phonecall"
     android:layout_width="match_parent" 
   <TextView
     android:id="@+id/phonecall"
     android:layout_width="match_parent" 
-    android:layout_height="match_parent
+    android:layout_height="0px
     android:gravity="center"
     android:gravity="center"
-    android:layout_weight="1"
+    android:layout_weight="3"
     android:textColor="#ff000000"
     android:textSize="24sp"
     android:text="phonecall"
     android:textColor="#ff000000"
     android:textSize="24sp"
     android:text="phonecall"
   <TextView
     android:id="@+id/timestamp"
     android:layout_width="match_parent" 
   <TextView
     android:id="@+id/timestamp"
     android:layout_width="match_parent" 
-    android:layout_height="match_parent
+    android:layout_height="0px
     android:gravity="center"
     android:layout_weight="1"
     android:textColor="#ff000000"
     android:gravity="center"
     android:layout_weight="1"
     android:textColor="#ff000000"
-    android:textSize="24sp"
-    android:text="timestamp"
+    android:textSize="18sp"
+    android:text="@string/lasttry"
   />
 </LinearLayout>
 
   />
 </LinearLayout>
 
index e141891a4de960ec790d713dc94fe66d826c26c8..ba098c5f92c4bf2d16a3a71322aa524c23ffd497 100644 (file)
@@ -3,6 +3,7 @@
     <string name="app_name">WhereAmI</string>
     <string name="updating">Обновление...</string>
     <string name="failure">Неудача</string>
     <string name="app_name">WhereAmI</string>
     <string name="updating">Обновление...</string>
     <string name="failure">Неудача</string>
+    <string name="lasttry">Последнее обновление</string>
     <string-array name="month">
         <item>января</item>
         <item>февраля</item>
     <string-array name="month">
         <item>января</item>
         <item>февраля</item>
index 20812aa04ecabf6fcedc3d8f0ad87bc22307de7e..0f193cd71d3a13d8047f3ee6108c165ac034e45a 100644 (file)
@@ -15,7 +15,17 @@ import android.widget.TextView;
 
 public class WhereAmI extends Activity
 {
 
 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;
     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);
         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);
         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();
         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");
     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);
         }
     };
 
             mHandler.postDelayed(this, 10000);
         }
     };
 
-    private class TimedUpdateTask extends AsyncTask<Integer, Void, String> {
+    private class TimedUpdateTask extends AsyncTask<UpdateTarget, Void, String> {
+        private UpdateTarget ut;
        @Override
        @Override
-        protected String doInBackground(Integer... howlong) {
+        protected String doInBackground(UpdateTarget... whereto) {
             Log.v("TimedUpdateTask", "starting");
             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");
             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");
         }
     
        @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"));
         }
     }
 }
         }
     }
 }