瀏覽代碼

Add stats to places app

master
Chris Smith 14 年之前
父節點
當前提交
2390d637ee

二進制
code/PlacesDisplay/dist/PlacesDisplay.apk 查看文件


+ 19
- 3
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesDisplay.java 查看文件

@@ -31,6 +31,7 @@ import android.content.res.Resources;
31 31
 import android.database.Cursor;
32 32
 import android.net.Uri;
33 33
 import android.os.Bundle;
34
+import android.text.format.DateFormat;
34 35
 
35 36
 import com.flurry.android.FlurryAgent;
36 37
 import com.google.android.maps.GeoPoint;
@@ -39,6 +40,7 @@ import com.google.android.maps.MapView;
39 40
 import com.google.android.maps.Overlay;
40 41
 import com.google.android.maps.OverlayItem;
41 42
 
43
+import java.util.Date;
42 44
 import java.util.List;
43 45
 
44 46
 import uk.co.md87.android.common.ExceptionHandler;
@@ -103,22 +105,36 @@ public class PlacesDisplay extends MapActivity {
103 105
         List<Overlay> mapOverlays = mapView.getOverlays();
104 106
 
105 107
         final Cursor cursor = managedQuery(Place.CONTENT_URI,
106
-                new String[] { Place.LATITUDE, Place.LONGITUDE, Place.NAME },
108
+                new String[] { Place.LATITUDE, Place.LONGITUDE,
109
+                Place.NAME, Place.LAST_VISIT, Place.VISIT_COUNT },
107 110
                 null, null, null);
108 111
 
112
+        final java.text.DateFormat dateFormat = DateFormat.getDateFormat(this);
113
+        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(this);
114
+
109 115
         if (cursor.moveToFirst()) {
110 116
             final int latitudeColumn = cursor.getColumnIndex(Place.LATITUDE);
111 117
             final int longitudeColumn = cursor.getColumnIndex(Place.LONGITUDE);
112 118
             final int nameColumn = cursor.getColumnIndex(Place.NAME);
119
+            final int lastVisitColumn = cursor.getColumnIndex(Place.LAST_VISIT);
120
+            final int visitCountColumn = cursor.getColumnIndex(Place.VISIT_COUNT);
113 121
 
114 122
             do {
115 123
                 final double latitude = cursor.getDouble(latitudeColumn);
116 124
                 final double longitude = cursor.getDouble(longitudeColumn);
117 125
                 final String name = cursor.getString(nameColumn);
126
+                final long lastVisit = cursor.getLong(lastVisitColumn);
127
+                final int visitCount = cursor.getInt(visitCountColumn);
118 128
 
119
-                GeoPoint point = new GeoPoint((int) (latitude * 1000000),
129
+                final GeoPoint point = new GeoPoint((int) (latitude * 1000000),
120 130
                         (int) (longitude * 1000000));
121
-                OverlayItem overlayitem = new OverlayItem(point, name, "I'm in Mexico City!");
131
+
132
+                final Date date = new Date(lastVisit * 1000);
133
+
134
+                final OverlayItem overlayitem = new OverlayItem(point, name,
135
+                        "Visited " + visitCount + " time" + (visitCount == 1 ? "" : "s")
136
+                        + "\nLast visited on " + dateFormat.format(date)
137
+                        + " at " + timeFormat.format(date));
122 138
 
123 139
                 overlay.addOverlay(overlayitem);
124 140
             } while (cursor.moveToNext());

+ 2
- 1
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesItemisedOverlay.java 查看文件

@@ -59,7 +59,8 @@ public class PlacesItemisedOverlay extends ItemizedOverlay<OverlayItem> {
59 59
 
60 60
     @Override
61 61
     protected boolean onTap(int arg0) {
62
-        Toast.makeText(context, overlays.get(arg0).getTitle(), 5000).show();
62
+        Toast.makeText(context, overlays.get(arg0).getTitle() + "\n\n"
63
+                + overlays.get(arg0).getSnippet(), Toast.LENGTH_LONG).show();
63 64
         return true;
64 65
     }
65 66
 

Loading…
取消
儲存