| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2010 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 |  */ | 
| Dmitri Plotnikov | 18ffaa2 | 2010-12-03 14:28:00 -0800 | [diff] [blame] | 16 | package com.android.contacts; | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 17 |  | 
 | 18 | import android.content.Context; | 
 | 19 | import android.content.CursorLoader; | 
| Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame] | 20 | import android.net.Uri; | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 21 | import android.provider.ContactsContract.Groups; | 
 | 22 |  | 
| Wenyi Wang | 9afadde | 2016-06-16 15:10:59 -0700 | [diff] [blame] | 23 | import com.android.contacts.group.GroupUtil; | 
 | 24 |  | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 25 | /** | 
| Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame] | 26 |  * Group meta-data loader. Loads all groups or just a single group from the | 
 | 27 |  * database (if given a {@link Uri}). | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 28 |  */ | 
 | 29 | public final class GroupMetaDataLoader extends CursorLoader { | 
 | 30 |  | 
| Walter Jang | 428824e | 2016-09-09 13:18:35 -0700 | [diff] [blame] | 31 |     public final static String[] COLUMNS = new String[] { | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 32 |         Groups.ACCOUNT_NAME, | 
 | 33 |         Groups.ACCOUNT_TYPE, | 
| Dave Santoro | 2b3f3c5 | 2011-07-26 17:35:42 -0700 | [diff] [blame] | 34 |         Groups.DATA_SET, | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 35 |         Groups._ID, | 
 | 36 |         Groups.TITLE, | 
 | 37 |         Groups.AUTO_ADD, | 
 | 38 |         Groups.FAVORITES, | 
| Katherine Kuan | c6b8afe | 2011-06-22 19:03:50 -0700 | [diff] [blame] | 39 |         Groups.GROUP_IS_READ_ONLY, | 
| Isaac Katzenelson | 2670734 | 2011-07-07 16:15:06 -0700 | [diff] [blame] | 40 |         Groups.DELETED, | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 41 |     }; | 
 | 42 |  | 
 | 43 |     public final static int ACCOUNT_NAME = 0; | 
 | 44 |     public final static int ACCOUNT_TYPE = 1; | 
| Dave Santoro | 2b3f3c5 | 2011-07-26 17:35:42 -0700 | [diff] [blame] | 45 |     public final static int DATA_SET = 2; | 
 | 46 |     public final static int GROUP_ID = 3; | 
 | 47 |     public final static int TITLE = 4; | 
 | 48 |     public final static int AUTO_ADD = 5; | 
 | 49 |     public final static int FAVORITES = 6; | 
 | 50 |     public final static int IS_READ_ONLY = 7; | 
 | 51 |     public final static int DELETED = 8; | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 52 |  | 
| Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame] | 53 |     public GroupMetaDataLoader(Context context, Uri groupUri) { | 
| Gary Mai | 5c1bff2 | 2016-09-30 15:10:25 -0700 | [diff] [blame] | 54 |         super(context, ensureIsGroupUri(groupUri), COLUMNS, GroupUtil.DEFAULT_SELECTION, null, | 
 | 55 |                 GroupUtil.getGroupsSortOrder()); | 
 | 56 |     } | 
 | 57 |  | 
 | 58 |     public GroupMetaDataLoader(Context context, Uri groupUri, String selection) { | 
 | 59 |         super(context, ensureIsGroupUri(groupUri), COLUMNS, selection, null, | 
| Walter Jang | dd2d8e2 | 2016-09-09 11:07:37 -0700 | [diff] [blame] | 60 |                 GroupUtil.getGroupsSortOrder()); | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 61 |     } | 
| Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame] | 62 |  | 
 | 63 |     /** | 
 | 64 |      * Ensures that this is a valid group URI. If invalid, then an exception is | 
 | 65 |      * thrown. Otherwise, the original URI is returned. | 
 | 66 |      */ | 
 | 67 |     private static Uri ensureIsGroupUri(final Uri groupUri) { | 
 | 68 |         // TODO: Fix ContactsProvider2 getType method to resolve the group Uris | 
 | 69 |         if (groupUri == null) { | 
 | 70 |             throw new IllegalArgumentException("Uri must not be null"); | 
 | 71 |         } | 
| Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 72 |         if (!GroupUtil.isGroupUri(groupUri)) { | 
| Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame] | 73 |             throw new IllegalArgumentException("Invalid group Uri: " + groupUri); | 
 | 74 |         } | 
 | 75 |         return groupUri; | 
 | 76 |     } | 
| Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 77 | } |