android.media.AudioManager#STREAM_RING源码实例Demo

下面列出了android.media.AudioManager#STREAM_RING 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: talkback   文件: VolumeMonitor.java
/**
 * Returns the volume announcement text for the specified stream.
 *
 * @param streamType The stream to announce.
 * @return The volume announcement text for the stream.
 */
private String getAnnouncementForStreamType(int templateResId, int streamType) {
  // The ringer has special cases for silent and vibrate.
  if (streamType == AudioManager.STREAM_RING) {
    switch (audioManager.getRingerMode()) {
      case AudioManager.RINGER_MODE_VIBRATE:
        return context.getString(R.string.value_ringer_vibrate);
      case AudioManager.RINGER_MODE_SILENT:
        return context.getString(R.string.value_ringer_silent);
      default: // fall out
    }
  }

  final String streamName = getStreamName(streamType);
  final int volume = getStreamVolume(streamType);

  return context.getString(templateResId, streamName, volume);
}
 
源代码2 项目: webrtc_android   文件: WebRtcAudioUtils.java
private static String streamTypeToString(int stream) {
  switch(stream) {
    case AudioManager.STREAM_VOICE_CALL:
      return "STREAM_VOICE_CALL";
    case AudioManager.STREAM_MUSIC:
      return "STREAM_MUSIC";
    case AudioManager.STREAM_RING:
      return "STREAM_RING";
    case AudioManager.STREAM_ALARM:
      return "STREAM_ALARM";
    case AudioManager.STREAM_NOTIFICATION:
      return "STREAM_NOTIFICATION";
    case AudioManager.STREAM_SYSTEM:
      return "STREAM_SYSTEM";
    default:
      return "STREAM_INVALID";
  }
}
 
源代码3 项目: webrtc_android   文件: WebRtcAudioUtils.java
private static void logAudioStateVolume(String tag, AudioManager audioManager) {
  final int[] streams = {AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC,
      AudioManager.STREAM_RING, AudioManager.STREAM_ALARM, AudioManager.STREAM_NOTIFICATION,
      AudioManager.STREAM_SYSTEM};
  Logging.d(tag, "Audio State: ");
  // Some devices may not have volume controls and might use a fixed volume.
  boolean fixedVolume = isVolumeFixed(audioManager);
  Logging.d(tag, "  fixed volume=" + fixedVolume);
  if (!fixedVolume) {
    for (int stream : streams) {
      StringBuilder info = new StringBuilder();
      info.append("  " + streamTypeToString(stream) + ": ");
      info.append("volume=").append(audioManager.getStreamVolume(stream));
      info.append(", max=").append(audioManager.getStreamMaxVolume(stream));
      logIsStreamMute(tag, audioManager, stream, info);
      Logging.d(tag, info.toString());
    }
  }
}
 
源代码4 项目: webrtc_android   文件: WebRtcAudioUtils.java
private static String streamTypeToString(int stream) {
  switch (stream) {
    case AudioManager.STREAM_VOICE_CALL:
      return "STREAM_VOICE_CALL";
    case AudioManager.STREAM_MUSIC:
      return "STREAM_MUSIC";
    case AudioManager.STREAM_RING:
      return "STREAM_RING";
    case AudioManager.STREAM_ALARM:
      return "STREAM_ALARM";
    case AudioManager.STREAM_NOTIFICATION:
      return "STREAM_NOTIFICATION";
    case AudioManager.STREAM_SYSTEM:
      return "STREAM_SYSTEM";
    default:
      return "STREAM_INVALID";
  }
}
 
