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:org.proninyaroslav.libretorrent.settings.BehaviorSettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_ALERT_RINGTONE && data != null) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        if (ringtone != null) {
            SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

            String keyNotifySound = getString(R.string.pref_key_notify_sound);
            Preference notifySound = findPreference(keyNotifySound);
            notifySound.setSummary(RingtoneManager.getRingtone(getActivity().getApplicationContext(), ringtone)
                    .getTitle(getActivity().getApplicationContext()));
            pref.put(keyNotifySound, ringtone.toString());
        }//from w w w . ja  v  a 2  s.c  om
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.jawnnypoo.geotune.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case REQUEST_GEOFENCE:
        if (resultCode == RESULT_OK && data != null) {
            GeoTune newGeoTune = data.getParcelableExtra(EXTRA_GEOTUNE);
            newGeoTune.setActive(true);/*from   ww w  . ja  va 2s  . c  om*/
            mGeoTuneAdapter.addGeoTune(newGeoTune);
            adapterDataChanged();
            GeoTuneModService.registerGeoTune(getApplicationContext(), newGeoTune);
            Snackbar.make(mRoot, getString(R.string.reminder_set_tune), Snackbar.LENGTH_LONG).show();
        }
        break;
    case REQUEST_AUDIO:
        if (resultCode == RESULT_OK) {
            if (data.getData() != null) {
                Timber.d("Uri was found: %s", data.getData());
                updateGeotuneUri(data.getData());
            }
        }
        break;
    case REQUEST_NOTIFICATION:
        if (resultCode == RESULT_OK) {
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            updateGeotuneUri(uri);
        }
        break;
    }
}

From source file:com.mattprecious.notisync.profile.SecondaryCustomProfileActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_RINGTONE_PICKER:
        if (resultCode == RESULT_OK) {
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            if (uri == null) {
                profile.setRingtone(null);
            } else {
                profile.setRingtone(uri.toString());
            }//from w ww.ja v  a  2  s  . c o m

            updateRingtoneSelector();
        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:org.schabi.terminightor.AlarmItemDetailFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case READ_NFC_ID:
        if (resultCode == SetTagActivity.ID_RECEIVED) {
            byte[] nfcTagId = data.getByteArrayExtra(SetTagActivity.NFC_ID);
            returnedNfcTagId = nfcTagId;
            nfcTagIdView.setText(Arrays.toString(nfcTagId));
            nfcTagLabelView.setVisibility(View.VISIBLE);
        }//  w  w  w. j a va  2  s  .  c  o m
        break;
    case SET_ALARM_TONE:
        if (data != null) {
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            if (uri != null) {
                alarm.setAlarmTone(uri.toString());
                setAlarmToneButton
                        .setText(RingtoneManager.getRingtone(getActivity(), uri).getTitle(getActivity()));
            } else {
                alarm.setAlarmTone("");
                setAlarmToneButton.setText(getString(R.string.noneAlarmTone));
            }
        }
        break;
    default:
        Log.e(TAG, "ERROR: request code not known");
    }
}

From source file:rikka.materialpreference.RingtonePreference.java

public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == mRequestCode) {
        if (data != null) {
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

            if ((uri == null || !uri.equals(mUri)) && callChangeListener(mUri != null ? mUri.toString() : "")) {
                //Log.d(TAG, uri == null ? "null" : uri.toString());

                mUri = uri;/*from ww  w .  j  av a  2 s.co  m*/
                onSaveRingtone(mUri);
            }
        }
        return true;
    }
    return false;
}

From source file:org.telegram.ui.ChatProfileActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    avatarUpdater.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 15) {
            Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            String name = null;//w w  w. j a  va 2  s.  co m
            if (ringtone != null && parentActivity != null) {
                Ringtone rng = RingtoneManager.getRingtone(parentActivity, ringtone);
                if (rng != null) {
                    name = rng.getTitle(parentActivity);
                    rng.stop();
                }
            }

            SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications",
                    Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = preferences.edit();

            if (name != null && ringtone != null) {
                editor.putString("sound_chat_" + chat_id, name);
                editor.putString("sound_chat_path_" + chat_id, ringtone.toString());
            } else {
                editor.putString("sound_chat_" + chat_id, "NoSound");
                editor.putString("sound_chat_path_" + chat_id, "NoSound");
            }
            editor.commit();
            listView.invalidateViews();
        }
    }
}

