Search in sources :

Example 36 with MatrixCursor

use of android.database.MatrixCursor in project Signal-Android by WhisperSystems.

the class ContactsCursorLoader method loadInBackground.

@Override
public Cursor loadInBackground() {
    ContactsDatabase contactsDatabase = DatabaseFactory.getContactsDatabase(getContext());
    ArrayList<Cursor> cursorList = new ArrayList<>(3);
    if (mode != MODE_OTHER_ONLY) {
        cursorList.add(contactsDatabase.queryTextSecureContacts(filter));
    }
    if (mode == MODE_ALL) {
        cursorList.add(contactsDatabase.querySystemContacts(filter));
    } else if (mode == MODE_OTHER_ONLY) {
        cursorList.add(filterNonPushContacts(contactsDatabase.querySystemContacts(filter)));
    }
    if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) {
        MatrixCursor newNumberCursor = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN }, 1);
        newNumberCursor.addRow(new Object[] { -1L, getContext().getString(R.string.contact_selection_list__unknown_contact), filter, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM, "⇢", ContactsDatabase.NEW_TYPE });
        cursorList.add(newNumberCursor);
    }
    return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
Also used : ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Example 37 with MatrixCursor

use of android.database.MatrixCursor in project Signal-Android by WhisperSystems.

the class ContactsCursorLoader method filterNonPushContacts.

@NonNull
private Cursor filterNonPushContacts(@NonNull Cursor cursor) {
    try {
        final long startMillis = System.currentTimeMillis();
        final MatrixCursor matrix = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN });
        while (cursor.moveToNext()) {
            final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
            final Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), number, true);
            if (DirectoryHelper.getUserCapabilities(getContext(), recipients).getTextCapability() != Capability.SUPPORTED) {
                matrix.addRow(new Object[] { cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)), number, cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN)), ContactsDatabase.NORMAL_TYPE });
            }
        }
        Log.w(TAG, "filterNonPushContacts() -> " + (System.currentTimeMillis() - startMillis) + "ms");
        return matrix;
    } finally {
        cursor.close();
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) MatrixCursor(android.database.MatrixCursor) NonNull(android.support.annotation.NonNull)

Example 38 with MatrixCursor

use of android.database.MatrixCursor in project k-9 by k9mail.

the class AttachmentProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    String[] columnNames = (projection == null) ? DEFAULT_PROJECTION : projection;
    List<String> segments = uri.getPathSegments();
    String accountUuid = segments.get(0);
    String id = segments.get(1);
    final AttachmentInfo attachmentInfo;
    try {
        final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid);
        attachmentInfo = LocalStore.getInstance(account, getContext()).getAttachmentInfo(id);
    } catch (MessagingException e) {
        Timber.e(e, "Unable to retrieve attachment info from local store for ID: %s", id);
        return null;
    }
    if (attachmentInfo == null) {
        Timber.d("No attachment info for ID: %s", id);
        return null;
    }
    MatrixCursor ret = new MatrixCursor(columnNames);
    Object[] values = new Object[columnNames.length];
    for (int i = 0, count = columnNames.length; i < count; i++) {
        String column = columnNames[i];
        if (AttachmentProviderColumns._ID.equals(column)) {
            values[i] = id;
        } else if (AttachmentProviderColumns.DATA.equals(column)) {
            values[i] = uri.toString();
        } else if (AttachmentProviderColumns.DISPLAY_NAME.equals(column)) {
            values[i] = attachmentInfo.name;
        } else if (AttachmentProviderColumns.SIZE.equals(column)) {
            values[i] = attachmentInfo.size;
        }
    }
    ret.addRow(values);
    return ret;
}
Also used : Account(com.fsck.k9.Account) MessagingException(com.fsck.k9.mail.MessagingException) AttachmentInfo(com.fsck.k9.mailstore.LocalStore.AttachmentInfo) MatrixCursor(android.database.MatrixCursor)

Example 39 with MatrixCursor

use of android.database.MatrixCursor in project XPrivacy by M66B.

the class PrivacyProvider method queryUsage.

private Cursor queryUsage(int uid, String restrictionName, String methodName) {
    MatrixCursor cursor = new MatrixCursor(new String[] { COL_UID, COL_RESTRICTION, COL_METHOD, COL_RESTRICTED, COL_USED });
    List<String> listRestriction;
    if (restrictionName == null)
        listRestriction = PrivacyManager.getRestrictions();
    else {
        listRestriction = new ArrayList<String>();
        listRestriction.add(restrictionName);
    }
    if (uid == 0) {
        // All
        for (String eRestrictionName : PrivacyManager.getRestrictions()) {
            SharedPreferences prefs = getContext().getSharedPreferences(PREF_USAGE + "." + eRestrictionName, Context.MODE_PRIVATE);
            for (String prefName : prefs.getAll().keySet()) if (prefName.startsWith(COL_USED)) {
                String[] prefParts = prefName.split("\\.");
                int rUid = Integer.parseInt(prefParts[1]);
                String rMethodName = prefName.substring(prefParts[0].length() + 1 + prefParts[1].length() + 1);
                getUsage(rUid, eRestrictionName, rMethodName, cursor);
            }
        }
    } else {
        // Selected restrictions/methods
        for (String eRestrictionName : listRestriction) if (methodName == null)
            for (Hook md : PrivacyManager.getHooks(eRestrictionName, null)) getUsage(uid, eRestrictionName, md.getName(), cursor);
        else
            getUsage(uid, eRestrictionName, methodName, cursor);
    }
    return cursor;
}
Also used : SharedPreferences(android.content.SharedPreferences) MatrixCursor(android.database.MatrixCursor)

Example 40 with MatrixCursor

use of android.database.MatrixCursor in project XPrivacy by M66B.

the class PrivacyProvider method querySettings.

private Cursor querySettings(String name) {
    SharedPreferences prefs = getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE);
    MatrixCursor cursor = new MatrixCursor(new String[] { COL_SETTING, COL_VALUE });
    if (name == null)
        for (String settingKey : prefs.getAll().keySet()) try {
            cursor.addRow(new Object[] { getSettingName(settingKey), prefs.getString(settingKey, null) });
        } catch (Throwable ex) {
        // Legacy boolean
        }
    else
        cursor.addRow(new Object[] { name, prefs.getString(getSettingPref(name), null) });
    return cursor;
}
Also used : SharedPreferences(android.content.SharedPreferences) MatrixCursor(android.database.MatrixCursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)259 Cursor (android.database.Cursor)37 DirectoryResult (com.android.documentsui.DirectoryResult)35 RowBuilder (android.database.MatrixCursor.RowBuilder)30 File (java.io.File)30 MergeCursor (android.database.MergeCursor)18 Uri (android.net.Uri)18 Test (org.junit.Test)17 Setting (com.android.providers.settings.SettingsState.Setting)15 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)10 BitSet (java.util.BitSet)10 Random (java.util.Random)10 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)7 ContentValues (android.content.ContentValues)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5