Java 类android.provider.ContactsContract.Groups 实例源码

项目:mc_backup    文件:ContactService.java   
private long getGroupId(String groupName) {
    long groupId = -1;
    Cursor cursor = getGroups(Groups.TITLE + " = '" + groupName + "'");

    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        String groupAccountName = cursor.getString(GROUP_ACCOUNT_NAME);
        String groupAccountType = cursor.getString(GROUP_ACCOUNT_TYPE);

        // Check if the account name and type for the group match the account name and type of
        // the account we're working with or the default "Phone" account if no account was found
        if (groupAccountName.equals(mAccountName) && groupAccountType.equals(mAccountType) ||
            (mAccountName == null && "Phone".equals(groupAccountType))) {
            if (groupName.equals(cursor.getString(GROUP_TITLE))) {
                groupId = cursor.getLong(GROUP_ID);
                break;
            }
        }
    }
    cursor.close();

    return groupId;
}
项目:mc_backup    文件:ContactService.java   
private Cursor getGroups(String selectArg) {
    String[] columns = new String[] {
        Groups.ACCOUNT_NAME,
        Groups.ACCOUNT_TYPE,
        Groups._ID,
        Groups.TITLE,
        (Versions.feature11Plus ? Groups.AUTO_ADD : Groups._ID)
    };

    if (selectArg != null) {
        selectArg = "AND " + selectArg;
    } else {
        selectArg = "";
    }

    return mContentResolver.query(Groups.CONTENT_URI, columns,
                                  Groups.ACCOUNT_TYPE + " NOT NULL AND " +
                                  Groups.ACCOUNT_NAME + " NOT NULL " + selectArg, null, null);
}
项目:mc_backup    文件:ContactService.java   
private long createGroup(String groupName) {
    if (DEBUG) {
        Log.d(LOGTAG, "Creating group: " + groupName);
    }

    ArrayList<ContentProviderOperation> newGroupOptions = new ArrayList<ContentProviderOperation>();

    // Create the group under the account we're using
    // If no account is selected, use a default account name/type for the group
    newGroupOptions.add(ContentProviderOperation.newInsert(Groups.CONTENT_URI)
                            .withValue(Groups.ACCOUNT_NAME, (mAccountName == null ? "Phone" : mAccountName))
                            .withValue(Groups.ACCOUNT_TYPE, (mAccountType == null ? "Phone" : mAccountType))
                            .withValue(Groups.TITLE, groupName)
                            .withValue(Groups.GROUP_VISIBLE, true)
                            .build());

    applyBatch(newGroupOptions);

    // Return the ID of the newly created group
    return getGroupId(groupName);
}
项目:ntsync-android    文件:GroupOperations.java   
public GroupOperations(String sourceId, String accountName, String title,
        String notes, boolean isSyncOperation, BatchOperation batchOperation) {
    this(isSyncOperation, batchOperation);
    mValues.put(Groups.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
    mValues.put(Groups.ACCOUNT_NAME, accountName);

    if (!TextUtils.isEmpty(title)) {
        mValues.put(Groups.TITLE, title);
    }

    if (!TextUtils.isEmpty(notes)) {
        mValues.put(Groups.NOTES, notes);
    }

    if (!TextUtils.isEmpty(sourceId)) {
        mValues.put(Groups.SOURCE_ID, sourceId);
    }

    ContentProviderOperation.Builder builder = newInsertCpo(
            Groups.CONTENT_URI, mIsSyncOperation, true).withValues(mValues);
    mBatchOperation.add(builder.build());
}
项目:ntsync-android    文件:ContactManager.java   
private static String getGroupSourceId(ContentResolver resolver,
        long groupId) {
    String sourceGroupId = null;
    final Cursor cursor = resolver.query(Groups.CONTENT_URI,
            new String[] { Groups.SOURCE_ID, }, Groups._ID + "=?",
            new String[] { String.valueOf(groupId) }, null);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                sourceGroupId = cursor.getString(0);
            }
        } finally {
            cursor.close();
        }
    }
    return sourceGroupId;
}
项目:fnzy    文件:ContactAccessorPost20.java   
public Map<Integer, Group> getGroups(Context context) {
  final Map<Integer, Group> map = new LinkedHashMap<Integer, Group>();

  map.put(EVERYBODY_ID, new Group(EVERYBODY_ID, context.getString(R.string.everybody), 0));

  final Cursor c = context.getContentResolver().query(
            Groups.CONTENT_SUMMARY_URI,
            new String[] { Groups._ID, Groups.TITLE, Groups.SUMMARY_COUNT },
            null,
            null,
            Groups.TITLE + " ASC");

  while (c != null && c.moveToNext()) {
    map.put(c.getInt(0), new Group(c.getInt(0), c.getString(1), c.getInt(2)));
  }

  if (c != null) c.close();
  return map;
}
项目:CSipSimple    文件:ContactsUtils5.java   
@Override
public Cursor getGroups(Context context) {
    Uri searchUri = Groups.CONTENT_URI;
    String[] projection = new String[] {
            Groups._ID,
            Groups.TITLE /* No need of as title, since already title */
    };

    return context.getContentResolver().query(searchUri, projection, null, null,
            Groups.TITLE + " ASC");
}
项目:phoneContact    文件:GroupDAO.java   
/**
 * ��ȡ������ϵ�˷���
 * 
 * @param context
 *            ������
 * @return
 */
