Example usage for android.media AudioManager RINGER_MODE_NORMAL

List of usage examples for android.media AudioManager RINGER_MODE_NORMAL

Introduction

In this page you can find the example usage for android.media AudioManager RINGER_MODE_NORMAL.

Prototype

int RINGER_MODE_NORMAL

To view the source code for android.media AudioManager RINGER_MODE_NORMAL.

Click Source Link

Document

Ringer mode that may be audible and may vibrate.

Usage

From source file:com.github.nutomic.pegasus.activities.ProfileList.java

/**
 * Handle ActionBar item selections.// ww  w .java2  s.c o m
 */
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.new_item:
        new UpdateTask() {

            @Override
            protected Long doInBackground(Void... params) {
                // Insert new profile into database.
                ContentValues cv = new ContentValues();
                cv.put(ProfileColumns.NAME, getResources().getString(R.string.profilelist_new));
                cv.put(ProfileColumns.RINGTONE_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE);
                cv.put(ProfileColumns.NOTIFICATION_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE);
                cv.put(ProfileColumns.MEDIA_VOLUME, 10 - ProfileColumns.VOLUME_APPLY_FALSE);
                cv.put(ProfileColumns.ALARM_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE);
                cv.put(ProfileColumns.RINGER_MODE, AudioManager.RINGER_MODE_NORMAL);

                return Database.getInstance(ProfileList.this).getWritableDatabase()
                        .insert(ProfileColumns.TABLE_NAME, null, cv);
            }

            @Override
            protected void onPostExecute(Long result) {
                super.onPostExecute(result);
                renameProfile(result, getProfileName((AdapterContextMenuInfo) item.getMenuInfo()));
            }
        }.execute((Void) null);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static void onState(int state, String caller) {
    if (ccCall == null) {
        ccCall = new Call();
        ccConn = new Connection();
        ccCall.setConn(ccConn);//from   ww  w.  java 2 s  . c  o m
        ccConn.setCall(ccCall);
    }
    if (call_state != state) {
        if (state != UserAgent.UA_STATE_IDLE)
            call_end_reason = -1;
        call_state = state;
        switch (call_state) {
        case UserAgent.UA_STATE_INCOMING_CALL:
            enable_wifi(true);
            RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0;
            RtpStreamReceiver.speakermode = speakermode();
            bluetooth = -1;
            String text = caller.toString();
            if (text.indexOf("<sip:") >= 0 && text.indexOf("@") >= 0)
                text = text.substring(text.indexOf("<sip:") + 5, text.indexOf("@"));
            String text2 = caller.toString();
            if (text2.indexOf("\"") >= 0)
                text2 = text2.substring(text2.indexOf("\"") + 1, text2.lastIndexOf("\""));
            broadcastCallStateChanged("RINGING", caller);
            mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
            ccCall.setState(Call.State.INCOMING);
            ccConn.setUserData(null);
            ccConn.setAddress(text, text2);
            ccConn.setIncoming(true);
            ccConn.date = System.currentTimeMillis();
            ccCall.base = 0;
            AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
            int rm = am.getRingerMode();
            int vs = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
            KeyguardManager mKeyguardManager = (KeyguardManager) mContext
                    .getSystemService(Context.KEYGUARD_SERVICE);
            if (v == null)
                v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
            if ((pstn_state == null || pstn_state.equals("IDLE"))
                    && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                            org.sipdroid.sipua.ui.Settings.PREF_AUTO_ON,
                            org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ON)
                    && !mKeyguardManager.inKeyguardRestrictedInputMode())
                v.vibrate(vibratePattern, 1);
            else {
                if ((pstn_state == null || pstn_state.equals("IDLE")) && (rm == AudioManager.RINGER_MODE_VIBRATE
                        || (rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON)))
                    v.vibrate(vibratePattern, 1);
                if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) {
                    String sUriSipRingtone = PreferenceManager.getDefaultSharedPreferences(mContext).getString(
                            org.sipdroid.sipua.ui.Settings.PREF_SIPRINGTONE,
                            Settings.System.DEFAULT_RINGTONE_URI.toString());
                    if (!TextUtils.isEmpty(sUriSipRingtone)) {
                        oRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(sUriSipRingtone));
                        if (oRingtone != null)
                            oRingtone.play();
                    }
                }
            }
            moveTop();
            if (wl == null) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                        "Sipdroid.onState");
            }
            wl.acquire();
            Checkin.checkin(true);
            break;
        case UserAgent.UA_STATE_OUTGOING_CALL:
            RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0;
            RtpStreamReceiver.speakermode = speakermode();
            bluetooth = -1;
            onText(MISSED_CALL_NOTIFICATION, null, 0, 0);
            engine(mContext).register();
            broadcastCallStateChanged("OFFHOOK", caller);
            ccCall.setState(Call.State.DIALING);
            ccConn.setUserData(null);
            ccConn.setAddress(caller, caller);
            ccConn.setIncoming(false);
            ccConn.date = System.currentTimeMillis();
            ccCall.base = 0;
            moveTop();
            Checkin.checkin(true);
            break;
        case UserAgent.UA_STATE_IDLE:
            broadcastCallStateChanged("IDLE", null);
            onText(CALL_NOTIFICATION, null, 0, 0);
            ccCall.setState(Call.State.DISCONNECTED);
            if (listener_video != null)
                listener_video.onHangup();
            stopRingtone();
            if (wl != null && wl.isHeld())
                wl.release();
            mContext.startActivity(createIntent(InCallScreen.class));
            ccConn.log(ccCall.base);
            ccConn.date = 0;
            engine(mContext).listen();
            break;
        case UserAgent.UA_STATE_INCALL:
            broadcastCallStateChanged("OFFHOOK", null);
            if (ccCall.base == 0) {
                ccCall.base = SystemClock.elapsedRealtime();
            }
            progress();
            ccCall.setState(Call.State.ACTIVE);
            stopRingtone();
            if (wl != null && wl.isHeld())
                wl.release();
            mContext.startActivity(createIntent(InCallScreen.class));
            break;
        case UserAgent.UA_STATE_HOLD:
            onText(CALL_NOTIFICATION, mContext.getString(R.string.card_title_on_hold),
                    android.R.drawable.stat_sys_phone_call_on_hold, ccCall.base);
            ccCall.setState(Call.State.HOLDING);
            if (InCallScreen.started && (pstn_state == null || !pstn_state.equals("RINGING")))
                mContext.startActivity(createIntent(InCallScreen.class));
            break;
        }
        pos(true);
        RtpStreamReceiver.ringback(false);
    }
}

