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

Commit 7a4627c5 authored by HrX03's avatar HrX03 Committed by Bruno Martins
Browse files

VolumeDialog: Redo expanded volume panel



[ HrX03 | AgentFabulous - POSP ]
- Google nuked expanded volume panel in pie. Redo the current
  implementation to bring this back from the past and dejank it.
- Back to Android 8.x functionality!

- Show the media output selector to not loose functionality.
- Increase ringer vibrate icon width/height to 24 to match the
  other icons

Change-Id: Ie4931a4ae09483ba737a74fc32ed0a1f6acf105d
Co-authored-by: default avatarKshitij Gupta <kshitijgm@gmail.com>
Co-authored-by: default avatarArian <arian.kulmer@web.de>
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent 055bb26f
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2020 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="24.0dp"
    android:width="24.0dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12.88,16.29L11,18.17V14.41M11,5.83L12.88,7.71L11,9.58M15.71,7.71L10,2H9V9.58L4.41,5L3,6.41L8.59,12L3,17.58L4.41,19L9,14.41V22H10L15.71,16.29L11.41,12M19.53,6.71L18.26,8C18.89,9.18 19.25,10.55 19.25,12C19.25,13.45 18.89,14.82 18.26,16L19.46,17.22C20.43,15.68 21,13.87 21,11.91C21,10 20.46,8.23 19.53,6.71M14.24,12L16.56,14.33C16.84,13.6 17,12.82 17,12C17,11.18 16.84,10.4 16.57,9.68L14.24,12Z" />
</vector>
+26 −5
Original line number Diff line number Diff line
@@ -92,21 +92,42 @@
                <!-- volume rows added and removed here! :-) -->
            </LinearLayout>
            <FrameLayout
                android:id="@+id/settings_container"
                android:id="@+id/media_output_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_bg_bottom_background">
                android:background="?android:attr/panelColorBackground">
                <com.android.keyguard.AlphaOptimizedImageButton
                    android:id="@+id/settings"
                    android:src="@drawable/ic_tune_black_16dp"
                    android:id="@+id/media_output"
                    android:src="@drawable/ic_bluetooth_audio"
                    android:layout_width="@dimen/volume_dialog_tap_target_size"
                    android:layout_height="@dimen/volume_dialog_tap_target_size"
                    android:layout_gravity="center"
                    android:layout_marginRight="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_gravity="right"
                    android:contentDescription="@string/accessibility_volume_settings"
                    android:background="@drawable/ripple_drawable_20dp"
                    android:tint="?android:attr/textColorSecondary"
                    android:soundEffectsEnabled="false" />
            </FrameLayout>
            <FrameLayout
                android:id="@+id/expandable_indicator_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_bg_bottom_background">
                <com.android.systemui.statusbar.phone.ExpandableIndicator
                    android:id="@+id/expandable_indicator"
                    android:layout_width="@dimen/volume_dialog_tap_target_size"
                    android:layout_height="@dimen/volume_dialog_tap_target_size"
                    android:layout_marginRight="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_gravity="right"
                    android:contentDescription="@string/accessibility_volume_expand"
                    android:background="@drawable/ripple_drawable_20dp"
                    android:tint="?android:attr/textColorSecondary"
                    android:soundEffectsEnabled="false"
                    android:padding="14dp"
                    android:rotation="90" />
            </FrameLayout>
        </LinearLayout>

        <FrameLayout
+26 −5
Original line number Diff line number Diff line
@@ -93,21 +93,42 @@
                    <!-- volume rows added and removed here! :-) -->
            </LinearLayout>
            <FrameLayout
                android:id="@+id/settings_container"
                android:id="@+id/media_output_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_bg_bottom_background">
                android:background="?android:attr/panelColorBackground">
                <com.android.keyguard.AlphaOptimizedImageButton
                    android:id="@+id/settings"
                    android:src="@drawable/ic_tune_black_16dp"
                    android:id="@+id/media_output"
                    android:src="@drawable/ic_bluetooth_audio"
                    android:layout_width="@dimen/volume_dialog_tap_target_size"
                    android:layout_height="@dimen/volume_dialog_tap_target_size"
                    android:layout_gravity="center"
                    android:layout_marginRight="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_gravity="right"
                    android:contentDescription="@string/accessibility_volume_settings"
                    android:background="@drawable/ripple_drawable_20dp"
                    android:tint="?android:attr/textColorSecondary"
                    android:soundEffectsEnabled="false" />
            </FrameLayout>
            <FrameLayout
                android:id="@+id/expandable_indicator_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_bg_bottom_background">
                <com.android.systemui.statusbar.phone.ExpandableIndicator
                    android:id="@+id/expandable_indicator"
                    android:layout_width="@dimen/volume_dialog_tap_target_size"
                    android:layout_height="@dimen/volume_dialog_tap_target_size"
                    android:layout_marginRight="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_gravity="right"
                    android:contentDescription="@string/accessibility_volume_expand"
                    android:background="@drawable/ripple_drawable_20dp"
                    android:tint="?android:attr/textColorSecondary"
                    android:soundEffectsEnabled="false"
                    android:padding="14dp"
                    android:rotation="90" />
            </FrameLayout>
        </LinearLayout>

        <FrameLayout
