use of android.media.RingtoneManager in project XobotOS by xamarin.
the class RingtonePickerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler = new Handler();
Intent intent = getIntent();
/*
* Get whether to show the 'Default' item, and the URI to play when the
* default is clicked
*/
mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI);
if (mUriForDefaultItem == null) {
mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
}
if (savedInstanceState != null) {
mClickedPos = savedInstanceState.getInt(SAVE_CLICKED_POS, -1);
}
// Get whether to show the 'Silent' item
mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
// Give the Activity so it can do managed queries
mRingtoneManager = new RingtoneManager(this);
// Get whether to include DRM ringtones
boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, true);
mRingtoneManager.setIncludeDrm(includeDrm);
// Get the types of ringtones to show
int types = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);
if (types != -1) {
mRingtoneManager.setType(types);
}
mCursor = mRingtoneManager.getCursor();
// The volume keys will control the stream that we are choosing a ringtone for
setVolumeControlStream(mRingtoneManager.inferStreamType());
// Get the URI whose list item should have a checkmark
mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
final AlertController.AlertParams p = mAlertParams;
p.mCursor = mCursor;
p.mOnClickListener = mRingtoneClickListener;
p.mLabelColumn = MediaStore.Audio.Media.TITLE;
p.mIsSingleChoice = true;
p.mOnItemSelectedListener = this;
p.mPositiveButtonText = getString(com.android.internal.R.string.ok);
p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(com.android.internal.R.string.cancel);
p.mPositiveButtonListener = this;
p.mOnPrepareListViewListener = this;
p.mTitle = intent.getCharSequenceExtra(RingtoneManager.EXTRA_RINGTONE_TITLE);
if (p.mTitle == null) {
p.mTitle = getString(com.android.internal.R.string.ringtone_picker_title);
}
setupAlert();
}
use of android.media.RingtoneManager in project Alarmio by TheAndroidMaster.
the class AlarmSoundChooserFragment 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_ALARM);
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());
}
SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds);
adapter.setListener(this);
recyclerView.setAdapter(adapter);
return view;
}
use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.
the class Utils method isAlarmUriValid.
public static boolean isAlarmUriValid(Context context, Uri uri) {
final RingtoneManager rm = new RingtoneManager(context);
rm.setType(RingtoneManager.TYPE_ALL);
return rm.getRingtonePosition(uri) != -1;
}
use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.
the class AlarmClockFragment method cacheAlarmTones.
private void cacheAlarmTones() {
mAlarms = new ArrayList<Uri>();
Cursor alarmsCursor = null;
try {
RingtoneManager ringtoneMgr = new RingtoneManager(getActivity().getApplicationContext());
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
return;
}
while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
int currentPosition = alarmsCursor.getPosition();
mAlarms.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 HandleApiCalls method cacheAlarmTones.
private void cacheAlarmTones() {
mAlarms = new ArrayList<Uri>();
Cursor alarmsCursor = null;
try {
RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
return;
}
while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
int currentPosition = alarmsCursor.getPosition();
mAlarms.add(ringtoneMgr.getRingtoneUri(currentPosition));
}
} finally {
if (alarmsCursor != null) {
alarmsCursor.close();
}
}
}
Aggregations