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

Unverified Commit e6bbee06 authored by Alberto97's avatar Alberto97 Committed by Michael Bestas
Browse files

SystemUI: Port brightness slider changes



 * Allow hiding brightness slider
 * Expose AutoBrightness button
 * Replace TunerService with content observers

Co-authored-by: default avatarAlexander Westphal <westphal.alex94@gmail.com>
Co-authored-by: default avatarLuca Stefani <luca020400@lineageos.org>
Co-authored-by: default avatarMichael Bestas <mkbestas@lineageos.org>
Co-authored-by: default avatarMichael W <baddaemon87@gmail.com>
Co-authored-by: default avatarOliver Scott <olivercscott@gmail.com>
Co-authored-by: default avatarqjohn <townex22@gmail.com>
Change-Id: Ic72b0084a4108fb4fa26e893bd6d1eaca96cbb6c
parent 8a6bb1e1
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2017 The LineageOS 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:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M20,8.69L20,4h-4.69L12,0.69 8.69,4L4,4v4.69L0.69,12 4,15.31L4,20h4.69L12,23.31 15.31,20L20,20v-4.69L23.31,12 20,8.69zM12,18c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6 6,2.69 6,6 -2.69,6 -6,6zM12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4z"/>
</vector>
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2017 The LineageOS 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:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M10.85,12.65h2.3L12,9l-1.15,3.65zM20,8.69V4h-4.69L12,0.69 8.69,4H4v4.69L0.69,12 4,15.31V20h4.69L12,23.31 15.31,20H20v-4.69L23.31,12 20,8.69zM14.3,16l-0.7,-2h-3.2l-0.7,2H7.8L11,7h2l3.2,9h-1.9z"/>
</vector>
+15 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
        android:id="@+id/brightness_slider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_gravity="center_vertical"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:contentDescription="@string/accessibility_brightness"
@@ -26,9 +26,10 @@

        <com.android.systemui.settings.brightness.ToggleSeekBar
            android:id="@+id/slider"
            android:layout_width="match_parent"
            android:layout_width="0dp"
            android:layout_height="@dimen/brightness_mirror_height"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:minHeight="48dp"
            android:thumb="@null"
            android:paddingStart="0dp"
@@ -36,4 +37,16 @@
            android:progressDrawable="@drawable/brightness_progress_drawable"
            android:splitTrack="false"
        />

        <ImageView
            android:id="@+id/brightness_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="4dp"
            android:layout_marginEnd="8dp"
            android:src="@drawable/ic_qs_brightness_auto_off"
            android:contentDescription="@null"
            android:visibility="gone"
        />
    </com.android.systemui.settings.brightness.BrightnessSliderView>
+37 −8
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.util.ArrayMap;
import android.util.AttributeSet;
@@ -47,11 +49,13 @@ import com.android.systemui.settings.brightness.BrightnessSliderController;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;

import lineageos.providers.LineageSettings;

import java.util.ArrayList;
import java.util.List;

/** View that represents the quick settings tile panel (when expanded/pulled down). **/
public class QSPanel extends LinearLayout implements Tunable {
public class QSPanel extends LinearLayout {

