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

Commit 960f29b4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Showing brightness slider in collapsed QS in split shade" into...

Merge "Showing brightness slider in collapsed QS in split shade" into sc-v2-dev am: 93148349 am: a10f077d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15301454

Change-Id: Ib0acd79dac06ec1f3400a60c7aa2ce044754c9a7
parents d1b6cd4a a10f077d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@
    android:paddingStart="0dp"
    android:elevation="4dp" >

    <!-- Date and privacy. Only visible in QS -->
    <!-- Date and privacy. Only visible in QS when not in split shade -->
    <include layout="@layout/quick_status_bar_header_date_privacy"/>

    <RelativeLayout
@@ -42,7 +42,7 @@
        android:layout_gravity="top"
        android:clipChildren="false"
        android:clipToPadding="false">
        <!-- Time, icons and Carrier (only in QS) -->
        <!-- Time, icons and Carrier (only in QS when not in split shade) -->
        <include layout="@layout/quick_qs_status_icons"/>

        <com.android.systemui.qs.QuickQSPanel
+3 −0
Original line number Diff line number Diff line
@@ -88,11 +88,14 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
                            Utils.shouldUseSplitNotificationShade(mFeatureFlags, getResources());
                    if (newConfig.orientation != mLastOrientation) {
                        mLastOrientation = newConfig.orientation;
                        onScreenRotated();
                        switchTileLayout(false);
                    }
                }
            };

    protected void onScreenRotated() { }

    private final Function1<Boolean, Unit> mMediaHostVisibilityListener = (visible) -> {
        if (mMediaVisibilityChangedListener != null) {
            mMediaVisibilityChangedListener.accept(visible);
+94 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */

package com.android.systemui.qs

import androidx.annotation.VisibleForTesting
import com.android.systemui.settings.brightness.BrightnessController
import com.android.systemui.settings.brightness.BrightnessSlider
import javax.inject.Inject

/**
 * Controls brightness slider in QQS, which is visible only in split shade. It's responsible for
 * showing/hiding it when appropriate and (un)registering listeners
 */
class QuickQSBrightnessController @VisibleForTesting constructor(
    private val brightnessControllerFactory: () -> BrightnessController
) {

    @Inject constructor(
        brightnessControllerFactory: BrightnessController.Factory,
        brightnessSliderFactory: BrightnessSlider.Factory,
        quickQSPanel: QuickQSPanel
    ) : this(brightnessControllerFactory = {
            val slider = brightnessSliderFactory.create(quickQSPanel.context, quickQSPanel)
            slider.init()
            quickQSPanel.setBrightnessView(slider.rootView)
            brightnessControllerFactory.create(slider)
        })

    private var isListening = false
    private var brightnessController: BrightnessController? = null

    fun init(shouldUseSplitNotificationShade: Boolean) {
        refreshVisibility(shouldUseSplitNotificationShade)
    }

    /**
     * Starts/Stops listening for brightness changing events.
     * It's fine to call this function even if slider is not visible (which would be the case for
     * all small screen devices), it will just do nothing in that case
     */
    fun setListening(listening: Boolean) {
        if (listening) {
            // controller can be null when slider was never shown
            if (!isListening && brightnessController != null) {
                brightnessController?.registerCallbacks()
                isListening = true
            }
        } else {
            brightnessController?.unregisterCallbacks()
            isListening = false
        }
    }

    fun checkRestrictionAndSetEnabled() {
        brightnessController?.checkRestrictionAndSetEnabled()
    }

    fun refreshVisibility(shouldUseSplitNotificationShade: Boolean) {
        if (shouldUseSplitNotificationShade) {
            showBrightnessSlider()
        } else {
            hideBrightnessSlider()
        }
    }

    private fun hideBrightnessSlider() {
        brightnessController?.hideSlider()
    }

    private fun showBrightnessSlider() {
        if (brightnessController == null) {
            brightnessController = brightnessControllerFactory()
        }
        brightnessController?.showSlider()
        if (!isListening) {
            brightnessController?.registerCallbacks()
            isListening = true
        }
    }
}
 No newline at end of file
+0 −5
Original line number Diff line number Diff line
@@ -45,11 +45,6 @@ public class QuickQSPanel extends QSPanel {
        mMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_tiles);
    }

    @Override
    public void setBrightnessView(View view) {
        // Don't add brightness view
    }

    @Override
    void initialize() {
        super.initialize();
+24 −1
Original line number Diff line number Diff line
@@ -49,16 +49,21 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
                }
            };

    // brightness is visible only in split shade
    private final QuickQSBrightnessController mBrightnessController;

    @Inject
    QuickQSPanelController(QuickQSPanel view, QSTileHost qsTileHost,
            QSCustomizerController qsCustomizerController,
            @Named(QS_USING_MEDIA_PLAYER) boolean usingMediaPlayer,
            @Named(QUICK_QS_PANEL) MediaHost mediaHost,
            MetricsLogger metricsLogger, UiEventLogger uiEventLogger, QSLogger qsLogger,
            DumpManager dumpManager, FeatureFlags featureFlags
            DumpManager dumpManager, FeatureFlags featureFlags,
            QuickQSBrightnessController quickQSBrightnessController
    ) {
        super(view, qsTileHost, qsCustomizerController, usingMediaPlayer, mediaHost, metricsLogger,
                uiEventLogger, qsLogger, dumpManager, featureFlags);
        mBrightnessController = quickQSBrightnessController;
    }

    @Override
@@ -67,6 +72,7 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
        mMediaHost.setExpansion(0.0f);
        mMediaHost.setShowsOnlyActiveMedia(true);
        mMediaHost.init(MediaHierarchyManager.LOCATION_QQS);
        mBrightnessController.init(mShouldUseSplitNotificationShade);
    }

    @Override
@@ -81,6 +87,12 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
        mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener);
    }

    @Override
    void setListening(boolean listening) {
        super.setListening(listening);
        mBrightnessController.setListening(listening);
    }

    public boolean isListening() {
        return mView.isListening();
    }
@@ -90,6 +102,17 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
        setTiles();
    }

    @Override
    public void refreshAllTiles() {
        mBrightnessController.checkRestrictionAndSetEnabled();
        super.refreshAllTiles();
    }

    @Override
    protected void onScreenRotated() {
        mBrightnessController.refreshVisibility(mShouldUseSplitNotificationShade);
    }

    @Override
    public void setTiles() {
        List<QSTile> tiles = new ArrayList<>();
Loading