Search in sources :

Example 1 with Uri

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

the class NotificationServiceImpl method showFileTransferNotification.

@Override
public void showFileTransferNotification(DataTransfer info, DataTransferEventCode event, CallContact contact) {
    if (event == null || info == null) {
        return;
    }
    long dataTransferId = info.getDataTransferId();
    int notificationId = getFileTransferNotificationId(dataTransferId);
    if (event == DataTransferEventCode.FINISHED) {
        notificationManager.cancel(notificationId);
        mNotificationBuilders.delete(notificationId);
        return;
    }
    NotificationCompat.Builder messageNotificationBuilder = mNotificationBuilders.get(notificationId);
    if (messageNotificationBuilder == null) {
        messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_FILE_TRANSFER);
    }
    boolean ongoing = event == DataTransferEventCode.CREATED || event == DataTransferEventCode.ONGOING;
    boolean outgoing = info.isOutgoing();
    String contactUri = new Uri(info.getPeerId()).getRawUriString();
    Intent intentConversation = new Intent(DRingService.ACTION_CONV_ACCEPT).setClass(mContext, DRingService.class).putExtra(ConversationFragment.KEY_ACCOUNT_ID, mAccountService.getCurrentAccount().getAccountID()).putExtra(ConversationFragment.KEY_CONTACT_RING_ID, contactUri);
    String titleMessage = mContext.getString(outgoing ? R.string.notif_outgoing_file_transfer_title : R.string.notif_incoming_file_transfer_title, contact.getDisplayName());
    byte[] photo = contact.getPhoto();
    Bitmap photo_bmp = photo == null ? null : BitmapFactory.decodeByteArray(photo, 0, photo.length);
    messageNotificationBuilder.setContentTitle(titleMessage).setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(false).setOngoing(ongoing).setSmallIcon(R.drawable.ic_ring_logo_white).setLargeIcon(photo_bmp).setCategory(NotificationCompat.CATEGORY_PROGRESS).setOnlyAlertOnce(true).setContentText(event == DataTransferEventCode.ONGOING ? FileUtils.readableFileProgress(info.getBytesProgress(), info.getTotalSize()) : info.getDisplayName() + ": " + ResourceMapper.getReadableFileTransferStatus(mContext, event)).setContentIntent(PendingIntent.getService(mContext, random.nextInt(), intentConversation, 0)).setColor(ResourcesCompat.getColor(mContext.getResources(), R.color.color_primary_dark, null));
    if (event.isOver()) {
        messageNotificationBuilder.setProgress(0, 0, false);
    } else if (ongoing) {
        Log.w(TAG, "messageNotificationBuilder.setProgress " + info.getTotalSize() + " " + info.getBytesProgress());
        messageNotificationBuilder.setProgress((int) info.getTotalSize(), (int) info.getBytesProgress(), false);
    } else {
        messageNotificationBuilder.setProgress(0, 0, true);
    }
    if (event == DataTransferEventCode.CREATED) {
        messageNotificationBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
    } else {
        messageNotificationBuilder.setDefaults(NotificationCompat.DEFAULT_LIGHTS);
    }
    messageNotificationBuilder.mActions.clear();
    if (event == DataTransferEventCode.WAIT_HOST_ACCEPTANCE) {
        messageNotificationBuilder.addAction(R.drawable.ic_incoming_black, mContext.getText(R.string.accept), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_FILE_ACCEPT).setClass(mContext, DRingService.class).putExtra(DRingService.KEY_TRANSFER_ID, dataTransferId), PendingIntent.FLAG_ONE_SHOT)).addAction(R.drawable.ic_cancel_black_24dp, mContext.getText(R.string.refuse), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_FILE_CANCEL).setClass(mContext, DRingService.class).putExtra(DRingService.KEY_TRANSFER_ID, dataTransferId), PendingIntent.FLAG_ONE_SHOT));
    } else if (!event.isOver()) {
        messageNotificationBuilder.addAction(R.drawable.ic_cancel_black_24dp, mContext.getText(android.R.string.cancel), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_FILE_CANCEL).setClass(mContext, DRingService.class).putExtra(DRingService.KEY_TRANSFER_ID, dataTransferId), PendingIntent.FLAG_ONE_SHOT));
    }
    mNotificationBuilders.put(notificationId, messageNotificationBuilder);
    notificationManager.notify(notificationId, messageNotificationBuilder.build());
}
Also used : Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) DRingService(cx.ring.service.DRingService) Uri(cx.ring.model.Uri)

Example 2 with Uri

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

the class ContactServiceImpl method fillContactDetails.

