<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/date"
- android:layout_width="wrap_content"
+ android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="5"
android:gravity="center"
<TextView
android:id="@+id/location"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="0px"
android:gravity="center"
- android:layout_weight="1"
+ android:layout_weight="3"
android:textColor="#ff000000"
android:textSize="24sp"
android:text="location"
<TextView
android:id="@+id/phonecall"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="0px"
android:gravity="center"
- android:layout_weight="1"
+ android:layout_weight="3"
android:textColor="#ff000000"
android:textSize="24sp"
android:text="phonecall"
<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:textSize="24sp"
- android:text="timestamp"
+ android:textSize="18sp"
+ android:text="@string/lasttry"
/>
</LinearLayout>
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;
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();
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"));
}
}
}