Bläddra i källkod

Make Module abstract and pass data helper around

master
Chris Smith 14 år sedan
förälder
incheckning
3f39998727

Binär
code/ContextHome/dist/ContextHome.apk Visa fil


+ 11
- 7
code/ContextHome/src/uk/co/md87/android/contexthome/ContextHome.java Visa fil

@@ -26,6 +26,7 @@ import android.app.Activity;
26 26
 import android.os.Bundle;
27 27
 import android.widget.LinearLayout.LayoutParams;
28 28
 import android.widget.LinearLayout;
29
+import java.util.Arrays;
29 30
 
30 31
 import uk.co.md87.android.contexthome.contexts.*;
31 32
 import uk.co.md87.android.contexthome.modules.*;
@@ -42,18 +43,21 @@ public class ContextHome extends Activity {
42 43
             = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
43 44
 
44 45
     private LinearLayout layout, fixedLayout;
45
-    private final Module[] fixedModules = new Module[] {
46
-        new ContactsModule(), new AppsModule()
47
-    };
48
-    
49
-    private final Module[] modules = new Module[]{
50
-        new EmailModule(), new SmsModule(),
51
-    };
52 46
 
53 47
     private final ContextType[] contexts = new ContextType[]{
54 48
         new GlobalContext(), new HourContext(), new PeriodContext()
55 49
     };
56 50
 
51
+    private final DataHelper helper = new DataHelper(this, Arrays.asList(contexts));
52
+
53
+    private final Module[] fixedModules = new Module[] {
54
+        new ContactsModule(helper), new AppsModule(helper)
55
+    };
56
+
57
+    private final Module[] modules = new Module[]{
58
+        new EmailModule(helper), new SmsModule(helper),
59
+    };
60
+
57 61
     /** Called when the activity is first created. */
58 62
     @Override
59 63
     public void onCreate(Bundle icicle) {

+ 8
- 2
code/ContextHome/src/uk/co/md87/android/contexthome/Module.java Visa fil

@@ -30,8 +30,14 @@ import android.view.View;
30 30
  *
31 31
  * @author chris
32 32
  */
33
-public interface Module {
33
+public abstract class Module {
34 34
 
35
-    View getView(final Context context, final int weight);
35
+    private final DataHelper helper;
36
+
37
+    public Module(final DataHelper helper) {
38
+        this.helper = helper;
39
+    }
40
+
41
+    public abstract View getView(final Context context, final int weight);
36 42
 
37 43
 }

+ 6
- 1
code/ContextHome/src/uk/co/md87/android/contexthome/modules/AppsModule.java Visa fil

@@ -33,6 +33,7 @@ import android.util.Log;
33 33
 import android.view.View;
34 34
 import android.widget.ImageView;
35 35
 import android.widget.LinearLayout;
36
+import uk.co.md87.android.contexthome.DataHelper;
36 37
 import uk.co.md87.android.contexthome.Module;
37 38
 import uk.co.md87.android.contexthome.R;
38 39
 
@@ -41,7 +42,11 @@ import uk.co.md87.android.contexthome.R;
41 42
  *
42 43
  * @author chris
43 44
  */
44
-public class AppsModule implements Module {
45
+public class AppsModule extends Module {
46
+
47
+    public AppsModule(DataHelper helper) {
48
+        super(helper);
49
+    }
45 50
 
46 51
     /** {@inheritDoc} */
47 52
     @Override

+ 6
- 1
code/ContextHome/src/uk/co/md87/android/contexthome/modules/ContactsModule.java Visa fil

@@ -32,6 +32,7 @@ import android.provider.Contacts.Photos;
32 32
 import android.view.View;
33 33
 import android.widget.ImageView;
34 34
 import android.widget.LinearLayout;
35
+import uk.co.md87.android.contexthome.DataHelper;
35 36
 
36 37
 import uk.co.md87.android.contexthome.Module;
37 38
 import uk.co.md87.android.contexthome.R;
@@ -41,7 +42,11 @@ import uk.co.md87.android.contexthome.R;
41 42
  *
42 43
  * @author chris
43 44
  */
44
-public class ContactsModule implements Module {
45
+public class ContactsModule extends Module {
46
+
47
+    public ContactsModule(DataHelper helper) {
48
+        super(helper);
49
+    }
45 50
 
46 51
     /** {@inheritDoc} */
47 52
     @Override

+ 6
- 1
code/ContextHome/src/uk/co/md87/android/contexthome/modules/EmailModule.java Visa fil

@@ -39,6 +39,7 @@ import android.widget.LinearLayout.LayoutParams;
39 39
 import android.widget.TextView;
40 40
 import java.util.ArrayList;
41 41
 import java.util.List;
42
+import uk.co.md87.android.contexthome.DataHelper;
42 43
 
43 44
 import uk.co.md87.android.contexthome.Module;
44 45
 import uk.co.md87.android.contexthome.R;
@@ -48,7 +49,11 @@ import uk.co.md87.android.contexthome.R;
48 49
  *
49 50
  * @author chris
50 51
  */
51
-public class EmailModule implements Module {
52
+public class EmailModule extends Module {
53
+
54
+    public EmailModule(DataHelper helper) {
55
+        super(helper);
56
+    }
52 57
 
53 58
     /** {@inheritDoc} */
54 59
     @Override

+ 6
- 1
code/ContextHome/src/uk/co/md87/android/contexthome/modules/SmsModule.java Visa fil

@@ -36,6 +36,7 @@ import android.widget.ImageView;
36 36
 import android.widget.LinearLayout;
37 37
 import android.widget.LinearLayout.LayoutParams;
38 38
 import android.widget.TextView;
39
+import uk.co.md87.android.contexthome.DataHelper;
39 40
 import uk.co.md87.android.contexthome.Module;
40 41
 import uk.co.md87.android.contexthome.R;
41 42
 
@@ -44,10 +45,14 @@ import uk.co.md87.android.contexthome.R;
44 45
  *
45 46
  * @author chris
46 47
  */
47
-public class SmsModule implements Module {
48
+public class SmsModule extends Module {
48 49
 
49 50
     private static final Uri INBOX_URI = Uri.parse("content://sms/inbox");
50 51
 
52
+    public SmsModule(DataHelper helper) {
53
+        super(helper);
54
+    }
55
+
51 56
     /** {@inheritDoc} */
52 57
     @Override
53 58
     public View getView(final Context context, final int weight) {

Laddar…
Avbryt
Spara