Search in sources :

Example 6 with RingtoneManager

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();
        }
    }
}
Also used : RingtoneManager(android.media.RingtoneManager) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 7 with RingtoneManager

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();
        }
    }
}
Also used : RingtoneManager(android.media.RingtoneManager) Cursor(android.database.Cursor)

Example 8 with RingtoneManager

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 "";
}
Also used : RingtoneManager(android.media.RingtoneManager) Cursor(android.database.Cursor) IOException(java.io.IOException)

Example 9 with RingtoneManager

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);
}
Also used : RingtoneManager(android.media.RingtoneManager) Ringtone(android.media.Ringtone) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint)

Example 10 with RingtoneManager

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 "";
}
Also used : RingtoneManager(android.media.RingtoneManager) Cursor(android.database.Cursor) IOException(java.io.IOException)

Aggregations

RingtoneManager (android.media.RingtoneManager)20 Cursor (android.database.Cursor)16 Uri (android.net.Uri)8 ArrayList (java.util.ArrayList)5 View (android.view.View)4 Handler (android.os.Handler)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Ringtone (android.media.Ringtone)2 Nullable (android.support.annotation.Nullable)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 SoundsAdapter (james.alarmio.adapters.SoundsAdapter)2 SoundData (james.alarmio.data.SoundData)2 IOException (java.io.IOException)2 AlertDialog (org.holoeverywhere.app.AlertDialog)2 Builder (org.holoeverywhere.app.AlertDialog.Builder)2 Intent (android.content.Intent)1