+58 −24
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
import static com.android.systemui.volume.Events.DISMISS_REASON_SETTINGS_CLICKED;

import android.animation.ObjectAnimator;
@@ -39,6 +40,8 @@ import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Dialog;
import android.app.KeyguardManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothProfile;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
@@ -96,6 +99,7 @@ import com.android.systemui.plugins.VolumeDialog;
import com.android.systemui.plugins.VolumeDialogController;
import com.android.systemui.plugins.VolumeDialogController.State;
import com.android.systemui.plugins.VolumeDialogController.StreamState;
import com.android.systemui.statusbar.phone.ExpandableIndicator;
import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -144,8 +148,10 @@ public class VolumeDialogImpl implements VolumeDialog,
    private ImageButton mRingerIcon;
    private ViewGroup mODICaptionsView;
    private CaptionsToggleImageButton mODICaptionsIcon;
    private View mSettingsView;
    private ImageButton mSettingsIcon;
    private View mMediaOutputView;
    private ImageButton mMediaOutputIcon;
    private View mExpandRowsView;
    private ExpandableIndicator mExpandRows;
    private FrameLayout mZenIcon;
    private final List<VolumeRow> mRows = new ArrayList<>();
    private ConfigurableTexts mConfigurableTexts;
@@ -175,6 +181,8 @@ public class VolumeDialogImpl implements VolumeDialog,
    // Volume panel placement left or right
    private boolean mVolumePanelOnLeft;

    private boolean mExpanded;

    public VolumeDialogImpl(Context context) {
        mContext =
                new ContextThemeWrapper(context, R.style.qs_theme);
@@ -221,6 +229,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        mConfigurableTexts = new ConfigurableTexts(mContext);
        mHovering = false;
        mShowing = false;
        mExpanded = false;
        mWindow = mDialog.getWindow();
        mWindow.requestFeature(Window.FEATURE_NO_TITLE);
        mWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
@@ -293,8 +302,11 @@ public class VolumeDialogImpl implements VolumeDialog,
            mODICaptionsTooltipViewStub = null;
        }

        mSettingsView = mDialog.findViewById(R.id.settings_container);
        mSettingsIcon = mDialog.findViewById(R.id.settings);
        mMediaOutputView = mDialog.findViewById(R.id.media_output_container);
        mMediaOutputIcon = mDialog.findViewById(R.id.media_output);

        mExpandRowsView = mDialog.findViewById(R.id.expandable_indicator_container);
        mExpandRows = mDialog.findViewById(R.id.expandable_indicator);

        if (mRows.isEmpty()) {
            if (!AudioSystem.isSingleVolume(mContext)) {
@@ -312,7 +324,7 @@ public class VolumeDialogImpl implements VolumeDialog,
                            R.drawable.ic_volume_notification_mute, true, false);
                }
                addRow(STREAM_ALARM,
                        R.drawable.ic_alarm, R.drawable.ic_volume_alarm_mute, true, false);
                        R.drawable.ic_volume_alarm, R.drawable.ic_volume_alarm_mute, true, false);
                addRow(AudioManager.STREAM_VOICE_CALL,
                        com.android.internal.R.drawable.ic_phone,
                        com.android.internal.R.drawable.ic_phone, false, false);
@@ -405,11 +417,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        if (D.BUG) Slog.d(TAG, "Adding row for stream " + stream);
        VolumeRow row = new VolumeRow();
        initRow(row, stream, iconRes, iconMuteRes, important, defaultStream);
        if (mVolumePanelOnLeft) {
            mDialogRowsView.addView(row.view, 0);
        } else {
            mDialogRowsView.addView(row.view);
        }
        mDialogRowsView.addView(row.view, mVolumePanelOnLeft ? -1 : 0);
        mRows.add(row);
    }

