Search in sources :

Example 11 with Uri

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));
}
Also used : Account(cx.ring.model.Account) NameLookupInputHandler(cx.ring.utils.NameLookupInputHandler) Uri(cx.ring.model.Uri)

Example 12 with Uri

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;
        }
    }
}
Also used : Uri(cx.ring.model.Uri)

Example 13 with Uri

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;
}
Also used : HashMap(java.util.HashMap) Cursor(android.database.Cursor) Uri(cx.ring.model.Uri) ContentResolver(android.content.ContentResolver) CallContact(cx.ring.model.CallContact)

Example 14 with Uri

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);
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) Uri(cx.ring.model.Uri)

Example 15 with Uri

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);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) Uri(cx.ring.model.Uri)

Aggregations

Uri (cx.ring.model.Uri)24 CallContact (cx.ring.model.CallContact)7 Account (cx.ring.model.Account)6 Conversation (cx.ring.model.Conversation)5 Intent (android.content.Intent)3 ServiceEvent (cx.ring.model.ServiceEvent)3 TextMessage (cx.ring.model.TextMessage)3 ContentResolver (android.content.ContentResolver)2 Cursor (android.database.Cursor)2 HistoryCall (cx.ring.model.HistoryCall)2 HistoryText (cx.ring.model.HistoryText)2 SipCall (cx.ring.model.SipCall)2 NameLookupInputHandler (cx.ring.utils.NameLookupInputHandler)2 ArrayList (java.util.ArrayList)2 PendingIntent (android.app.PendingIntent)1 ContentValues (android.content.ContentValues)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1