Ver código fonte

Journeys content provider

master
Chris Smith 14 anos atrás
pai
commit
7e32a9793a

+ 15
- 0
code/ContextAnalyser/AndroidManifest.xml Ver arquivo

@@ -15,6 +15,11 @@
15 15
             android:authorities="uk.co.md87.android.contextanalyser.placescontentprovider"
16 16
             android:readPermission="uk.co.md87.android.contextanalyser.READ_PLACES"
17 17
             android:writePermission="uk.co.md87.android.contextanalyser.WRITE_PLACES"/>
18
+
19
+        <provider android:name="uk.co.md87.android.contextanalyser.JourneysContentProvider"
20
+            android:authorities="uk.co.md87.android.contextanalyser.journeyscontentprovider"
21
+            android:readPermission="uk.co.md87.android.contextanalyser.READ_JOURNEYS"
22
+            android:writePermission="uk.co.md87.android.contextanalyser.WRITE_JOURNEYS"/>
18 23
     </application>
19 24
 
20 25
     <permission-group android:description="@string/permgroupdesc"
@@ -36,6 +41,16 @@
36 41
         android:description="@string/permdesc_writePlaces"
37 42
         android:permissionGroup="uk.co.md87.android.contextanalyser.CONTEXT"
38 43
         android:protectionLevel="dangerous" />
44
+    <permission android:name="uk.co.md87.android.contextanalyser.READ_JOURNEYS"
45
+        android:label="@string/permlab_readJourneys"
46
+        android:description="@string/permdesc_readJourneys"
47
+        android:permissionGroup="uk.co.md87.android.contextanalyser.CONTEXT"
48
+        android:protectionLevel="dangerous" />
49
+    <permission android:name="uk.co.md87.android.contextanalyser.WRITE_JOURNEYS"
50
+        android:label="@string/permlab_writeJourneys"
51
+        android:description="@string/permdesc_writeJourneys"
52
+        android:permissionGroup="uk.co.md87.android.contextanalyser.CONTEXT"
53
+        android:protectionLevel="dangerous" />
39 54
     <permission android:name="uk.co.md87.android.contextanalyser.BROADCAST"
40 55
         android:label="@string/permlab_broadcast"
41 56
         android:description="@string/permdesc_broadcast"

BIN
code/ContextAnalyser/dist/ContextAnalyser.apk Ver arquivo


+ 9
- 0
code/ContextAnalyser/res/values/strings.xml Ver arquivo

@@ -16,6 +16,15 @@
16 16
     <string name="permdesc_writePlaces">Allows the application to
17 17
         modify the list of places that the context analyser knows about.</string>
18 18
 
19
+    <string name="permlab_readJourneys">retrieve your journeys</string>
20
+    <string name="permdesc_readJourneys">Allows the application to
21
+        retrieve a list of journeys you have made, including the activities
22
+        that make up the journeys and symbolic locations they run between.</string>
23
+
24
+    <string name="permlab_writeJourneys">modify your journeys</string>
25
+    <string name="permdesc_writeJourneys">Allows the application to
26
+        modify the list of journeys that the context analyser knows about.</string>
27
+
19 28
     <string name="permgrouplabel">Context permissions</string>
20 29
     <string name="permgroupdesc">Permissions related to the context analyser
21 30
         service and its API.</string>

+ 4
- 3
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/DataHelper.java Ver arquivo

@@ -140,8 +140,8 @@ public class DataHelper {
140 140
             query = String.format(JOURNEY_BOTH_QUERY, start.getId(), end.getId());
141 141
         }
142 142
 