public ArrayList<GroupBean> getGroups() {
    Cursor cursor = context.getContentResolver().query(Groups.CONTENT_URI,
            null, null, null, null);
    ArrayList<GroupBean> list = new ArrayList<GroupBean>();

    while (cursor.moveToNext()) {
        // �õ�״̬--�Ƿ�ɾ��
        int isDeleted = cursor
                .getInt(cursor.getColumnIndex(Groups.DELETED));
        if (isDeleted == 0) {
            GroupBean gb = new GroupBean();
            // �������
            String name = cursor.getString(cursor
                    .getColumnIndex(Groups.TITLE));
            gb.setName(name);
            // �����id
            int groupId = cursor.getInt(cursor.getColumnIndex(Groups._ID));
            gb.setId(groupId);
            int count = new ContactDAO(context).getContactsByGroupId(
                    groupId).size();
            gb.setCount(count);
            list.add(gb);
        }
    }
    cursor.close();
    return list;
}
项目:phoneContact    文件:GroupDAO.java   
/**
 * �޸�Ⱥ����
 * 
 * @param rawContactId
 */
public void updataGroup(int groupId, String groupName) {
    System.out.println("update group...");
    ContentValues values = new ContentValues();
    values.put(Groups.TITLE, groupName);
    String where = ContactsContract.Groups._ID + "=? ";
    String[] selectionArgs = new String[] { String.valueOf(groupId) };
    context.getContentResolver().update(Groups.CONTENT_URI, values, where,
            selectionArgs);
}
项目:phoneContact    文件:GroupDAO.java   
public String getGroupNameByGroupId(long groupId) {
    String groupName = "";
    String[] PROJECTION = new String[] { Groups.TITLE };
    String SELECTION = Groups._ID + "=?";
    Cursor cursor = context.getContentResolver().query(Groups.CONTENT_URI,
            PROJECTION, SELECTION, new String[] { groupId + "" }, null);
    while (cursor.moveToNext()) {
        groupName = cursor.getString(cursor.getColumnIndex(Groups.TITLE));
    }
    cursor.close();
    return groupName;
}
项目:phoneContact    文件:GroupDAO.java   
public int getIdByGroupName(String groupName) {
    int groupId = 0;
    String[] PROJECTION = new String[] { Groups._ID };
    String SELECTION = Groups.TITLE + "=?";
    Cursor cursor = context.getContentResolver().query(Groups.CONTENT_URI,
            PROJECTION, SELECTION, new String[] { groupName + "" }, null);
    while (cursor.moveToNext()) {
        groupId = cursor.getInt(cursor.getColumnIndex(Groups._ID));
    }
    cursor.close();
    return groupId;
}
项目:text-merge    文件:GroupListLoader.java   
public GroupListLoader(Context context) {
    super(context, GROUP_LIST_URI, COLUMNS, Groups.ACCOUNT_TYPE + " NOT NULL AND "
                    + Groups.ACCOUNT_NAME + " NOT NULL AND " + Groups.AUTO_ADD + "=0 AND " +
                    Groups.FAVORITES + "=0 AND " + Groups.DELETED + "=0", null,
            Groups.ACCOUNT_TYPE + ", " + Groups.ACCOUNT_NAME + ", " + Groups.DATA_SET + ", " +
                    Groups.TITLE + " COLLATE LOCALIZED ASC");
}
项目:mc_backup    文件:ContactService.java   
private String getGroupName(long groupId) {
    Cursor cursor = getGroups(Groups._ID + " = " + groupId);

    if (cursor.getCount() == 0) {
        cursor.close();
        return null;
    }

    cursor.moveToPosition(0);
    String groupName = cursor.getString(cursor.getColumnIndex(Groups.TITLE));
    cursor.close();

    return groupName;
}
项目:PanBox    文件:AddressbookManagerAndroid.java   
public AddressbookManagerAndroid(Context context,
        ContentResolver contentResolver) {
    this.cr = contentResolver;
    // this.context = context;

    am = AccountManager.get(context);

    panboxAccount = new Account(accountName, accountType);
    am.addAccountExplicitly(panboxAccount, null, null);

    ContentProviderClient client = contentResolver
            .acquireContentProviderClient(ContactsContract.AUTHORITY_URI);
    ContentValues values = new ContentValues();
    values.put(ContactsContract.Groups.ACCOUNT_NAME, accountName);
    values.put(Groups.ACCOUNT_TYPE, accountType);
    values.put(Settings.UNGROUPED_VISIBLE, true);
    values.put(Settings.SHOULD_SYNC, false);
    try {
        client.insert(
                Settings.CONTENT_URI
                        .buildUpon()
                        .appendQueryParameter(
                                ContactsContract.CALLER_IS_SYNCADAPTER,
                                "true").build(), values);
    } catch (RemoteException e) {
        e.printStackTrace();
    }

}
项目:android-authenticator    文件:ContactManager.java   
public static long ensureXWikiGroupExists(Context context, String accountName) {
    final ContentResolver resolver = context.getContentResolver();

    // Lookup the group
    long groupId = 0;
    final Cursor cursor = resolver.query(Groups.CONTENT_URI, new String[]{Groups._ID},
            Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=? AND " +
                    Groups.TITLE + "=?",
            new String[]{accountName, Constants.ACCOUNT_TYPE, XWIKI_GROUP_NAME}, null);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                groupId = cursor.getLong(0);
            }
        } finally {
            cursor.close();
        }
    }

    if (groupId == 0) {
        // the group doesn't exist yet, so create it
        final ContentValues contentValues = new ContentValues();
        contentValues.put(Groups.ACCOUNT_NAME, accountName);
        contentValues.put(Groups.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
        contentValues.put(Groups.TITLE, XWIKI_GROUP_NAME);
        contentValues.put(Groups.GROUP_IS_READ_ONLY, true);

        final Uri newGroupUri = resolver.insert(Groups.CONTENT_URI, contentValues);
        groupId = ContentUris.parseId(newGroupUri);
    }
    return groupId;
}
项目:ntsync-android    文件:GroupOperations.java   
public GroupOperations updateDirtyFlag(boolean isDirty, Uri uri) {
    int isDirtyValue = isDirty ? 1 : 0;
    mValues.clear();
    mValues.put(Groups.DIRTY, isDirtyValue);
    addUpdateOp(uri);
    return this;
}
项目:ntsync-android    文件:GroupOperations.java   
public GroupOperations updateGroup(Uri uri, String existingTitle,
        String existingNotes, String title, String notes) {

    mValues.clear();
    if (!TextUtils.equals(existingTitle, title)) {
        mValues.put(Groups.TITLE, title);
    }
    if (!TextUtils.equals(existingNotes, notes)) {
        mValues.put(Groups.NOTES, notes);
    }
    if (mValues.size() > 0) {
        addUpdateOp(uri);
    }
    return this;
}
项目:ntsync-android    文件:GroupOperations.java   
public GroupOperations updateSourceId(String sourceId, Uri uri) {
    mValues.clear();
    if (TextUtils.isEmpty(sourceId)) {
        mValues.putNull(Groups.SOURCE_ID);
    } else {
        mValues.put(Groups.SOURCE_ID, sourceId);
    }
    addUpdateOp(uri);
    return this;
}
项目:ntsync-android    文件:ContactManager.java   
public static void setContactGroupDirtyFlag(Context context, Account account)
        throws OperationApplicationException {
    final ContentResolver resolver = context.getContentResolver();
    final BatchOperation batchOperation = new BatchOperation(resolver);

    final Cursor c = resolver.query(GroupQuery.CONTENT_URI,
            GroupQuery.PROJECTION, GroupQuery.SELECTION_ALL,
            new String[] { account.name }, null);
    try {
        while (c.moveToNext()) {
            final long groupId = c.getLong(GroupQuery.COLUMN_ID);
            final GroupOperations groupOp = GroupOperations
                    .updateExistingGroup(true, batchOperation);

            final Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI,
                    groupId);
            groupOp.updateDirtyFlag(true, uri);
        }

    } finally {
        if (c != null) {
            c.close();
        }
    }

    batchOperation.execute();
}
项目:ntsync-android    文件:ContactManager.java   
/**
 * Create a default Group.
 * 
 * @param context
 * @param account
 * @return
 */
