Settings: Add settings to change QS column count [2/2]
Change-Id: I01ee97fb58f9cf1a0b74f44c1494d68571660ba4
diff --git a/res/values/leaf_strings.xml b/res/values/leaf_strings.xml
index ab66e0f..9d4dd59 100644
--- a/res/values/leaf_strings.xml
+++ b/res/values/leaf_strings.xml
@@ -72,6 +72,20 @@
<string name="qs_style_default">Large pill</string>
<string name="qs_style_round">Small circle</string>
+ <!-- QS columns customization -->
+ <string name="qs_columns">QS columns in portrait</string>
+ <string name="qs_columns_min" translatable="false">2</string>
+ <string name="qs_columns_max" translatable="false">5</string>
+ <string name="qs_columns_landscape">QS columns in landscape</string>
+ <string name="qs_columns_landscape_min" translatable="false">@string/qs_columns_min</string>
+ <string name="qs_columns_landscape_max" translatable="false">6</string>
+ <string name="qqs_columns">QQS columns in portrait</string>
+ <string name="qqs_columns_min" translatable="false">@string/qs_columns_min</string>
+ <string name="qqs_columns_max" translatable="false">@string/qs_columns_max</string>
+ <string name="qqs_columns_landscape">QQS columns in landscape</string>
+ <string name="qqs_columns_landscape_min" translatable="false">@string/qs_columns_landscape_min</string>
+ <string name="qqs_columns_landscape_max" translatable="false">@string/qs_columns_landscape_max</string>
+
<!-- Annoying Notifications -->
<string name="notification_sound_vib_screen_on_title">Annoying Notifications</string>
<string name="notification_sound_vib_screen_on_summary">Play sound and vibration for notifications when screen is on</string>
diff --git a/res/xml/qs_panel_settings.xml b/res/xml/qs_panel_settings.xml
index a85f72f..e7d6d15 100644
--- a/res/xml/qs_panel_settings.xml
+++ b/res/xml/qs_panel_settings.xml
@@ -67,5 +67,41 @@
android:entries="@array/qs_tile_shape_entries"
android:entryValues="@array/qs_tile_shape_values"
android:defaultValue="2" />
+
+ <com.android.settings.support.SecureSettingSeekBarPreference
+ android:key="qqs_num_columns"
+ android:title="@string/qqs_columns"
+ android:min="@string/qqs_columns_min"
+ android:max="@string/qqs_columns_max"
+ android:defaultValue="5"
+ settings:textStart="@string/qqs_columns_min"
+ settings:textEnd="@string/qqs_columns_max" />
+
+ <com.android.settings.support.SecureSettingSeekBarPreference
+ android:key="qqs_num_columns_landscape"
+ android:title="@string/qqs_columns_landscape"
+ android:min="@string/qqs_columns_landscape_min"
+ android:max="@string/qqs_columns_landscape_max"
+ android:defaultValue="6"
+ settings:textStart="@string/qqs_columns_landscape_min"
+ settings:textEnd="@string/qqs_columns_landscape_max" />
+
+ <com.android.settings.support.SecureSettingSeekBarPreference
+ android:key="qs_num_columns"
+ android:title="@string/qs_columns"
+ android:min="@string/qs_columns_min"
+ android:max="@string/qs_columns_max"
+ android:defaultValue="4"
+ settings:textStart="@string/qs_columns_min"
+ settings:textEnd="@string/qs_columns_max" />
+
+ <com.android.settings.support.SecureSettingSeekBarPreference
+ android:key="qs_num_columns_landscape"
+ android:title="@string/qs_columns_landscape"
+ android:min="@string/qs_columns_landscape_min"
+ android:max="@string/qs_columns_landscape_max"
+ android:defaultValue="6"
+ settings:textStart="@string/qs_columns_landscape_min"
+ settings:textEnd="@string/qs_columns_landscape_max" />
</PreferenceCategory>
</PreferenceScreen>
diff --git a/src/com/android/settings/support/SecureSettingSeekBarPreference.java b/src/com/android/settings/support/SecureSettingSeekBarPreference.java
new file mode 100644
index 0000000..94f218d
--- /dev/null
+++ b/src/com/android/settings/support/SecureSettingSeekBarPreference.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2023 The LeafOS 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.settings.support;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import com.android.settings.widget.LabeledSeekBarPreference;
+
+public class SecureSettingSeekBarPreference extends LabeledSeekBarPreference {
+
+ public SecureSettingSeekBarPreference(Context context, AttributeSet attrs, int defStyle,
+ int defStyleRes) {
+ super(context, attrs, defStyle, defStyleRes);
+ setPreferenceDataStore(new SecureSettingsStore(context.getContentResolver()));
+ }
+
+ public SecureSettingSeekBarPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setPreferenceDataStore(new SecureSettingsStore(context.getContentResolver()));
+ }
+
+ public SecureSettingSeekBarPreference(Context context) {
+ super(context, null);
+ setPreferenceDataStore(new SecureSettingsStore(context.getContentResolver()));
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
+ setProgress(restoreValue ? getPersistedInt((Integer) defaultValue) : (Integer) defaultValue);
+ }
+}
diff --git a/src/org/leafos/settings/qs/QSPanelSettings.java b/src/org/leafos/settings/qs/QSPanelSettings.java
index 21e95ea..155081a 100644
--- a/src/org/leafos/settings/qs/QSPanelSettings.java
+++ b/src/org/leafos/settings/qs/QSPanelSettings.java
@@ -17,6 +17,8 @@
package org.leafos.settings.qs;
import android.os.Bundle;
+import android.os.UserHandle;
+import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -30,6 +32,9 @@
private static final String KEY_QS_SHOW_AUTO_BRIGHTNESS = "qs_show_auto_brightness";
private static final String TAG = "QSPanelSettings";
+ private static final String[] qsCustPreferences = { "qs_tile_shape",
+ "qqs_num_columns", "qqs_num_columns_landscape",
+ "qs_num_columns", "qs_num_columns_landscape" };
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -45,6 +50,18 @@
qsShowAutoBrightnessPreference.setVisible(false);
}
}
+
+ boolean qsStyleRound = Settings.Secure.getIntForUser(getContext().getContentResolver(),
+ Settings.Secure.QS_STYLE_ROUND, 1, UserHandle.USER_CURRENT) == 1;
+
+ if (!qsStyleRound) {
+ for (String key : qsCustPreferences) {
+ Preference preference = preferenceScreen.findPreference(key);
+ if (preference != null) {
+ preference.setEnabled(false);
+ }
+ }
+ }
}
@Override