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; }
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); }
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); }
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()); }
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; }
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; }
@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"); }
/** * ��ȡ������ϵ�˷��� * * @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; }
/** * ��Ⱥ���� * * @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); }
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; }
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; }
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"); }
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; }
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(); } }
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; }
public GroupOperations updateDirtyFlag(boolean isDirty, Uri uri) { int isDirtyValue = isDirty ? 1 : 0; mValues.clear(); mValues.put(Groups.DIRTY, isDirtyValue); addUpdateOp(uri); return this; }
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; }
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; }
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(); }
/** * 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; }
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); }
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); }
private static void deleteContactGroup(long rawContactGroupId, BatchOperation batchOperation) { batchOperation.add(GroupOperations.newDeleteCpo( ContentUris.withAppendedId(Groups.CONTENT_URI, rawContactGroupId), true, true).build()); }
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; }
/** * 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; }
/** * ɾ���� * * @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); }
/** * �½��� * * @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); }