Search in sources :

Example 21 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class NotificationServiceImpl method showCallNotification.

@Override
public void showCallNotification(Conference conference) {
    if (conference == null || conference.getParticipants().isEmpty() || !(conference.isOnGoing() || conference.isRinging())) {
        return;
    }
    SipCall call = conference.getParticipants().get(0);
    CallContact contact = call.getContact();
    final int notificationId = call.getCallId().hashCode();
    notificationManager.cancel(notificationId);
    PendingIntent gotoIntent = PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_CALL_VIEW).setClass(mContext, DRingService.class).putExtra(KEY_CALL_ID, call.getCallId()), 0);
    NotificationCompat.Builder messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_CALL);
    if (conference.isOnGoing()) {
        messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_current_call_title, contact.getRingUsername())).setContentText(mContext.getText(R.string.notif_current_call)).setContentIntent(gotoIntent).addAction(R.drawable.ic_call_end_white, mContext.getText(R.string.action_call_hangup), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_CALL_END).setClass(mContext, DRingService.class).putExtra(KEY_CALL_ID, call.getCallId()), PendingIntent.FLAG_ONE_SHOT));
    } else if (conference.isRinging()) {
        if (conference.isIncoming()) {
            Bundle extras = new Bundle();
            messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_incoming_call_title, contact.getRingUsername())).setPriority(NotificationCompat.PRIORITY_MAX).setContentText(mContext.getText(R.string.notif_incoming_call)).setContentIntent(gotoIntent).setFullScreenIntent(gotoIntent, true).addAction(R.drawable.ic_call_end_white, mContext.getText(R.string.action_call_decline), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_CALL_REFUSE).setClass(mContext, DRingService.class).putExtra(KEY_CALL_ID, call.getCallId()), PendingIntent.FLAG_ONE_SHOT)).addAction(R.drawable.ic_action_accept, mContext.getText(R.string.action_call_accept), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_CALL_ACCEPT).setClass(mContext, DRingService.class).putExtra(KEY_CALL_ID, call.getCallId()), PendingIntent.FLAG_ONE_SHOT)).addExtras(extras);
        } else {
            messageNotificationBuilder.setContentTitle(mContext.getString(R.string.notif_outgoing_call_title, contact.getRingUsername())).setContentText(mContext.getText(R.string.notif_outgoing_call)).setContentIntent(gotoIntent).addAction(R.drawable.ic_call_end_white, mContext.getText(R.string.action_call_hangup), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_CALL_END).setClass(mContext, DRingService.class).putExtra(KEY_CALL_ID, call.getCallId()), PendingIntent.FLAG_ONE_SHOT));
        }
    }
    messageNotificationBuilder.setOngoing(true).setCategory(NotificationCompat.CATEGORY_CALL).setSmallIcon(R.drawable.ic_ring_logo_white);
    setContactPicture(contact, messageNotificationBuilder);
    messageNotificationBuilder.setColor(ResourcesCompat.getColor(mContext.getResources(), R.color.color_primary_dark, null));
    notificationManager.notify(notificationId, messageNotificationBuilder.build());
    mNotificationBuilders.put(notificationId, messageNotificationBuilder);
}
Also used : SipCall(cx.ring.model.SipCall) Bundle(android.os.Bundle) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) DRingService(cx.ring.service.DRingService) CallContact(cx.ring.model.CallContact)

Example 22 with CallContact

use of cx.ring.model.CallContact 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 23 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class ContactServiceImpl method findContactByIdFromSystem.

@Override
protected CallContact findContactByIdFromSystem(Long id, String key) {
    CallContact contact = null;
    ContentResolver contentResolver = mContext.getContentResolver();
    try {
        android.net.Uri contentUri;
        if (key != null) {
            contentUri = ContactsContract.Contacts.lookupContact(contentResolver, ContactsContract.Contacts.getLookupUri(id, key));
        } else {
            contentUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
        }
        Cursor result = null;
        if (contentUri != null) {
            result = contentResolver.query(contentUri, CONTACT_PROJECTION, null, null, null);
        }
        if (result == null) {
            return null;
        }
        if (result.moveToFirst()) {
            int indexId = result.getColumnIndex(ContactsContract.Data._ID);
            int indexKey = result.getColumnIndex(ContactsContract.Data.LOOKUP_KEY);
            int indexName = result.getColumnIndex(ContactsContract.Data.DISPLAY_NAME);
            int indexPhoto = result.getColumnIndex(ContactsContract.Data.PHOTO_ID);
            int indexStared = result.getColumnIndex(ContactsContract.Contacts.STARRED);
            long contactId = result.getLong(indexId);
            Log.d(TAG, "Contact name: " + result.getString(indexName) + " id:" + contactId + " key:" + result.getString(indexKey));
            contact = new CallContact(contactId, result.getString(indexKey), result.getString(indexName), result.getLong(indexPhoto));
            if (result.getInt(indexStared) != 0) {
                contact.setStared();
            }
            fillContactDetails(contact);
        }
        result.close();
    } catch (Exception e) {
        Log.d(TAG, "findContactByIdFromSystem: Error while searching for contact id=" + id, e);
    }
    if (contact == null) {
        Log.d(TAG, "findContactByIdFromSystem: findById " + id + " can't find contact.");
    }
    return contact;
}
Also used : Cursor(android.database.Cursor) CallContact(cx.ring.model.CallContact) IOException(java.io.IOException) ContentResolver(android.content.ContentResolver)

