Example usage for android.media RingtoneManager EXTRA_RINGTONE_PICKED_URI

List of usage examples for android.media RingtoneManager EXTRA_RINGTONE_PICKED_URI

Introduction

In this page you can find the example usage for android.media RingtoneManager EXTRA_RINGTONE_PICKED_URI.

Prototype

String EXTRA_RINGTONE_PICKED_URI

To view the source code for android.media RingtoneManager EXTRA_RINGTONE_PICKED_URI.

Click Source Link

Document

Returned from the ringtone picker as a Uri .

Usage

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

/**
 * Called when another activity returns and this one is displayed. Since the app is fragment based, this is only
 * called when querying for TTS support, or when returning from a ringtone picker. The preference fragment does
 * not handle the ringtone result correctly, so it must be caught here.
 *
 * @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to
 *                    identify who this result came from.
 * @param resultCode  The integer result code returned by the child activity through its setResult().
 * @param data        An Intent, which can return result data to the caller (various data can be attached to Intent
 *                    "extras")./*from   w ww  .  ja v  a 2s  .  co  m*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    mTutorCards.onActivityResult(requestCode, resultCode);

    /* The ringtone picker in the preference fragment and RoundTimerFragment will send a result here */
    if (data != null && data.getExtras() != null) {
        if (data.getExtras().keySet().contains(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)) {
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            if (uri != null) {
                mPreferenceAdapter.setTimerSound(uri.toString());
            }
        }
    }
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case REQUEST_NOTIFICATION_RINGTONE: {
            PreferencesManager.setNotificationRingTone(getActivity(),
                    (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI));

            // test if the selected ring tone can be played
            if (null == PreferencesManager.getNotificationRingToneName(getActivity())) {
                PreferencesManager.setNotificationRingTone(getActivity(),
                        PreferencesManager.getNotificationRingTone(getActivity()));
            }//from  w  w  w  . jav a 2  s .  co m

            refreshNotificationRingTone();
            break;
        }
        case REQUEST_E2E_FILE_REQUEST_CODE:
            importKeys(data);
            break;
        case REQUEST_NEW_PHONE_NUMBER:
            refreshPhoneNumbersList();
            break;
        case REQUEST_PHONEBOOK_COUNTRY:
            onPhonebookCountryUpdate(data);
            break;
        case REQUEST_LOCALE:
            startActivity(getActivity().getIntent());
            getActivity().finish();
            break;
        case VectorUtils.TAKE_IMAGE:
            Uri thumbnailUri = VectorUtils.getThumbnailUriFromIntent(getActivity(), data,
                    mSession.getMediasCache());

            if (null != thumbnailUri) {
                displayLoadingView();

                ResourceUtils.Resource resource = ResourceUtils.openResource(getActivity(), thumbnailUri, null);

                if (null != resource) {
                    mSession.getMediasCache().uploadContent(resource.mContentStream, null, resource.mMimeType,
                            null, new MXMediaUploadListener() {

                                @Override
                                public void onUploadError(final String uploadId, final int serverResponseCode,
                                        final String serverErrorMessage) {
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            onCommonDone(serverResponseCode + " : " + serverErrorMessage);
                                        }
                                    });
                                }

                                @Override
                                public void onUploadComplete(final String uploadId, final String contentUri) {
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            mSession.getMyUser().updateAvatarUrl(contentUri,
                                                    new ApiCallback<Void>() {
                                                        @Override
                                                        public void onSuccess(Void info) {
                                                            onCommonDone(null);
                                                            refreshDisplay();
                                                        }

                                                        @Override
                                                        public void onNetworkError(Exception e) {
                                                            onCommonDone(e.getLocalizedMessage());
                                                        }

                                                        @Override
                                                        public void onMatrixError(final MatrixError e) {
                                                            if (MatrixError.M_CONSENT_NOT_GIVEN
                                                                    .equals(e.errcode)) {
                                                                if (null != getActivity()) {
                                                                    getActivity().runOnUiThread(new Runnable() {
                                                                        @Override
                                                                        public void run() {
                                                                            hideLoadingView();
                                                                            ((RiotAppCompatActivity) getActivity())
                                                                                    .getConsentNotGivenHelper()
                                                                                    .displayDialog(e);
                                                                        }
                                                                    });
                                                                }
                                                            } else {
                                                                onCommonDone(e.getLocalizedMessage());
                                                            }
                                                        }

                                                        @Override
                                                        public void onUnexpectedError(Exception e) {
                                                            onCommonDone(e.getLocalizedMessage());
                                                        }
                                                    });
                                        }
                                    });
                                }
                            });
                }
            }
            break;
        }
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (LogTag.VERBOSE) {
        log("onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode + ", data=" + data);
    }/*from w  w  w  . j  a  v a  2  s.c  om*/
    mWaitingForSubActivity = false; // We're back!
    mShouldLoadDraft = false;
    if (mWorkingMessage.isFakeMmsForDraft()) {
        // We no longer have to fake the fact we're an Mms. At this point we are or we aren't,
        // based on attachments and other Mms attrs.
        mWorkingMessage.removeFakeMmsForDraft();
    }

    if (requestCode == REQUEST_CODE_PICK) {
        mWorkingMessage.asyncDeleteDraftSmsMessage(mConversation);
    }

    if (requestCode == REQUEST_CODE_ADD_CONTACT) {
        // The user might have added a new contact. When we tell contacts to add a contact
        // and tap "Done", we're not returned to Messaging. If we back out to return to
        // messaging after adding a contact, the resultCode is RESULT_CANCELED. Therefore,
        // assume a contact was added and get the contact and force our cached contact to
        // get reloaded with the new info (such as contact name). After the
        // contact is reloaded, the function onUpdate() in this file will get called
        // and it will update the title bar, etc.
        if (mAddContactIntent != null) {
            String address = mAddContactIntent.getStringExtra(ContactsContract.Intents.Insert.EMAIL);
            if (address == null) {
                address = mAddContactIntent.getStringExtra(ContactsContract.Intents.Insert.PHONE);
            }
            if (address != null) {
                Contact contact = Contact.get(address, false);
                if (contact != null) {
                    contact.reload();
                }
            }
        }
    }

    if (resultCode != RESULT_OK) {
        if (LogTag.VERBOSE)
            log("bail due to resultCode=" + resultCode);
        return;
    }

    switch (requestCode) {
    case REQUEST_CODE_CREATE_SLIDESHOW:
        if (data != null) {
            WorkingMessage newMessage = WorkingMessage.load(this, data.getData());
            if (newMessage != null) {
                // Here we should keep the subject from the old mWorkingMessage.
                setNewMessageSubject(newMessage);
                mWorkingMessage = newMessage;
                mWorkingMessage.setConversation(mConversation);
                updateThreadIdIfRunning();
                drawTopPanel(false);
                drawBottomPanel();
                updateSendButtonState();
            }
        }
        break;

    case REQUEST_CODE_TAKE_PICTURE: {
        // create a file based uri and pass to addImage(). We want to read the JPEG
        // data directly from file (using UriImage) instead of decoding it into a Bitmap,
        // which takes up too much memory and could easily lead to OOM.
        File file = new File(TempFileProvider.getScrapPath(this));
        Uri uri = Uri.fromFile(file);

        // Remove the old captured picture's thumbnail from the cache
        MmsApp.getApplication().getThumbnailManager().removeThumbnail(uri);

        addImageAsync(uri, false);
        break;
    }

    case REQUEST_CODE_ATTACH_IMAGE: {
        if (data != null) {
            addImageAsync(data.getData(), false);
        }
        break;
    }

    case REQUEST_CODE_TAKE_VIDEO:
        Uri videoUri = TempFileProvider.renameScrapFile(".3gp", null, this);
        // Remove the old captured video's thumbnail from the cache
        MmsApp.getApplication().getThumbnailManager().removeThumbnail(videoUri);

        addVideoAsync(videoUri, false); // can handle null videoUri
        break;

    case REQUEST_CODE_ATTACH_VIDEO:
        if (data != null) {
            addVideoAsync(data.getData(), false);
        }
        break;

    case REQUEST_CODE_ATTACH_SOUND: {
        // Attempt to add the audio to the  attachment.
        Uri uri = (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        if (uri == null) {
            uri = data.getData();
        } else if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) {
            break;
        }
        addAudio(uri);
        break;
    }

    case REQUEST_CODE_RECORD_SOUND:
        if (data != null) {
            addAudio(data.getData());
        }
        break;

    case REQUEST_CODE_ECM_EXIT_DIALOG:
        boolean outOfEmergencyMode = data.getBooleanExtra(EXIT_ECM_RESULT, false);
        if (outOfEmergencyMode) {
            sendMessage(false);
        }
        break;

    case REQUEST_CODE_PICK:
        if (data != null) {
            processPickResult(data);
        }
        break;

    case REQUEST_CODE_ADD_RECIPIENTS:
        insertNumbersIntoRecipientsEditor(data.getStringArrayListExtra(SelectRecipientsList.EXTRA_RECIPIENTS));
        break;

    default:
        if (LogTag.VERBOSE)
            log("bail due to unknown requestCode=" + requestCode);
        break;
    }
}