下面列出了android.media.AudioManager#STREAM_ACCESSIBILITY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int getIconResource() {
switch (volumeStreamType) {
case AudioManager.STREAM_MUSIC:
return R.drawable.quantum_ic_music_note_white_24;
case AudioManager.STREAM_VOICE_CALL:
return R.drawable.quantum_ic_phone_white_24;
case AudioManager.STREAM_RING:
return R.drawable.quantum_ic_vibration_white_24;
case AudioManager.STREAM_ALARM:
return R.drawable.quantum_ic_alarm_white_24;
case AudioManager.STREAM_ACCESSIBILITY:
return R.drawable.quantum_ic_accessibility_new_white_24;
}
return 0;
}
@Override
public String getText() {
switch (volumeStreamType) {
case AudioManager.STREAM_MUSIC:
return context.getString(R.string.volume_menu_media);
case AudioManager.STREAM_VOICE_CALL:
return context.getString(R.string.volume_menu_call);
case AudioManager.STREAM_RING:
return context.getString(R.string.volume_menu_ring);
case AudioManager.STREAM_ALARM:
return context.getString(R.string.volume_menu_alarm);
case AudioManager.STREAM_ACCESSIBILITY:
return context.getString(R.string.volume_menu_accessibility);
}
return "";
}
private static SwitchAccessMenuItemEnum.MenuItem getMenuItemEnumFromVolumeType(int volumeType) {
switch (volumeType) {
case AudioManager.STREAM_MUSIC:
return SwitchAccessMenuItemEnum.MenuItem.VOLUME_SUBMENU_MEDIA;
case AudioManager.STREAM_VOICE_CALL:
return SwitchAccessMenuItemEnum.MenuItem.VOLUME_SUBMENU_CALL;
case AudioManager.STREAM_RING:
return SwitchAccessMenuItemEnum.MenuItem.VOLUME_SUBMENU_RING;
case AudioManager.STREAM_ALARM:
return SwitchAccessMenuItemEnum.MenuItem.VOLUME_SUBMENU_ALARM;
case AudioManager.STREAM_ACCESSIBILITY:
return SwitchAccessMenuItemEnum.MenuItem.VOLUME_SUBMENU_ACCESSIBILITY;
}
return SwitchAccessMenuItemEnum.MenuItem.ITEM_UNSPECIFIED;
}
private boolean canStreamBeMuted() {
// TODO: Instead of hiding the mute button for alarm and accessibility, investigate
// a more elegant way of determining is a volume stream can be muted and/or manually setting
// the volume to 0 instead of using ADJUST_STREAM_MUTE. There's a bug in AudioManager that
// causes some volume types on certain versions to not be muteable. Alarm and accessibility
// volume are generally not considered "muteable" volume types, so manually hiding the mute
// button for these streams doesn't significantly impact user experience.
boolean isValidStreamType =
(volumeStreamType != AudioManager.STREAM_ALARM)
&& (volumeStreamType != AudioManager.STREAM_ACCESSIBILITY);
return isValidStreamType
&& ((audioManager != null) && (audioManager.getStreamMinVolume(volumeStreamType) == 0));
}
/**
* Called after volume changes. Handles acquiring control of the current stream and providing
* feedback.
*
* @param streamType The stream type constant.
* @param volume The current volume.
* @param prevVolume The previous volume.
*/
private void internalOnVolumeChanged(int streamType, int volume, int prevVolume) {
if (isSelfAdjusted(streamType, volume)) {
// Ignore self-adjustments.
return;
}
if (FeatureSupport.hasAcessibilityAudioStream(context)
&& streamType == AudioManager.STREAM_ACCESSIBILITY) {
cacheAccessibilityStreamVolume();
}
if (currentStream < 0) {
// If the current stream hasn't been set, acquire control.
currentStream = streamType;
AudioManagerCompatUtils.forceVolumeControlStream(audioManager, currentStream);
handler.onControlAcquired(streamType);
return;
}
if (volume == prevVolume) {
// Ignore ADJUST_SAME if we've already acquired control.
return;
}
handler.releaseControlDelayed();
}