源代码5 项目: NoiseCapture   文件: CalibrationService.java
private int getAudioOutput() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_MUSIC");

    if("STREAM_VOICE_CALL".equals(value)) {
        return AudioManager.STREAM_VOICE_CALL;
    } else if("STREAM_SYSTEM".equals(value)) {
        return AudioManager.STREAM_SYSTEM;
    } else if("STREAM_RING".equals(value)) {
        return AudioManager.STREAM_RING;
    } else if("STREAM_MUSIC".equals(value)) {
        return AudioManager.STREAM_MUSIC;
    } else if("STREAM_ALARM".equals(value)) {
        return AudioManager.STREAM_ALARM;
    } else if("STREAM_NOTIFICATION".equals(value)) {
        return AudioManager.STREAM_NOTIFICATION;
    } else if("STREAM_DTMF".equals(value)) {
        return AudioManager.STREAM_DTMF;
    } else {
        return AudioManager.STREAM_RING;
    }
}
 
源代码6 项目: CSipSimple   文件: MediaManager.java
public void adjustStreamVolume(int streamType, int direction, int flags) {
	broadcastVolumeWillBeUpdated(streamType, EXTRA_VALUE_UNKNOWN);
       audioManager.adjustStreamVolume(streamType, direction, flags);
       if(streamType == AudioManager.STREAM_RING) {
       	// Update ringer 
       	ringer.updateRingerMode();
       }
       
       int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
       if(streamType == inCallStream) {
       	int maxLevel = audioManager.getStreamMaxVolume(inCallStream);
       	float modifiedLevel = (audioManager.getStreamVolume(inCallStream)/(float) maxLevel)*10.0f;
       	// Update default stream level
           service.getPrefs().setPreferenceFloatValue(SipConfigManager.SND_STREAM_LEVEL, modifiedLevel);
       	
       }
}
 
源代码7 项目: GravityBox   文件: VolumePreference.java
private void initSeekBar(SeekBar seekBar, Uri defaultUri) {
    seekBar.setMax(mAudioManager.getStreamMaxVolume(mStreamType));
    mOriginalStreamVolume = mAudioManager.getStreamVolume(mStreamType);
    seekBar.setProgress(mOriginalStreamVolume);
    seekBar.setOnSeekBarChangeListener(this);
    // TODO: removed in MM, find different approach
    mContext.getContentResolver().registerContentObserver(
            System.getUriFor("volume_ring"),
            false, mVolumeObserver);
    if (defaultUri == null) {
        if (mStreamType == AudioManager.STREAM_RING) {
            defaultUri = Settings.System.DEFAULT_RINGTONE_URI;
        } else if (mStreamType == AudioManager.STREAM_NOTIFICATION) {
            defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
        } else {
            defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI;
        }
    }
    mRingtone = RingtoneManager.getRingtone(mContext, defaultUri);
    if (mRingtone != null) {
        mRingtone.setStreamType(mStreamType);
    }
}
 
源代码8 项目: Noyze   文件: StatusBarPlusVolumePanel.java
@Override
public void onRingerModeChange(int ringerMode) {
    super.onRingerModeChange(ringerMode);
    if (null != mLastVolumeChange) {
        switch (mLastVolumeChange.mStreamType) {
            case AudioManager.STREAM_NOTIFICATION:
            case AudioManager.STREAM_RING:
                switch (ringerMode) {
                    case RINGER_MODE_VIBRATE:
                        icon.setImageResource(getVibrateIcon());
                        break;
                    case RINGER_MODE_SILENT:
                    default:
                        icon.setImageResource(getSilentIcon());
                        break;
                }
                break;
        }
    }
}
 
private static String streamTypeToString(int streamtype) {
    switch (streamtype) {
        case AudioManager.STREAM_ALARM:
            return "ALARM";
        case AudioManager.STREAM_DTMF:
            return "DTMF";
        case AudioManager.STREAM_MUSIC:
            return "MUSIC";
        case AudioManager.STREAM_NOTIFICATION:
            return "NOTIFICATION";
        case AudioManager.STREAM_RING:
            return "RING";
        case AudioManager.STREAM_SYSTEM:
            return "SYSTEM";
        case AudioManager.STREAM_VOICE_CALL:
            return "VOICE_CALL";
        default:
            return "Unknown stream type; " + streamtype;
    }
}
 
