• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.contacts;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.net.Uri;
23 import android.os.Bundle;
24 import android.provider.ContactsContract.Contacts;
25 import android.provider.LiveFolders;
26 
27 public 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
onCreate(Bundle savedInstanceState)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_folder_live_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
onCreate(Bundle savedInstanceState)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_folder_live_contacts_phone));
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
onCreate(Bundle savedInstanceState)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_folder_live_contacts));
89             } else {
90                 setResult(RESULT_CANCELED);
91             }
92 
93             finish();
94         }
95     }
96 
createLiveFolder(Context context, Uri uri, String name, int icon)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,
104                 new Intent(Intent.ACTION_VIEW, Contacts.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 }
113