From 0d7962e1af14f0264b93d733f0ffff93082c9eab Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Thu, 26 Jan 2012 20:52:24 +0400 Subject: [PATCH] tweak layout --- res/layout/main.xml | 20 ++++++------ res/values/strings.xml | 1 + src/org/average/whereami/WhereAmI.java | 44 ++++++++++++++++++-------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/res/layout/main.xml b/res/layout/main.xml index f78b746..2a604b3 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -8,8 +8,8 @@ diff --git a/res/values/strings.xml b/res/values/strings.xml index e141891..ba098c5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3,6 +3,7 @@ WhereAmI Обновление... Неудача + Последнее обновление января февраля 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")); } } } -- 2.43.0