143
-        final Cursor cursor = db.query(JOURNEYS_TABLE,
144
-                new String[] { "_id", "start", "end", "steps", "number" },
143
+        final Cursor cursor = db.query(JOURNEYS_TABLE, new String[] { Journey._ID,
144
+                Journey.START, Journey.END, Journey.STEPS, Journey.NUMBER },
145 145
                 query, null, null, null, null);
146 146
 
147 147
         if (cursor.moveToFirst()) {
@@ -196,7 +196,8 @@ public class DataHelper {
196 196
         final String query = String.format(JOURNEY_STEPS_QUERY, journey.getId());
197 197
 
198 198
         final Cursor cursor = db.query(JOURNEYSTEPS_TABLE,
199
-                new String[] { "_id", "activity", "repetitions", "next" },
199
+                new String[] { JourneyStep._ID, JourneyStep.ACTIVITY,
200
+                JourneyStep.REPETITIONS, JourneyStep.NEXT },
200 201
                 query, null, null, null, null);
201 202
 
202 203
         if (cursor.moveToFirst()) {

+ 129
- 0
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/JourneysContentProvider.java Ver arquivo

@@ -0,0 +1,129 @@
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.contextanalyser;
24
+
25
+import android.content.ContentProvider;
26
+import android.content.ContentUris;
27
+import android.content.ContentValues;
28
+import android.content.UriMatcher;
29
+import android.database.Cursor;
30
+import android.database.SQLException;
31
+import android.net.Uri;
32
+import uk.co.md87.android.contextanalyser.model.Journey;
33
+import uk.co.md87.android.contextanalyser.model.JourneyStep;
34
+
35
+/**
36
+ * A content provider for journeys and journey steps.
37
+ *
38
+ * @author chris
39
+ */
40
+public class JourneysContentProvider extends ContentProvider {
41
+
42
+    public static final String AUTHORITY = "uk.co.md87.android.contextanalyser.journeyscontentprovider";
43
+
44
+    private static final int CODE_JOURNEY = 1;
45
+    private static final int CODE_STEP = 2;
46
+    private static final UriMatcher URI_MATCHER;
47
+
48
+    static {
49
+        URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
50
+        URI_MATCHER.addURI(AUTHORITY, "journeys", CODE_JOURNEY);
51
+        URI_MATCHER.addURI(AUTHORITY, "steps", CODE_STEP);
52
+    }
53
+
54
+    private DataHelper helper;
55
+
56
+    /** {@inheritDoc} */
57
+    @Override
58
+    public boolean onCreate() {
59
+        helper = new DataHelper(getContext());
60
+        return true;
61
+    }
62
+
63
+    protected String getTable(final int code) {
64
+        switch (code) {
65
+            case CODE_JOURNEY:
66
+                return DataHelper.JOURNEYS_TABLE;
67
+            case CODE_STEP:
68
+                return DataHelper.JOURNEYSTEPS_TABLE;
69
+            default:
70
+                throw new IllegalArgumentException("Unknown URI");
71
+        }
72
+    }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public Cursor query(final Uri uri, final String[] projection,
77
+            final String selection, final String[] selectionArgs,
78
+            final String sortOrder) {
79
+        return helper.getDatabase().query(getTable(URI_MATCHER.match(uri)),
80
+                projection, selection, selectionArgs, null, null, sortOrder);
81
+    }
82
+
83
+    /** {@inheritDoc} */
84
+    @Override
85
+    public String getType(final Uri uri) {
86
+        final int code = URI_MATCHER.match(uri);
87
+        
88
+        return "vnd.android.cursor." + (ContentUris.parseId(uri) == -1 ? "dir" : "item")
89
+                + (code == CODE_JOURNEY ? Journey.CONTENT_TYPE : JourneyStep.CONTENT_TYPE);
90
+    }
91
+
92
+    /** {@inheritDoc} */
93
+    @Override
94
+    public Uri insert(final Uri uri, final ContentValues values) {
95
+        final int code = URI_MATCHER.match(uri);
96
+        long rowId = helper.getDatabase().insert(getTable(code),
97
+                code == CODE_JOURNEY ? Journey.START : JourneyStep.JOURNEY, values);
98
+
99
+        if (rowId > 0) {
100
+            final Uri placeUri = ContentUris.withAppendedId(code == CODE_JOURNEY
101
+                    ? Journey.CONTENT_URI : JourneyStep.CONTENT_URI, rowId);
102
+            getContext().getContentResolver().notifyChange(placeUri, null);
103
+            return placeUri;
104
+        }
105
+
106
+        throw new SQLException("Failed to insert row into " + uri);
107
+    }
108
+
109
+    /** {@inheritDoc} */
110
+    @Override
111
+    public int delete(Uri uri, String where, String[] whereArgs) {
112
+        final int count = helper.getDatabase().delete(getTable(URI_MATCHER.match(uri)),
113
+                where, whereArgs);
114
+
115
+        getContext().getContentResolver().notifyChange(uri, null);
116
+        return count;
117
+    }
118
+
119
+    /** {@inheritDoc} */
120
+    @Override
121
+    public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
122
+        final int count = helper.getDatabase().update(getTable(URI_MATCHER.match(uri)),
123
+                values, where, whereArgs);
124
+
125
+        getContext().getContentResolver().notifyChange(uri, null);
126
+        return count;
127
+    }
128
+
129
+}

+ 2
- 0
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/Manifest.java Ver arquivo

@@ -10,8 +10,10 @@ package uk.co.md87.android.contextanalyser;
10 10
 public final class Manifest {
11 11
     public static final class permission {
12 12
         public static final String BROADCAST="uk.co.md87.android.contextanalyser.BROADCAST";
13
+        public static final String READ_JOURNEYS="uk.co.md87.android.contextanalyser.READ_JOURNEYS";
13 14
         public static final String READ_PLACES="uk.co.md87.android.contextanalyser.READ_PLACES";
14 15
         public static final String RECEIVE_UPDATES="uk.co.md87.android.contextanalyser.RECEIVE_UPDATES";
16
+        public static final String WRITE_JOURNEYS="uk.co.md87.android.contextanalyser.WRITE_JOURNEYS";
15 17
         public static final String WRITE_PLACES="uk.co.md87.android.contextanalyser.WRITE_PLACES";
16 18
     }
17 19
     public static final class permission_group {

+ 8
- 4
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/R.java Ver arquivo

@@ -21,15 +21,19 @@ public final class R {
21 21
     }
22 22
     public static final class string {
23 23
         public static final int app_name=0x7f050000;
24
-        public static final int permdesc_broadcast=0x7f05000a;
24
+        public static final int permdesc_broadcast=0x7f05000e;
25
+        public static final int permdesc_readJourneys=0x7f050008;
25 26
         public static final int permdesc_readPlaces=0x7f050004;
26 27
         public static final int permdesc_receiveUpdates=0x7f050002;
28
+        public static final int permdesc_writeJourneys=0x7f05000a;
27 29
         public static final int permdesc_writePlaces=0x7f050006;
28
-        public static final int permgroupdesc=0x7f050008;
29
-        public static final int permgrouplabel=0x7f050007;
30
-        public static final int permlab_broadcast=0x7f050009;
30
+        public static final int permgroupdesc=0x7f05000c;
31
+        public static final int permgrouplabel=0x7f05000b;
32
+        public static final int permlab_broadcast=0x7f05000d;
33
+        public static final int permlab_readJourneys=0x7f050007;
31 34
         public static final int permlab_readPlaces=0x7f050003;
32 35
         public static final int permlab_receiveUpdates=0x7f050001;
36
+        public static final int permlab_writeJourneys=0x7f050009;
33 37
         public static final int permlab_writePlaces=0x7f050005;
34 38
     }
35 39
 }

+ 14
- 0
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/model/Journey.java Ver arquivo

@@ -22,6 +22,10 @@
22 22
 
23 23
 package uk.co.md87.android.contextanalyser.model;
24 24
 
25
+import android.net.Uri;
26
+
27
+import uk.co.md87.android.contextanalyser.JourneysContentProvider;
28
+
25 29
 /**
26 30
  * A journey is a sequence of actions which were observed as the user travelled
27 31
  * between one known {@link Place} and another.
@@ -30,6 +34,16 @@ package uk.co.md87.android.contextanalyser.model;
30 34
  */
31 35
 public class Journey {
32 36
 
37
+    public static final String _ID = "_id";
38
+    public static final String START = "start";
39
+    public static final String END = "end";
40
+    public static final String STEPS = "steps";
41
+    public static final String NUMBER = "number";
42
+
43
+    public static final Uri CONTENT_URI = Uri.parse("content://"
44
+                + JourneysContentProvider.AUTHORITY + "/journeys");
45
+    public static final String CONTENT_TYPE = "vnd.contextanalyser.journey";
46
+
33 47
     private final long id;
34 48
     private final long start;
35 49
     private final long end;

+ 13
- 0
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/model/JourneyStep.java Ver arquivo

@@ -22,6 +22,9 @@
22 22
 
23 23
 package uk.co.md87.android.contextanalyser.model;
24 24
 
25
+import android.net.Uri;
26
+import uk.co.md87.android.contextanalyser.JourneysContentProvider;
27
+
25 28
 /**
26 29
  * A journey step is a single activity which occurred one or more times in a
27 30
  * {@link Journey}. The activity may be repeated any number of times in a row.
@@ -30,6 +33,16 @@ package uk.co.md87.android.contextanalyser.model;
30 33
  */
31 34
 public class JourneyStep {
32 35
 
36
+    public static final String _ID = "_id";
37
+    public static final String ACTIVITY = "activity";
38
+    public static final String REPETITIONS = "repetitions";
39
+    public static final String JOURNEY = "journey";
40
+    public static final String NEXT = "next";
41
+
42
+    public static final Uri CONTENT_URI = Uri.parse("content://"
43
+                + JourneysContentProvider.AUTHORITY + "/steps");
44
+    public static final String CONTENT_TYPE = "vnd.contextanalyser.journeystep";
45
+
33 46
     private final long id;
34 47
     private final String activity;
35 48
     private final int repetitions;

Carregando…
Cancelar
Salvar