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

Commit 42722bfa authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Volume panel changes.

Combined volume panel only in tablets. On phones show active volume.
Added dummy assets for ring+notification icon.

Deprecated the NOTIFICATION_USES_RING_VOLUME. Now they are always
tied together. Audio manager changes still required to ensure that.

Initialize all feedback sounds to true.

Change-Id: I3ad7890c9be9334eedb5f3b709a4b6995fe24638
parent 34e1fb1e
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -1445,17 +1445,16 @@ public final class Settings {
        public static final String VOLUME_BLUETOOTH_SCO = "volume_bluetooth_sco";

        /**
         * Whether the notifications should use the ring volume (value of 1) or
         * a separate notification volume (value of 0). In most cases, users
         * will have this enabled so the notification and ringer volumes will be
         * the same. However, power users can disable this and use the separate
         * notification volume control.
         * <p>
         * Note: This is a one-off setting that will be removed in the future
         * when there is profile support. For this reason, it is kept hidden
         * from the public APIs.
         * Whether the notifications should use the ring volume (value of 1) or a separate
         * notification volume (value of 0). In most cases, users will have this enabled so the
         * notification and ringer volumes will be the same. However, power users can disable this
         * and use the separate notification volume control.
         * <p>
         * Note: This is a one-off setting that will be removed in the future when there is profile
         * support. For this reason, it is kept hidden from the public APIs.
         *
         * @hide
         * @deprecated
         */
        public static final String NOTIFICATIONS_USE_RING_VOLUME =
            "notifications_use_ring_volume";
+34 −94
Original line number Diff line number Diff line
@@ -89,30 +89,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;

//    private static final int RINGTONE_VOLUME_TEXT = com.android.internal.R.string.volume_ringtone;
//    private static final int MUSIC_VOLUME_TEXT = com.android.internal.R.string.volume_music;
//    private static final int INCALL_VOLUME_TEXT = com.android.internal.R.string.volume_call;
//    private static final int ALARM_VOLUME_TEXT = com.android.internal.R.string.volume_alarm;
//    private static final int UNKNOWN_VOLUME_TEXT = com.android.internal.R.string.volume_unknown;
//    private static final int NOTIFICATION_VOLUME_TEXT =
//            com.android.internal.R.string.volume_notification;
//    private static final int BLUETOOTH_INCALL_VOLUME_TEXT =
//            com.android.internal.R.string.volume_bluetooth_call;

    protected Context mContext;
    private AudioManager mAudioManager;
    protected AudioService mAudioService;
    private boolean mRingIsSilent;
    private boolean mShowCombinedVolumes;

    /** Dialog containing all the sliders */
    private final Dialog mDialog;
    /** Dialog's content view */
    private final View mView;
//    private final TextView mMessage;
//    private final TextView mAdditionalMessage;
//    private final ImageView mSmallStreamIcon;
//    private final ImageView mLargeStreamIcon;
//    private final ProgressBar mLevel;

    /** Contains the sliders and their touchable icons */
    private final ViewGroup mSliderGroup;
@@ -127,7 +113,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    private HashMap<Integer,StreamControl> mStreamControls;

    // List of stream types and their order
    // RING and VOICE_CALL are hidden unless explicitly requested
    // RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
    private static final int [] STREAM_TYPES = {
        AudioManager.STREAM_BLUETOOTH_SCO,
        AudioManager.STREAM_RING,
@@ -136,10 +122,18 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        AudioManager.STREAM_NOTIFICATION
    };

    private static final int [] CONTENT_DESCRIPTIONS = {
        R.string.volume_icon_description_bluetooth,
        R.string.volume_icon_description_ringer,
        R.string.volume_icon_description_incall,
        R.string.volume_icon_description_media,
        R.string.volume_icon_description_notification
    };

    // These icons need to correspond to the ones above.
    private static final int [] STREAM_ICONS_NORMAL = {
        R.drawable.ic_audio_bt,
        R.drawable.ic_audio_phone,
        R.drawable.ic_audio_ring_notif,
        R.drawable.ic_audio_phone,
        R.drawable.ic_audio_vol,
        R.drawable.ic_audio_notification,
@@ -148,7 +142,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    // These icons need to correspond to the ones above.
    private static final int [] STREAM_ICONS_MUTED = {
        R.drawable.ic_audio_bt,
        R.drawable.ic_audio_phone,
        R.drawable.ic_audio_ring_notif_mute,
        R.drawable.ic_audio_phone,
        R.drawable.ic_audio_vol_mute,
        R.drawable.ic_audio_notification_mute,
@@ -184,7 +178,6 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        });
        mSliderGroup = (ViewGroup) mView.findViewById(R.id.slider_group);
        mMoreButton = (ImageView) mView.findViewById(R.id.expand_button);
        mMoreButton.setOnClickListener(this);
        mDivider = (ImageView) mView.findViewById(R.id.expand_button_divider);

        mDialog = new Dialog(context, R.style.Theme_Panel_Volume);
@@ -205,16 +198,18 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        window.setAttributes(lp);
        window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

//        mMessage = (TextView) view.findViewById(com.android.internal.R.id.message);
//        mAdditionalMessage =
//                (TextView) view.findViewById(com.android.internal.R.id.additional_message);
//        mSmallStreamIcon = (ImageView) view.findViewById(com.android.internal.R.id.other_stream_icon);
//        mLargeStreamIcon = (ImageView) view.findViewById(com.android.internal.R.id.ringer_stream_icon);
//        mLevel = (ProgressBar) view.findViewById(com.android.internal.R.id.level);

        mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()];
        mVibrator = new Vibrator();

        mShowCombinedVolumes = !context.getResources().getBoolean(R.bool.config_voice_capable);
        // 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);
        } else {
            mMoreButton.setOnClickListener(this);
        }

        listenToRingerMode();
    }

