Procházet zdrojové kódy

Add some contexts

master
Chris Smith před 14 roky
rodič
revize
a5616930b6

+ 7
- 4
code/ContextHome/src/uk/co/md87/android/contexthome/ContextHome.java Zobrazit soubor

26
 import android.os.Bundle;
26
 import android.os.Bundle;
27
 import android.widget.LinearLayout.LayoutParams;
27
 import android.widget.LinearLayout.LayoutParams;
28
 import android.widget.LinearLayout;
28
 import android.widget.LinearLayout;
29
-import uk.co.md87.android.contexthome.modules.AppsModule;
30
-import uk.co.md87.android.contexthome.modules.ContactsModule;
31
-import uk.co.md87.android.contexthome.modules.EmailModule;
32
-import uk.co.md87.android.contexthome.modules.SmsModule;
29
+
30
+import uk.co.md87.android.contexthome.contexts.*;
31
+import uk.co.md87.android.contexthome.modules.*;
33
 
32
 
34
 /**
33
 /**
35
  * A home screen that displays e-mails, text messages, etc, and responds to
34
  * A home screen that displays e-mails, text messages, etc, and responds to
51
         new EmailModule(), new SmsModule(),
50
         new EmailModule(), new SmsModule(),
52
     };
51
     };
53
 
52
 
53
+    private final ContextType[] contexts = new ContextType[]{
54
+        new GlobalContext(), new HourContext(), new PeriodContext()
55
+    };
56
+
54
     /** Called when the activity is first created. */
57
     /** Called when the activity is first created. */
55
     @Override
58
     @Override
56
     public void onCreate(Bundle icicle) {
59
     public void onCreate(Bundle icicle) {

+ 5
- 5
code/ContextHome/src/uk/co/md87/android/contexthome/DataHelper.java Zobrazit soubor

50
       + " WHERE module = ? AND actiontype = ? AND actionvalue = ?"
50
       + " WHERE module = ? AND actiontype = ? AND actionvalue = ?"
51
       + " AND contexttype = ? AND contextvalue = ?";
51
       + " AND contexttype = ? AND contextvalue = ?";
52
 
52
 
53
+    private final List<ContextType> contexts;
53
     private final SQLiteDatabase db;
54
     private final SQLiteDatabase db;
54
     private final SQLiteStatement insertActionStatement,
55
     private final SQLiteStatement insertActionStatement,
55
             updateActionStatement;
56
             updateActionStatement;
56
 
57
 
57
-    public DataHelper(final Context context) {
58
+    public DataHelper(final Context context, final List<ContextType> contexts) {
58
         final OpenHelper helper = new OpenHelper(context);
59
         final OpenHelper helper = new OpenHelper(context);
59
         this.db = helper.getWritableDatabase();
60
         this.db = helper.getWritableDatabase();
61
+        this.contexts = contexts;
60
 
62
 
61
         this.insertActionStatement = db.compileStatement(INSERT_ACTION);
63
         this.insertActionStatement = db.compileStatement(INSERT_ACTION);
62
         this.updateActionStatement = db.compileStatement(UPDATE_ACTION);
64
         this.updateActionStatement = db.compileStatement(UPDATE_ACTION);
63
     }
65
     }
64
 
66
 
65
-    public void registerAction(final String module, final List<ContextType> contexts,
66
-            final Map<String, String> actions) {
67
+    public void registerAction(final String module, final Map<String, String> actions) {
67
         // TODO: It'd be nice if the two statements could be merged
68
         // TODO: It'd be nice if the two statements could be merged
68
         insertActionStatement.bindString(0, module);
69
         insertActionStatement.bindString(0, module);
69
         updateActionStatement.bindString(0, module);
70
         updateActionStatement.bindString(0, module);
85
         }
86
         }
86
     }
87
     }
87
 
88
 
88
-    public Map<String, Map<String, Integer>> getActions(final String module,
89
-            final List<ContextType> contexts) {
89
+    public Map<String, Map<String, Integer>> getActions(final String module) {
90
         final Map<String, Map<String, Integer>> res = new HashMap<String, Map<String, Integer>>();
90
         final Map<String, Map<String, Integer>> res = new HashMap<String, Map<String, Integer>>();
91
 
91
 
92
         final StringBuilder query = new StringBuilder("SELECT sum(number) AS total, "
92
         final StringBuilder query = new StringBuilder("SELECT sum(number) AS total, "

+ 42
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/GlobalContext.java Zobrazit soubor

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
+ * A context which always returns the value "true".
29
+ *
30
+ * @author chris
31
+ */
32
+public class GlobalContext implements ContextType {
33
+
34
+    public String getName() {
35
+        return "global";
36
+    }
37
+
38
+    public String getValue() {
39
+        return "true";
40
+    }
41
+
42
+}

+ 44
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/HourContext.java Zobrazit soubor

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 java.util.Calendar;
26
+
27
+import uk.co.md87.android.contexthome.ContextType;
28
+
29
+/**
30
+ * A context for the hour of the day.
31
+ *
32
+ * @author chris
33
+ */
34
+public class HourContext implements ContextType {
35
+
36
+    public String getName() {
37
+        return "hour";
38
+    }
39
+
40
+    public String getValue() {
41
+        return String.valueOf(Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
42
+    }
43
+
44
+}

+ 54
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/contexts/PeriodContext.java Zobrazit soubor

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 java.util.Calendar;
26
+
27
+import uk.co.md87.android.contexthome.ContextType;
28
+
29
+/**
30
+ * A context for the period of the day (morning, afternoon, evening or night).
31
+ *
32
+ * @author chris
33
+ */
34
+public class PeriodContext implements ContextType {
35
+
36
+    public String getName() {
37
+        return "period";
38
+    }
39
+
40
+    public String getValue() {
41
+        final int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
42
+
43
+        if (hour >= 6 && hour < 12) {
44
+            return "Morning";
45
+        } else if (hour >= 12 && hour <= 17) {
46
+            return "Afternoon";
47
+        } else if (hour > 17 && hour <= 23) {
48
+            return "Evening";
49
+        } else {
50
+            return "Night";
51
+        }
52
+    }
53
+
54
+}

Načítá se…
Zrušit
Uložit