Przeglądaj źródła

Add ContextAPI

master
Chris Smith 14 lat temu
rodzic
commit
2ff8ffebec

+ 128
- 0
code/API/ContextApi.java Wyświetl plik

@@ -0,0 +1,128 @@
1
+/*
2
+ * Copyright (c) 2009-2010 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.android.contextapi;
24
+
25
+import android.net.Uri;
26
+
27
+/**
28
+ * Provides access to constants used to access the exported API of the Context
29
+ * Analyser.
30
+ *
31
+ * @author chris
32
+ */
33
+public class ContextApi {
34
+
35
+    public static class Intents {
36
+        public static final String ACTIVITY_CHANGED
37
+                = "uk.co.md87.android.contextanalyser.ACTIVITY_CHANGED";
38
+        public static final String CONTEXT_CHANGED
39
+                = "uk.co.md87.android.contextanalyser.CONTEXT_CHANGED";
40
+        public static final String PREDICTION_AVAILABLE
41
+                = "uk.co.md87.android.contextanalyser.PREDICTION_AVAILABLE";
42
+
43
+        public static class ContextTypes {
44
+            public static final int PLACE = 1;
45
+        }
46
+    }
47
+
48
+    public static class Places {
49
+
50
+        public static final Uri CONTENT_URI = Uri.parse("content://uk.co.md87"
51
+            + ".android.contextanalyser.placescontentprovider/places");
52
+        
53
+        public static final String CONTENT_TYPE = "vnd.contextanalyser.location";
54
+
55
+        public static class ColumnNames {
56
+            public static final String _ID = "_id";
57
+            public static final String NAME = "name";
58
+            public static final String LATITUDE = "lat";
59
+            public static final String LONGITUDE = "lon";
60
+            public static final String DURATION = "duration";
61
+            public static final String VISIT_COUNT = "times";
62
+            public static final String LAST_VISIT = "lastvisit";
63
+        }
64
+
65
+    }
66
+
67
+    public static class Journeys {
68
+
69
+        public static final Uri CONTENT_URI = Uri.parse("content://uk.co.md87"
70
+                + ".android.contextanalyser.journeyscontentprovider/journeys");
71
+
72
+        public static final String CONTENT_TYPE = "vnd.contextanalyser.journey";
73
+
74
+        public static class ColumnNames {
75
+            public static final String _ID = "_id";
76
+            public static final String START = "start";
77
+            public static final String END = "end";
78
+            public static final String STEPS = "steps";
79
+            public static final String NUMBER = "number";
80
+        }
81
+
82
+    }
83
+
84
+    public static class JourneySteps {
85
+
86
+        public static final Uri CONTENT_URI = Uri.parse("content://uk.co.md87"
87
+                + ".android.contextanalyser.journeyscontentprovider/steps");
88
+
89
+        public static final String CONTENT_TYPE = "vnd.contextanalyser.journeystep";
90
+
91
+        public static class ColumnNames {
92
+            public static final String _ID = "_id";
93
+            public static final String ACTIVITY = "activity";
94
+            public static final String REPETITIONS = "repetitions";
95
+            public static final String JOURNEY = "journey";
96
+            public static final String NEXT = "next";
97
+        }
98
+
99
+    }
100
+
101
+    public static class Predictions {
102
+
103
+        public static final Uri CONTENT_URI = Uri.parse("content://uk.co.md87"
104
+                + ".android.contextanalyser.predictionscontentprovider/destination");
105
+
106
+        public static final String CONTENT_TYPE = "vnd.contextanalyser.prediction";
107
+
108
+        public static class ColumnNames {
109
+            public static final String _ID = "_id";
110
+            public static final String PLACE = "place";
111
+            public static final String COUNT = "count";
112
+        }
113
+
114
+    }
115
+
116
+    public static class Activities {
117
+
118
+        public static final Uri CONTENT_URI = Uri.parse("content://uk.co.md87"
119
+                + ".android.contextanalyser.activitiescontentprovider/current");
120
+
121
+        public static final String CONTENT_TYPE = "vnd.contextanalyser.activity";
122
+
123
+        public static class ColumnNames {
124
+            public static final String ACTIVITY = "activity";
125
+        }
126
+    }
127
+
128
+}

+ 8
- 6
code/LocalePlugin/src/uk/co/md87/android/contextanalyser/locale/Receiver.java Wyświetl plik

@@ -26,9 +26,11 @@ import android.content.BroadcastReceiver;
26 26
 import android.content.Context;
27 27
 import android.content.Intent;
28 28
 import android.database.Cursor;
29
-import android.net.Uri;
30 29
 import android.os.Bundle;
31 30
 
