android.media.Ringtone#stop ( )源码实例Demo

下面列出了android.media.Ringtone#stop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Yahala-Messenger   文件: UserProfileActivity.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("Default", R.string.Default);
                } else {
                    name = rng.getTitle(parentActivity);
                }
                rng.stop();
            }
        }

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

        if (requestCode == 0) {
            if (name != null && ringtone != null) {
                editor.putString("sound_" + user_id, name);
                editor.putString("sound_path_" + user_id, ringtone.toString());
            } else {
                editor.putString("sound_" + user_id, "NoSound");
                editor.putString("sound_path_" + user_id, "NoSound");
            }
        }
        editor.commit();
        listView.invalidateViews();
    }
}
 
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("Default", R.string.Default);
                } else {
                    name = rng.getTitle(getParentActivity());
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        FileLog.e("name", name);
        if (requestCode == 0) {
            if (name != null && ringtone != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        listView.invalidateViews();
    }
}
 
源代码3 项目: yiim_v2   文件: CallActivity.java
public static void stopRingtone() {
	android.os.Vibrator v = (Vibrator) mContext
			.getSystemService(Context.VIBRATOR_SERVICE);
	v.cancel();
	if (oRingtone != null) {
		Ringtone ringtone = oRingtone;
		oRingtone = null;
		ringtone.stop();
	}
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (requestCode == callsRingtoneRow) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == messageSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GlobalSound", name);
                editor.putString("GlobalSoundPath", ringtone.toString());
            } else {
                editor.putString("GlobalSound", "NoSound");
                editor.putString("GlobalSoundPath", "NoSound");
            }
        } else if (requestCode == groupSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GroupSound", name);
                editor.putString("GroupSoundPath", ringtone.toString());
            } else {
                editor.putString("GroupSound", "NoSound");
                editor.putString("GroupSoundPath", "NoSound");
            }
        } else if (requestCode == callsRingtoneRow) {
            if (name != null && ringtone != null) {
                editor.putString("CallsRingtone", name);
                editor.putString("CallsRingtonePath", ringtone.toString());
            } else {
                editor.putString("CallsRingtone", "NoSound");
                editor.putString("CallsRingtonePath", "NoSound");
            }
        }
        editor.commit();
        if (requestCode == messageSoundRow || requestCode == groupSoundRow) {
            updateServerNotificationsSettings(requestCode == groupSoundRow);
        }
        adapter.notifyItemChanged(requestCode);
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (requestCode == callsRingtoneRow) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == messageSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GlobalSound", name);
                editor.putString("GlobalSoundPath", ringtone.toString());
            } else {
                editor.putString("GlobalSound", "NoSound");
                editor.putString("GlobalSoundPath", "NoSound");
            }
        } else if (requestCode == groupSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GroupSound", name);
                editor.putString("GroupSoundPath", ringtone.toString());
            } else {
                editor.putString("GroupSound", "NoSound");
                editor.putString("GroupSoundPath", "NoSound");
            }
        } else if (requestCode == callsRingtoneRow) {
            if (name != null && ringtone != null) {
                editor.putString("CallsRingtone", name);
                editor.putString("CallsRingtonePath", ringtone.toString());
            } else {
                editor.putString("CallsRingtone", "NoSound");
                editor.putString("CallsRingtonePath", "NoSound");
            }
        }
        editor.commit();
        if (requestCode == messageSoundRow || requestCode == groupSoundRow) {
            updateServerNotificationsSettings(requestCode == groupSoundRow);
        }
        adapter.notifyItemChanged(requestCode);
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}
 
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("Default", R.string.Default);
                } else {
                    name = rng.getTitle(getParentActivity());
                }
                rng.stop();
            }
        }
        FileLog.d(" ringtone.toString()", ringtone.toString());
        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == messageSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GlobalSound", name);
                editor.putString("GlobalSoundPath", ringtone.toString());
            } else {
                editor.putString("GlobalSound", "NoSound");
                editor.putString("GlobalSoundPath", "NoSound");
            }
        } else if (requestCode == groupSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GroupSound", name);
                editor.putString("GroupSoundPath", ringtone.toString());
            } else {
                editor.putString("GroupSound", "NoSound");
                editor.putString("GroupSoundPath", "NoSound");
            }
        }

        editor.commit();
        listView.invalidateViews();
    }
}
 