源代码10 项目: Noyze   文件: ParanoidVolumePanel.java
protected int[] _getStreamIcons(StreamControl sc) {
    int[] icons = getStreamIcons(sc);
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
            sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                icons[1] = getVibrateIcon();
                break;
            case AudioManager.RINGER_MODE_SILENT:
                icons[1] = getSilentIcon();
                break;
        }
    }
    return icons;
}
 
源代码11 项目: Noyze   文件: ParanoidVolumePanel.java
protected int[] getStreamIcons(StreamControl sc) {
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
        sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                return new int[] { sc.iconRes, getVibrateIcon() };
            case AudioManager.RINGER_MODE_SILENT:
                return new int[] { sc.iconRes, getSilentIcon() };
        }
    }
    return new int[] { sc.iconRes, sc.iconMuteRes }; // Default icons
}
 
源代码12 项目: Noyze   文件: AudioHelper.java
boolean updateRingerModeAffectedStreams(Context context) {
    int ringerModeAffectedStreams;

    // make sure settings for ringer mode are consistent with device type: non voice capable
    // devices (tablets) include media stream in silent mode whereas phones don't.
    ringerModeAffectedStreams = Settings.System.getInt(context.getContentResolver(),
            Settings.System.MODE_RINGER_STREAMS_AFFECTED,
            ((1 << AudioManager.STREAM_RING)|(1 << AudioManager.STREAM_NOTIFICATION)|
             (1 << AudioManager.STREAM_SYSTEM)));

    // ringtone, notification and system streams are always affected by ringer mode
    ringerModeAffectedStreams |= (1 << AudioManager.STREAM_RING)|
            (1 << AudioManager.STREAM_NOTIFICATION)|
            (1 << AudioManager.STREAM_SYSTEM);

    if (mVoiceCapable) {
        ringerModeAffectedStreams &= ~(1 << AudioManager.STREAM_MUSIC);
    } else {
        ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
    }

    if (ringerModeAffectedStreams != mRingerModeAffectedStreams) {
        mRingerModeAffectedStreams = ringerModeAffectedStreams;
        return true;
    }
    return false;
}
 
源代码13 项目: Noyze   文件: ParanoidVolumePanel.java
protected int[] _getStreamIcons(StreamControl sc) {
    int[] icons = getStreamIcons(sc);
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
            sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                icons[1] = getVibrateIcon();
                break;
            case AudioManager.RINGER_MODE_SILENT:
                icons[1] = getSilentIcon();
                break;
        }
    }
    return icons;
}
 
源代码14 项目: GravityBox   文件: ModRinger.java
@Override
public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(IncreasingRingPreference.ACTION_INCREASING_RING_CHANGED) &&
           intent.getIntExtra(IncreasingRingPreference.EXTRA_STREAM_TYPE, -1) ==
               AudioManager.STREAM_RING) {
       mRingerConfig.enabled = intent.getBooleanExtra(
               IncreasingRingPreference.EXTRA_ENABLED, false);
       mRingerConfig.minVolume = intent.getFloatExtra(
               IncreasingRingPreference.EXTRA_MIN_VOLUME, 0.1f);
       mRingerConfig.rampUpDuration = intent.getIntExtra(
               IncreasingRingPreference.EXTRA_RAMP_UP_DURATION, 10);
       if (DEBUG) log(mRingerConfig.toString());
   }
}
 