31
+import uk.co.md87.android.contextapi.ContextApi.Activities;
32
+import uk.co.md87.android.contextapi.ContextApi.Intents;
33
+
32 34
 /**
33 35
  * Receives broadcast intents from Locale and the Context Analyser.
34 36
  *
@@ -46,12 +48,12 @@ public class Receiver extends BroadcastReceiver {
46 48
             }
47 49
 
48 50
             final Cursor cursor = context.getContentResolver().query(
49
-                    Uri.parse("content://uk.co.md87.android.contextanalyser."
50
-                    + "activitiescontentprovider/current"),
51
-                    new String[] { "activity" }, null, null, null);
51
+                    Activities.CONTENT_URI,
52
+                    new String[] { Activities.ColumnNames.ACTIVITY }, null, null, null);
52 53
 
53 54
             if (cursor.moveToFirst()) {
54
-                final String activity = cursor.getString(cursor.getColumnIndex("activity"));
55
+                final String activity = cursor.getString(
56
+                        cursor.getColumnIndex(Activities.ColumnNames.ACTIVITY));
55 57
 
56 58
                 if (activity.equals(bundle.getString("activity"))) {
57 59
                     setResultCode(com.twofortyfouram.Intent.RESULT_CONDITION_SATISFIED);
@@ -61,7 +63,7 @@ public class Receiver extends BroadcastReceiver {
61 63
             } else {
62 64
                 setResultCode(com.twofortyfouram.Intent.RESULT_CONDITION_UNKNOWN);
63 65
             }
64
-        } else if ("uk.co.md87.android.contextanalyser.ACTIVITY_CHANGED".equals(intent.getAction())) {
66
+        } else if (Intents.ACTIVITY_CHANGED.equals(intent.getAction())) {
65 67
             final Intent broadcast = new Intent(com.twofortyfouram.Intent.ACTION_REQUEST_QUERY);
66 68
             broadcast.putExtra(com.twofortyfouram.Intent.EXTRA_ACTIVITY, EditActivity.class.getName());
67 69
             context.sendBroadcast(intent);

+ 1
- 0
code/LocalePlugin/src/uk/co/md87/android/contextapi Wyświetl plik

@@ -0,0 +1 @@
1
+../../../../../../API

+ 0
- 1
code/PlacesDisplay/src/uk/co/md87/android/common Wyświetl plik

@@ -1 +0,0 @@
1
-../../../../../../Common/

+ 1
- 0
code/PlacesDisplay/src/uk/co/md87/android/contextapi Wyświetl plik

@@ -0,0 +1 @@
1
+../../../../../../API

+ 10
- 12
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesDisplay.java Wyświetl plik

@@ -43,8 +43,8 @@ import com.google.android.maps.OverlayItem;
43 43
 import java.util.Date;
44 44
 import java.util.List;
45 45
 
46
-import uk.co.md87.android.common.ExceptionHandler;
47
-import uk.co.md87.android.common.model.Place;
46
+import uk.co.md87.android.contextapi.ContextApi;
47
+import uk.co.md87.android.contextapi.ContextApi.Places.ColumnNames;
48 48
 
49 49
 /**
50 50
  * Activity which displays all known places on a map.
@@ -58,8 +58,6 @@ public class PlacesDisplay extends MapActivity {
58 58
     public void onCreate(Bundle icicle) {
59 59
         super.onCreate(icicle);
60 60
 
61
-        Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
62
-
63 61
         FlurryAgent.onStartSession(this, "XXXXGE95S8R54R6M7S6X");
64 62
 
65 63
         final String pkg = "uk.co.md87.android.contextanalyser";
@@ -104,20 +102,20 @@ public class PlacesDisplay extends MapActivity {
104 102
                 Resources.getSystem().getDrawable(android.R.drawable.btn_star_big_on));
105 103
         List<Overlay> mapOverlays = mapView.getOverlays();
106 104
 
107
-        final Cursor cursor = managedQuery(Place.CONTENT_URI,
108
-                new String[] { Place.LATITUDE, Place.LONGITUDE,
109
-                Place.NAME, Place.LAST_VISIT, Place.VISIT_COUNT },
105
+        final Cursor cursor = managedQuery(ContextApi.Places.CONTENT_URI,
106
+                new String[] { ColumnNames.LATITUDE, ColumnNames.LONGITUDE,
107
+                ColumnNames.NAME, ColumnNames.LAST_VISIT, ColumnNames.VISIT_COUNT },
110 108
                 null, null, null);
111 109
 
112 110
         final java.text.DateFormat dateFormat = DateFormat.getDateFormat(this);
113 111
         final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(this);
114 112
 
115 113
         if (cursor.moveToFirst()) {
116
-            final int latitudeColumn = cursor.getColumnIndex(Place.LATITUDE);
117
-            final int longitudeColumn = cursor.getColumnIndex(Place.LONGITUDE);
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);
114
+            final int latitudeColumn = cursor.getColumnIndex(ColumnNames.LATITUDE);
115
+            final int longitudeColumn = cursor.getColumnIndex(ColumnNames.LONGITUDE);
116
+            final int nameColumn = cursor.getColumnIndex(ColumnNames.NAME);
117
+            final int lastVisitColumn = cursor.getColumnIndex(ColumnNames.LAST_VISIT);
118
+            final int visitCountColumn = cursor.getColumnIndex(ColumnNames.VISIT_COUNT);
121 119
 
122 120
             do {
123 121
                 final double latitude = cursor.getDouble(latitudeColumn);

+ 2
- 1
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesItemisedOverlay.java Wyświetl plik

@@ -24,10 +24,11 @@ package uk.co.md87.android.placesdisplay;
24 24
 
25 25
 import android.content.Context;
26 26
 import android.graphics.drawable.Drawable;
27
-import android.util.Log;
28 27
 import android.widget.Toast;
28
+
29 29
 import com.google.android.maps.ItemizedOverlay;
30 30
 import com.google.android.maps.OverlayItem;
31
+
31 32
 import java.util.ArrayList;
32 33
 import java.util.List;
33 34
 

Ładowanie…
Anuluj
Zapisz