public static long ensureSampleGroupExists(Context context, Account account) {
    final ContentResolver resolver = context.getContentResolver();

    String sampleGroupName = context.getText(R.string.samplegroup_name)
            .toString();
    long groupId = 0;
    final Cursor cursor = resolver.query(Groups.CONTENT_URI,
            new String[] { Groups._ID },
            Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE
                    + "=? AND " + Groups.TITLE + "=?", new String[] {
                    account.name, account.type, sampleGroupName }, null);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                groupId = cursor.getLong(0);
            }
        } finally {
            cursor.close();
        }
    }

    if (groupId == 0) {
        // Sample group doesn't exist yet, so create it
        final ContentValues contentValues = new ContentValues();
        contentValues.put(Groups.ACCOUNT_NAME, account.name);
        contentValues.put(Groups.ACCOUNT_TYPE, account.type);
        contentValues.put(Groups.TITLE, sampleGroupName);

        final Uri newGroupUri = resolver.insert(Groups.CONTENT_URI,
                contentValues);
        groupId = ContentUris.parseId(newGroupUri);
    }
    return groupId;
}
项目:ntsync-android    文件:ContactManager.java   
private static void setGroupSourceId(long groupId, String sourceId,
        BatchOperation batchOperation) {
    GroupOperations groupOp = GroupOperations.updateExistingGroup(true,
            batchOperation);
    final Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);
    groupOp.updateSourceId(sourceId, uri);
}
项目:ntsync-android    文件:ContactManager.java   
private static void clearGroupDirtyFlag(long rawGroupId,
        BatchOperation batchOperation) {
    final GroupOperations groupOp = GroupOperations.updateExistingGroup(
            true, batchOperation);
    final Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI,
            rawGroupId);
    groupOp.updateDirtyFlag(false, uri);
}
项目:ntsync-android    文件:ContactManager.java   
private static void deleteContactGroup(long rawContactGroupId,
        BatchOperation batchOperation) {

    batchOperation.add(GroupOperations.newDeleteCpo(
            ContentUris.withAppendedId(Groups.CONTENT_URI,
                    rawContactGroupId), true, true).build());
}
项目:businessmap    文件:ContactUtils.java   
public static List<ContactsGroup> getContactsGroupList(Context context) {
    List<ContactsGroup> list = new ArrayList<ContactsGroup>();
    ContactsGroup all = new ContactsGroup(
            ContactsGroup.ID_GROUP_ALL_CONTACTS,
            context.getString(R.string.group_all_contacts), "");
    list.add(all);

    Cursor groupCursor = null;
    try {
        groupCursor = context.getContentResolver().query(
                Groups.CONTENT_URI,
                new String[] {
                        Groups._ID,
                        Groups.TITLE,
                        Groups.ACCOUNT_NAME },
                Groups.DELETED + "=0",
                null,
                null);
        while (groupCursor.moveToNext()) {
            long _id = groupCursor.getLong(0);
            String title = groupCursor.getString(1);
            String accountName = groupCursor.getString(2);
            ContactsGroup group = new ContactsGroup(_id, title, accountName);
            list.add(group);
        }
    } finally {
        if (groupCursor != null) {
            groupCursor.close();
        }
    }
    return list;
}
项目:ntsync-android    文件:ContactManager.java   
/**
 * Search a Group by Name (for import) or create a new group.
 * 
 * @param resolver
 * @param groupId
 * @param importAccountNameDest
 * @return Group-Id
 */