From source file:fr.inria.ucn.collectors.SysStateCollector.java

@SuppressWarnings("deprecation")
private JSONObject getAudioState(Context c) throws JSONException {
    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    JSONObject data = new JSONObject();

    data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn());
    data.put("is_microphone_mute", am.isMicrophoneMute());
    data.put("is_music_active", am.isMusicActive());
    data.put("is_speaker_phone_on", am.isSpeakerphoneOn());
    data.put("is_wired_headset_on", am.isWiredHeadsetOn());

    switch (am.getMode()) {
    case AudioManager.MODE_IN_CALL:
        data.put("mode", "in_call");
        break;/*from ww  w .j  a  va2 s  .  com*/
    case AudioManager.MODE_IN_COMMUNICATION:
        data.put("mode", "in_comm");
        break;
    case AudioManager.MODE_NORMAL:
        data.put("mode", "normal");
        break;
    case AudioManager.MODE_RINGTONE:
        data.put("mode", "ringtone");
        break;
    case AudioManager.MODE_INVALID:
    default:
        data.put("mode", "invalid");
        break;
    }

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        data.put("ringer_mode", "vibrate");
        break;
    case AudioManager.RINGER_MODE_SILENT:
        data.put("ringer_mode", "silent");
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        data.put("ringer_mode", "normal");
        break;
    default:
        data.put("ringer_mode", "invalid");
        break;
    }
    return data;
}

From source file:cc.psdev.heywifi.MainService.java

private void changeFromSavedRingmode(int ringmode) {
    switch (ringmode) {
    case 2://from  w w w .  j av  a 2 s  .c o m
        audm.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        break;
    case 1:
        audm.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        break;
    case 0:
        audm.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        break;
    }
}

From source file:org.kontalk.ui.MessagingNotification.java