源代码15 项目: Noyze   文件: ParanoidVolumePanel.java
private void addOtherVolumes() {
    LOGI(TAG, "addOtherVolumes()");
    boolean mVoiceCapable = mAudioHelper.isVoiceCapable();
    for (StreamResources stream : StreamResources.STREAMS) {
        // Skip the phone specific ones and the active one
        final int streamType = stream.getStreamType();
        StreamControl sc = mStreamControls.get(streamType);
        if (!stream.show() || streamType == mActiveStreamType) {
            continue;
        }
        // Skip ring volume for non-phone devices
        if (!mVoiceCapable && streamType == AudioManager.STREAM_RING) {
            continue;
        }
        // Skip notification volume if linked with ring volume
        if (streamType == AudioManager.STREAM_NOTIFICATION) {
            if (mVoiceCapable && mNotificationRingerLink) {
                continue;
            } else if (linkNotifRinger) {
                // User has asked to link notification & ringer volume.
                continue;
            }
        }

        mSliderGroup.addView(sc.group);
        updateSlider(sc);
    }
}
 
源代码16 项目: prayer-times-android   文件: MyPlayer.java
private int getStreamType() {
    switch (volume) {
        case Alarm.VOLUME_MODE_ALARM:
            return AudioManager.STREAM_ALARM;
        case Alarm.VOLUME_MODE_RINGTONE:
            return AudioManager.STREAM_RING;
        case Alarm.VOLUME_MODE_NOTIFICATION:
            return AudioManager.STREAM_NOTIFICATION;
        case Alarm.VOLUME_MODE_MEDIA:
        default:
            return AudioManager.STREAM_MUSIC;
    }
}
 
源代码17 项目: Noyze   文件: ParanoidVolumePanel.java
@Override public void onRingerModeChange(int ringerMode) {

        // Pulled from VolumePanel to also have the small vibration/ feedback.
        switch (ringerMode) {
            case RINGER_MODE_VIBRATE:
                if (isEnabled()) mAudioHelper.vibrate(VIBRATE_DURATION);
                break;
        }

        LOGI(TAG, "onRingerModeChange(" + ringerMode + ')');
        if (null != mLastVolumeChange &&
                (mLastVolumeChange.mStreamType == AudioManager.STREAM_NOTIFICATION ||
                 mLastVolumeChange.mStreamType == AudioManager.STREAM_RING)) {
            StreamControl sc = mStreamControls.get(mLastVolumeChange.mStreamType);
            if (null != sc) {
                switch (ringerMode) {
                    case RINGER_MODE_VIBRATE:
                        sc.iconMuteRes = getVibrateIcon();
                        break;
                    case RINGER_MODE_SILENT:
                    default:
                        sc.iconMuteRes = getSilentIcon();
                        break;
                }
            }
        }

        if (isShowing()) updateStates();
    }
 
private int volumeChangeDetect(int volumeStream, int previousVolume, boolean muted, AudioManager audioManager) {
    if (muted)
        return previousVolume;

    try {
        int currentVolume = audioManager.getStreamVolume(volumeStream);
        /*if (PPApplication.logEnabled()) {
            PPApplication.logE("SettingsContentObserver.volumeChangeDetect", "channel=" + volumeStream + " currentVolume=" + currentVolume);
            PPApplication.logE("SettingsContentObserver.volumeChangeDetect", "channel=" + volumeStream + " previousVolume=" + previousVolume);
            PPApplication.logE("SettingsContentObserver.volumeChangeDetect", "internalChange=" + RingerModeChangeReceiver.internalChange);
            if (volumeStream == AudioManager.STREAM_RING) {
                PPApplication.logE("[VOL] SettingsContentObserver.volumeChangeDetect", "currentVolume=" + currentVolume);
                PPApplication.logE("[VOL] SettingsContentObserver.volumeChangeDetect", "maxVolume=" + audioManager.getStreamMaxVolume(AudioManager.STREAM_RING));
            }
        }*/

        int delta = previousVolume - currentVolume;

        if (delta > 0) {
            if (!RingerModeChangeReceiver.internalChange) {
                if (volumeStream == AudioManager.STREAM_RING) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setRingerVolume(context, currentVolume);
                    if (PhoneProfilesService.getInstance() != null)
                        PhoneProfilesService.getInstance().ringingVolume = currentVolume;
                }
                if (volumeStream == AudioManager.STREAM_NOTIFICATION) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setNotificationVolume(context, currentVolume);
                    //PhoneProfilesService.notificationVolume = currentVolume;
                }
            }
        } else if (delta < 0) {
            if (!RingerModeChangeReceiver.internalChange) {
                if (volumeStream == AudioManager.STREAM_RING) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setRingerVolume(context, currentVolume);
                    if (PhoneProfilesService.getInstance() != null)
                        PhoneProfilesService.getInstance().ringingVolume = currentVolume;
                }
                if (volumeStream == AudioManager.STREAM_NOTIFICATION) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setNotificationVolume(context, currentVolume);
                    //PhoneProfilesService.notificationVolume = currentVolume;
                }
            }
        }
        return currentVolume;
    } catch (Exception e) {
        PPApplication.recordException(e);
        return -1;
    }
}
 
