Search in sources :

Example 11 with RingtoneManager

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);
}
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 12 with RingtoneManager

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;
}
Also used : AlertDialog(org.holoeverywhere.app.AlertDialog) RingtoneManager(android.media.RingtoneManager) Builder(org.holoeverywhere.app.AlertDialog.Builder) Handler(android.os.Handler) Activity(android.app.Activity)

Example 13 with RingtoneManager

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;
}
Also used : AlertDialog(org.holoeverywhere.app.AlertDialog) RingtoneManager(android.media.RingtoneManager) Builder(org.holoeverywhere.app.AlertDialog.Builder) Handler(android.os.Handler) Activity(android.app.Activity)

Example 14 with RingtoneManager

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

Example 15 with RingtoneManager

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;
}
Also used : RingtoneManager(android.media.RingtoneManager) SoundsAdapter(james.alarmio.adapters.SoundsAdapter) ArrayList(java.util.ArrayList) RecyclerView(android.support.v7.widget.RecyclerView) SoundData(james.alarmio.data.SoundData) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Cursor(android.database.Cursor) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

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