Bläddra i källkod

Initial work on some kind of sensible threading. TBC.

master
Chris Smith 14 år sedan
förälder
incheckning
74640a5751

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


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

@@ -24,6 +24,7 @@ package uk.co.md87.android.contexthome;
24 24
 
25 25
 import android.app.Activity;
26 26
 import android.os.Bundle;
27
+import android.util.Log;
27 28
 import android.widget.LinearLayout.LayoutParams;
28 29
 import android.widget.LinearLayout;
29 30
 import java.util.Arrays;
@@ -39,9 +40,6 @@ import uk.co.md87.android.contexthome.modules.*;
39 40
  */
40 41
 public class ContextHome extends Activity {
41 42
 
42
-    private static final LayoutParams MODULE_PARAMS
43
-            = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
44
-
45 43
     private LinearLayout layout, fixedLayout;
46 44
 
47 45
     private ContextType[] contexts;
@@ -81,12 +79,20 @@ public class ContextHome extends Activity {
81 79
         fixedLayout.removeAllViews();
82 80
         layout.removeAllViews();
83 81
 
82
+        long start, end;
83
+
84 84
         for (Module module : fixedModules) {
85
-            fixedLayout.addView(module.getView(this, 1), MODULE_PARAMS);
85
+            start = System.currentTimeMillis();
86
+            module.addViews(fixedLayout, this, 1);
87
+            end = System.currentTimeMillis();
88
+            Log.v("ContextHome", module.getClass().getSimpleName() + ": " + (end - start));
86 89
         }
87 90
 
88 91
         for (Module module : modules) {
89
-            layout.addView(module.getView(this, 10), MODULE_PARAMS);
92
+            start = System.currentTimeMillis();
93
+            module.addViews(layout, this, 10);
94
+            end = System.currentTimeMillis();
95
+            Log.v("ContextHome", module.getClass().getSimpleName() + ": " + (end - start));
90 96
         }
91 97
     }
92 98
 

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

@@ -23,7 +23,9 @@
23 23
 package uk.co.md87.android.contexthome;
24 24
 
25 25
 import android.content.Context;
26
+import android.text.Layout;
26 27
 import android.view.View;
28
+import android.view.ViewGroup;
27 29
 
28 30
 import java.util.Map;
29 31
 
@@ -66,6 +68,6 @@ public abstract class Module {
66 68
         helper.registerAction(module, params);
67 69
     }
68 70
 
69
-    public abstract View getView(final Context context, final int weight);
71
+    public abstract void addViews(final ViewGroup parent, final Context context, final int weight);
70 72
 
71 73
 }

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

@@ -27,9 +27,12 @@ import android.content.Intent;
27 27
 import android.content.pm.ActivityInfo;
28 28
 import android.content.pm.PackageManager;
29 29
 import android.content.pm.ResolveInfo;
30
+import android.os.Handler;
30 31
 import android.view.View;
32
+import android.view.ViewGroup;
31 33
 import android.widget.ImageView;
32 34
 import android.widget.LinearLayout;
35
+import java.util.ArrayList;
33 36
 import java.util.Collections;
34 37
 import java.util.Comparator;
35 38
 