@@ -242,6 +237,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mStreamControls = new HashMap<Integer,StreamControl>(STREAM_TYPES.length);
        Resources res = mContext.getResources();
        for (int i = 0; i < STREAM_TYPES.length; i++) {
            StreamControl sc = new StreamControl();
            sc.streamType = STREAM_TYPES[i];
@@ -250,6 +246,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            sc.icon = (ImageView) sc.group.findViewById(R.id.stream_icon);
            sc.icon.setOnClickListener(this);
            sc.icon.setTag(sc);
            sc.icon.setContentDescription(res.getString(CONTENT_DESCRIPTIONS[i]));
            sc.iconRes = STREAM_ICONS_NORMAL[i];
            sc.iconMuteRes = STREAM_ICONS_MUTED[i];
            sc.icon.setImageResource(sc.iconRes);
@@ -275,13 +272,19 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            updateSlider(active);
        }

        addOtherVolumes();
    }

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

        for (int i = 0; i < STREAM_TYPES.length; i++) {
            // Skip the phone specific ones and the active one
            final int streamType = STREAM_TYPES[i];
            if (streamType == AudioManager.STREAM_RING
                    || streamType == AudioManager.STREAM_VOICE_CALL
                    || streamType == AudioManager.STREAM_BLUETOOTH_SCO
                    || streamType == activeStreamType) {
                    || streamType == mActiveStreamType) {
                continue;
            }
            StreamControl sc = mStreamControls.get(streamType);
@@ -392,31 +395,23 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie

            case AudioManager.STREAM_RING: {
//                setRingerIcon();
//                message = RINGTONE_VOLUME_TEXT;
                Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri(
                        mContext, RingtoneManager.TYPE_RINGTONE);
                if (ringuri == null) {
//                    additionalMessage =
//                        com.android.internal.R.string.volume_music_hint_silent_ringtone_selected;
                    mRingIsSilent = true;
                }
                break;
            }

            case AudioManager.STREAM_MUSIC: {
//                message = MUSIC_VOLUME_TEXT;
                // Special case for when Bluetooth is active for music
                if ((mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC) &
                        (AudioManager.DEVICE_OUT_BLUETOOTH_A2DP |
                        AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
                        AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) != 0) {
//                    additionalMessage =
//                        com.android.internal.R.string.volume_music_hint_playing_through_bluetooth;
//                    setLargeIcon(com.android.internal.R.drawable.ic_volume_bluetooth_ad2p);
                    setMusicIcon(R.drawable.ic_audio_bt, R.drawable.ic_audio_bt_mute);
                } else {
                    setMusicIcon(R.drawable.ic_audio_vol, R.drawable.ic_audio_vol_mute);
//                    setSmallIcon(index);
                }
                break;
            }
@@ -429,25 +424,17 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                 */
                index++;
                max++;
//                message = INCALL_VOLUME_TEXT;
//                setSmallIcon(index);
                break;
            }

            case AudioManager.STREAM_ALARM: {
//                message = ALARM_VOLUME_TEXT;
//                setSmallIcon(index);
                break;
            }

            case AudioManager.STREAM_NOTIFICATION: {
//                message = NOTIFICATION_VOLUME_TEXT;
//                setSmallIcon(index);
                Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri(
                        mContext, RingtoneManager.TYPE_NOTIFICATION);
                if (ringuri == null) {
//                    additionalMessage =
//                        com.android.internal.R.string.volume_music_hint_silent_ringtone_selected;
                    mRingIsSilent = true;
                }
                break;
@@ -461,29 +448,10 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                 */
                index++;
                max++;
//                message = BLUETOOTH_INCALL_VOLUME_TEXT;
//                setLargeIcon(com.android.internal.R.drawable.ic_volume_bluetooth_in_call);
                break;
            }
        }

