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 | |
| 23 | /** |
Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame^] | 24 | * Group meta-data loader. Loads all groups or just a single group from the |
| 25 | * database (if given a {@link Uri}). |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 26 | */ |
| 27 | public final class GroupMetaDataLoader extends CursorLoader { |
| 28 | |
| 29 | private final static String[] COLUMNS = new String[] { |
| 30 | Groups.ACCOUNT_NAME, |
| 31 | Groups.ACCOUNT_TYPE, |
| 32 | Groups._ID, |
| 33 | Groups.TITLE, |
| 34 | Groups.AUTO_ADD, |
| 35 | Groups.FAVORITES, |
| 36 | }; |
| 37 | |
| 38 | public final static int ACCOUNT_NAME = 0; |
| 39 | public final static int ACCOUNT_TYPE = 1; |
| 40 | public final static int GROUP_ID = 2; |
| 41 | public final static int TITLE = 3; |
| 42 | public final static int AUTO_ADD = 4; |
| 43 | public final static int FAVORITES = 5; |
| 44 | |
Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame^] | 45 | public GroupMetaDataLoader(Context context, Uri groupUri) { |
| 46 | super(context, ensureIsGroupUri(groupUri), COLUMNS, Groups.ACCOUNT_TYPE + " NOT NULL AND " |
Dmitri Plotnikov | 234e784 | 2010-11-29 16:10:20 -0800 | [diff] [blame] | 47 | + Groups.ACCOUNT_NAME + " NOT NULL", null, null); |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 48 | } |
Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame^] | 49 | |
| 50 | /** |
| 51 | * Ensures that this is a valid group URI. If invalid, then an exception is |
| 52 | * thrown. Otherwise, the original URI is returned. |
| 53 | */ |
| 54 | private static Uri ensureIsGroupUri(final Uri groupUri) { |
| 55 | // TODO: Fix ContactsProvider2 getType method to resolve the group Uris |
| 56 | if (groupUri == null) { |
| 57 | throw new IllegalArgumentException("Uri must not be null"); |
| 58 | } |
| 59 | if (!groupUri.toString().startsWith(Groups.CONTENT_URI.toString())) { |
| 60 | throw new IllegalArgumentException("Invalid group Uri: " + groupUri); |
| 61 | } |
| 62 | return groupUri; |
| 63 | } |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 64 | } |