blob: 8ca199a982277468491231f3b5cebe1e041e59be [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
19import android.content.Intent;
20import android.content.Context;
21import android.net.Uri;
22import android.app.Activity;
23import android.os.Bundle;
24import android.provider.LiveFolders;
25import android.provider.Contacts;
26
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),
42 R.drawable.ic_launcher_contacts_starred));
43 } 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),
65 R.drawable.ic_launcher_contacts_phones));
66 } 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),
88 R.drawable.ic_launcher_contacts));
89 } 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);
103 intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent(Intent.ACTION_VIEW,
104 Contacts.People.CONTENT_URI));
105 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}