private void fillContactDetails(@NonNull CallContact callContact) {
    ContentResolver contentResolver = mContext.getContentResolver();
    try {
        Cursor cursorPhones = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, ID_SELECTION, new String[] { String.valueOf(callContact.getId()) }, null);
        if (cursorPhones != null) {
            final int indexNumber = cursorPhones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
            final int indexType = cursorPhones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
            final int indexLabel = cursorPhones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL);
            while (cursorPhones.moveToNext()) {
                callContact.addNumber(cursorPhones.getString(indexNumber), cursorPhones.getInt(indexType), cursorPhones.getString(indexLabel), cx.ring.model.Phone.NumberType.TEL);
                Log.d(TAG, "Phone:" + cursorPhones.getString(cursorPhones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
            }
            cursorPhones.close();
        }
        android.net.Uri baseUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, callContact.getId());
        android.net.Uri targetUri = android.net.Uri.withAppendedPath(baseUri, ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
        Cursor cursorSip = contentResolver.query(targetUri, CONTACTS_SIP_PROJECTION, ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + " =?", new String[] { ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE }, null);
        if (cursorSip != null) {
            final int indexMime = cursorSip.getColumnIndex(ContactsContract.Data.MIMETYPE);
            final int indexSip = cursorSip.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
            final int indexType = cursorSip.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.TYPE);
            final int indexLabel = cursorSip.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.LABEL);
            while (cursorSip.moveToNext()) {
                String contactMime = cursorSip.getString(indexMime);
                String contactNumber = cursorSip.getString(indexSip);
                if (!contactMime.contentEquals(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE) || new Uri(contactNumber).isRingId() || "ring".equalsIgnoreCase(cursorSip.getString(indexLabel))) {
                    callContact.addNumber(contactNumber, cursorSip.getInt(indexType), cursorSip.getString(indexLabel), cx.ring.model.Phone.NumberType.SIP);
                }
                Log.d(TAG, "SIP phone:" + contactNumber + " " + contactMime + " ");
            }
            cursorSip.close();
        }
    } catch (Exception e) {
        Log.d(TAG, "fillContactDetails: Error while retrieving detail contact info", e);
    }
}
Also used : Cursor(android.database.Cursor) Uri(cx.ring.model.Uri) IOException(java.io.IOException) ContentResolver(android.content.ContentResolver)

Example 3 with Uri

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

the class MainPresenter method subscribePresence.

private void subscribePresence() {
    if (mAccountService.getCurrentAccount() == null || mTvListViewModels == null || mTvListViewModels.isEmpty()) {
        return;
    }
    String accountId = mAccountService.getCurrentAccount().getAccountID();
    for (TVListViewModel tvListViewModel : mTvListViewModels) {
        String ringId = tvListViewModel.getCallContact().getPhones().get(0).getNumber().getRawRingId();
        Uri uri = new Uri(ringId);
        if (uri.isRingId()) {
            mPresenceService.subscribeBuddy(accountId, ringId, true);
        } else {
            Log.i(TAG, "Trying to subscribe to an invalid uri " + ringId);
        }
    }
}
Also used : TVListViewModel(cx.ring.tv.model.TVListViewModel) Uri(cx.ring.model.Uri)

Example 4 with Uri

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

the class RingSearchPresenter method parseEventState.

private void parseEventState(String name, String address, int state) {
    switch(state) {
        case 0:
            // on found
            if (mLastBlockchainQuery != null && mLastBlockchainQuery.equals(name)) {
                mCallContact = CallContact.buildRingContact(new Uri(address), name);
                getView().displayContact(mCallContact);
                mLastBlockchainQuery = null;
            }
            break;
        case 1:
            // invalid name
            Uri uriName = new Uri(name);
            if (uriName.isRingId() && mLastBlockchainQuery != null && mLastBlockchainQuery.equals(name)) {
                mCallContact = CallContact.buildUnknown(name, address);
                getView().displayContact(mCallContact);
            } else {
                getView().clearSearch();
            }
            break;
        default:
            // on error
            Uri uriAddress = new Uri(address);
            if (uriAddress.isRingId() && mLastBlockchainQuery != null && mLastBlockchainQuery.equals(name)) {
                mCallContact = CallContact.buildUnknown(name, address);
                getView().displayContact(mCallContact);
            } else {
                getView().clearSearch();
            }
            break;
    }
}
Also used : Uri(cx.ring.model.Uri)

Example 5 with Uri

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

the class RingSearchPresenter method queryTextChanged.

public void queryTextChanged(String query) {
    if (query.equals("")) {
        getView().clearSearch();
    } else {
        Account currentAccount = mAccountService.getCurrentAccount();
        if (currentAccount == null) {
            return;
        }
        Uri uri = new Uri(query);
        if (uri.isRingId()) {
            mCallContact = CallContact.buildUnknown(uri);
            getView().displayContact(mCallContact);
        } else {
            getView().clearSearch();
            // Ring search
            if (mNameLookupInputHandler == null) {
                mNameLookupInputHandler = new NameLookupInputHandler(mAccountService, currentAccount.getAccountID());
            }
            mLastBlockchainQuery = query;
            mNameLookupInputHandler.enqueueNextLookup(query);
        }
    }
}
Also used : Account(cx.ring.model.Account) NameLookupInputHandler(cx.ring.utils.NameLookupInputHandler) 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