Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae5a53d7 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Update volume slider on device changed." into mnc-dr-dev

parents 67ea77ec 3a10b10e
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -383,6 +383,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
                final IntentFilter filter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION);
                filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
                filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
                filter.addAction(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
                mContext.registerReceiver(this, filter);
            } else {
                mContext.unregisterReceiver(this);
@@ -395,13 +396,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
            if (AudioManager.VOLUME_CHANGED_ACTION.equals(action)) {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                int streamValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1);
                final boolean streamMatch = mNotificationOrRing ? isNotificationOrRing(streamType)
                        : (streamType == mStreamType);
                if (mSeekBar != null && streamMatch && streamValue != -1) {
                    final boolean muted = mAudioManager.isStreamMute(mStreamType)
                            || streamValue == 0;
                    mUiHandler.postUpdateSlider(streamValue, mLastAudibleStreamVolume, muted);
                }
                updateVolumeSlider(streamType, streamValue);
            } else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
                if (mNotificationOrRing) {
                    mRingerMode = mAudioManager.getRingerModeInternal();
@@ -409,10 +404,24 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
                if (mAffectedByRingerMode) {
                    updateSlider();
                }
            } else if (AudioManager.STREAM_DEVICES_CHANGED_ACTION.equals(action)) {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                int streamVolume = mAudioManager.getStreamVolume(streamType);
                updateVolumeSlider(streamType, streamVolume);
            } else if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED.equals(action)) {
                mZenMode = mNotificationManager.getZenMode();
                updateSlider();
            }
        }

        private void updateVolumeSlider(int streamType, int streamValue) {
            final boolean streamMatch = mNotificationOrRing ? isNotificationOrRing(streamType)
                    : (streamType == mStreamType);
            if (mSeekBar != null && streamMatch && streamValue != -1) {
                final boolean muted = mAudioManager.isStreamMute(mStreamType)
                        || streamValue == 0;
                mUiHandler.postUpdateSlider(streamValue, mLastAudibleStreamVolume, muted);
            }
        }
    }
}