From source file:support.plus.reportit.SettingsActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (resultCode == Activity.RESULT_OK && requestCode == 5) {
        Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

        if (uri != null) {
            final SharedPreferences pref5 = getApplicationContext().getSharedPreferences("soundNotifications",
                    MODE_PRIVATE);/* w  ww  . j  a  v a  2s  .c  om*/
            SharedPreferences.Editor editor = pref5.edit();
            editor.putString("alarmSound", String.valueOf(uri));
            editor.commit();
        } else {
            final SharedPreferences pref5 = getApplicationContext().getSharedPreferences("soundNotifications",
                    MODE_PRIVATE);
            SharedPreferences.Editor editor = pref5.edit();
            editor.putString("alarmSound", null);
            editor.commit();
        }
    }
}

From source file:com.silentcircle.contacts.detail.ContactLoaderFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;/*  w w w. j a  v a  2 s.c  om*/
    }

    switch (requestCode) {
    case REQUEST_CODE_PICK_RINGTONE: {
        Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        handleRingtonePicked(pickedUri);
        break;
    }
    }
}

From source file:com.android.deskclock.AlarmClockFragment.java

private void saveRingtoneUri(Intent intent) {
    Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    if (uri == null) {
        uri = Alarm.NO_RINGTONE_URI;
    }// www  . j a va2  s.  c o m
    /// M: if the alarm to change ringtone is null, then do nothing @{
    if (null == mSelectedAlarm) {
        LogUtils.w("saveRingtoneUri the alarm to change ringtone is null");
        return;
    }
    /// @}
    mSelectedAlarm.alert = uri;

    // Save the last selected ringtone as the default for new alarms
    // setDefaultRingtoneUri(uri);

    //        asyncUpdateAlarm(mSelectedAlarm, false);

    // If the user chose an external ringtone and has not yet granted the permission to read
    // external storage, ask them for that permission now.
    if (!AlarmUtils.hasPermissionToDisplayRingtoneTitle(getActivity(), uri)) {
        final String[] perms = { Manifest.permission.READ_EXTERNAL_STORAGE };
        requestPermissions(perms, REQUEST_CODE_PERMISSIONS);
    } else {
        /// M: Permissions already granted, save the ringtone
        setDefaultRingtoneUri(uri);
        asyncUpdateAlarm(mSelectedAlarm, false);
    }
}

From source file:com.bai.android.ui.OtherActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CHANGE_RINGTONE_REQUEST_CODE && resultCode == RESULT_OK) {
        Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        if (uri != null) {
            String ringTonePath = uri.toString();

            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            SharedPreferences.Editor editor = pref.edit();
            editor.putString(getResources().getString(R.string.default_sound), ringTonePath);
            editor.commit();//from   w w w  . j  ava2  s  .  co m
            pref = null;

        }
    } else {

        int rotation = ExifInterface.ORIENTATION_NORMAL;

        if (requestCode == GALLERY_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK
                && data.getData() != null) {
            Uri imageUri = data.getData();
            setAvatarFromInputStreamUri(imageUri);
            rotation = getOrientationFromMediaStore(getApplicationContext(), imageUri);
            rotateImageIfNecessary(rotation);
            if (avatarPicture != null) {
                avatar.setImageBitmap(avatarPicture);
            }
        } else if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
            String imagePath = getSharedPreferences(SHR_PRF_APP_KEY, MODE_PRIVATE).getString(SHR_PRF_IMG_URI,
                    null);

            setAvatarFromFilePath(imagePath);
            if (avatarPicture == null) {
                Toast.makeText(getApplicationContext(), "Image cannot be decoded", Toast.LENGTH_LONG).show();
                return;
            }

            rotation = getOrientationFromFile(imagePath);
            //         }
            rotateImageIfNecessary(rotation);
            if (avatarPicture != null) {
                avatar.setImageBitmap(avatarPicture);
            }

        }

    }
}