private static void setDefaults(Context context, NotificationCompat.Builder builder) {
    int defaults = 0;

    if (Preferences.getNotificationLED(context)) {
        int ledColor = Preferences.getNotificationLEDColor(context);
        builder.setLights(ledColor, 1000, 1000);
    } else {/*from   w  w  w  .j av  a 2 s  . c  o m*/
        // this will disable the LED completely
        builder.setLights(0, 0, 0);
    }

    String ringtone = Preferences.getNotificationRingtone(context);
    if (ringtone != null && ringtone.length() > 0)
        builder.setSound(Uri.parse(ringtone));

    String vibrate = Preferences.getNotificationVibrate(context);
    if ("always".equals(vibrate) || ("silent_only".equals(vibrate)
            && ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE))
                    .getRingerMode() != AudioManager.RINGER_MODE_NORMAL))
        defaults |= Notification.DEFAULT_VIBRATE;

    builder.setDefaults(defaults);
}

From source file:org.smssecure.smssecure.notifications.MessageNotifier.java

private static void sendInThreadNotification(Context context, Recipients recipients) {
    if (!SilencePreferences.isInThreadNotifications(context)
            || ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        return;/*  w w w  . j a  v  a 2  s  .  c  om*/
    }

    Uri uri = recipients != null ? recipients.getRingtone() : null;

    if (uri == null) {
        String ringtone = SilencePreferences.getNotificationRingtone(context);

        if (ringtone == null) {
            Log.w(TAG, "ringtone preference was null.");
            return;
        }

        uri = Uri.parse(ringtone);

        if (uri == null) {
            Log.w(TAG, "couldn't parse ringtone uri " + ringtone);
            return;
        }
    }

    if (uri.toString().isEmpty()) {
        Log.d(TAG, "ringtone uri is empty");
        return;
    }

    Ringtone ringtone = RingtoneManager.getRingtone(context, uri);

    if (ringtone == null) {
        Log.w(TAG, "ringtone is null");
        return;
    }

    if (Build.VERSION.SDK_INT >= 21) {
        ringtone.setAudioAttributes(
                new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    } else {
        ringtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
    }

    ringtone.play();
}

From source file:com.z3r0byte.magistify.Services.OldBackgroundService.java

private void autoSilentTimer() {
    Log.d(TAG, "autoSilentTimer: Starting autoSilent Timer");
    TimerTask silentTask = new TimerTask() {
        @Override/*from w ww  .j  a  v  a 2s  .c o m*/
        public void run() {
            appointments = calendarDB.getSilentAppointments(getMargin());
            if (doSilent(appointments)) {
                silenced(true);
                AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                configUtil.setInteger("previous_silent_state", audiomanager.getRingerMode());
                if (audiomanager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
                    audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                }
            } else {
                if (isSilencedByApp()) {
                    AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                    if (configUtil.getBoolean("reverse_silent_state")) {
                        audiomanager.setRingerMode(configUtil.getInteger("previous_silent_state"));
                    } else {
                        audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                    }
                    silenced(false);
                }
            }
        }
    };
    timer.schedule(silentTask, 6000, 10 * 1000);
}

From source file:com.bangz.smartmute.services.LocationMuteService.java

private void handleGeofenceTrigger(Intent intent) {

    LogUtils.LOGD(TAG, "Handling Geofence trigger ...");
    HashMap<Integer, String> mapRingerMode = new HashMap<Integer, String>();
    mapRingerMode.put(AudioManager.RINGER_MODE_NORMAL, "Normal");
    mapRingerMode.put(AudioManager.RINGER_MODE_SILENT, "Silent");
    mapRingerMode.put(AudioManager.RINGER_MODE_VIBRATE, "Vibrate");

    HashMap<Integer, String> mapTransition = new HashMap<Integer, String>();
    mapTransition.put(Geofence.GEOFENCE_TRANSITION_DWELL, "DWELL");
    mapTransition.put(Geofence.GEOFENCE_TRANSITION_ENTER, "ENTER");
    mapTransition.put(Geofence.GEOFENCE_TRANSITION_EXIT, "EXIT");

    GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent);

    if (geoEvent.hasError() == false) {
        LogUtils.LOGD(TAG, "\tgeoEvent has no error.");
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        if (audioManager == null) {
            LogUtils.LOGD(TAG, "\t !!!!!  AudioManager == null !!!!!!!");
            return;
        }/*w  w  w.jav  a 2s .  c  o m*/
        int currringermode = audioManager.getRingerMode();

        List<Geofence> geofences = geoEvent.getTriggeringGeofences();

        int transition = geoEvent.getGeofenceTransition();
        ContentResolver cr = getContentResolver();

        //int enterTransition = Config.TEST_BUILD ? Geofence.GEOFENCE_TRANSITION_ENTER : Geofence.GEOFENCE_TRANSITION_DWELL;
        LogUtils.LOGD(TAG, "\tTransition: " + mapTransition.get(transition));
        if (transition == Geofence.GEOFENCE_TRANSITION_DWELL
                || transition == Geofence.GEOFENCE_TRANSITION_ENTER) {

            boolean setted = false;
            for (Geofence geofence : geofences) {
                long id = Long.parseLong(geofence.getRequestId());
                Uri uri = ContentUris.withAppendedId(RulesColumns.CONTENT_ID_URI_BASE, id);
                Cursor cursor = cr.query(uri, PROJECTS, RulesColumns.ACTIVATED + " = 1", null, null);

                if (cursor.getCount() != 0) {
                    cursor.moveToFirst();
                    int setmode = cursor.getInt(cursor.getColumnIndex(RulesColumns.RINGMODE));

                    if (currringermode == setmode) {
                        LogUtils.LOGD(TAG, "\tringer mode already is in silent or vibrate. we do nothing");
                    } else {

                        LogUtils.LOGD(TAG, "\tset ringer mode to " + setmode);
                        audioManager.setRingerMode(setmode);
                        PrefUtils.rememberWhoMuted(this, id);
                        //TODO Notify to user ?
                    }
                    setted = true;

                } else {
                    LogUtils.LOGD(TAG,
                            "\tid = " + id + " trigger, but does not find in database. maybe disabled.");
                }

                cursor.close();
                cursor = null;

                if (setted == true) {
                    break;
                }
            }
        } else if (transition == Geofence.GEOFENCE_TRANSITION_EXIT) {

            for (Geofence geofence : geofences) {
                long id = Long.parseLong(geofence.getRequestId());
                if (id == PrefUtils.getLastSetMuteId(this)) {
                    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                    if (am != null) {
                        am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                    }
                    PrefUtils.cleanLastMuteId(this);
                    break;
                }
            }
        } else {
            LogUtils.LOGD(TAG, "transition is " + transition + " ; != entertransition && !! EXIT");
        }

    } else {
        PrefUtils.Geofencing(this, false);
        if (geoEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {

            NotificationUserFailed();

            ReceUtils.enableReceiver(this, LocationProviderChangedReceiver.class, true);
        } else {
            LogUtils.LOGD(TAG, "\tHandle Geofence trigger error. errcode = " + geoEvent.getErrorCode());
        }
    }

    LogUtils.LOGD(TAG, "Successful Leave handling Geofence trigger.");
}

From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java

private void mute(int alarmId) {
    Log.d(TAG, "mute()");

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    if (Preferences.getLocationStatus(preferences) == Preferences.LOCATION_STATUS_WAITING) {
        Log.d(TAG, "mute() blocked - waiting for a location update");
        return;//from   w  w w. ja  v a 2 s.  co  m
    }

    // check if phone is already muted by the user
    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    boolean isPhoneAlreadyMuted = audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL
            && !Preferences.isMutingPeriod(preferences);
    if (isPhoneAlreadyMuted) {
        Log.d(TAG, "phone is already muted, scheduling next mute");
        scheduleMute(true);
        return;
    }

    // load the current period from the db
    MutingPeriod mutingPeriod = null;
    Log.d(TAG, "muting period id: " + alarmId);
    if (DEBUG_WITH_FAKE_ALARMS) {
        mutingPeriod = new MutingPeriod();
        mutingPeriod.setId(-1);
        mutingPeriod.setBegin(System.currentTimeMillis());
        mutingPeriod.setEnd(mutingPeriod.getBegin() + 10000);
        mutingPeriod.setName("Fakeevent");
    } else {
        mutingPeriod = Studentportal.getStudentPortalDB().mutingPeriods_getPeriod(alarmId);
    }

    // check if phone is located at university
    notifyUser(Studentportal.NOTIFICATION_MS_INFO, true, mutingPeriod.getName(), mutingPeriod.getName(),
            getString(R.string.automute_notification_course_started_locating));
    boolean isPhoneLocationKnown = false;
    boolean isPhoneLocatedAtUniversity = false;
    String locationSource = null;

    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    if (wifiManager.isWifiEnabled()) {
        ScanResult scanResult = MutingUtils.findMutingWifiNetwork(wifiManager.getScanResults());
        if (scanResult != null) {
            Log.d(TAG, "phone located by wifi: " + scanResult.SSID);
            isPhoneLocationKnown = true;
            isPhoneLocatedAtUniversity = true;
            locationSource = "wifi (" + scanResult.SSID + ")";
        }
    }

    if (!isPhoneLocationKnown) {
        // phone location could not be determined by wifi, trying network location instead...
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            Intent locationIntent = new Intent("at.ac.uniklu.mobile.sportal.LOCATION_UPDATE")
                    .putExtra(EXTRA_ALARM_ID, alarmId);
            PendingIntent pendingLocationIntent = PendingIntent.getBroadcast(this, 0, locationIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            // remove the location receiver (so it doesn't get registered multiple times [could also happen on overlapping mute() calls)
            locationManager.removeUpdates(pendingLocationIntent);

            if (Preferences.getLocationStatus(preferences) == Preferences.LOCATION_STATUS_RECEIVED) {
                isPhoneLocationKnown = true;
                pendingLocationIntent.cancel();
                Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                if (location == null) {
                    Log.d(TAG, "location received but still null");
                } else {
                    MutingRegion mutingRegion = MutingUtils.findOverlappingMutingRegion(location);
                    if (mutingRegion != null) {
                        Log.d(TAG, "phone located by network @ " + mutingRegion.getName());
                        isPhoneLocatedAtUniversity = true;
                        locationSource = "location (" + mutingRegion.getName() + ")";
                    }
                }
            } else {
                Log.d(TAG, "trying to locate the phone by network...");
                // wait for a location update
                Preferences.setLocationStatus(preferences, Preferences.LOCATION_STATUS_WAITING);
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                        pendingLocationIntent);
                return; // exit method - it will be re-called from the location broadcast receiver on a location update
            }
        }
    }

    boolean isAlwaysMuteEnabled = Preferences.isAutomuteWithoutLocation(this, preferences);

    if (isPhoneLocationKnown) {
        if (!isPhoneLocatedAtUniversity) {
            Log.d(TAG, "phone is not located at university, scheduling next mute");
            scheduleMute(true);
            removeNotification(Studentportal.NOTIFICATION_MS_INFO);
            return;
        }
    } else {
        Log.d(TAG, "phone cannot be located");
        if (!isAlwaysMuteEnabled) {
            Log.d(TAG, "alwaysmute is disabled, scheduling next mute");
            Preferences.setLocationStatus(preferences, Preferences.LOCATION_STATUS_NONE);
            scheduleMute(true);
            removeNotification(Studentportal.NOTIFICATION_MS_INFO);
            return;
        }
    }

    // only turn the ringtone off if we aren't currently in a muting period.
    // if we are in a muting period the ringtone is already muted and the request should be ignored,
    // else rintoneTurnOn() won't turn the ringtone back on because ringtone override will be set to true
    if (!Preferences.isMutingPeriod(preferences)) {
        MutingUtils.ringtoneTurnOff(this);
    }

    // persist that from now on the phone is in a muting period
    Preferences.setMutingPeriod(preferences, true);

    // inform user via a notification that a course has started and the phone has been muted
    notifyUser(Studentportal.NOTIFICATION_MS_INFO, true, mutingPeriod.getName(), mutingPeriod.getName(),
            getString(R.string.automute_notification_course_muted));

    final boolean isPhoneLocationKnownAnalytics = isPhoneLocationKnown;
    final String locationSourceAnalytics = locationSource;
    Analytics.onEvent(Analytics.EVENT_MUTINGSERVICE_MUTE, "isPhoneLocationKnown",
            isPhoneLocationKnownAnalytics + "", "locationSource", locationSourceAnalytics);

    scheduleUnmute(mutingPeriod.getEnd());
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void autoSilent() {
    Appointment[] appointments = calendarDB.getSilentAppointments(getMargin());
    if (doSilent(appointments)) {
        setSilenced(true);/* ww  w .java 2  s .  c  o  m*/
        AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (audiomanager == null)
            return;
        if (!isSilencedByApp())
            configUtil.setInteger("previous_silent_state", audiomanager.getRingerMode());
        if (audiomanager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
            audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
    } else {
        if (isSilencedByApp()) {
            AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            if (audiomanager == null)
                return;
            if (configUtil.getBoolean("reverse_silent_state")) {
                audiomanager.setRingerMode(configUtil.getInteger("previous_silent_state"));
            } else {
                audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
            setSilenced(false);
        }
    }
}