use of android.media.RingtoneManager in project PhoneProfilesPlus 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 HoloEverywhere by Prototik.
the class _RingtonePickerDialog method create.
public _RingtonePickerDialog create() {
if (dialog != null) {
return this;
}
handler = new Handler();
hasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
uriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI);
if (uriForDefaultItem == null) {
uriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
}
hasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
ringtoneManager = new RingtoneManager(context);
final boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, true);
ringtoneManager.setIncludeDrm(includeDrm);
int types = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);
if (types != -1) {
ringtoneManager.setType(types);
}
cursor = ringtoneManager.getCursor();
if (context instanceof Activity) {
((Activity) context).setVolumeControlStream(ringtoneManager.inferStreamType());
}
existingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
builder = new AlertDialog.Builder(context);
dialog = onCreateDialog(builder);
return this;
}
use of android.media.RingtoneManager in project little-bear-dictionary by daimajia.
the class RingtonePicker method create.
public RingtonePicker create() {
if (dialog != null) {
return this;
}
handler = new Handler();
hasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
uriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI);
if (uriForDefaultItem == null) {
uriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
}
hasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
ringtoneManager = new RingtoneManager(context);
final boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, true);
ringtoneManager.setIncludeDrm(includeDrm);
int types = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);
if (types != -1) {
ringtoneManager.setType(types);
}
cursor = ringtoneManager.getCursor();
if (context instanceof Activity) {
((Activity) context).setVolumeControlStream(ringtoneManager.inferStreamType());
}
existingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
builder = new AlertDialog.Builder(context);
dialog = onCreateDialog(builder);
return this;
}
use of android.media.RingtoneManager in project PhoneProfilesPlus by henrichg.
the class TonesHandler method getToneName.
static String getToneName(Context context, int type, String _uri) {
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 (uriId.equals(_uri))
return title;
}
return "";
}
use of android.media.RingtoneManager in project Alarmio by TheAndroidMaster.
the class RingtoneSoundChooserFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false);
RecyclerView recyclerView = view.findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
List<SoundData> sounds = new ArrayList<>();
RingtoneManager manager = new RingtoneManager(getContext());
manager.setType(RingtoneManager.TYPE_RINGTONE);
Cursor cursor = manager.getCursor();
int count = cursor.getCount();
if (count > 0 && cursor.moveToFirst()) {
do {
sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
} while (cursor.moveToNext());
}
adapter = new SoundsAdapter(getAlarmio(), sounds);
adapter.setListener(this);
recyclerView.setAdapter(adapter);
return view;
}
Aggregations