diff options
Diffstat (limited to 'core/java/android/view')
-rw-r--r-- | core/java/android/view/VolumePanel.java | 147 | ||||
-rw-r--r-- | core/java/android/view/WindowManagerPolicy.java | 1 |
2 files changed, 132 insertions, 16 deletions
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java index d7c7f46..2497e95 100644 --- a/core/java/android/view/VolumePanel.java +++ b/core/java/android/view/VolumePanel.java @@ -35,7 +35,10 @@ import android.media.ToneGenerator; import android.net.Uri; import android.os.Handler; import android.os.Message; +import android.os.RemoteException; import android.os.Vibrator; +import android.provider.Settings; +import android.provider.Settings.System; import android.util.Log; import android.view.WindowManager.LayoutParams; import android.widget.ImageView; @@ -99,12 +102,16 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie private static final int STREAM_MASTER = -100; // Pseudo stream type for remote volume is defined in AudioService.STREAM_REMOTE_MUSIC + public static final String ACTION_VOLUME_OVERLAY_CHANGED + = "android.intent.action.VOLUME_OVERLAY_CHANGED"; + protected Context mContext; private AudioManager mAudioManager; protected AudioService mAudioService; private boolean mRingIsSilent; private boolean mShowCombinedVolumes; private boolean mVoiceCapable; + private int mCurrentOverlayStyle = -1; // True if we want to play tones on the system stream when the master stream is specified. private final boolean mPlayMasterStreamTones; @@ -326,12 +333,26 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie mPlayMasterStreamTones = masterVolumeOnly && masterVolumeKeySounds; + // get the users preference + int choosenStyle = Settings.System.getInt(context.getContentResolver(),Settings.System.MODE_VOLUME_OVERLAY, -1); + // by default -1 is expected - deal with choosing the right default + if (choosenStyle == -1) { + if (mVoiceCapable) { + choosenStyle = Settings.System.VOLUME_OVERLAY_SINGLE; + } else { + choosenStyle = Settings.System.VOLUME_OVERLAY_EXPANDABLE; + } + } + changeOverlayStyle(choosenStyle); + mMoreButton.setOnClickListener(this); + listenToRingerMode(); } private void listenToRingerMode() { final IntentFilter filter = new IntentFilter(); filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); + filter.addAction(ACTION_VOLUME_OVERLAY_CHANGED); mContext.registerReceiver(new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { @@ -340,18 +361,45 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { removeMessages(MSG_RINGER_MODE_CHANGED); sendMessage(obtainMessage(MSG_RINGER_MODE_CHANGED)); + } else if (ACTION_VOLUME_OVERLAY_CHANGED.equals(action)) { + int state = (Integer) intent.getExtra("state"); + changeOverlayStyle(state); } } }, filter); } - private boolean isMuted(int streamType) { - if (streamType == STREAM_MASTER) { - return mAudioManager.isMasterMute(); - } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) { - return (mAudioService.getRemoteStreamVolume() <= 0); - } else { - return mAudioManager.isStreamMute(streamType); + private void changeOverlayStyle(int newStyle) { + Log.i("VolumePanel", "changeOverlayStyle : " + newStyle); + // Don't change to the same style + if (newStyle == mCurrentOverlayStyle) return; + switch (newStyle) { + case Settings.System.VOLUME_OVERLAY_SINGLE : + mMoreButton.setVisibility(View.GONE); + mDivider.setVisibility(View.GONE); + mShowCombinedVolumes = false; + mCurrentOverlayStyle = Settings.System.VOLUME_OVERLAY_SINGLE; + break; + case Settings.System.VOLUME_OVERLAY_EXPANDABLE : + mMoreButton.setVisibility(View.VISIBLE); + mDivider.setVisibility(View.VISIBLE); + mShowCombinedVolumes = true; + mCurrentOverlayStyle = Settings.System.VOLUME_OVERLAY_EXPANDABLE; + break; + case Settings.System.VOLUME_OVERLAY_EXPANDED : + mMoreButton.setVisibility(View.GONE); + mDivider.setVisibility(View.GONE); + mShowCombinedVolumes = true; + if (mCurrentOverlayStyle == Settings.System.VOLUME_OVERLAY_NONE) { + addOtherVolumes(); + expand(); + } + mCurrentOverlayStyle = Settings.System.VOLUME_OVERLAY_EXPANDED; + break; + case Settings.System.VOLUME_OVERLAY_NONE : + mShowCombinedVolumes = false; + mCurrentOverlayStyle = Settings.System.VOLUME_OVERLAY_NONE; + break; } } @@ -385,6 +433,10 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie } } + private boolean isMuted(int streamType) { + return mAudioManager.isStreamMute(streamType); + } + private void createSliders() { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); @@ -406,6 +458,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie sc.iconRes = streamRes.iconRes; sc.iconMuteRes = streamRes.iconMuteRes; sc.icon.setImageResource(sc.iconRes); + sc.icon.setOnClickListener(this); sc.seekbarView = (SeekBar) sc.group.findViewById(R.id.seekbar); int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO || streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0; @@ -442,6 +495,10 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie if (!STREAMS[i].show || streamType == mActiveStreamType) { continue; } + // Skip ring volume for non-phone devices + if (!mVoiceCapable && streamType == AudioManager.STREAM_RING) { + continue; + } StreamControl sc = mStreamControls.get(streamType); mSliderGroup.addView(sc.group); updateSlider(sc); @@ -475,10 +532,22 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie private void expand() { final int count = mSliderGroup.getChildCount(); for (int i = 0; i < count; i++) { - mSliderGroup.getChildAt(i).setVisibility(View.VISIBLE); + if (mSliderGroup.getChildAt(i).getVisibility() != View.VISIBLE) { + mSliderGroup.getChildAt(i).setVisibility(View.VISIBLE); + } + } + mMoreButton.setVisibility(View.GONE); + mDivider.setVisibility(View.GONE); + } + + private void hideSlider(int mActiveStreamType) { + final int count = mSliderGroup.getChildCount(); + for (int i = 0; i < count; i++) { + StreamControl sc = (StreamControl) mSliderGroup.getChildAt(i).getTag(); + if (mActiveStreamType == sc.streamType) { + mSliderGroup.getChildAt(i).setVisibility(View.GONE); + } } - mMoreButton.setVisibility(View.INVISIBLE); - mDivider.setVisibility(View.INVISIBLE); } private void collapse() { @@ -578,8 +647,12 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie if ((flags & AudioManager.FLAG_SHOW_UI) != 0) { synchronized (this) { - if (mActiveStreamType != streamType) { - reorderSliders(streamType); + if (mActiveStreamType == -1 || streamType != mActiveStreamType) { + if (streamType != mActiveStreamType && + mCurrentOverlayStyle == Settings.System.VOLUME_OVERLAY_EXPANDABLE) { + hideSlider(mActiveStreamType); + } + reorderSliders(streamType); } onShowVolumeChanged(streamType, flags); } @@ -709,17 +782,32 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie } else { sc.seekbarView.setEnabled(true); } + // If adjusting Ring volume and preference is to link it to Notification + if (streamType == mAudioManager.STREAM_RING && + System.getInt(mContext.getContentResolver(),System.VOLUME_LINK_NOTIFICATION, 1) == 1) { + StreamControl notifySc = mStreamControls.get(mAudioManager.STREAM_NOTIFICATION); + if (index > notifySc.seekbarView.getMax()) { + notifySc.seekbarView.setProgress(notifySc.seekbarView.getMax()); + } else { + notifySc.seekbarView.setProgress(index); + } + } } - if (!mDialog.isShowing()) { + // Only Show if style needs it + if (!mDialog.isShowing() && mCurrentOverlayStyle != Settings.System.VOLUME_OVERLAY_NONE) { int stream = (streamType == AudioService.STREAM_REMOTE_MUSIC) ? -1 : streamType; // when the stream is for remote playback, use -1 to reset the stream type evaluation mAudioManager.forceVolumeControlStream(stream); mDialog.setContentView(mView); // Showing dialog - use collapsed state - if (mShowCombinedVolumes) { + if (mShowCombinedVolumes && mCurrentOverlayStyle != Settings.System.VOLUME_OVERLAY_EXPANDED) { collapse(); } + // If just changed the style and we need to expand + if (mCurrentOverlayStyle == Settings.System.VOLUME_OVERLAY_EXPANDED) { + expand(); + } mDialog.show(); } @@ -995,13 +1083,34 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie sendMessage(obtainMessage(MSG_TIMEOUT)); } - public void onProgressChanged(SeekBar seekBar, int progress, - boolean fromUser) { + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { final Object tag = seekBar.getTag(); if (fromUser && tag instanceof StreamControl) { StreamControl sc = (StreamControl) tag; if (getStreamVolume(sc.streamType) != progress) { setStreamVolume(sc.streamType, progress, 0); + // if audio is linked then adjust other one if change made by user + if (fromUser && System.getInt(mContext.getContentResolver(),System.VOLUME_LINK_NOTIFICATION, 1) == 1) { + if (sc.streamType == AudioManager.STREAM_RING) { + StreamControl notifySc = mStreamControls.get(AudioManager.STREAM_NOTIFICATION); + if (notifySc != null) { + if (progress > notifySc.seekbarView.getMax()) { + notifySc.seekbarView.setProgress(notifySc.seekbarView.getMax()); + } else { + notifySc.seekbarView.setProgress(progress); + } + } + } else if (sc.streamType == AudioManager.STREAM_NOTIFICATION) { + StreamControl phoneSc = mStreamControls.get(AudioManager.STREAM_RING); + if (phoneSc != null) { + if (progress > phoneSc.seekbarView.getMax()) { + phoneSc.seekbarView.setProgress(phoneSc.seekbarView.getMax()); + } else { + phoneSc.seekbarView.setProgress(progress); + } + } + } + } } } resetTimeout(); @@ -1027,6 +1136,12 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie public void onClick(View v) { if (v == mMoreButton) { expand(); + } else if (v instanceof ImageView) { + Intent volumeSettings = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS); + volumeSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + forceTimeout(); + mContext.startActivity(volumeSettings); + return; } resetTimeout(); } diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index 26739b3..fd5449c 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -399,6 +399,7 @@ public interface WindowManagerPolicy { public void shutdown(boolean confirm); public void rebootSafeMode(boolean confirm); + public void reboot(); } /** |