Просмотр исходного кода

Add people names and photos

master
Chris Smith 14 лет назад
Родитель
Сommit
236697549a

+ 1
- 0
code/ContextHome/AndroidManifest.xml Просмотреть файл

14
     </application>
14
     </application>
15
 
15
 
16
     <uses-permission android:name="android.permission.READ_SMS"/>
16
     <uses-permission android:name="android.permission.READ_SMS"/>
17
+    <uses-permission android:name="android.permission.READ_CONTACTS"/>
17
 
18
 
18
     <uses-sdk android:minSdkVersion="3" />
19
     <uses-sdk android:minSdkVersion="3" />
19
 </manifest>
20
 </manifest>

Двоичные данные
code/ContextHome/dist/ContextHome.apk Просмотреть файл


+ 22
- 0
code/ContextHome/res/layout/titledimage.xml Просмотреть файл

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+        android:layout_width="fill_parent" android:layout_height="wrap_content">
4
+    <ImageView
5
+        android:id="@+id/image"
6
+        android:layout_width="14pt"
7
+        android:layout_height="14pt"
8
+        android:layout_marginRight="4pt"
9
+        android:layout_centerVertical="true"
10
+        android:src="@drawable/icon"/>
11
+    <TextView
12
+        android:id="@+id/title"
13
+        android:layout_toRightOf="@id/image"
14
+        android:layout_width="wrap_content"
15
+        android:layout_height="wrap_content"/>
16
+    <TextView
17
+        android:id="@+id/body"
18
+        android:layout_below="@id/title"
19
+        android:layout_toRightOf="@id/image"
20
+        android:layout_width="wrap_content"
21
+        android:layout_height="wrap_content"/>
22
+</RelativeLayout>

+ 9
- 1
code/ContextHome/src/uk/co/md87/android/contexthome/R.java Просмотреть файл

13
     public static final class drawable {
13
     public static final class drawable {
14
         public static final int icon=0x7f020000;
14
         public static final int icon=0x7f020000;
15
     }
15
     }
16
+    public static final class id {
17
+        public static final int body=0x7f050002;
18
+        public static final int image=0x7f050000;
19
+        public static final int title=0x7f050001;
20
+    }
21
+    public static final class layout {
22
+        public static final int titledimage=0x7f030000;
23
+    }
16
     public static final class string {
24
     public static final class string {
17
-        public static final int app_name=0x7f030000;
25
+        public static final int app_name=0x7f040000;
18
     }
26
     }
19
 }
27
 }

+ 53
- 4
code/ContextHome/src/uk/co/md87/android/contexthome/modules/SmsModule.java Просмотреть файл

22
 
22
 
23
 package uk.co.md87.android.contexthome.modules;
23
 package uk.co.md87.android.contexthome.modules;
24
 
24
 
25
+import android.content.ContentUris;
25
 import android.content.Context;
26
 import android.content.Context;
26
 import android.database.Cursor;
27
 import android.database.Cursor;
27
 import android.net.Uri;
28
 import android.net.Uri;
29
+import android.provider.Contacts;
30
+import android.provider.Contacts.People;
31
+import android.text.Html;
28
 import android.view.View;
32
 import android.view.View;
33
+import android.view.ViewGroup;
34
+import android.widget.ImageView;
29
 import android.widget.LinearLayout;
35
 import android.widget.LinearLayout;
36
+import android.widget.LinearLayout.LayoutParams;
30
 import android.widget.TextView;
37
 import android.widget.TextView;
31
 import uk.co.md87.android.contexthome.Module;
38
 import uk.co.md87.android.contexthome.Module;
39
+import uk.co.md87.android.contexthome.R;
32
 
40
 
33
 /**
41
 /**
34
  * A module which displays SMS messages.
42
  * A module which displays SMS messages.
46
         layout.setOrientation(LinearLayout.VERTICAL);
54
         layout.setOrientation(LinearLayout.VERTICAL);
47
 
55
 
48
         final Cursor cursor = context.getContentResolver().query(INBOX_URI,
56
         final Cursor cursor = context.getContentResolver().query(INBOX_URI,
49
-                new String[] { "_id", "date", "body" }, null, null, "date DESC");
57
+                new String[] { "_id", "date", "body", "address" }, null, null, "date DESC");
58
+        final int bodyIndex = cursor.getColumnIndex("body");
59
+        final int addressIndex = cursor.getColumnIndex("address");
60
+
61
+        final LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
62
+                LayoutParams.WRAP_CONTENT);
63
+        params.weight = 1;
64
+
50
         boolean success = cursor.moveToFirst();
65
         boolean success = cursor.moveToFirst();
51
         for (int i = 0; i < weight && success; i++) {
66
         for (int i = 0; i < weight && success; i++) {
52
-            final TextView text = new TextView(context);
53
-            text.setText(cursor.getString(cursor.getColumnIndex("body")));
54
-            layout.addView(text);
67
+            final String body = cursor.getString(bodyIndex);
68
+            final String address = cursor.getString(addressIndex);
69
+
70
+            layout.addView(getView(context, layout, body, address), params);
71
+
55
             success = cursor.moveToNext();
72
             success = cursor.moveToNext();
56
         }
73
         }
57
         cursor.close();
74
         cursor.close();
60
         return layout;
77
         return layout;
61
     }
78
     }
62
 
79
 
80
+    private View getView(Context context, ViewGroup layout, String text, String address) {
81
+        final View view = View.inflate(context, R.layout.titledimage, null);
82
+
83
+        final Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL,
84
+                Uri.encode(address));
85
+
86
+        final Cursor cursor = context.getContentResolver().query(contactUri,
87
+                new String[] { Contacts.Phones.PERSON_ID,
88
+                Contacts.Phones.DISPLAY_NAME }, null, null, null);
89
+
90
+        final TextView title = (TextView) view.findViewById(R.id.title);
91
+        final ImageView image = (ImageView) view.findViewById(R.id.image);
92
+
93
+        if (cursor.moveToFirst()) {
94
+            title.setText(Html.fromHtml("<b>" + cursor.getString(cursor
95
+                    .getColumnIndex(Contacts.Phones.DISPLAY_NAME)) + "</b>"));
96
+            Uri uri = ContentUris.withAppendedId(People.CONTENT_URI,
97
+                    cursor.getLong(cursor.getColumnIndex(Contacts.Phones.PERSON_ID)));
98
+            image.setImageBitmap(Contacts.People.loadContactPhoto(context,
99
+                    uri, R.drawable.icon, null));
100
+        } else {
101
+            title.setText(Html.fromHtml("<b>" + address + "</b>"));
102
+        }
103
+
104
+        cursor.close();
105
+
106
+        final TextView body = (TextView) view.findViewById(R.id.body);
107
+        body.setText(text);
108
+
109
+        return view;
110
+    }
111
+
63
 }
112
 }

Загрузка…
Отмена
Сохранить