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 */ 16 package com.android.contacts; 17 18 import android.content.Context; 19 import android.content.CursorLoader; 20 import android.net.Uri; 21 import android.provider.ContactsContract.Groups; 22 23 /** 24 * Group meta-data loader. Loads all groups or just a single group from the 25 * database (if given a {@link Uri}). 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.DATA_SET, 33 Groups._ID, 34 Groups.TITLE, 35 Groups.AUTO_ADD, 36 Groups.FAVORITES, 37 Groups.GROUP_IS_READ_ONLY, 38 Groups.DELETED, 39 }; 40 41 public final static int ACCOUNT_NAME = 0; 42 public final static int ACCOUNT_TYPE = 1; 43 public final static int DATA_SET = 2; 44 public final static int GROUP_ID = 3; 45 public final static int TITLE = 4; 46 public final static int AUTO_ADD = 5; 47 public final static int FAVORITES = 6; 48 public final static int IS_READ_ONLY = 7; 49 public final static int DELETED = 8; 50 51 public GroupMetaDataLoader(Context context, Uri groupUri) { 52 super(context, ensureIsGroupUri(groupUri), COLUMNS, Groups.ACCOUNT_TYPE + " NOT NULL AND " 53 + Groups.ACCOUNT_NAME + " NOT NULL", null, null); 54 } 55 56 /** 57 * Ensures that this is a valid group URI. If invalid, then an exception is 58 * thrown. Otherwise, the original URI is returned. 59 */ 60 private static Uri ensureIsGroupUri(final Uri groupUri) { 61 // TODO: Fix ContactsProvider2 getType method to resolve the group Uris 62 if (groupUri == null) { 63 throw new IllegalArgumentException("Uri must not be null"); 64 } 65 if (!groupUri.toString().startsWith(Groups.CONTENT_URI.toString())) { 66 throw new IllegalArgumentException("Invalid group Uri: " + groupUri); 67 } 68 return groupUri; 69 } 70 } 71