Java Code Examples for android.media.Ringtone#stop()

The following examples show how to use android.media.Ringtone#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserProfileActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example 2
Source File: ProfileNotificationsActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example 3
Source File: CallActivity.java    From yiim_v2 with GNU General Public License v2.0 5 votes vote down vote up
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();
	}
}
 
Example 4
Source File: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: ProfileNotificationsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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);
        }
    }
}
 
Example 6
Source File: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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);
    }
}
 
Example 7
Source File: ProfileNotificationsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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);
        }
    }
}
 
Example 8
Source File: SettingsNotificationsActivity.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
@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();
    }
}
 
Example 9
Source File: AlarmClockActivity.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example 10
Source File: AlarmClockActivity.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
@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;
    }
}
 
Example 11
Source File: NotificationsSettingsActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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);
    }
}
 
Example 12
Source File: ProfileNotificationsActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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);
        }
    }
}
 
Example 13
Source File: NotificationsCustomSettingsActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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);
        }
    }
}
 
Example 14
Source File: NotificationsSettingsActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: ProfileNotificationsActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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);
        }
    }
}
 
Example 16
Source File: NotificationsCustomSettingsActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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);
        }
    }
}