Settings: Port brightness slider changes [2/2]

Change-Id: I3e895f214a04b8509397eadbde1d1043c481788a
diff --git a/res/values/leaf_arrays.xml b/res/values/leaf_arrays.xml
index 10fa78c..8ca7931 100644
--- a/res/values/leaf_arrays.xml
+++ b/res/values/leaf_arrays.xml
@@ -15,6 +15,29 @@
      limitations under the License.
 -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <!-- QS brightness slider -->
+    <string-array name="qs_brightness_slider_entries" translatable="false">
+        <item>@string/qs_brightness_slider_never</item>
+        <item>@string/qs_brightness_slider_expanded</item>
+        <item>@string/qs_brightness_slider_always</item>
+    </string-array>
+
+    <string-array name="qs_brightness_slider_values" translatable="false">
+        <item>0</item>
+        <item>1</item>
+        <item>2</item>
+    </string-array>
+
+    <string-array name="qs_brightness_slider_position_entries" translatable="false">
+        <item>@string/qs_brightness_slider_position_top</item>
+        <item>@string/qs_brightness_slider_position_bottom</item>
+    </string-array>
+
+    <string-array name="qs_brightness_slider_position_values" translatable="false">
+        <item>0</item>
+        <item>1</item>
+    </string-array>
+
     <!-- QS tile shape -->
     <string-array name="qs_tile_shape_entries">
         <item>@string/qs_tile_round</item>
@@ -22,7 +45,6 @@
         <item>@string/qs_tile_mix</item>
     </string-array>
 
-
     <string-array name="qs_tile_shape_values">
         <item>0</item>
         <item>1</item>
diff --git a/res/values/leaf_strings.xml b/res/values/leaf_strings.xml
index a9c9d2f..da3696c 100644
--- a/res/values/leaf_strings.xml
+++ b/res/values/leaf_strings.xml
@@ -33,9 +33,9 @@
    <!-- Hide power menu on lockscreen -->
     <string name="hide_powermenu_lockscreen">Hide power menu on lockscreen</string>
 
-    <!-- QS panel -->
+    <!-- QS customization -->
     <string name="qs_panel_options_title">Quick settings</string>
-    <string name="qs_panel_options_summary">Customize quick settings tiles</string>
+    <string name="qs_panel_options_summary">Customize quick settings appearance</string>
     <string name="category_name_qs_tiles">QS tiles</string>
 
     <!-- QS tile shape -->
@@ -43,4 +43,18 @@
     <string name="qs_tile_round">Round</string>
     <string name="qs_tile_rect">Rounded Rectangle</string>
     <string name="qs_tile_mix">Round for active tiles and Rounded Rectangle for inactive tiles</string>
+
+    <!-- QS brightness slider -->
+    <string name="category_name_qs_brightness_slider">Brightness slider</string>
+    <string name="qs_brightness_slider_title">Brightness slider</string>
+    <string name="qs_brightness_slider_summary">Adjust brightness slider from the Quick Settings</string>
+    <string name="qs_brightness_slider_never">Never show</string>
+    <string name="qs_brightness_slider_expanded">Show when expanded</string>
+    <string name="qs_brightness_slider_always">Show always</string>
+    <string name="qs_brightness_slider_position_title">Brightness slider position</string>
+    <string name="qs_brightness_slider_position_top">Top</string>
+    <string name="qs_brightness_slider_position_bottom">Bottom</string>
+    <!-- QS auto brightness icon -->
+    <string name="qs_auto_brightness_title">Auto brightness icon</string>
+    <string name="qs_auto_brightness_summary">Show toggle for adaptive brightness near the slider</string>
 </resources>
diff --git a/res/xml/qs_panel_settings.xml b/res/xml/qs_panel_settings.xml
index a86084b..f43034b 100644
--- a/res/xml/qs_panel_settings.xml
+++ b/res/xml/qs_panel_settings.xml
@@ -21,6 +21,30 @@
     android:title="@string/qs_panel_options_title">
 
     <PreferenceCategory
+        android:title="@string/category_name_qs_brightness_slider">
+
+        <com.android.settings.support.SecureSettingListPreference
+            android:key="qs_show_brightness_slider"
+            android:title="@string/qs_brightness_slider_title"
+            android:entries="@array/qs_brightness_slider_entries"
+            android:entryValues="@array/qs_brightness_slider_values"
+            android:defaultValue="1" />
+
+        <com.android.settings.support.SecureSettingListPreference
+            android:key="qs_brightness_slider_position"
+            android:title="@string/qs_brightness_slider_position_title"
+            android:entries="@array/qs_brightness_slider_position_entries"
+            android:entryValues="@array/qs_brightness_slider_position_values"
+            android:defaultValue="0" />
+
+        <com.android.settings.support.SecureSettingSwitchPreference
+            android:key="qs_show_auto_brightness"
+            android:title="@string/qs_auto_brightness_title"
+            android:summary="@string/qs_auto_brightness_summary"
+            android:defaultValue="true" />
+    </PreferenceCategory>
+
+    <PreferenceCategory
         android:title="@string/category_name_qs_tiles">
 
         <com.android.settings.support.SecureSettingListPreference
diff --git a/src/org/leafos/settings/qs/QSPanelSettings.java b/src/org/leafos/settings/qs/QSPanelSettings.java
index 0be5684..21e95ea 100644
--- a/src/org/leafos/settings/qs/QSPanelSettings.java
+++ b/src/org/leafos/settings/qs/QSPanelSettings.java
@@ -16,6 +16,10 @@
 
 package org.leafos.settings.qs;
 
+import android.os.Bundle;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
 import com.android.settings.R;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -24,9 +28,26 @@
 @SearchIndexable
 public class QSPanelSettings extends DashboardFragment {
 
+    private static final String KEY_QS_SHOW_AUTO_BRIGHTNESS = "qs_show_auto_brightness";
     private static final String TAG = "QSPanelSettings";
 
     @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        PreferenceScreen preferenceScreen = getPreferenceScreen();
+        Preference qsShowAutoBrightnessPreference = preferenceScreen.findPreference(KEY_QS_SHOW_AUTO_BRIGHTNESS);
+
+        if (qsShowAutoBrightnessPreference != null) {
+            boolean automaticBrightnessAvailable = getContext().getResources().getBoolean(
+                    com.android.internal.R.bool.config_automatic_brightness_available);
+            if (!automaticBrightnessAvailable) {
+                qsShowAutoBrightnessPreference.setVisible(false);
+            }
+        }
+    }
+
+    @Override
     public int getMetricsCategory() {
         return METRICS_CATEGORY_UNKNOWN;
     }