blob: 64be0e22af6d2fafd1513b1d0cd061d1fe82618d [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts;
18
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080019import android.app.Activity;
Dmitri Plotnikove2b2f702009-09-17 18:15:44 -070020import android.content.Context;
21import android.content.Intent;
22import android.net.Uri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080023import android.os.Bundle;
Dmitri Plotnikove2b2f702009-09-17 18:15:44 -070024import android.provider.ContactsContract.Contacts;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080025import android.provider.LiveFolders;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080026
27public class ContactsLiveFolders {
28 public static class StarredContacts extends Activity {
29 public static final Uri CONTENT_URI =
30 Uri.parse("content://contacts/live_folders/favorites");
31
32 @Override
33 protected void onCreate(Bundle savedInstanceState) {
34 super.onCreate(savedInstanceState);
35
36 final Intent intent = getIntent();
37 final String action = intent.getAction();
38
39 if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
40 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,
41 getString(R.string.liveFolder_favorites_label),
Romain Guy4eb77b62009-03-24 18:10:17 -070042 R.drawable.ic_launcher_folder_live_contacts_starred));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043 } else {
44 setResult(RESULT_CANCELED);
45 }
46
47 finish();
48 }
49 }
50
51 public static class PhoneContacts extends Activity {
52 public static final Uri CONTENT_URI =
53 Uri.parse("content://contacts/live_folders/people_with_phones");
54
55 @Override
56 protected void onCreate(Bundle savedInstanceState) {
57 super.onCreate(savedInstanceState);
58
59 final Intent intent = getIntent();
60 final String action = intent.getAction();
61
62 if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
63 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,
64 getString(R.string.liveFolder_phones_label),
Romain Guy4eb77b62009-03-24 18:10:17 -070065 R.drawable.ic_launcher_folder_live_contacts_phone));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080066 } else {
67 setResult(RESULT_CANCELED);
68 }
69
70 finish();
71 }
72 }
73
74 public static class AllContacts extends Activity {
75 public static final Uri CONTENT_URI =
76 Uri.parse("content://contacts/live_folders/people");
77
78 @Override
79 protected void onCreate(Bundle savedInstanceState) {
80 super.onCreate(savedInstanceState);
81
82 final Intent intent = getIntent();
83 final String action = intent.getAction();
84
85 if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
86 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,
87 getString(R.string.liveFolder_all_label),
Romain Guy4eb77b62009-03-24 18:10:17 -070088 R.drawable.ic_launcher_folder_live_contacts));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080089 } else {
90 setResult(RESULT_CANCELED);
91 }
92
93 finish();
94 }
95 }
96
97 private static Intent createLiveFolder(Context context, Uri uri, String name,
98 int icon) {
99
100 final Intent intent = new Intent();
101
102 intent.setData(uri);
Dmitri Plotnikove2b2f702009-09-17 18:15:44 -0700103 intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,
104 new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800105 intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);
106 intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
107 Intent.ShortcutIconResource.fromContext(context, icon));
108 intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
109
110 return intent;
111 }
112}