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

Commit d628aa06 authored by StevenHarperUK's avatar StevenHarperUK Committed by Ricardo Cerqueira
Browse files

Make the volume overlay more functional 1/2

This Patch is to add new Volume Overlay Styles

 * Make the Icon on left touchable to go to Sound Menu
 * Always show the Phone Ring volume in expanded (for devices that have phone)
 * Always show the Alarm volume in expanded mode
 * Put an Option in Sound menu to choose a Style (see 2/2 patch)
    - Single : as default
    - Expandable : Enable the more link to expand all choosen volumes
    - Expanded : Show all volumes
    - Off : show no overlay
 * Fix a BUG that when you linked the volumes you got 2 phone icons
 * Fix a BUG when linked all volumes did not move when using hard buttons
 * Fix a BUG when you drag when linked, other expanded did not move
 * Added a default mode so non-telephone devices get Expandable by default

Note : When you are using BT in phone call
or the phone normally there is an extra expanded volume

Change-Id: Ie716e55ba6d4e89a1a67c59b9934d4e088833c5b
parent 1ebf4a31
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1542,6 +1542,22 @@ public final class Settings {
                "always_finish_activities";


        /**
         * Volume Overlay Mode, This is behaviour of the volume overlay panel
         * Defaults to 0 - which is simple
         * @hide
         */
        public static final String MODE_VOLUME_OVERLAY = "mode_volume_overlay";

        /** @hide */
        public static final int VOLUME_OVERLAY_SINGLE = 0;
        /** @hide */
        public static final int VOLUME_OVERLAY_EXPANDABLE = 1;
        /** @hide */
        public static final int VOLUME_OVERLAY_EXPANDED = 2;
        /** @hide */
        public static final int VOLUME_OVERLAY_NONE = 3;

        /**
         * Ringer mode. This is used internally, changing this value will not
         * change the ringer mode. See AudioManager.
+122 −28
Original line number Diff line number Diff line
@@ -92,12 +92,16 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    private static final int MSG_TIMEOUT = 5;
    private static final int MSG_RINGER_MODE_CHANGED = 6;

    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;

    /** Dialog containing all the sliders */
    private final Dialog mDialog;
@@ -128,7 +132,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                R.string.volume_icon_description_ringer,
                R.drawable.ic_audio_ring_notif,
                R.drawable.ic_audio_ring_notif_mute,
                false),
                true),
        VoiceStream(AudioManager.STREAM_VOICE_CALL,
                R.string.volume_icon_description_incall,
                R.drawable.ic_audio_phone,
@@ -138,7 +142,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                R.string.volume_alarm,
                R.drawable.ic_audio_alarm,
                R.drawable.ic_audio_alarm_mute,
                false),
                true),
        MediaStream(AudioManager.STREAM_MUSIC,
                R.string.volume_icon_description_media,
                R.drawable.ic_audio_vol,
@@ -154,7 +158,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        int descRes;
        int iconRes;
        int iconMuteRes;
        // RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
        // VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
        boolean show;

        StreamResources(int streamType, int descRes, int iconRes, int iconMuteRes, boolean show) {
@@ -194,7 +198,6 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        mContext = context;
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mAudioService = volumeService;

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = mView = inflater.inflate(R.layout.volume_adjust, null);
@@ -245,21 +248,27 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        mVibrator = new Vibrator();

        mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable);
        mShowCombinedVolumes = !mVoiceCapable;
        // If we don't want to show multiple volumes, hide the settings button and divider
        if (!mShowCombinedVolumes) {
            mMoreButton.setVisibility(View.GONE);
            mDivider.setVisibility(View.GONE);

        // get the users preference
        mCurrentOverlayStyle = Settings.System.getInt(context.getContentResolver(),Settings.System.MODE_VOLUME_OVERLAY, Settings.System.VOLUME_OVERLAY_SINGLE);
        // by default -1 is expected - deal with choosing the right default
        if (mCurrentOverlayStyle == -1) {
            if (mVoiceCapable) {
                mCurrentOverlayStyle = Settings.System.VOLUME_OVERLAY_SINGLE;
            } else {
            mMoreButton.setOnClickListener(this);
                mCurrentOverlayStyle = Settings.System.VOLUME_OVERLAY_EXPANDABLE;
            }
        }
        changeOverlayStyle(mCurrentOverlayStyle);
        mMoreButton.setOnClickListener(this);

        listenToRingerMode();
        listenToRingerModeAndConfigChanges();
    }

    private void listenToRingerMode() {
    private void listenToRingerModeAndConfigChanges() {
        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) {
@@ -268,11 +277,46 @@ 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 void changeOverlayStyle(int newStyle) {
        Log.i("VolumePanel", "changeOverlayStyle : " + newStyle);
        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;
        }
    }

    private boolean isMuted(int streamType) {
        return mAudioManager.isStreamMute(streamType);
    }
@@ -285,9 +329,6 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        for (int i = 0; i < STREAMS.length; i++) {
            StreamResources streamRes = STREAMS[i];
            int streamType = streamRes.streamType;
            if (mVoiceCapable && streamRes == StreamResources.NotificationStream) {
                streamRes = StreamResources.RingerStream;
            }
            StreamControl sc = new StreamControl();
            sc.streamType = streamType;
            sc.group = (ViewGroup) inflater.inflate(R.layout.volume_adjust_item, null);
@@ -298,6 +339,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;
@@ -321,19 +363,21 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            active.group.setVisibility(View.VISIBLE);
            updateSlider(active);
        }

        addOtherVolumes();
    }

    private void addOtherVolumes() {
        if (!mShowCombinedVolumes) return;

        for (int i = 0; i < STREAMS.length; i++) {
            // Skip the phone specific ones and the active one
            final int streamType = STREAMS[i].streamType;
            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);
@@ -357,11 +401,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);
        }
        mMoreButton.setVisibility(View.INVISIBLE);
        mDivider.setVisibility(View.INVISIBLE);
        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);
            }
        }
    }

    private void collapse() {
@@ -404,6 +459,10 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            // then it is likely that the audio stream being updated has been swapped by an app
            // we need to reorder the sliders to bring the new active one to the front
            if (mActiveStreamType == -1 || streamType != mActiveStreamType) {
                if (streamType != mActiveStreamType && 
                       mCurrentOverlayStyle == Settings.System.VOLUME_OVERLAY_EXPANDABLE) {
                    hideSlider(mActiveStreamType);
                }
                reorderSliders(streamType);
            }
            onShowVolumeChanged(streamType, flags);
@@ -439,13 +498,11 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        }

        // get max volume for progress bar

        int max = mAudioService.getStreamMaxVolume(streamType);

        switch (streamType) {

            case AudioManager.STREAM_RING: {
//                setRingerIcon();
                Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri(
                        mContext, RingtoneManager.TYPE_RINGTONE);
                if (ringuri == null) {
@@ -509,13 +566,23 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                sc.seekbarView.setMax(max);
            }
            sc.seekbarView.setProgress(index);
            // If adjusting Ring volume and preference is to link it to Notification
            if (streamType == AudioManager.STREAM_RING &&
                    System.getInt(mContext.getContentResolver(),System.VOLUME_LINK_NOTIFICATION, 1) == 1) {
                StreamControl notifySc = mStreamControls.get(AudioManager.STREAM_NOTIFICATION);
                if (index > notifySc.seekbarView.getMax()) {
                    notifySc.seekbarView.setProgress(notifySc.seekbarView.getMax());
                } else {
                    notifySc.seekbarView.setProgress(index);
                }
            }

        if (!mDialog.isShowing()) {
            mAudioManager.forceVolumeControlStream(streamType);
            mDialog.setContentView(mView);
        }

        // Only Show if style needs it
        if (!mDialog.isShowing() && mCurrentOverlayStyle != Settings.System.VOLUME_OVERLAY_NONE) {
            // Showing dialog - use collapsed state
            if (mShowCombinedVolumes) {
            if (mShowCombinedVolumes && mCurrentOverlayStyle != Settings.System.VOLUME_OVERLAY_EXPANDED) {
                collapse();
            }
            mDialog.show();
@@ -669,13 +736,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 (mAudioManager.getStreamVolume(sc.streamType) != progress) {
                mAudioManager.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();
@@ -690,6 +778,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();
    }
+3 −0
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@
    <string name="def_lock_sound" translatable="false">/system/media/audio/ui/Lock.ogg</string>
    <string name="def_unlock_sound" translatable="false">/system/media/audio/ui/Unlock.ogg</string>

    <!-- type of volume overlay - Deaults to -1 so that detection occurs on first load -->
    <integer name="def_volume_overlay_mode">-1</integer>

    <!-- Notifications use ringer volume -->
    <bool name="def_notifications_use_ring_volume">true</bool>

+3 −0
Original line number Diff line number Diff line
@@ -1428,6 +1428,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        loadStringSetting(stmt, Settings.System.CAR_UNDOCK_SOUND,
            R.string.def_car_undock_sound);

        loadIntegerSetting(stmt, Settings.System.MODE_VOLUME_OVERLAY,
            R.integer.def_volume_overlay_mode);

        loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
            R.integer.def_lockscreen_sounds_enabled);
        loadStringSetting(stmt, Settings.System.LOCK_SOUND,
+1 −1

File changed.

Contains only whitespace changes.