Browse Source

Add stats to places app

master
Chris Smith 14 years ago
parent
commit
2390d637ee

BIN
code/PlacesDisplay/dist/PlacesDisplay.apk View File


+ 19
- 3
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesDisplay.java View File

31
 import android.database.Cursor;
31
 import android.database.Cursor;
32
 import android.net.Uri;
32
 import android.net.Uri;
33
 import android.os.Bundle;
33
 import android.os.Bundle;
34
+import android.text.format.DateFormat;
34
 
35
 
35
 import com.flurry.android.FlurryAgent;
36
 import com.flurry.android.FlurryAgent;
36
 import com.google.android.maps.GeoPoint;
37
 import com.google.android.maps.GeoPoint;
39
 import com.google.android.maps.Overlay;
40
 import com.google.android.maps.Overlay;
40
 import com.google.android.maps.OverlayItem;
41
 import com.google.android.maps.OverlayItem;
41
 
42
 
43
+import java.util.Date;
42
 import java.util.List;
44
 import java.util.List;
43
 
45
 
44
 import uk.co.md87.android.common.ExceptionHandler;
46
 import uk.co.md87.android.common.ExceptionHandler;
103
         List<Overlay> mapOverlays = mapView.getOverlays();
105
         List<Overlay> mapOverlays = mapView.getOverlays();
104
 
106
 
105
         final Cursor cursor = managedQuery(Place.CONTENT_URI,
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
                 null, null, null);
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
         if (cursor.moveToFirst()) {
115
         if (cursor.moveToFirst()) {
110
             final int latitudeColumn = cursor.getColumnIndex(Place.LATITUDE);
116
             final int latitudeColumn = cursor.getColumnIndex(Place.LATITUDE);
111
             final int longitudeColumn = cursor.getColumnIndex(Place.LONGITUDE);
117
             final int longitudeColumn = cursor.getColumnIndex(Place.LONGITUDE);
112
             final int nameColumn = cursor.getColumnIndex(Place.NAME);
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
             do {
122
             do {
115
                 final double latitude = cursor.getDouble(latitudeColumn);
123
                 final double latitude = cursor.getDouble(latitudeColumn);
116
                 final double longitude = cursor.getDouble(longitudeColumn);
124
                 final double longitude = cursor.getDouble(longitudeColumn);
117
                 final String name = cursor.getString(nameColumn);
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
                         (int) (longitude * 1000000));
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
                 overlay.addOverlay(overlayitem);
139
                 overlay.addOverlay(overlayitem);
124
             } while (cursor.moveToNext());
140
             } while (cursor.moveToNext());

+ 2
- 1
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesItemisedOverlay.java View File

59
 
59
 
60
     @Override
60
     @Override
61
     protected boolean onTap(int arg0) {
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
         return true;
64
         return true;
64
     }
65
     }
65
 
66
 

Loading…
Cancel
Save