//        String messageString = Resources.getSystem().getString(message);
//        if (!mMessage.getText().equals(messageString)) {
//            mMessage.setText(messageString);
//        }
//
//        if (additionalMessage == 0) {
//            mAdditionalMessage.setVisibility(View.GONE);
//        } else {
//            mAdditionalMessage.setVisibility(View.VISIBLE);
//            mAdditionalMessage.setText(Resources.getSystem().getString(additionalMessage));
//        }

//        if (max != mLevel.getMax()) {
//            mLevel.setMax(max);
//        }
//        mLevel.setProgress(index);

        StreamControl sc = mStreamControls.get(streamType);
        if (sc != null) {
            sc.seekbarView.setProgress(index);
@@ -493,7 +461,9 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            mAudioManager.forceVolumeControlStream(streamType);
            mDialog.setContentView(mView);
            // Showing dialog - use collapsed state
            if (mShowCombinedVolumes) {
                collapse();
            }
            mDialog.show();
        }

@@ -565,31 +535,6 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        }
    }

//    /**
//     * Makes the small icon visible, and hides the large icon.
//     *
//     * @param index The volume index, where 0 means muted.
//     */
//    private void setSmallIcon(int index) {
//        mLargeStreamIcon.setVisibility(View.GONE);
//        mSmallStreamIcon.setVisibility(View.VISIBLE);
//
//        mSmallStreamIcon.setImageResource(index == 0
//                ? com.android.internal.R.drawable.ic_volume_off_small
//                : com.android.internal.R.drawable.ic_volume_small);
//    }
//
//    /**
//     * Makes the large image view visible with the given icon.
//     *
//     * @param resId The icon to display.
//     */
//    private void setLargeIcon(int resId) {
//        mSmallStreamIcon.setVisibility(View.GONE);
//        mLargeStreamIcon.setVisibility(View.VISIBLE);
//        mLargeStreamIcon.setImageResource(resId);
//    }
//
//    /**
//     * Makes the ringer icon visible with an icon that is chosen
//     * based on the current ringer mode.
@@ -627,11 +572,6 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    }

    protected void onFreeResources() {
        // We'll keep the views, just ditch the cached drawable and hence
        // bitmaps
//        mSmallStreamIcon.setImageDrawable(null);
//        mLargeStreamIcon.setImageDrawable(null);

        synchronized (this) {
            for (int i = mToneGenerators.length - 1; i >= 0; i--) {
                if (mToneGenerators[i] != null) {
@@ -718,7 +658,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            mAudioManager.setRingerMode(mAudioManager.isSilentMode()
                    ? AudioManager.RINGER_MODE_NORMAL : AudioManager.RINGER_MODE_SILENT);
            // Expand the dialog if it hasn't been expanded yet.
            if (!isExpanded()) expand();
            if (mShowCombinedVolumes && !isExpanded()) expand();
        }
        resetTimeout();
    }
+4.35 KiB
Loading image diff...
+4.74 KiB
Loading image diff...
+3.82 KiB
Loading image diff...
Loading