@@ -419,11 +427,7 @@ public class VolumeDialogImpl implements VolumeDialog,
            final VolumeRow row = mRows.get(i);
            initRow(row, row.stream, row.iconRes, row.iconMuteRes, row.important,
                    row.defaultStream);
            if (mVolumePanelOnLeft) {
                mDialogRowsView.addView(row.view, 0);
            } else {
                mDialogRowsView.addView(row.view);
            }
            mDialogRowsView.addView(row.view, mVolumePanelOnLeft ? -1 : 0);
            updateVolumeRowH(row);
        }
    }
@@ -522,22 +526,46 @@ public class VolumeDialogImpl implements VolumeDialog,
        }
    }

    private static boolean isBluetoothA2dpConnected() {
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
                && mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP)
                == BluetoothProfile.STATE_CONNECTED;
    }

    public void initSettingsH() {
        if (mSettingsView != null) {
            mSettingsView.setVisibility(
        if (mMediaOutputView != null) {
            mMediaOutputView.setVisibility(
                    mDeviceProvisionedController.isCurrentUserSetup() &&
                            mActivityManager.getLockTaskModeState() == LOCK_TASK_MODE_NONE ?
                            VISIBLE : GONE);
                            mActivityManager.getLockTaskModeState() == LOCK_TASK_MODE_NONE &&
                            isBluetoothA2dpConnected() ? VISIBLE : GONE);
        }
        if (mSettingsIcon != null) {
            mSettingsIcon.setOnClickListener(v -> {
        if (mMediaOutputIcon != null) {
            mMediaOutputIcon.setOnClickListener(v -> {
                Events.writeEvent(mContext, Events.EVENT_SETTINGS_CLICK);
                Intent intent = new Intent(Settings.Panel.ACTION_VOLUME);
                Intent intent = new Intent(ACTION_MEDIA_OUTPUT);
                dismissH(DISMISS_REASON_SETTINGS_CLICKED);
                Dependency.get(ActivityStarter.class).startActivity(intent,
                        true /* dismissShade */);
            });
        }

        if (mExpandRowsView != null) {
            mExpandRowsView.setVisibility(
                    mDeviceProvisionedController.isCurrentUserSetup() &&
                            mActivityManager.getLockTaskModeState() == LOCK_TASK_MODE_NONE ?
                            VISIBLE : GONE);
        }
        if (mExpandRows != null) {
            mExpandRows.setOnClickListener(v -> {
                Util.setVisOrGone(findRow(AudioManager.STREAM_RING).view, !mExpanded);
                Util.setVisOrGone(findRow(STREAM_ALARM).view, !mExpanded);

                if (mExpanded) mController.setActiveStream(AudioManager.STREAM_MUSIC);
                mExpandRows.setExpanded(!mExpanded);
                mExpanded = !mExpanded;
            });
        }
    }

    public void initRingerH() {
@@ -798,6 +826,10 @@ public class VolumeDialogImpl implements VolumeDialog,
            Log.d(TAG, "mDialog.dismiss() reason: " + Events.DISMISS_REASONS[reason]
                    + " from: " + Debug.getCaller());
        }
        if (!mShowing) {
            // This may happen when dismissing an expanded panel, don't animate again
            return;
        }
        mHandler.removeMessages(H.DISMISS);
        mHandler.removeMessages(H.SHOW);
        mDialogView.animate().cancel();
@@ -815,6 +847,8 @@ public class VolumeDialogImpl implements VolumeDialog,
                .withEndAction(() -> mHandler.postDelayed(() -> {
                    mDialog.dismiss();
                    tryToRemoveCaptionsTooltip();
                    mExpanded = false;
                    mExpandRows.setExpanded(mExpanded);
                    mController.notifyVisible(false);
                }, 50));
        animator.translationX(getAnimatorX());
@@ -874,7 +908,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        for (final VolumeRow row : mRows) {
            final boolean isActive = row == activeRow;
            final boolean shouldBeVisible = shouldBeVisibleH(row, activeRow);
            Util.setVisOrGone(row.view, shouldBeVisible);
            if (!mExpanded) Util.setVisOrGone(row.view, shouldBeVisible);
            if (row.view.isShown()) {
                updateVolumeRowTintH(row, isActive);
            }
@@ -1183,7 +1217,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        final int alpha = useActiveColoring
                ? Color.alpha(tint.getDefaultColor())
                : getAlphaAttr(android.R.attr.secondaryContentAlpha);
        if (tint == row.cachedTint) return;
        if (tint == row.cachedTint && mExpanded) return;
        row.slider.setProgressTintList(tint);
        row.slider.setThumbTintList(tint);
        row.slider.setProgressBackgroundTintList(tint);