private static Long getGroupByName(ContentResolver resolver, long groupId,
        String importAccountNameDest) {
    // Search Group by Name
    // Get Name
    String groupName = null;
    Cursor cursor = resolver.query(Groups.CONTENT_URI,
            new String[] { Groups.TITLE, }, Groups._ID + "=?",
            new String[] { String.valueOf(groupId) }, null);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                groupName = cursor.getString(0);
            }
        } finally {
            cursor.close();
        }
    }

    Long newGroupId = null;
    // Search by name with importAccountNameDest
    if (!TextUtils.isEmpty(groupName)) {
        cursor = resolver.query(Groups.CONTENT_URI,
                new String[] { Groups._ID, }, Groups.ACCOUNT_TYPE
                        + "=? AND " + Groups.ACCOUNT_NAME + "=? AND "
                        + Groups.TITLE + "=?", new String[] {
                        Constants.ACCOUNT_TYPE, importAccountNameDest,
                        groupName }, null);
        try {
            if (cursor.moveToFirst()) {
                newGroupId = cursor.getLong(0);
            }
        } finally {
            cursor.close();
        }

        if (newGroupId == null) {
            // Create a new Group
            ContentValues values = new ContentValues();
            values.put(Groups.TITLE, groupName);
            values.put(Groups.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
            values.put(Groups.ACCOUNT_NAME, importAccountNameDest);
            Uri groupUri = resolver.insert(Groups.CONTENT_URI, values);
            newGroupId = ContentUris.parseId(groupUri);
        }
    }

    return newGroupId;
}
项目:phoneContact    文件:GroupDAO.java   
/**
 * ɾ����
 * 
 * @param groupId
 *            ��id
 * @param context
 *            ������
 */
public void deleteGroup(int groupId) {
    context.getContentResolver().delete(
            Uri.parse(Groups.CONTENT_URI + "?"
                    + ContactsContract.CALLER_IS_SYNCADAPTER + "=true"),
            Groups._ID + "=" + groupId, null);
}
项目:phoneContact    文件:GroupDAO.java   
/**
 * �½���
 * 
 * @param groupName
 *            ����
 * @param context
 *            ������
 */
public void addGroup(String groupName) {
    ContentValues values = new ContentValues();
    values.put(Groups.TITLE, groupName);
    context.getContentResolver().insert(Groups.CONTENT_URI, values);
}