X-Git-Url: http://www.average.org/gitweb/?p=WhereAmI.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fwhereami%2FWhereAmI.java;h=0f193cd71d3a13d8047f3ee6108c165ac034e45a;hp=20812aa04ecabf6fcedc3d8f0ad87bc22307de7e;hb=0d7962e1af14f0264b93d733f0ffff93082c9eab;hpb=ca6debb0783f0cd561b042df3dd0495654a4a503 diff --git a/src/org/average/whereami/WhereAmI.java b/src/org/average/whereami/WhereAmI.java index 20812aa..0f193cd 100644 --- a/src/org/average/whereami/WhereAmI.java +++ b/src/org/average/whereami/WhereAmI.java @@ -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 { + private class TimedUpdateTask extends AsyncTask { + 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")); } } }