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

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


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

@@ -27,6 +27,7 @@ import android.os.Bundle;
27 27
 import android.widget.LinearLayout.LayoutParams;
28 28
 import android.widget.LinearLayout;
29 29
 import uk.co.md87.android.contexthome.modules.AppsModule;
30
+import uk.co.md87.android.contexthome.modules.ContactsModule;
30 31
 import uk.co.md87.android.contexthome.modules.EmailModule;
31 32
 import uk.co.md87.android.contexthome.modules.SmsModule;
32 33
 
@@ -43,7 +44,7 @@ public class ContextHome extends Activity {
43 44
 
44 45
     private LinearLayout layout;
45 46
     private final Module[] modules = new Module[]{
46
-        new AppsModule(), new SmsModule(), new EmailModule(), new SmsModule(),
47
+        new ContactsModule(), new AppsModule(), new EmailModule(), new SmsModule(),
47 48
     };
48 49
 
49 50
     /** Called when the activity is first created. */

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

@@ -0,0 +1,97 @@
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.ComponentName;
26
+import android.content.ContentUris;
27
+import android.content.Context;
28
+import android.content.Intent;
29
+import android.content.pm.ActivityInfo;
30
+import android.content.pm.PackageInfo;
31
+import android.content.pm.PackageManager;
32
+import android.content.pm.ResolveInfo;
33
+import android.database.Cursor;
34
+import android.net.Uri;
35
+import android.provider.Contacts;
36
+import android.provider.Contacts.People;
37
+import android.provider.Contacts.Photos;
38
+import android.util.Log;
39
+import android.view.View;
40
+import android.widget.ImageView;
41
+import android.widget.LinearLayout;
42
+import java.util.Arrays;
43
+import uk.co.md87.android.contexthome.Module;
44
+import uk.co.md87.android.contexthome.R;
45
+
46
+/**
47
+ * A module which displays contact shortcuts.
48
+ *
49
+ * @author chris
50
+ */
51
+public class ContactsModule implements Module {
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public View getView(final Context context, final int weight) {
56
+        final View view = View.inflate(context, R.layout.scroller, null);
57
+        final LinearLayout layout = (LinearLayout) view.findViewById(R.id.content);
58
+
59
+        final View.OnClickListener listener = new View.OnClickListener() {
60
+
61
+            public void onClick(View view) {
62
+                Intent intent = new Intent(Intent.ACTION_VIEW);
63
+                intent.setType(People.CONTENT_ITEM_TYPE);
64
+                intent.setData((Uri) view.getTag());
65
+                context.startActivity(intent);
66
+
67
+            }
68
+        };
69
+
70
+        final Cursor cursor = context.getContentResolver().query(Photos.CONTENT_URI,
71
+                new String[] { "person" }, "exists_on_server != 0", null, null);
72
+
73
+        final int column = cursor.getColumnIndex("person");
74
+        if (cursor.moveToFirst()) {
75
+            do {
76
+                layout.addView(getView(context, listener, cursor.getLong(column)));
77
+            } while (cursor.moveToNext());
78
+        }
79
+
80
+        return view;
81
+    }
82
+
83
+    private final View getView(final Context context, View.OnClickListener listener,
84
+            final long id) {
85
+        final ImageView image = new ImageView(context);
86
+        image.setFocusable(true);
87
+        image.setClickable(true);
88
+        Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, id);
89
+        image.setTag(uri);
90
+        image.setImageBitmap(People.loadContactPhoto(context,
91
+                    uri, R.drawable.blank, null));
92
+        image.setOnClickListener(listener);
93
+
94
+        return image;
95
+    }
96
+
97
+}

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