@@ -54,8 +57,13 @@ public class AppsModule extends Module implements Comparator<ResolveInfo> {
54 57
 
55 58
     /** {@inheritDoc} */
56 59
     @Override
57
-    public View getView(final Context context, final int weight) {
60
+    public void addViews(final ViewGroup parent, final Context context, final int weight) {
58 61
         final View view = View.inflate(context, R.layout.scroller, null);
62
+        final Handler handler = new Handler();
63
+
64
+        new Thread(new Runnable() {
65
+
66
+            public void run() {
59 67
         final LinearLayout layout = (LinearLayout) view.findViewById(R.id.content);
60 68
         final PackageManager pm = context.getPackageManager();
61 69
         final Intent intent = new Intent(Intent.ACTION_MAIN);
@@ -75,7 +83,9 @@ public class AppsModule extends Module implements Comparator<ResolveInfo> {
75 83
         intent.addCategory(Intent.CATEGORY_LAUNCHER);
76 84
 
77 85
         final List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
78
-        Collections.sort(infos, this);
86
+        Collections.sort(infos, AppsModule.this);
87
+
88
+        final List<View> views = new ArrayList<View>(infos.size());
79 89
         
80 90
         for (ResolveInfo res : infos) {
81 91
             final ImageView image = new ImageView(context);
@@ -86,10 +96,21 @@ public class AppsModule extends Module implements Comparator<ResolveInfo> {
86 96
             image.setOnClickListener(listener);
87 97
             image.setPadding(2, 2, 2, 2);
88 98
             image.setBackgroundResource(R.drawable.grid_selector);
89
-            layout.addView(image, 52, 52);
99
+            views.add(image);
100
+        }
101
+
102
+        handler.post(new Runnable() {
103
+
104
+                    public void run() {
105
+                        for (View myView : views) {
106
+                            layout.addView(myView, 52, 52);
107
+                        }
108
+                    }
109
+                });
90 110
         }
111
+        }).start();
91 112
 
92
-        return view;
113
+        parent.addView(view);
93 114
     }
94 115
 
95 116
     public Map<String, String> getMap(final ResolveInfo info) {

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

@@ -27,9 +27,11 @@ import android.content.Context;
27 27
 import android.content.Intent;
28 28
 import android.database.Cursor;
29 29
 import android.net.Uri;
30
+import android.os.Handler;
30 31
 import android.provider.Contacts.People;
31 32
 import android.provider.Contacts.Photos;
32 33
 import android.view.View;
34
+import android.view.ViewGroup;
33 35
 import android.widget.ImageView;
34 36
 import android.widget.LinearLayout;
35 37
 import java.util.ArrayList;
@@ -56,7 +58,7 @@ public class ContactsModule extends Module implements Comparator<Long> {
56 58
 
57 59
     /** {@inheritDoc} */
58 60
     @Override
59
-    public View getView(final Context context, final int weight) {
61
+    public void addViews(final ViewGroup parent, final Context context, final int weight) {
60 62
         final View view = View.inflate(context, R.layout.scroller, null);
61 63
         final LinearLayout layout = (LinearLayout) view.findViewById(R.id.content);
62 64
 
@@ -72,25 +74,42 @@ public class ContactsModule extends Module implements Comparator<Long> {
72 74
             }
73 75
         };
74 76
 
75
-        final Cursor cursor = context.getContentResolver().query(Photos.CONTENT_URI,
76
-                new String[] { "person" }, "exists_on_server != 0", null, null);
77
-
78
-        final int column = cursor.getColumnIndex("person");
79
-        final List<Long> hits = new ArrayList<Long>(cursor.getCount());
80
-        if (cursor.moveToFirst()) {
81
-            int i = 0;
82
-            do {
83
-                hits.add(cursor.getLong(column));
84
-            } while (cursor.moveToNext());
85
-        }
86
-        
87
-        Collections.sort(hits, this);
88
-
89
-        for (Long id : hits) {
90
-            layout.addView(getView(context, listener, id), 52, 52);
91
-        }
92
-
93
-        return view;
77
+        final Handler handler = new Handler();
78
+
79
+        new Thread(new Runnable() {
80
+
81
+            public void run() {
82
+                final Cursor cursor = context.getContentResolver().query(Photos.CONTENT_URI,
83
+                        new String[] { "person" }, "exists_on_server != 0", null, null);
84
+
85
+                final int column = cursor.getColumnIndex("person");
86
+                final List<Long> hits = new ArrayList<Long>(cursor.getCount());
87
+                if (cursor.moveToFirst()) {
88
+                    do {
89
+                        hits.add(cursor.getLong(column));
90
+                    } while (cursor.moveToNext());
91
+                }
92
+
93
+                Collections.sort(hits, ContactsModule.this);
94
+
95
+                final List<View> views = new ArrayList<View>(hits.size());
96
+
97
+                for (Long id : hits) {
98
+                    views.add(getView(context, listener, id));
99
+                }
100
+
101
+                handler.post(new Runnable() {
102
+
103
+                    public void run() {
104
+                        for (View myView : views) {
105
+                            layout.addView(myView, 52, 52);
106
+                        }
107
+                    }
108
+                });
109
+            }
110
+        }).start();
111
+
112
+        parent.addView(view);
94 113
     }
95 114
 
96 115
     private final View getView(final Context context, View.OnClickListener listener,

+ 155
- 0
code/ContextHome/src/uk/co/md87/android/contexthome/modules/Email.java Visa fil

@@ -0,0 +1,155 @@
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.modules;
24
+
25
+import android.content.ContentUris;
26
+import android.content.Context;
27
+import android.database.Cursor;
28
+import android.net.Uri;
29
+import android.os.Handler;
30
+import android.provider.Contacts;
31
+import android.provider.Contacts.People;
32
+import android.text.Html;
33
+import android.view.View;
34
+import android.widget.ImageView;
35
+import android.widget.TextView;
36
+import uk.co.md87.android.contexthome.R;
37
+
38
+public class Email implements Runnable {
39
+
40
+    private String body;
41
+    private String address;
42
+    private int count;
43
+    private final long convId;
44
+    private final Handler handler;
45
+    private final Context context;
46
+    private final View view;
47
+    private long id = -1;
48
+
49
+    public Email(Handler handler, Context context, long convId, View view) {
50
+        this.handler = handler;
51
+        this.convId = convId;
52
+        this.context = context;
53
+        this.view = view;
54
+        
55
+        new Thread(this).start(); // Ick!
56
+    }
57
+
58
+    public String getAddress() {
59
+        return address;
60
+    }
61
+
62
+    public String getBody() {
63
+        return body;
64
+    }
65
+
66
+    public int getCount() {
67
+        return count;
68
+    }
69
+
70
+    public long getId() {
71
+        return id;
72
+    }
73
+
74
+    public void setId(long id) {
75
+        this.id = id;
76
+    }
77
+
78
+    public View getView() {
79
+        return view;
80
+    }
81
+
82
+    public void run() {
83
+        final Uri inboxUri = Uri.parse("content://gmail-ls/"
84
+            + "conversations/" + context.getSharedPreferences("email",
85
+            Context.MODE_WORLD_READABLE).getString("account", "chris87@gmail.com"));
86
+
87
+       final Uri uri = inboxUri.buildUpon().appendEncodedPath(String.valueOf(convId)
88
+                    + "/messages").build();
89
+
90
+       final Cursor messageCursor = context.getContentResolver().query(uri,
91
+            new String[] { "fromAddress", "subject", "messageId" }, null, null, null);
92
+
93
+        while (messageCursor.getExtras().getString("status").equals("LOADING")) {
94
+            messageCursor.requery();
95
+            Thread.yield();
96
+        }
97
+
98
+        if (messageCursor.moveToFirst()) {
99
+            final int subjectIndex = messageCursor.getColumnIndex("subject");
100
+            final int addressIndex = messageCursor.getColumnIndex("fromAddress");
101
+
102
+            body = messageCursor.getString(subjectIndex);
103
+            address = messageCursor.getString(addressIndex);
104
+            count = messageCursor.getCount();
105
+        }
106
+
107
+        messageCursor.close();
108
+
109
+        final Uri contactUri = Uri.parse("content://contacts/contact_methods");
110
+
111
+        final String name = address.replaceAll("^.*\"(.*?)\".*$", "$1")
112
+                .replaceAll("(.*), (.*)", "$2 $1");
113
+        final String email = address.replaceAll("^.*<(.*?)>.*$", "$1");
114
+
115
+        final Cursor cursor = context.getContentResolver().query(contactUri,
116
+                new String[] { "person", "name" }, "data LIKE ?", new String[] { email }, null);
117
+
118
+        final TextView title = (TextView) view.findViewById(R.id.title);
119
+        final ImageView image = (ImageView) view.findViewById(R.id.image);
120
+
121
+        if (cursor.moveToFirst()) {
122
+            final Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI,
123
+                    cursor.getLong(cursor.getColumnIndex("person")));
124
+            setId(cursor.getLong(cursor.getColumnIndex("person")));
125
+            final String sender = cursor.getString(cursor.getColumnIndex("name"));
126
+            handler.post(new Runnable() {
127
+
128
+                public void run() {
129
+                    title.setText(Html.fromHtml("<b>" + sender + "</b> (" + count + ")"));
130
+                    image.setImageBitmap(Contacts.People.loadContactPhoto(context,
131
+                        personUri, R.drawable.blank, null));
132
+                }
133
+            });
134
+        } else {
135
+            handler.post(new Runnable() {
136
+
137
+                public void run() {
138
+                    title.setText(Html.fromHtml("<b>" + (name.length() == 0 ? email : name)
139
+                            + "</b> (" + getCount() + ")"));
140
+                }
141
+            });
142
+        }
143
+
144
+        cursor.close();
145
+
146
+        final TextView body = (TextView) view.findViewById(R.id.body);
147
+
148
+        handler.post(new Runnable() {
149
+
150
+            public void run() {
151
+                body.setText(getBody());
152
+            }
153
+        });
154
+    }
155
+}

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

@@ -22,23 +22,20 @@
22 22
 
23 23
 package uk.co.md87.android.contexthome.modules;
24 24
 
25
-import android.content.ContentUris;
26 25
 import android.content.Context;
27 26
 import android.content.Intent;
28
-import android.content.SharedPreferences;
29 27
 import android.database.Cursor;
30 28
 import android.net.Uri;
31
-import android.provider.Contacts;
32
-import android.provider.Contacts.People;
33
-import android.text.Html;
34
-import android.util.Log;
29
+import android.os.Handler;
35 30
 import android.view.View;
36
-import android.widget.ImageView;
37
-import android.widget.LinearLayout;
31
+import android.view.ViewGroup;
38 32
 import android.widget.LinearLayout.LayoutParams;
39
-import android.widget.TextView;
40 33
 import java.util.ArrayList;
34
+import java.util.Collections;
35
+import java.util.Comparator;
36
+import java.util.HashMap;
41 37
 import java.util.List;
38
+import java.util.Map;
42 39
 import uk.co.md87.android.contexthome.DataHelper;
43 40
 
44 41
 import uk.co.md87.android.contexthome.Module;
@@ -49,7 +46,7 @@ import uk.co.md87.android.contexthome.R;
49 46
  *
50 47
  * @author chris
51 48
  */
52
-public class EmailModule extends Module {
49
+public class EmailModule extends Module implements Comparator<Email> {
53 50
 
54 51
     public EmailModule(DataHelper helper) {
55 52
         super(helper);
@@ -57,10 +54,12 @@ public class EmailModule extends Module {
57 54
 
58 55
     /** {@inheritDoc} */
59 56
     @Override
60
-    public View getView(final Context context, final int weight) {
61
-        final LinearLayout layout = new LinearLayout(context);
62
-        layout.setOrientation(LinearLayout.VERTICAL);
57
+    public void addViews(final ViewGroup parent, final Context context, final int weight) {
58
+        final Handler handler = new Handler();
63 59
 
60
+        new Thread(new Runnable() {
61
+
62
+            public void run() {
64 63
         final Uri inboxUri = Uri.parse("content://gmail-ls/"
65 64
             + "conversations/" + context.getSharedPreferences("email",
66 65
             Context.MODE_WORLD_READABLE).getString("account", "chris87@gmail.com"));
@@ -68,103 +67,72 @@ public class EmailModule extends Module {
68 67
         final Cursor cursor = context.getContentResolver().query(inboxUri,
69 68
                 new String[] { "conversation_id" }, null, null, null);
70 69
 
70
+        while (cursor.getExtras().getString("status").equals("LOADING")) {
71
+            cursor.requery();
72
+            Thread.yield();
73
+        }
74
+
71 75
         final int convIdIndex = cursor.getColumnIndex("conversation_id");
72 76
 
73 77
         final LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
74 78
                 LayoutParams.WRAP_CONTENT);
75 79
         params.weight = 1;
76 80
 
77
-        final List<Object[]> messages = new ArrayList<Object[]>(weight);
78
-        final List<Long> convIds = new ArrayList<Long>();
81
+        final List<Email> messages = new ArrayList<Email>(weight);
79 82
 
80 83
         if (cursor.moveToFirst()) {
81 84
             do {
82
-                convIds.add(cursor.getLong(convIdIndex));
83
-            } while (cursor.moveToNext());
84
-        }
85
+                final View view = View.inflate(context, R.layout.titledimage, null);
86
+                view.setClickable(true);
87
+                view.setFocusable(true);
88
+                view.setOnClickListener(new View.OnClickListener() {
85 89
 
86
-        cursor.close();
90
+                    public void onClick(View arg0) {
91
+                        final Intent intent = new Intent();
92
+                        intent.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
93
+                        context.startActivity(intent);
87 94
 
88
-        Log.e("!!!!!", convIds.toString());
95
+                        recordAction(getMap((Email) arg0.getTag()));
96
+                    }
97
+                });
89 98
 
90
-        for (Long convId : convIds) {
91
-            final Uri uri = inboxUri.buildUpon().appendEncodedPath(String.valueOf(convId)
92
-                    + "/messages").build();
99
+                final Email message = new Email(handler, context,
100
+                        cursor.getLong(convIdIndex), view);
101
+                view.setTag(message);
93 102
 
94
-            final Cursor messageCursor = context.getContentResolver().query(uri,
95
-                new String[] { "fromAddress", "subject", "messageId" }, null, null, null);
96
-
97
-            while (messageCursor.getExtras().getString("status").equals("LOADING")) {
98
-                messageCursor.requery();
99
-                Thread.yield();
100
-            }
101
-
102
-            if (messageCursor.moveToFirst()) {
103
-                final int subjectIndex = messageCursor.getColumnIndex("subject");
104
-                final int addressIndex = messageCursor.getColumnIndex("fromAddress");
103
+                messages.add(message);
104
+            } while (cursor.moveToNext());
105
+        }
105 106
 
106
-                final String body = messageCursor.getString(subjectIndex);
107
-                final String address = messageCursor.getString(addressIndex);
108
-                final int count = messageCursor.getCount();
107
+        cursor.close();
109 108
 
110
-                messages.add(new Object[] { body, address, count });
111
-            }
109
+        Collections.sort(messages, EmailModule.this);
112 110
 
113
-            messageCursor.close();
114
-        }
111
+        handler.post(new Runnable() {
115 112
 
116
-        for (Object[] message : messages) {
117
-            layout.addView(getView(context, (String) message[0],
118
-                    (String) message[1], (Integer) message[2]), params);
113
+                    public void run() {
114
+                                for (Email message : messages) {
115
+            parent.addView(message.getView(), params);
119 116
         }
120
-
121
-        return layout;
117
+                    }
118
+                });
119
+                    }
120
+        }).start();
122 121
     }
123 122
 
124
-    private View getView(final Context context, final String text, final String address,
125
-            final int count) {
126
-        final View view = View.inflate(context, R.layout.titledimage, null);
127
-        view.setClickable(true);
128
-        view.setFocusable(true);
129
-        view.setOnClickListener(new View.OnClickListener() {
130
-
131
-            public void onClick(View arg0) {
132
-                final Intent intent = new Intent();
133
-                intent.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
134
-                context.startActivity(intent);
135
-            }
136
-        });
137
-
138
-        final Uri contactUri = Uri.parse("content://contacts/contact_methods");
139
-
140
-        final String name = address.replaceAll("^.*\"(.*?)\".*$", "$1")
141
-                .replaceAll("(.*), (.*)", "$2 $1");
142
-        final String email = address.replaceAll("^.*<(.*?)>.*$", "$1");
143
-
144
-        final Cursor cursor = context.getContentResolver().query(contactUri,
145
-                new String[] { "person", "name" }, "data LIKE ?", new String[] { email }, null);
146
-
147
-        final TextView title = (TextView) view.findViewById(R.id.title);
148
-        final ImageView image = (ImageView) view.findViewById(R.id.image);
149
-
150
-        if (cursor.moveToFirst()) {
151
-            title.setText(Html.fromHtml("<b>" + cursor.getString(cursor
152
-                    .getColumnIndex("name")) + "</b> (" + count + ")"));
153
-            Uri uri = ContentUris.withAppendedId(People.CONTENT_URI,
154
-                    cursor.getLong(cursor.getColumnIndex("person")));
155
-            image.setImageBitmap(Contacts.People.loadContactPhoto(context,
156
-                    uri, R.drawable.blank, null));
157
-        } else {
158
-            title.setText(Html.fromHtml("<b>" + (name.length() == 0 ? email : name) + "</b> ("
159
-                    + count + ")"));
123
+    public Map<String, String> getMap(final Email email) {
124
+        final Map<String, String> params = new HashMap<String, String>();
125
+        if (email.getId() >= 0) {
126
+            params.put("contactid", String.valueOf(email.getId()));
160 127
         }
161 128
 
162
-        cursor.close();
129
+        params.put("contactemail", email.getAddress());
163 130
 
164
-        final TextView body = (TextView) view.findViewById(R.id.body);
165
-        body.setText(text);
131
+        return params;
132
+    }
166 133
 
167
-        return view;
134
+    public int compare(final Email arg0, final Email arg1) {
135
+        return getScore(getMap(arg1)) - getScore(getMap(arg0));
168 136
     }
169 137
 
170 138
 }

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

@@ -27,6 +27,7 @@ import android.content.Context;
27 27
 import android.content.Intent;
28 28
 import android.database.Cursor;
29 29
 import android.net.Uri;
30
+import android.os.Handler;
30 31
 import android.provider.Contacts;
31 32
 import android.provider.Contacts.People;
32 33
 import android.text.Html;
@@ -36,6 +37,8 @@ import android.widget.ImageView;
36 37
 import android.widget.LinearLayout;
37 38
 import android.widget.LinearLayout.LayoutParams;
38 39
 import android.widget.TextView;
40
+import java.util.ArrayList;
41
+import java.util.List;
39 42
 import uk.co.md87.android.contexthome.DataHelper;
40 43
 import uk.co.md87.android.contexthome.Module;
41 44
 import uk.co.md87.android.contexthome.R;
@@ -55,10 +58,12 @@ public class SmsModule extends Module {
55 58
 
56 59
     /** {@inheritDoc} */
57 60
     @Override
58
-    public View getView(final Context context, final int weight) {
59
-        final LinearLayout layout = new LinearLayout(context);
60
-        layout.setOrientation(LinearLayout.VERTICAL);
61
+    public void addViews(final ViewGroup parent, final Context context, final int weight) {
62
+        final Handler handler = new Handler();
61 63
 
64
+        new Thread(new Runnable() {
65
+
66
+            public void run() {
62 67
         final Cursor cursor = context.getContentResolver().query(INBOX_URI,
63 68
                 new String[] { "thread_id", "date", "body", "address" }, null, null, "date DESC");
64 69
         final int idIndex = cursor.getColumnIndex("thread_id");
@@ -69,23 +74,30 @@ public class SmsModule extends Module {
69 74
                 LayoutParams.WRAP_CONTENT);
70 75
         params.weight = 1;
71 76
 
77
+        final List<View> views = new ArrayList<View>(weight);
72 78
         boolean success = cursor.moveToFirst();
73 79
         for (int i = 0; i < weight && success; i++) {
74 80
             final String body = cursor.getString(bodyIndex);
75 81
             final String address = cursor.getString(addressIndex);
76 82
 
77
-            layout.addView(getView(context, layout, body, address, cursor.getLong(idIndex)),
78
-                    params);
83
+            final View view = getView(context, body, address, cursor.getLong(idIndex));
84
+
85
+        handler.post(new Runnable() {
86
+
87
+                    public void run() {
88
+                        parent.addView(view);
89
+                    }
90
+                });
79 91
 
80 92
             success = cursor.moveToNext();
81 93
         }
82 94
         cursor.close();
83
-        
84
-
85
-        return layout;
95
+       
96
+                    }
97
+        }).start();
86 98
     }
87 99
 
88
-    private View getView(final Context context, ViewGroup layout, String text,
100
+    private View getView(final Context context, String text,
89 101
             String address, final long threadId) {
90 102
         final View view = View.inflate(context, R.layout.titledimage, null);
91 103
         view.setClickable(true);

Laddar…
Avbryt
Spara