Java Code Examples for android.media.RingtoneManager#TYPE_ALL

The following examples show how to use android.media.RingtoneManager#TYPE_ALL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RingtonePreference.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the selected ringtone's title, or {@code null} if no ringtone is picked.
 *
 * @return The selected ringtone's title, or {@code null} if no ringtone is picked.
 */
public String getRingtoneTitle() {
  Context context = getContext();
  ContentResolver cr = context.getContentResolver();
  String[] projection = {MediaStore.MediaColumns.TITLE};

  String ringtoneTitle = null;

  if (ringtoneUri != null) {
    int type = RingtoneManager.getDefaultType(ringtoneUri);

    switch (type) {
      case RingtoneManager.TYPE_ALL:
      case RingtoneManager.TYPE_RINGTONE:
        ringtoneTitle = context.getString(R.string.RingtonePreference_ringtone_default);
        break;
      case RingtoneManager.TYPE_ALARM:
        ringtoneTitle = context.getString(R.string.RingtonePreference_alarm_sound_default);
        break;
      case RingtoneManager.TYPE_NOTIFICATION:
        ringtoneTitle = context.getString(R.string.RingtonePreference_notification_sound_default);
        break;
      default:
        try {
          Cursor cursor = cr.query(ringtoneUri, projection, null, null, null);
          if (cursor != null) {
            if (cursor.moveToFirst()) {
              ringtoneTitle = cursor.getString(0);
            }

            cursor.close();
          }
        } catch (Exception ignore) {
        }
    }
  }

  return ringtoneTitle;
}
 
Example 2
Source File: RingtonePreferenceDialogFragmentCompat.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private static String getDirForType(int type) {
  switch (type) {
    case RingtoneManager.TYPE_ALL:
    case RingtoneManager.TYPE_RINGTONE:
      return Environment.DIRECTORY_RINGTONES;
    case RingtoneManager.TYPE_NOTIFICATION:
      return Environment.DIRECTORY_NOTIFICATIONS;
    case RingtoneManager.TYPE_ALARM:
      return Environment.DIRECTORY_ALARMS;
    default:
      throw new IllegalArgumentException("Unsupported ringtone type: " + type);
  }
}
 
Example 3
Source File: RingtonePreferenceDialogFragmentCompat.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
private Cursor createCursor(Uri ringtoneUri) {
  RingtonePreference ringtonePreference = getRingtonePreference();
  ringtoneManager = new RingtoneManager(getContext());

  ringtoneManager.setType(ringtonePreference.getRingtoneType());
  ringtoneManager.setStopPreviousRingtone(true);

  Cursor ringtoneCursor = ringtoneManager.getCursor();

  String colId = ringtoneCursor.getColumnName(RingtoneManager.ID_COLUMN_INDEX);
  String colTitle = ringtoneCursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX);

  MatrixCursor extras = new MatrixCursor(new String[]{colId, colTitle});

  final int ringtoneType = ringtonePreference.getRingtoneType();
  final boolean showDefault = ringtonePreference.getShowDefault();
  final boolean showSilent = ringtonePreference.getShowSilent();

  if (showDefault) {
    switch (ringtoneType) {
      case RingtoneManager.TYPE_ALARM:
        extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_alarm_sound_default)});
        break;
      case RingtoneManager.TYPE_NOTIFICATION:
        extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_notification_sound_default)});
        break;
      case RingtoneManager.TYPE_RINGTONE:
      case RingtoneManager.TYPE_ALL:
      default:
        extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_ringtone_default)});
        break;
    }
  }

  if (showSilent) {
    extras.addRow(new String[]{CURSOR_NONE_ID, getString(R.string.RingtonePreference_ringtone_silent)});
  }

  selectedIndex = ringtoneManager.getRingtonePosition(ringtoneUri);
  if (selectedIndex >= 0) {
    selectedIndex += (showDefault ? 1 : 0) + (showSilent ? 1 : 0);
  }

  if (selectedIndex < 0 && showDefault) {
    if (RingtoneManager.getDefaultType(ringtoneUri) != -1) {
      selectedIndex = 0;
    }
  }

  if (selectedIndex < 0 && showSilent) {
    selectedIndex = showDefault ? 1 : 0;
  }

  Cursor[] cursors = {extras, ringtoneCursor};
  return this.cursor = new MergeCursor(cursors);
}