Browse Source

New contexts

master
Chris Smith 14 years ago
parent
commit
05830e5510

+ 1
- 0
code/ContextHome/AndroidManifest.xml View File

@@ -16,6 +16,7 @@
16 16
     <uses-permission android:name="android.permission.READ_SMS"/>
17 17
     <uses-permission android:name="android.permission.READ_CONTACTS"/>
18 18
     <uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL"/>
19
+    <uses-permission android:name="uk.co.md87.android.contextanalyser.RECEIVE_UPDATES"/>
19 20
 
20 21
     <uses-sdk android:minSdkVersion="3" />
21 22
 </manifest>

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


+ 1
- 0
code/ContextHome/src/uk/co/md87/android/contextapi View File

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

+ 4
- 3
code/ContextHome/src/uk/co/md87/android/contexthome/ContextHome.java View File

@@ -26,10 +26,9 @@ import android.app.Activity;
26 26
 import android.os.Bundle;
27 27
 import android.os.Handler;
28 28
 import android.util.Log;
29
-import android.view.Menu;
30 29
 import android.view.View;
31
-import android.widget.LinearLayout.LayoutParams;
32 30
 import android.widget.LinearLayout;
31
+
33 32
 import java.util.Arrays;
34 33
 
35 34
 import uk.co.md87.android.contexthome.contexts.*;
@@ -63,7 +62,9 @@ public class ContextHome extends Activity implements Runnable {
63 62
         super.onCreate(icicle);
64 63
 
65 64
         contexts = new ContextType[]{
66
-            new GlobalContext(), new HourContext(), new PeriodContext()
65
+            new GlobalContext(), new HourContext(), new PeriodContext(),
66
+            new ActivityContext(this), new DestinationContext(this),
67
+            new LocationContext(this)
67 68
         };
68 69
 
69 70
         helper = new DataHelper(this, Arrays.asList(contexts));

+ 59
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/ActivityContext.java View File

@@ -0,0 +1,59 @@
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.contexthome.contexts;
24
+
25
+import android.content.BroadcastReceiver;
26
+import android.content.Context;
27
+import android.content.Intent;
28
+import android.content.IntentFilter;
29
+
30
+import uk.co.md87.android.contextapi.ContextApi;
31
+import uk.co.md87.android.contexthome.ContextType;
32
+
33
+/**
34
+ * Provides the user's currently inferred activity.
35
+ *
36
+ * @author chris
37
+ */
38
+public class ActivityContext extends BroadcastReceiver implements ContextType {
39
+
40
+    private String value = "";
41
+
42
+    public ActivityContext(final Context context) {
43
+        context.registerReceiver(this, new IntentFilter(ContextApi.Intents.ACTIVITY_CHANGED));
44
+    }
45
+
46
+    public String getName() {
47
+        return "activity";
48
+    }
49
+
50
+    public String getValue() {
51
+        return value;
52
+    }
53
+
54
+    @Override
55
+    public void onReceive(Context arg0, Intent arg1) {
56
+        value = String.valueOf(arg1.getStringExtra("new"));
57
+    }
58
+
59
+}

+ 59
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/DestinationContext.java View File

@@ -0,0 +1,59 @@
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.contexthome.contexts;
24
+
25
+import android.content.BroadcastReceiver;
26
+import android.content.Context;
27
+import android.content.Intent;
28
+import android.content.IntentFilter;
29
+
30
+import uk.co.md87.android.contextapi.ContextApi;
31
+import uk.co.md87.android.contexthome.ContextType;
32
+
33
+/**
34
+ * Provides the user's currently predicted destination.
35
+ *
36
+ * @author chris
37
+ */
38
+public class DestinationContext extends BroadcastReceiver implements ContextType {
39
+
40
+    private String value = "-1";
41
+
42
+    public DestinationContext(final Context context) {
43
+        context.registerReceiver(this, new IntentFilter(ContextApi.Intents.PREDICTION_AVAILABLE));
44
+    }
45
+
46
+    public String getName() {
47
+        return "destination";
48
+    }
49
+
50
+    public String getValue() {
51
+        return value;
52
+    }
53
+
54
+    @Override
55
+    public void onReceive(Context arg0, Intent arg1) {
56
+        value = String.valueOf(arg1.getLongExtra("best_target", -1));
57
+    }
58
+
59
+}

+ 54
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/FakeContext.java View File

@@ -0,0 +1,54 @@
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.contexthome.contexts;
24
+
25
+import uk.co.md87.android.contexthome.ContextType;
26
+
27
+/**
28
+ * Provides fake contextual information for demo/testing purposes.
29
+ *
30
+ * @author chris
31
+ */
32
+public class FakeContext implements ContextType {
33
+
34
+    private final String name;
35
+    private String value;
36
+
37
+    public FakeContext(String name, String value) {
38
+        this.name = name;
39
+        this.value = value;
40
+    }
41
+
42
+    public void setValue(String value) {
43
+        this.value = value;
44
+    }
45
+
46
+    public String getName() {
47
+        return name;
48
+    }
49
+
50
+    public String getValue() {
51
+        return value;
52
+    }
53
+
54
+}

+ 59
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/LocationContext.java View File

@@ -0,0 +1,59 @@
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.contexthome.contexts;
24
+
25
+import android.content.BroadcastReceiver;
26
+import android.content.Context;
27
+import android.content.Intent;
28
+import android.content.IntentFilter;
29
+
30
+import uk.co.md87.android.contextapi.ContextApi;
31
+import uk.co.md87.android.contexthome.ContextType;
32
+
33
+/**
34
+ * Provides the user's currently detected location.
35
+ *
36
+ * @author chris
37
+ */
38
+public class LocationContext extends BroadcastReceiver implements ContextType {
39
+
40
+    private String value = "-1";
41
+
42
+    public LocationContext(final Context context) {
43
+        context.registerReceiver(this, new IntentFilter(ContextApi.Intents.CONTEXT_CHANGED));
44
+    }
45
+
46
+    public String getName() {
47
+        return "location";
48
+    }
49
+
50
+    public String getValue() {
51
+        return value;
52
+    }
53
+
54
+    @Override
55
+    public void onReceive(Context arg0, Intent arg1) {
56
+        value = String.valueOf(arg1.getLongExtra("new", -1));
57
+    }
58
+
59
+}

Loading…
Cancel
Save