<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:background="#ffffffff"
>
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ >
+ <TextView
+ android:id="@+id/time"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="2"
+ android:gravity="center"
+ android:textColor="#ff000000"
+ android:textSize="48sp"
+ />
+ <View
+ android:layout_width="3dp"
+ android:layout_height="match_parent"
+ android:background="#ff000000"
+ />
+ <TextView
+ android:id="@+id/date"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="5"
+ android:gravity="center"
+ android:textColor="#ff000000"
+ android:textSize="24sp"
+ />
+ </LinearLayout>
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="3dp"
+ android:background="#ff000000"
+ />
+ <TextView
+ android:id="@+id/location"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:layout_weight="1"
+ android:textColor="#ff000000"
+ android:textSize="24sp"
+ android:text="location"
+ />
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="3dp"
+ android:background="#ff000000"
+ />
+ <TextView
+ android:id="@+id/phonecall"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:layout_weight="1"
+ android:textColor="#ff000000"
+ android:textSize="24sp"
+ android:text="phonecall"
+ />
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="3dp"
+ android:background="#ff000000"
+ />
<TextView
- android:id="@+id/tv"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
+ android:id="@+id/timestamp"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:textColor="#ff000000"
+ android:textSize="24sp"
+ android:text="timestamp"
/>
</LinearLayout>
public class WhereAmI extends Activity
{
- private TextView tv;
+ private TextView tv, tvt, tvd;
private Resources res;
private String[] month;
private String[] wday;
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");
}
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<Integer, Void, String> {
@Override
protected String doInBackground(Integer... howlong) {
@Override
protected void onPostExecute(String str) {
Log.v("TimedUpdateTask", "callback executing");
- tv.setText(str);
+ tv.setText(R.string.failure);
}
}
}