源代码9 项目: SuntimesWidget   文件: AlarmClockActivity.java
protected void addAlarm(AlarmClockItem.AlarmType type, String label, SolarEvents event, int hour, int minute, boolean vibrate, Uri ringtoneUri, ArrayList<Integer> repetitionDays)
{
    //Log.d("DEBUG", "addAlarm: type is " + type.toString());
    final AlarmClockItem alarm = new AlarmClockItem();
    alarm.enabled = AlarmSettings.loadPrefAlarmAutoEnable(AlarmClockActivity.this);
    alarm.type = type;
    alarm.label = label;

    alarm.hour = hour;
    alarm.minute = minute;
    alarm.event = event;
    alarm.location = WidgetSettings.loadLocationPref(AlarmClockActivity.this, 0);

    alarm.repeating = false;

    alarm.vibrate = vibrate;
    alarm.ringtoneURI = (ringtoneUri != null ? ringtoneUri.toString() : null);
    if (alarm.ringtoneURI != null)
    {
        Ringtone ringtone = RingtoneManager.getRingtone(AlarmClockActivity.this, ringtoneUri);
        alarm.ringtoneName = ringtone.getTitle(AlarmClockActivity.this);
        ringtone.stop();
    }

    alarm.setState(alarm.enabled ? AlarmState.STATE_NONE : AlarmState.STATE_DISABLED);
    alarm.modified = true;

    AlarmDatabaseAdapter.AlarmUpdateTask task = new AlarmDatabaseAdapter.AlarmUpdateTask(AlarmClockActivity.this, true, true);
    task.setTaskListener(new AlarmDatabaseAdapter.AlarmItemTaskListener()
    {
        @Override
        public void onFinished(Boolean result, AlarmClockItem item)
        {
            if (result) {
                Log.d(TAG, "onAlarmAdded: " + item.rowID);
                t_selectedItem = item.rowID;
                updateViews(AlarmClockActivity.this);

                if (item.enabled) {
                    sendBroadcast( AlarmNotifications.getAlarmIntent(AlarmClockActivity.this, AlarmNotifications.ACTION_SCHEDULE, item.getUri()) );
                }
            }
        }
    });
    task.execute(alarm);
}
 
