The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 19 | import android.app.Activity; |
Dmitri Plotnikov | e2b2f70 | 2009-09-17 18:15:44 -0700 | [diff] [blame^] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.net.Uri; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 23 | import android.os.Bundle; |
Dmitri Plotnikov | e2b2f70 | 2009-09-17 18:15:44 -0700 | [diff] [blame^] | 24 | import android.provider.ContactsContract.Contacts; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 25 | import android.provider.LiveFolders; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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 |
| 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 Guy | 4eb77b6 | 2009-03-24 18:10:17 -0700 | [diff] [blame] | 42 | R.drawable.ic_launcher_folder_live_contacts_starred)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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), |
Romain Guy | 4eb77b6 | 2009-03-24 18:10:17 -0700 | [diff] [blame] | 65 | R.drawable.ic_launcher_folder_live_contacts_phone)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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), |
Romain Guy | 4eb77b6 | 2009-03-24 18:10:17 -0700 | [diff] [blame] | 88 | R.drawable.ic_launcher_folder_live_contacts)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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); |
Dmitri Plotnikov | e2b2f70 | 2009-09-17 18:15:44 -0700 | [diff] [blame^] | 103 | intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, |
| 104 | new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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 | } |