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

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

SystemUI: Port brightness slider changes

 * Expose AutoBrightness button
 * Add content observers
 * Use vector drawables for brightness icons

[BadDaemon]
 * Adapt to SystemUI changes
 * Change code style to use lambdas and locals where possible

Author: Luca Stefani <luca020400@lineageos.org>
Date:   Thu Apr 20 18:00:52 2017 +0200

    SystemUI: Use AOSP AutoBrightness implementation

    Change-Id: I3e3660065407d460f30c6e936d951d4d5eae30c6

Author: Michael Bestas <mikeioannina@gmail.com>
Date:   Thu Apr 27 14:57:49 2017 +0300

    SystemUI: Use already existing overlay to show QS auto brightness

    * No need for a new overlay when one exists for years

    Change-Id: I9e09a1770f8e645093e880cf1a48597405e0bcf2

Author: Alberto97 <albertop2197@gmail.com>
Date:   Mon May 29 21:07:05 2017 +0200

    SystemUI: Specify user while changing brightness mode

    Allow any user changing brightness mode,
    without this only the main one is able to do that.

    BUGBASH-598

    Change-Id: Ib51e9a45c42837cabb1cfb0d48334165b023a827

Author: Michael Bestas <mkbestas@lineageos.org>
Date:   Sun Apr 30 13:45:39 2017 +0300

    SystemUI: Add tunable for auto brightness icon

    Change-Id: I02fe3f5500f95ba9369b952bbec2a073b7ae8316

Author: Alexander Westphal <westphal.alex94@gmail.com>
Date:   Wed Apr 26 09:20:53 2017 +0100

    SystemUI: use vector drawables for brightness icons

    Change-Id: I8d22f8de22040d68ed1bfab0da3a78aec717fa62

Author: qjohn <townex22@gmail.com>
Date:   Sun Jun 18 16:28:10 2017 +0700

    SystemUI: Remove unnecessary brightness icons

    Change-Id: I7e60ff73125bd0304f9ca14ad5c5a9ce11ffceda

Author: Michael W <baddaemon87@gmail.com>
Date:   Mon May 25 15:38:33 2020 +0200

    SystemUI: Brightness slider: Always show the brightness icon

    * Right now, we reserve the space for the icon but it's not displayed
      (reserved space is there so the slider doesn't jump)
    * Always display the icon (if automatic brightness is available)
      so it's more consistent

    Change-Id: I5238dc6aad51407349a8d42fae840ea76841dc3d

Author: Michael W <baddaemon87@gmail.com>
Date:   Fri May 29 20:09:18 2020 +0200

    SystemUI: Fix for auto brightness icon being shown when disabled

    * With commit 9d42c48c the case of a
      manually disabled auto brightness icon got lost
    * Re-implement it by also respecting the Settings value instead of just
      the build time flag

    Change-Id: I991977be7e1f7c33947073dbd3ce7a800fb158bf

Change-Id: Ic72b0084a4108fb4fa26e893bd6d1eaca96cbb6c
parent 89dd34dd
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,15 +18,16 @@
        android:id="@+id/brightness_slider"
        android:layout_width="match_parent"
        android:layout_height="@dimen/brightness_mirror_height"
        android:layout_gravity="center"
        android:layout_gravity="center_vertical"
        android:contentDescription="@string/accessibility_brightness"
        android:importantForAccessibility="no" >

        <com.android.systemui.settings.brightness.ToggleSeekBar
            android:id="@+id/slider"
            android:layout_width="match_parent"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:minHeight="48dp"
            android:thumb="@null"
            android:background="@null"
@@ -36,4 +37,16 @@
            android:splitTrack="false"
            android:clickable="true"
        />

        <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>
+36 −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;
@@ -46,11 +48,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";
@@ -70,6 +74,8 @@ public class QSPanel extends LinearLayout implements Tunable {

    @Nullable
    protected View mBrightnessView;
    protected View mAutoBrightnessView;

    @Nullable
    protected BrightnessSliderController mToggleSliderController;

@@ -79,6 +85,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<>();

@@ -123,6 +132,27 @@ public class QSPanel extends LinearLayout implements Tunable {

        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) {
@@ -153,6 +183,10 @@ public class QSPanel extends LinearLayout implements Tunable {
        }
    }

    public ContentObserver getContentObserver() {
        return mContentObserver;
    }

    protected void setHorizontalContentContainerClipping() {
        mHorizontalContentContainer.setClipChildren(true);
        mHorizontalContentContainer.setClipToPadding(false);
@@ -184,6 +218,7 @@ public class QSPanel extends LinearLayout implements Tunable {
        }
        addView(view, 0);
        mBrightnessView = view;
        mAutoBrightnessView = view.findViewById(R.id.brightness_icon);

        setBrightnessViewMargin();

@@ -319,13 +354,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.QSFragmentModule.QS_USING_MEDIA_PLAYER;

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

@@ -39,7 +40,8 @@ import com.android.systemui.settings.brightness.BrightnessMirrorHandler;
import com.android.systemui.settings.brightness.BrightnessSliderController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.BrightnessMirrorController;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;

import javax.inject.Inject;
import javax.inject.Named;
@@ -50,7 +52,6 @@ import javax.inject.Named;
@QSScope
public class QSPanelController extends QSPanelControllerBase<QSPanel> {

    private final TunerService mTunerService;
    private final QSCustomizerController mQsCustomizerController;
    private final QSTileRevealController.Factory mQsTileRevealControllerFactory;
    private final FalsingManager mFalsingManager;
@@ -71,7 +72,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,
@@ -83,7 +84,6 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
            StatusBarKeyguardViewManager statusBarKeyguardViewManager) {
        super(view, qsHost, qsCustomizerController, usingMediaPlayer, mediaHost,
                metricsLogger, uiEventLogger, qsLogger, dumpManager);
        mTunerService = tunerService;
        mQsCustomizerController = qsCustomizerController;
        mQsTileRevealControllerFactory = qsTileRevealControllerFactory;
        mFalsingManager = falsingManager;
@@ -112,7 +112,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();
        if (mView.isListening()) {
            refreshAllTiles();
@@ -131,7 +144,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {

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