Skip to content

Commit 0000538

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Use ringer assets for notification volume since the two volumes are tied." into ics-mr0
2 parents 33210ec + 71def77 commit 0000538

File tree

1 file changed

+63
-44
lines changed

1 file changed

+63
-44
lines changed

core/java/android/view/VolumePanel.java

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
9797
protected AudioService mAudioService;
9898
private boolean mRingIsSilent;
9999
private boolean mShowCombinedVolumes;
100+
private boolean mVoiceCapable;
100101

101102
/** Dialog containing all the sliders */
102103
private final Dialog mDialog;
@@ -117,40 +118,56 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
117118
/** All the slider controls mapped by stream type */
118119
private HashMap<Integer,StreamControl> mStreamControls;
119120

120-
// List of stream types and their order
121-
// RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
122-
private static final int [] STREAM_TYPES = {
123-
AudioManager.STREAM_BLUETOOTH_SCO,
124-
AudioManager.STREAM_RING,
125-
AudioManager.STREAM_VOICE_CALL,
126-
AudioManager.STREAM_MUSIC,
127-
AudioManager.STREAM_NOTIFICATION
128-
};
121+
private enum StreamResources {
122+
BluetoothSCOStream(AudioManager.STREAM_BLUETOOTH_SCO,
123+
R.string.volume_icon_description_bluetooth,
124+
R.drawable.ic_audio_bt,
125+
R.drawable.ic_audio_bt,
126+
false),
127+
RingerStream(AudioManager.STREAM_RING,
128+
R.string.volume_icon_description_ringer,
129+
R.drawable.ic_audio_ring_notif,
130+
R.drawable.ic_audio_ring_notif_mute,
131+
false),
132+
VoiceStream(AudioManager.STREAM_VOICE_CALL,
133+
R.string.volume_icon_description_incall,
134+
R.drawable.ic_audio_phone,
135+
R.drawable.ic_audio_phone,
136+
false),
137+
MediaStream(AudioManager.STREAM_MUSIC,
138+
R.string.volume_icon_description_media,
139+
R.drawable.ic_audio_vol,
140+
R.drawable.ic_audio_vol_mute,
141+
true),
142+
NotificationStream(AudioManager.STREAM_NOTIFICATION,
143+
R.string.volume_icon_description_notification,
144+
R.drawable.ic_audio_notification,
145+
R.drawable.ic_audio_notification_mute,
146+
true);
129147

130-
private static final int [] CONTENT_DESCRIPTIONS = {
131-
R.string.volume_icon_description_bluetooth,
132-
R.string.volume_icon_description_ringer,
133-
R.string.volume_icon_description_incall,
134-
R.string.volume_icon_description_media,
135-
R.string.volume_icon_description_notification
136-
};
137-
138-
// These icons need to correspond to the ones above.
139-
private static final int [] STREAM_ICONS_NORMAL = {
140-
R.drawable.ic_audio_bt,
141-
R.drawable.ic_audio_ring_notif,
142-
R.drawable.ic_audio_phone,
143-
R.drawable.ic_audio_vol,
144-
R.drawable.ic_audio_notification,
148+
int streamType;
149+
int descRes;
150+
int iconRes;
151+
int iconMuteRes;
152+
// RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
153+
boolean show;
154+
155+
StreamResources(int streamType, int descRes, int iconRes, int iconMuteRes, boolean show) {
156+
this.streamType = streamType;
157+
this.descRes = descRes;
158+
this.iconRes = iconRes;
159+
this.iconMuteRes = iconMuteRes;
160+
this.show = show;
161+
}
145162
};
146163

147-
// These icons need to correspond to the ones above.
148-
private static final int [] STREAM_ICONS_MUTED = {
149-
R.drawable.ic_audio_bt,
150-
R.drawable.ic_audio_ring_notif_mute,
151-
R.drawable.ic_audio_phone,
152-
R.drawable.ic_audio_vol_mute,
153-
R.drawable.ic_audio_notification_mute,
164+
// List of stream types and their order
165+
private static final StreamResources[] STREAMS = {
166+
StreamResources.BluetoothSCOStream,
167+
StreamResources.RingerStream,
168+
StreamResources.VoiceStream,
169+
StreamResources.MediaStream,
170+
StreamResources.NotificationStream
154171
};
155172

156173
/** Object that contains data for each slider */
@@ -221,7 +238,8 @@ public void onDismiss(DialogInterface dialog) {
221238
mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()];
222239
mVibrator = new Vibrator();
223240

224-
mShowCombinedVolumes = !context.getResources().getBoolean(R.bool.config_voice_capable);
241+
mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable);
242+
mShowCombinedVolumes = !mVoiceCapable;
225243
// If we don't want to show multiple volumes, hide the settings button and divider
226244
if (!mShowCombinedVolumes) {
227245
mMoreButton.setVisibility(View.GONE);
@@ -260,10 +278,14 @@ private void createSliders() {
260278

261279
LayoutInflater inflater = (LayoutInflater) mContext
262280
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
263-
mStreamControls = new HashMap<Integer,StreamControl>(STREAM_TYPES.length);
281+
mStreamControls = new HashMap<Integer, StreamControl>(STREAMS.length);
264282
Resources res = mContext.getResources();
265-
for (int i = 0; i < STREAM_TYPES.length; i++) {
266-
final int streamType = STREAM_TYPES[i];
283+
for (int i = 0; i < STREAMS.length; i++) {
284+
StreamResources streamRes = STREAMS[i];
285+
int streamType = streamRes.streamType;
286+
if (mVoiceCapable && streamRes == StreamResources.NotificationStream) {
287+
streamRes = StreamResources.RingerStream;
288+
}
267289
StreamControl sc = new StreamControl();
268290
sc.streamType = streamType;
269291
sc.group = (ViewGroup) inflater.inflate(R.layout.volume_adjust_item, null);
@@ -273,9 +295,9 @@ private void createSliders() {
273295
sc.icon.setOnClickListener(this);
274296
}
275297
sc.icon.setTag(sc);
276-
sc.icon.setContentDescription(res.getString(CONTENT_DESCRIPTIONS[i]));
277-
sc.iconRes = STREAM_ICONS_NORMAL[i];
278-
sc.iconMuteRes = STREAM_ICONS_MUTED[i];
298+
sc.icon.setContentDescription(res.getString(streamRes.descRes));
299+
sc.iconRes = streamRes.iconRes;
300+
sc.iconMuteRes = streamRes.iconMuteRes;
279301
sc.icon.setImageResource(sc.iconRes);
280302
sc.seekbarView = (SeekBar) sc.group.findViewById(R.id.seekbar);
281303
int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO ||
@@ -307,13 +329,10 @@ private void reorderSliders(int activeStreamType) {
307329
private void addOtherVolumes() {
308330
if (!mShowCombinedVolumes) return;
309331

310-
for (int i = 0; i < STREAM_TYPES.length; i++) {
332+
for (int i = 0; i < STREAMS.length; i++) {
311333
// Skip the phone specific ones and the active one
312-
final int streamType = STREAM_TYPES[i];
313-
if (streamType == AudioManager.STREAM_RING
314-
|| streamType == AudioManager.STREAM_VOICE_CALL
315-
|| streamType == AudioManager.STREAM_BLUETOOTH_SCO
316-
|| streamType == mActiveStreamType) {
334+
final int streamType = STREAMS[i].streamType;
335+
if (!STREAMS[i].show || streamType == mActiveStreamType) {
317336
continue;
318337
}
319338
StreamControl sc = mStreamControls.get(streamType);

0 commit comments

Comments
 (0)