Example usage for android.media AudioManager getVibrateSetting

List of usage examples for android.media AudioManager getVibrateSetting

Introduction

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

Prototype

public int getVibrateSetting(int vibrateType) 

Source Link

Document

Returns whether the user's vibrate setting for a vibrate type.

Usage

From source file:Main.java

public static boolean isRingAndVibrate(AudioManager mAudioManager) {
    int ringerMode = mAudioManager.getRingerMode();
    int vibrateMode = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
    return ringerMode == AudioManager.RINGER_MODE_NORMAL && vibrateMode == AudioManager.VIBRATE_SETTING_ON;
}

From source file:Main.java

public static boolean isRingOnly(AudioManager mAudioManager) {
    int ringerMode = mAudioManager.getRingerMode();
    int vibrateMode = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
    return ringerMode == AudioManager.RINGER_MODE_NORMAL && vibrateMode == AudioManager.VIBRATE_SETTING_OFF;
}

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.j  a  v a  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);
    }
}