Example 24 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class AccountService method registeredNameFound.

public void registeredNameFound(String accountId, int state, String address, String name) {
    Log.d(TAG, "registeredNameFound: " + accountId + ", " + state + ", " + name + ", " + address);
    Account account = getAccount(accountId);
    if (account != null) {
        if (state == 0) {
            CallContact contact = account.getContact(address);
            if (contact != null) {
                contact.setUsername(name);
            }
        }
        TrustRequest request = account.getRequest(address);
        if (request != null) {
            Log.d(TAG, "registeredNameFound: updating TrustRequest " + name);
            boolean resolved = request.isNameResolved();
            request.setUsername(name);
            if (!resolved) {
                Log.d(TAG, "registeredNameFound: TrustRequest resolved " + name);
                setChanged();
                ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.INCOMING_TRUST_REQUEST);
                event.addEventInput(ServiceEvent.EventInput.ACCOUNT_ID, accountId);
                event.addEventInput(ServiceEvent.EventInput.FROM, request.getContactId());
                notifyObservers(event);
            }
        }
    }
    setChanged();
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.REGISTERED_NAME_FOUND);
    event.addEventInput(ServiceEvent.EventInput.ACCOUNT_ID, accountId);
    event.addEventInput(ServiceEvent.EventInput.STATE, state);
    event.addEventInput(ServiceEvent.EventInput.ADDRESS, address);
    event.addEventInput(ServiceEvent.EventInput.NAME, name);
    notifyObservers(event);
}
Also used : Account(cx.ring.model.Account) ServiceEvent(cx.ring.model.ServiceEvent) TrustRequest(cx.ring.model.TrustRequest) CallContact(cx.ring.model.CallContact)

Example 25 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class CallService method placeCall.

public SipCall placeCall(final String account, final String number, final boolean audioOnly) {
    return FutureUtils.executeDaemonThreadCallable(mExecutor, mDeviceRuntimeService.provideDaemonThreadId(), true, () -> {
        Log.i(TAG, "placeCall() thread running... " + number + " audioOnly: " + audioOnly);
        HashMap<String, String> volatileDetails = new HashMap<>();
        volatileDetails.put(SipCall.KEY_AUDIO_ONLY, String.valueOf(audioOnly));
        String callId = Ringservice.placeCall(account, number, StringMap.toSwig(volatileDetails));
        if (callId == null || callId.isEmpty())
            return null;
        if (audioOnly) {
            Ringservice.muteLocalMedia(callId, "MEDIA_TYPE_VIDEO", true);
        }
        CallContact contact = mContactService.findContactByNumber(number);
        SipCall call = addCall(account, callId, number, SipCall.Direction.OUTGOING);
        call.muteVideo(audioOnly);
        call.setContact(contact);
        return call;
    });
}
Also used : SipCall(cx.ring.model.SipCall) HashMap(java.util.HashMap) CallContact(cx.ring.model.CallContact)

Aggregations

CallContact (cx.ring.model.CallContact)38 Conversation (cx.ring.model.Conversation)9 Uri (cx.ring.model.Uri)8 Account (cx.ring.model.Account)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)5 ContentResolver (android.content.ContentResolver)4 Cursor (android.database.Cursor)4 SipCall (cx.ring.model.SipCall)4 ServiceEvent (cx.ring.model.ServiceEvent)3 Settings (cx.ring.model.Settings)3 TextMessage (cx.ring.model.TextMessage)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Intent (android.content.Intent)2 StringMap (cx.ring.daemon.StringMap)2 TrustRequest (cx.ring.model.TrustRequest)2 TVListViewModel (cx.ring.tv.model.TVListViewModel)2 List (java.util.List)2 PendingIntent (android.app.PendingIntent)1