use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.
the class AlarmRingtoneDialog method cacheRingtones.
private void cacheRingtones() {
mRingtones = new ArrayList<Uri>();
Cursor alarmsCursor = null;
try {
RingtoneManager ringtoneMgr = new RingtoneManager(getActivity().getApplicationContext());
ringtoneMgr.setType(RingtoneManager.TYPE_RINGTONE);
alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
return;
}
while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
int currentPosition = alarmsCursor.getPosition();
mRingtones.add(ringtoneMgr.getRingtoneUri(currentPosition));
}
} finally {
if (alarmsCursor != null) {
alarmsCursor.close();
}
}
}
use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.
the class BrowseActivity method cacheAlarmTones.
private void cacheAlarmTones() {
mAlarms = new ArrayList<QueryItem>();
Cursor alarmsCursor = null;
try {
RingtoneManager ringtoneMgr = new RingtoneManager(this.getApplicationContext());
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
return;
}
while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
QueryItem queryItem = new QueryItem();
queryItem.mName = alarmsCursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
queryItem.mUri = getUriFromCursor(alarmsCursor).toString();
queryItem.mIconId = R.drawable.ic_alarm;
mAlarms.add(queryItem);
}
} finally {
if (alarmsCursor != null) {
alarmsCursor.close();
}
}
}
use of android.media.RingtoneManager in project PhoneProfiles by henrichg.
the class TonesHandler method getPhoneProfilesSilentUri.
static String getPhoneProfilesSilentUri(Context context, int type) {
try {
RingtoneManager manager = new RingtoneManager(context);
manager.setType(type);
Cursor cursor = manager.getCursor();
while (cursor.moveToNext()) {
String id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
String uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String uriId = uri + "/" + id;
if (title.equals("PhoneProfiles Silent") || title.equals("phoneprofiles_silent"))
return uriId;
}
} catch (Exception ignored) {
}
return "";
}
use of android.media.RingtoneManager in project PhoneProfiles by henrichg.
the class RingtonePreference method refreshListView.
void refreshListView() {
RingtoneManager manager = new RingtoneManager(prefContext);
Uri uri = null;
if (ringtoneType.equals("ringtone"))
uri = Settings.System.DEFAULT_RINGTONE_URI;
else if (ringtoneType.equals("notification"))
uri = Settings.System.DEFAULT_NOTIFICATION_URI;
else if (ringtoneType.equals("alarm"))
uri = Settings.System.DEFAULT_ALARM_ALERT_URI;
Ringtone _ringtone = RingtoneManager.getRingtone(prefContext, uri);
if (_ringtone == null) {
// ringtone not found
View positive = mDialog.getActionButton(DialogAction.POSITIVE);
positive.setEnabled(false);
}
if (ringtoneType.equals("ringtone")) {
manager.setType(RingtoneManager.TYPE_RINGTONE);
if (showDefault) {
uri = Settings.System.DEFAULT_RINGTONE_URI;
_ringtone = RingtoneManager.getRingtone(prefContext, uri);
String ringtoneName;
try {
ringtoneName = _ringtone.getTitle(prefContext);
} catch (Exception e) {
ringtoneName = prefContext.getString(R.string.ringtone_preference_default_ringtone);
}
toneList.put(Settings.System.DEFAULT_RINGTONE_URI.toString(), ringtoneName);
}
} else if (ringtoneType.equals("notification")) {
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
if (showDefault) {
uri = Settings.System.DEFAULT_NOTIFICATION_URI;
_ringtone = RingtoneManager.getRingtone(prefContext, uri);
String ringtoneName;
try {
ringtoneName = _ringtone.getTitle(prefContext);
} catch (Exception e) {
ringtoneName = prefContext.getString(R.string.ringtone_preference_default_notification);
}
toneList.put(Settings.System.DEFAULT_NOTIFICATION_URI.toString(), ringtoneName);
}
} else if (ringtoneType.equals("alarm")) {
manager.setType(RingtoneManager.TYPE_ALARM);
if (showDefault) {
uri = Settings.System.DEFAULT_ALARM_ALERT_URI;
_ringtone = RingtoneManager.getRingtone(prefContext, uri);
String ringtoneName;
try {
ringtoneName = _ringtone.getTitle(prefContext);
} catch (Exception e) {
ringtoneName = prefContext.getString(R.string.ringtone_preference_default_alarm);
}
toneList.put(Settings.System.DEFAULT_ALARM_ALERT_URI.toString(), ringtoneName);
}
}
if (showSilent)
toneList.put("", prefContext.getString(R.string.ringtone_preference_none));
Cursor cursor = manager.getCursor();
while (cursor.moveToNext()) {
String _uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
String _title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String _id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
toneList.put(_uri + "/" + _id, _title);
}
listAdapter.notifyDataSetChanged();
List<String> uris = new ArrayList<>(listAdapter.toneList.keySet());
final int position = uris.indexOf(ringtone);
listView.setSelection(position);
PPApplication.logE("RingtonePreference._setSummary", "refreshListView");
_setSummary(ringtone);
}
use of android.media.RingtoneManager in project PhoneProfilesPlus by henrichg.
the class TonesHandler method getPhoneProfilesSilentUri.
static String getPhoneProfilesSilentUri(Context context, int type) {
try {
RingtoneManager manager = new RingtoneManager(context);
manager.setType(type);
Cursor cursor = manager.getCursor();
while (cursor.moveToNext()) {
String id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
String uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String uriId = uri + "/" + id;
if (title.equals("PhoneProfiles Silent") || title.equals("phoneprofiles_silent"))
return uriId;
}
} catch (Exception ignored) {
}
return "";
}
Aggregations