From: Eugene Crosser Date: Thu, 26 Jan 2012 12:38:48 +0000 (+0400) Subject: time & date display; final layout X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=ca6debb0783f0cd561b042df3dd0495654a4a503;p=WhereAmI.git time & date display; final layout --- diff --git a/res/layout/main.xml b/res/layout/main.xml index 58c56a2..f78b746 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -1,17 +1,84 @@ + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 09882c2..e141891 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,7 +1,8 @@ WhereAmI - Где это я?! + Обновление... + Неудача января февраля diff --git a/src/org/average/whereami/WhereAmI.java b/src/org/average/whereami/WhereAmI.java index f440364..20812aa 100644 --- a/src/org/average/whereami/WhereAmI.java +++ b/src/org/average/whereami/WhereAmI.java @@ -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 { @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); } } }