Example usage for android.media RingtoneManager TYPE_ALARM

List of usage examples for android.media RingtoneManager TYPE_ALARM

Introduction

In this page you can find the example usage for android.media RingtoneManager TYPE_ALARM.

Prototype

int TYPE_ALARM

To view the source code for android.media RingtoneManager TYPE_ALARM.

Click Source Link

Document

Type that refers to sounds that are used for the alarm.

Usage

From source file:org.schabi.terminightor.AlarmItemDetailFragment.java

public void restoreItem(long id) {
    Context c = getContext();//w w  w . j  a  v a  2s  . c o m
    assert c != null;
    if (id >= 0) {
        try {
            alarm = Alarm.getFromCursorItem(AlarmDBOpenHelper.getAlarmDBOpenHelper(c).getReadableItem(id));
        } catch (Exception e) {
            e.printStackTrace();
        }
        restoreAlarm(alarm);
        timeValueSet = true;
    } else {
        alarm = new Alarm();
        repeatCheckBox.setChecked(false);
        chooseDateView.setRepeatEnabled(false);
        displayNoTimeEntered();
        Uri alarmToneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        alarm.setAlarmTone(alarmToneUri.toString());
        try {
            setAlarmToneButton.setText(RingtoneManager.getRingtone(c, alarmToneUri).getTitle(c));
        } catch (Exception e) {
            e.printStackTrace();
            setAlarmToneButton.setText(c.getString(R.string.defaultRingTone));
        }
    }
}

From source file:com.mattprecious.prioritysms.activity.ProfileListActivity.java

private void doUpdate(int from, int to) {
    switch (from) {
    case 1:/* w w w.  ja v a  2s .  co m*/
    case 2:
        // too old, don't worry
        break;
    case 3:
        // move 'contact' preference to 'sms_contact'
        preferences.edit().putString("sms_contact", preferences.getString("contact", null)).remove("contact")
                .commit();

    case 4:
        // enabled defaulted to false previously
        preferences.edit()
                .putBoolean(getString(R.string.pref_key_enabled), preferences.getBoolean("enabled", false))
                .commit();

        SmsProfile smsProfile = new SmsProfile();
        smsProfile.setName("SMS Profile");

        PhoneProfile phoneProfile = new PhoneProfile();
        phoneProfile.setName("Phone Profile");

        String ringtone = preferences.getString("alarm", null);
        Uri ringtoneUri = ringtone == null ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
                : Uri.parse(ringtone);
        smsProfile.setRingtone(ringtoneUri);
        phoneProfile.setRingtone(ringtoneUri);

        boolean vibrate = preferences.getBoolean("vibrate", false);
        smsProfile.setVibrate(vibrate);
        phoneProfile.setVibrate(vibrate);

        // import the SMS settings
        boolean smsWorthSaving = false;

        String smsLookup = preferences.getString("sms_contact", null);
        if (preferences.getBoolean("filter_contact", false) && !Strings.isBlank(smsLookup)) {
            smsProfile.addContact(smsLookup);
            smsWorthSaving = true;
        }

        String keywords = preferences.getString("keyword", null);
        if (preferences.getBoolean("filter_keyword", false) && !Strings.isBlank(keywords)) {
            String[] keywordArr = keywords.split(",");
            smsProfile.setKeywords(new LinkedHashSet<String>(Arrays.asList(keywordArr)));
            smsWorthSaving = true;
        }

        if (smsWorthSaving) {
            smsProfile.save(this);
        }

        // import the missed call settings
        phoneProfile.setEnabled(preferences.getBoolean("on_call", false));

        boolean phoneWorthSaving = false;

        String phoneLookup = preferences.getString("call_contact", null);
        if (!Strings.isBlank(phoneLookup)) {
            phoneProfile.addContact(phoneLookup);
            phoneWorthSaving = true;
        }

        if (phoneWorthSaving) {
            phoneProfile.save(this);
        }

        // delete all those old preferences
        preferences.edit().remove("filter_keyword").remove("keyword").remove("filter_contact")
                .remove("sms_contact").remove("on_call").remove("call_contact").remove("alarm")
                .remove("override").remove("vibrate").commit();
    }
}

