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]));
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations