use of cx.ring.model.Uri in project ring-client-android by savoirfairelinux.
the class SmartListPresenter method queryTextChanged.
public void queryTextChanged(String query) {
if (query.equals("")) {
getView().hideSearchRow();
getView().setLoading(false);
} else {
Account currentAccount = mAccountService.getCurrentAccount();
if (currentAccount == null) {
return;
}
if (currentAccount.isSip()) {
// sip search
mCallContact = CallContact.buildUnknown(query, null);
getView().displayContact(mCallContact);
} else {
Uri uri = new Uri(query);
if (uri.isRingId()) {
mCallContact = CallContact.buildUnknown(uri);
getView().displayContact(mCallContact);
} else {
getView().hideSearchRow();
// Ring search
if (mNameLookupInputHandler == null) {
mNameLookupInputHandler = new NameLookupInputHandler(mAccountService, currentAccount.getAccountID());
}
mLastBlockchainQuery = query;
mNameLookupInputHandler.enqueueNextLookup(query);
getView().setLoading(true);
}
}
}
getView().updateList(filter(mSmartListViewModels, query));
}
use of cx.ring.model.Uri in project ring-client-android by savoirfairelinux.
the class SmartListPresenter method updateContactName.
private void updateContactName(String contactName, String contactId) {
Iterator<SmartListViewModel> it = mSmartListViewModels.iterator();
while (it.hasNext()) {
SmartListViewModel smartListViewModel = it.next();
if (smartListViewModel.getUuid() != null && smartListViewModel.getUuid().contains(contactId)) {
if (smartListViewModel.getContactName() != null && !smartListViewModel.getContactName().contains(CallContact.PREFIX_RING)) {
break;
}
mContactService.updateContactUserName(new Uri(smartListViewModel.getUuid()), contactName);
if (!smartListViewModel.getContactName().equals(contactName)) {
it.remove();
SmartListViewModel newViewModel = new SmartListViewModel(smartListViewModel);
newViewModel.setContactName(contactName);
mSmartListViewModels.add(newViewModel);
Collections.sort(mSmartListViewModels, new SmartListViewModel.SmartListComparator());
getView().updateList(mSmartListViewModels);
}
break;
}
}
}
use of cx.ring.model.Uri in project ring-client-android by savoirfairelinux.
the class ContactServiceImpl method loadContactsFromSystem.
@Override
public Map<Long, CallContact> loadContactsFromSystem(boolean loadRingContacts, boolean loadSipContacts) {
Map<Long, CallContact> systemContacts = new HashMap<>();
ContentResolver contentResolver = mContext.getContentResolver();
StringBuilder contactsIds = new StringBuilder();
LongSparseArray<CallContact> cache;
Cursor contactCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, CONTACTS_DATA_PROJECTION, ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?", new String[] { ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE }, null);
if (contactCursor != null) {
cache = new LongSparseArray<>(contactCursor.getCount());
contactsIds.ensureCapacity(contactCursor.getCount() * 4);
final int indexId = contactCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);
final int indexMime = contactCursor.getColumnIndex(ContactsContract.Data.MIMETYPE);
final int indexNumber = contactCursor.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
final int indexType = contactCursor.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.TYPE);
final int indexLabel = contactCursor.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.LABEL);
while (contactCursor.moveToNext()) {
long contactId = contactCursor.getLong(indexId);
CallContact contact = cache.get(contactId);
boolean isNewContact = false;
if (contact == null) {
contact = new CallContact(contactId);
isNewContact = true;
contact.setFromSystem(true);
}
String contactNumber = contactCursor.getString(indexNumber);
int contactType = contactCursor.getInt(indexType);
String contactLabel = contactCursor.getString(indexLabel);
Uri uri = new Uri(contactNumber);
if (uri.isSingleIp() || (uri.isRingId() && loadRingContacts) || loadSipContacts) {
switch(contactCursor.getString(indexMime)) {
case ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE:
contact.addPhoneNumber(contactNumber, contactType, contactLabel);
break;
case ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE:
contact.addNumber(contactNumber, contactType, contactLabel, cx.ring.model.Phone.NumberType.SIP);
break;
case ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE:
if (uri.isRingId()) {
contact.addNumber(contactNumber, contactType, contactLabel, cx.ring.model.Phone.NumberType.UNKNOWN);
}
break;
}
}
if (isNewContact && !contact.getPhones().isEmpty()) {
cache.put(contactId, contact);
if (contactsIds.length() > 0) {
contactsIds.append(",");
}
contactsIds.append(contactId);
}
}
contactCursor.close();
} else {
cache = new LongSparseArray<>();
}
contactCursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, ContactsContract.Contacts._ID + " in (" + contactsIds.toString() + ")", null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
if (contactCursor != null) {
final int indexId = contactCursor.getColumnIndex(ContactsContract.Contacts._ID);
final int indexKey = contactCursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY);
final int indexName = contactCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int indexPhoto = contactCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
while (contactCursor.moveToNext()) {
long contactId = contactCursor.getLong(indexId);
CallContact contact = cache.get(contactId);
if (contact == null)
Log.w(TAG, "Can't find contact with ID " + contactId);
else {
contact.setContactInfos(contactCursor.getString(indexKey), contactCursor.getString(indexName), contactCursor.getLong(indexPhoto));
systemContacts.put(contactId, contact);
}
}
contactCursor.close();
}
return systemContacts;
}
use of cx.ring.model.Uri in project ring-client-android by savoirfairelinux.
the class AvatarFactory method getAvatar.
public static Drawable getAvatar(Context context, byte[] photo, String username, String ringId, int pictureSize) {
if (context == null || pictureSize <= 0) {
throw new IllegalArgumentException();
}
Log.d(TAG, "getAvatar: username=" + username + ", ringid=" + ringId + ", pictureSize=" + pictureSize);
if (photo != null && photo.length > 0) {
return new BitmapDrawable(context.getResources(), BitmapFactory.decodeByteArray(photo, 0, photo.length));
}
Uri uriUsername = new Uri(username);
Uri uri = new Uri(ringId);
Character firstCharacter = getFirstCharacter(uriUsername.getRawRingId());
if (uri.isEmpty() || uriUsername.isRingId() || firstCharacter == null) {
return createDefaultAvatar(context, generateAvatarColor(uri.getRawUriString()), pictureSize);
}
return createLetterAvatar(context, firstCharacter, generateAvatarColor(uri.getRawUriString()), pictureSize);
}
use of cx.ring.model.Uri in project ring-client-android by savoirfairelinux.
the class OutgoingCallHandler method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String phoneNumber = getResultData();
if (phoneNumber == null)
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean systemDialer = sharedPreferences.getBoolean(context.getString(R.string.pref_systemDialer_key), false);
if (systemDialer) {
boolean systemDialerSip = sharedPreferences.getBoolean(KEY_CACHE_HAVE_SIPACCOUNT, false);
boolean systemDialerRing = sharedPreferences.getBoolean(KEY_CACHE_HAVE_RINGACCOUNT, false);
Uri uri = new Uri(phoneNumber);
boolean isRingId = uri.isRingId();
if ((!isRingId && systemDialerSip) || (isRingId && systemDialerRing) || uri.isSingleIp()) {
Intent i = new Intent(CallActivity.ACTION_CALL).setClass(context, CallActivity.class).setData(android.net.Uri.parse(phoneNumber)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
setResultData(null);
}
}
}
Aggregations