From source file:com.android.deskclock.AlarmClockFragment.java

private void launchRingTonePicker(Alarm alarm) {
    mSelectedAlarm = alarm;//from   w  w w  .  j ava2 s .c  om
    Uri oldRingtone = Alarm.NO_RINGTONE_URI.equals(alarm.alert) ? null : alarm.alert;
    final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, oldRingtone);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
    startActivityForResult(intent, REQUEST_CODE_RINGTONE);
}

From source file:com.embeddedlog.LightUpDroid.LightUpPiSync.java

private Alarm alarmFromJson(JSONObject aJson) {
    // If mSelectedAlarm is null then we're creating a new alarm.
    Alarm alarm = new Alarm();
    alarm.alert = RingtoneManager.getActualDefaultRingtoneUri(mActivityContext, RingtoneManager.TYPE_ALARM);
    if (alarm.alert == null) {
        alarm.alert = Uri.parse("content://settings/system/alarm_alert");
    }/*from   ww w .  j  a va 2 s  .com*/
    // Setting the vibrate option to always true, as there is no attribute in LightUpPi
    alarm.vibrate = true;
    // Setting the 'delete after use' option to always false, as there is no such feature in
    // the LightUpPi alarm system and all alarms are repeatable
    alarm.deleteAfterUse = false;

    // Parsing the JSON data
    try {
        alarm.hour = aJson.getInt("hour");
        alarm.minutes = aJson.getInt("minute");
        alarm.enabled = aJson.getBoolean("enabled");
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("monday"), Calendar.MONDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("tuesday"), Calendar.TUESDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("wednesday"), Calendar.WEDNESDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("thursday"), Calendar.THURSDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("friday"), Calendar.FRIDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("saturday"), Calendar.SATURDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("sunday"), Calendar.SUNDAY);
        alarm.label = aJson.getString("label");
        alarm.lightuppiId = aJson.getLong("id");
        alarm.timestamp = aJson.getLong("timestamp");
    } catch (JSONException e) {
        Log.w(LOG_TAG + " JSONException: " + e.toString());
        alarm = null;
    }
    return alarm;
}

From source file:com.android.deskclock.AlarmClockFragment.java

private Uri getDefaultRingtoneUri() {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    final String ringtoneUriString = sp.getString(PREF_KEY_DEFAULT_ALARM_RINGTONE_URI, null);

    final Uri ringtoneUri;
    if (ringtoneUriString != null) {
        ringtoneUri = Uri.parse(ringtoneUriString);
    } else {/*from  w  ww . j  a  v  a2s .  co  m*/
        ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(getActivity(), RingtoneManager.TYPE_ALARM);
    }

    return ringtoneUri;
}

From source file:saphion.fragments.alarm.AlarmFragment.java

private void saveRingtoneUri(Intent intent) {
    Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    if (uri == null) {
        uri = Alarm.NO_RINGTONE_URI;
    }/*from   w w  w  .j  av  a  2  s. c  o m*/
    mSelectedAlarm.alert = uri;

    // Save the last selected ringtone as the default for new alarms
    if (!Alarm.NO_RINGTONE_URI.equals(uri)) {
        RingtoneManager.setActualDefaultRingtoneUri(getActivity(), RingtoneManager.TYPE_ALARM, uri);
    }
    asyncUpdateAlarm(mSelectedAlarm, false);
}

From source file:dk.dr.radio.afspilning.Afspiller.java

void ringDenAlarm() {
      Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
      if (alert == null) {
          // alert is null, using backup
          alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          if (alert == null) { // I can't see this ever being null (as always have a default notification) but just incase
              // alert backup is null, using 2nd backup
              alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
          }/*from w  w w.  j ava2 s  .  co  m*/
      }
      lydkilde = new AlarmLydkilde(alert.toString(), lydkilde);
      handler.postDelayed(startAfspilningIntern, 100);
      vibru(4000);
  }