源代码19 项目: Study_Android_Demo   文件: DatabaseHelper.java
/**
 * Loads the default volume levels. It is actually inserting the index of
 * the volume array for each of the volume controls.
 *
 * @param db the database to insert the volume levels into
 */
private void loadVolumeLevels(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");

        loadSetting(stmt, Settings.System.VOLUME_MUSIC,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
        loadSetting(stmt, Settings.System.VOLUME_RING,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
        loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
        loadSetting(
                stmt,
                Settings.System.VOLUME_VOICE,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
        loadSetting(stmt, Settings.System.VOLUME_ALARM,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
        loadSetting(
                stmt,
                Settings.System.VOLUME_NOTIFICATION,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
        loadSetting(
                stmt,
                Settings.System.VOLUME_BLUETOOTH_SCO,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);

        // By default:
        // - ringtones, notification, system and music streams are affected by ringer mode
        // on non voice capable devices (tablets)
        // - ringtones, notification and system streams are affected by ringer mode
        // on voice capable devices (phones)
        int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
                                        (1 << AudioManager.STREAM_NOTIFICATION) |
                                        (1 << AudioManager.STREAM_SYSTEM) |
                                        (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
        if (!mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_voice_capable)) {
            ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
        }
        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                ringerModeAffectedStreams);

        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
                ((1 << AudioManager.STREAM_MUSIC) |
                 (1 << AudioManager.STREAM_RING) |
                 (1 << AudioManager.STREAM_NOTIFICATION) |
                 (1 << AudioManager.STREAM_SYSTEM)));
    } finally {
        if (stmt != null) stmt.close();
    }

    loadVibrateWhenRingingSetting(db);
}
 
源代码20 项目: Study_Android_Demo   文件: DatabaseHelper.java
/**
 * Loads the default volume levels. It is actually inserting the index of
 * the volume array for each of the volume controls.
 *
 * @param db the database to insert the volume levels into
 */
private void loadVolumeLevels(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");

        loadSetting(stmt, Settings.System.VOLUME_MUSIC,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
        loadSetting(stmt, Settings.System.VOLUME_RING,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
        loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
        loadSetting(
                stmt,
                Settings.System.VOLUME_VOICE,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
        loadSetting(stmt, Settings.System.VOLUME_ALARM,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
        loadSetting(
                stmt,
                Settings.System.VOLUME_NOTIFICATION,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
        loadSetting(
                stmt,
                Settings.System.VOLUME_BLUETOOTH_SCO,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));

        // By default:
        // - ringtones, notification, system and music streams are affected by ringer mode
        // on non voice capable devices (tablets)
        // - ringtones, notification and system streams are affected by ringer mode
        // on voice capable devices (phones)
        int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
                                        (1 << AudioManager.STREAM_NOTIFICATION) |
                                        (1 << AudioManager.STREAM_SYSTEM) |
                                        (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
        if (!mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_voice_capable)) {
            ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
        }
        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                ringerModeAffectedStreams);

        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
                AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
    } finally {
        if (stmt != null) stmt.close();
    }

    loadVibrateWhenRingingSetting(db);
}