源代码10 项目: SuntimesWidget   文件: AlarmClockActivity.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    boolean recreateActivity = false;
    AlarmClockItem item = (adapter != null) ? adapter.findItem(t_selectedItem) : null;

    switch (requestCode)
    {
        case REQUEST_SETTINGS:
            recreateActivity = ((!AppSettings.loadThemePref(AlarmClockActivity.this).equals(appTheme))                           // theme mode changed
             //       || (appThemeOverride != null && !appThemeOverride.themeName().equals(getThemeOverride()))                       // or theme override changed
                    || (localeInfo.localeMode != AppSettings.loadLocaleModePref(AlarmClockActivity.this))                             // or localeMode changed
                    || ((localeInfo.localeMode == AppSettings.LocaleMode.CUSTOM_LOCALE                                              // or customLocale changed
                    && !AppSettings.loadLocalePref(AlarmClockActivity.this).equals(localeInfo.customLocale)))
            );
            if (recreateActivity) {
                Handler handler = new Handler();
                handler.postDelayed(recreateRunnable, 0);    // post to end of execution queue (onResume must be allowed to finish before calling recreate)
            }
            break;

        case REQUEST_RINGTONE:
            if (resultCode == RESULT_OK && item != null && data != null)
            {
                Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
                if (uri != null)
                {
                    Ringtone ringtone = RingtoneManager.getRingtone(this, uri);
                    if (ringtone != null)
                    {
                        String ringtoneName = ringtone.getTitle(this);
                        ringtone.stop();

                        item.ringtoneName = ringtoneName;
                        item.ringtoneURI = uri.toString();
                        Log.d(TAG, "onActivityResult: uri: " + item.ringtoneURI + ", title: " + ringtoneName);

                    } else {
                        item.ringtoneName = null;
                        item.ringtoneURI = null;
                        Log.d(TAG, "onActivityResult: uri: " + uri + " <null ringtone>");
                    }

                } else {
                    item.ringtoneName = null;
                    item.ringtoneURI = null;
                    Log.d(TAG, "onActivityResult: null uri");
                }
                item.modified = true;

                AlarmDatabaseAdapter.AlarmUpdateTask task = new AlarmDatabaseAdapter.AlarmUpdateTask(this, false, false);
                task.setTaskListener(onUpdateItem);
                task.execute(item);
            } else {
                Log.d(TAG, "onActivityResult: bad result: " + resultCode + ", " + item + ", " + data);
            }
            break;
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (requestCode == callsRingtoneRow) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == callsRingtoneRow) {
            if (name != null && ringtone != null) {
                editor.putString("CallsRingtone", name);
                editor.putString("CallsRingtonePath", ringtone.toString());
            } else {
                editor.putString("CallsRingtone", "NoSound");
                editor.putString("CallsRingtonePath", "NoSound");
            }
        }
        editor.commit();
        adapter.notifyItemChanged(requestCode);
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                } else {
                    name = rng.getTitle(getParentActivity());
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = getNotificationsSettings();
        SharedPreferences.Editor editor = preferences.edit();

        if (currentType == NotificationsController.TYPE_PRIVATE) {
            if (name != null && ringtone != null) {
                editor.putString("GlobalSound", name);
                editor.putString("GlobalSoundPath", ringtone.toString());
            } else {
                editor.putString("GlobalSound", "NoSound");
                editor.putString("GlobalSoundPath", "NoSound");
            }
        } else if (currentType == NotificationsController.TYPE_GROUP) {
            if (name != null && ringtone != null) {
                editor.putString("GroupSound", name);
                editor.putString("GroupSoundPath", ringtone.toString());
            } else {
                editor.putString("GroupSound", "NoSound");
                editor.putString("GroupSoundPath", "NoSound");
            }
        } else if (currentType == NotificationsController.TYPE_CHANNEL) {
            if (name != null && ringtone != null) {
                editor.putString("ChannelSound", name);
                editor.putString("ChannelSoundPath", ringtone.toString());
            } else {
                editor.putString("ChannelSound", "NoSound");
                editor.putString("ChannelSoundPath", "NoSound");
            }
        }
        editor.commit();
        getNotificationsController().updateServerNotificationsSettings(currentType);
        RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(requestCode);
        if (holder != null) {
            adapter.onBindViewHolder(holder, requestCode);
        }
    }
}
 
源代码14 项目: Telegram   文件: NotificationsSettingsActivity.java
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (requestCode == callsRingtoneRow) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == callsRingtoneRow) {
            if (name != null && ringtone != null) {
                editor.putString("CallsRingtone", name);
                editor.putString("CallsRingtonePath", ringtone.toString());
            } else {
                editor.putString("CallsRingtone", "NoSound");
                editor.putString("CallsRingtonePath", "NoSound");
            }
        }
        editor.commit();
        adapter.notifyItemChanged(requestCode);
    }
}
 
源代码15 项目: Telegram   文件: ProfileNotificationsActivity.java
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}
 
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                } else {
                    name = rng.getTitle(getParentActivity());
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = getNotificationsSettings();
        SharedPreferences.Editor editor = preferences.edit();

        if (currentType == NotificationsController.TYPE_PRIVATE) {
            if (name != null && ringtone != null) {
                editor.putString("GlobalSound", name);
                editor.putString("GlobalSoundPath", ringtone.toString());
            } else {
                editor.putString("GlobalSound", "NoSound");
                editor.putString("GlobalSoundPath", "NoSound");
            }
        } else if (currentType == NotificationsController.TYPE_GROUP) {
            if (name != null && ringtone != null) {
                editor.putString("GroupSound", name);
                editor.putString("GroupSoundPath", ringtone.toString());
            } else {
                editor.putString("GroupSound", "NoSound");
                editor.putString("GroupSoundPath", "NoSound");
            }
        } else if (currentType == NotificationsController.TYPE_CHANNEL) {
            if (name != null && ringtone != null) {
                editor.putString("ChannelSound", name);
                editor.putString("ChannelSoundPath", ringtone.toString());
            } else {
                editor.putString("ChannelSound", "NoSound");
                editor.putString("ChannelSoundPath", "NoSound");
            }
        }
        editor.commit();
        getNotificationsController().updateServerNotificationsSettings(currentType);
        RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(requestCode);
        if (holder != null) {
            adapter.onBindViewHolder(holder, requestCode);
        }
    }
}
 
 方法所在类