    public static final String QS_SHOW_BRIGHTNESS = "qs_show_brightness";
    public static final String QS_SHOW_HEADER = "qs_show_header";
@@ -71,6 +75,8 @@ public class QSPanel extends LinearLayout implements Tunable {

    @Nullable
    protected View mBrightnessView;
    protected View mAutoBrightnessView;

    @Nullable
    protected BrightnessSliderController mToggleSliderController;

@@ -80,6 +86,9 @@ public class QSPanel extends LinearLayout implements Tunable {
    protected boolean mExpanded;
    protected boolean mListening;

    private ContentObserver mContentObserver;
    private boolean mIsAutomaticBrightnessAvailable = false;

    private final List<OnConfigurationChangedListener> mOnConfigurationChangedListeners =
            new ArrayList<>();

@@ -128,6 +137,28 @@ public class QSPanel extends LinearLayout implements Tunable {
        setOrientation(VERTICAL);

        mMovableContentStartIndex = getChildCount();

        mIsAutomaticBrightnessAvailable = getResources().getBoolean(
                com.android.internal.R.bool.config_automatic_brightness_available);

        mContentObserver = new ContentObserver(null) {
            @Override
            public void onChange(boolean selfChange, @Nullable Uri uri) {
                if (LineageSettings.Secure.getUriFor(
                            LineageSettings.Secure.QS_SHOW_AUTO_BRIGHTNESS).equals(uri)
                        && mIsAutomaticBrightnessAvailable) {
                    updateViewVisibilityForTuningValue(mAutoBrightnessView,
                            LineageSettings.Secure.getString(mContext.getContentResolver(),
                                    LineageSettings.Secure.QS_SHOW_AUTO_BRIGHTNESS));
                } else if (LineageSettings.Secure.getUriFor(
                            LineageSettings.Secure.QS_SHOW_BRIGHTNESS_SLIDER).equals(uri)
                        && mBrightnessView != null) {
                    updateViewVisibilityForTuningValue(mBrightnessView,
                            LineageSettings.Secure.getString(mContext.getContentResolver(),
                                    LineageSettings.Secure.QS_SHOW_BRIGHTNESS_SLIDER));
                }
            }
        };
    }

    void initialize(QSLogger qsLogger, boolean usingMediaPlayer) {
@@ -173,6 +204,10 @@ public class QSPanel extends LinearLayout implements Tunable {
        }
    }

    public ContentObserver getContentObserver() {
        return mContentObserver;
    }

    protected void setHorizontalContentContainerClipping() {
        if (mHorizontalContentContainer != null) {
            mHorizontalContentContainer.setClipChildren(true);
@@ -208,6 +243,7 @@ public class QSPanel extends LinearLayout implements Tunable {
        }
        addView(view, 0);
        mBrightnessView = view;
        mAutoBrightnessView = view.findViewById(R.id.brightness_icon);

        setBrightnessViewMargin();

@@ -346,13 +382,6 @@ public class QSPanel extends LinearLayout implements Tunable {
        return TAG;
    }

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (QS_SHOW_BRIGHTNESS.equals(key) && mBrightnessView != null) {
            updateViewVisibilityForTuningValue(mBrightnessView, newValue);
        }
    }

    private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) {
        view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE);
    }
+19 −6
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.systemui.media.dagger.MediaModule.QS_PANEL;
import static com.android.systemui.qs.QSPanel.QS_SHOW_BRIGHTNESS;
import static com.android.systemui.qs.dagger.QSScopeModule.QS_USING_MEDIA_PLAYER;

import android.provider.Settings;
import android.view.MotionEvent;
import android.view.View;

@@ -45,7 +46,8 @@ import com.android.systemui.settings.brightness.BrightnessSliderController;
import com.android.systemui.settings.brightness.MirrorController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.SplitShadeStateController;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;

import kotlinx.coroutines.flow.StateFlow;

@@ -60,7 +62,6 @@ import javax.inject.Provider;
@QSScope
public class QSPanelController extends QSPanelControllerBase<QSPanel> {

    private final TunerService mTunerService;
    private final QSCustomizerController mQsCustomizerController;
    private final QSTileRevealController.Factory mQsTileRevealControllerFactory;
    private final FalsingManager mFalsingManager;
@@ -89,7 +90,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
    };

    @Inject
    QSPanelController(QSPanel view, TunerService tunerService,
    QSPanelController(QSPanel view,
            QSHost qsHost, QSCustomizerController qsCustomizerController,
            @Named(QS_USING_MEDIA_PLAYER) boolean usingMediaPlayer,
            @Named(QS_PANEL) MediaHost mediaHost,
@@ -105,7 +106,6 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
        super(view, qsHost, qsCustomizerController, usingMediaPlayer, mediaHost,
                metricsLogger, uiEventLogger, qsLogger, dumpManager, splitShadeStateController,
                longPRessEffectProvider);
        mTunerService = tunerService;
        mQsCustomizerController = qsCustomizerController;
        mQsTileRevealControllerFactory = qsTileRevealControllerFactory;
        mFalsingManager = falsingManager;
@@ -144,7 +144,20 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {

        updateMediaDisappearParameters();

        mTunerService.addTunable(mView, QS_SHOW_BRIGHTNESS);
        getContext().getContentResolver().registerContentObserver(
                LineageSettings.Secure.getUriFor(LineageSettings.Secure.QS_SHOW_AUTO_BRIGHTNESS),
                false, mView.getContentObserver());
        mView.getContentObserver().onChange(true,
                LineageSettings.Secure.getUriFor(LineageSettings.Secure.QS_SHOW_AUTO_BRIGHTNESS));
        getContext().getContentResolver().registerContentObserver(
                LineageSettings.Secure.getUriFor(LineageSettings.Secure.QS_SHOW_BRIGHTNESS_SLIDER),
                false, mView.getContentObserver());
        mView.getContentObserver().onChange(true,
                LineageSettings.Secure.getUriFor(LineageSettings.Secure.QS_SHOW_BRIGHTNESS_SLIDER));
        getContext().getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(QS_SHOW_BRIGHTNESS), false, mView.getContentObserver());
        mView.getContentObserver().onChange(true,
                Settings.Secure.getUriFor(QS_SHOW_BRIGHTNESS));
        mView.updateResources();
        mView.setSceneContainerEnabled(mSceneContainerEnabled);
        if (mView.isListening()) {
@@ -165,7 +178,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {

    @Override
    protected void onViewDetached() {
        mTunerService.removeTunable(mView);
        getContext().getContentResolver().unregisterContentObserver(mView.getContentObserver());
        mBrightnessMirrorHandler.onQsPanelDettached();
        super.onViewDetached();
    }
Loading