From source file:com.ringdroid.RingdroidEditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_USE_ALL) {
        return new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.ring_picker_title)
                .setSingleChoiceItems(R.array.set_ring_option, 0, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        ring_button_type = whichButton;
                    }//from   ww  w  .j  a v  a 2 s  .  com
                }).setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        int ring_type = 0;
                        if (ring_button_type == 3) {
                            Intent intent = new Intent();
                            Uri currentFileUri = Uri.parse(mFilename);
                            intent.setData(currentFileUri);
                            intent.setClass(RingdroidEditActivity.this,
                                    com.ringdroid.ChooseContactActivity.class);
                            RingdroidEditActivity.this.startActivity(intent);
                            return;
                        } else if (ring_button_type == 0) {
                            ring_type = RingtoneManager.TYPE_RINGTONE;
                        } else if (ring_button_type == 1) {
                            ring_type = RingtoneManager.TYPE_NOTIFICATION;
                        } else if (ring_button_type == 2) {
                            ring_type = RingtoneManager.TYPE_ALARM;
                        }
                        // u = Const.mp3dir + ring.getString(Const.mp3);
                        Uri currentFileUri = null;
                        if (!mFilename.startsWith("content:")) {
                            String selection;
                            selection = MediaStore.Audio.Media.DATA + "=?";//+"='"+DatabaseUtils.sqlEscapeString(mFilename)+"'";
                            String[] selectionArgs = new String[1];
                            selectionArgs[0] = mFilename;

                            Uri head = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                            Cursor c = getExternalAudioCursor(selection, selectionArgs);
                            if (c == null || c.getCount() == 0) {
                                head = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
                                c = getInternalAudioCursor(selection, selectionArgs);
                            }
                            startManagingCursor(c);
                            if (c == null || c.getCount() == 0)
                                return;
                            c.moveToFirst();
                            String itemUri = head.toString() + "/"
                                    + c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
                            currentFileUri = Uri.parse(itemUri);
                        } else {
                            currentFileUri = Uri.parse(mFilename);
                        }
                        RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this, ring_type,
                                currentFileUri);
                        Toast.makeText(RingdroidEditActivity.this,
                                "" + getResources().getStringArray(R.array.set_ring_option)[ring_button_type],
                                Toast.LENGTH_SHORT).show();
                    }
                }).setNegativeButton(R.string.alertdialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                }).create();
    }
    return super.onCreateDialog(id);
}

From source file:com.android.deskclock.AlarmClockFragment.java

/**
 * M: Set the system default Alarm Ringtone,
 * then save it as the Clock internal used ringtone.
 *///  www  .j av  a  2 s  . c o m
public void setSystemAlarmRingtoneToPref() {
    Uri systemDefaultRingtone = RingtoneManager.getActualDefaultRingtoneUri(getActivity(),
            RingtoneManager.TYPE_ALARM);
    /// M: The RingtoneManager may return null alert. @{
    if (systemDefaultRingtone == null) {
        systemDefaultRingtone = Uri.parse(SYSTEM_SETTINGS_ALARM_ALERT);
    }
    /// @}
    setDefaultRingtone(systemDefaultRingtone.toString());
    LogUtils.v("setSystemAlarmRingtone: " + systemDefaultRingtone);
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean playBackDefaultAlarm(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse tr, ActionResponse ar) {
    if (!isRingerModeNormal(envParms)) {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal;
        return false;
    }/*ww w.  ja  v  a2s .c o  m*/
    Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_ALARM);
    //      Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (uri != null) {
        playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id,
                PROFILE_ACTION_RINGTONE_TYPE_ALARM, "", uri.getEncodedPath(), "-1", "-1");
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "Default alarm does not exists";
    }
    return true;
}