diff --git a/res/layout/qs_tile_apply_change_button.xml b/res/layout/qs_tile_apply_change_button.xml
new file mode 100644
index 0000000..8eaad8c
--- /dev/null
+++ b/res/layout/qs_tile_apply_change_button.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml
index 87eea4d..0ba2086 100644
--- a/res/values/cherish_strings.xml
+++ b/res/values/cherish_strings.xml
@@ -611,23 +611,21 @@
Reflected
Surround
ThinLine
-
-
- Tile layout
- Title Alignment
- Enable for centered layout.
-
-
- Hide tile titles
- Toggle to hide tile titles
-
- Tiles layout
- Hide label
- Only show icon in tile
- Label text size
- Columns (portrait)
- Columns (landscape)
+
+ Quick Settings layout
+ QS tiles layout
+ Customize tiles layout in QS panel
+ Tiles layout
+ Rows (Portrait)
+ Rows (Quick QS portrait)
+ Columns (Portrait)
+ Apply change
+ Failed to apply change
+ Hide labels
+ Show only icon for QS tiles
+ Vertical layout
+ Enable vertical layout for QS tiles
Power menu animation
diff --git a/res/xml/cherish_settings_quicksettings.xml b/res/xml/cherish_settings_quicksettings.xml
index 92bbb2b..eeadf09 100644
--- a/res/xml/cherish_settings_quicksettings.xml
+++ b/res/xml/cherish_settings_quicksettings.xml
@@ -96,43 +96,12 @@
android:key="qs_layout_category"
android:title="@string/qs_layout_category_title">
-
-
-
-
-
-
-
-
-
-
+
diff --git a/res/xml/qs_tile_layout.xml b/res/xml/qs_tile_layout.xml
new file mode 100644
index 0000000..5fc20d4
--- /dev/null
+++ b/res/xml/qs_tile_layout.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/cherish/settings/fragments/QsTileLayoutSettings.java b/src/com/cherish/settings/fragments/QsTileLayoutSettings.java
new file mode 100644
index 0000000..c5a6805
--- /dev/null
+++ b/src/com/cherish/settings/fragments/QsTileLayoutSettings.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2022 The Nameless-AOSP 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.cherish.settings.fragments;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Toast;
+
+import androidx.preference.Preference;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.internal.util.systemui.qs.QSLayoutUtils;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import com.android.settingslib.widget.LayoutPreference;
+
+import com.cherish.settings.preferences.CustomSeekBarPreference;
+import com.cherish.settings.preferences.SystemSettingSwitchPreference;
+
+public class QsTileLayoutSettings extends SettingsPreferenceFragment
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_QS_HIDE_LABEL = "qs_tile_label_hide";
+ private static final String KEY_QS_VERTICAL_LAYOUT = "qs_tile_vertical_layout";
+ private static final String KEY_QS_COLUMN_PORTRAIT = "qs_layout_columns";
+ private static final String KEY_QS_ROW_PORTRAIT = "qs_layout_rows";
+ private static final String KEY_QQS_ROW_PORTRAIT = "qqs_layout_rows";
+ private static final String KEY_APPLY_CHANGE_BUTTON = "apply_change_button";
+
+ private Context mContext;
+
+ private CustomSeekBarPreference mQsColumns;
+ private CustomSeekBarPreference mQsRows;
+ private CustomSeekBarPreference mQqsRows;
+
+ private Button mApplyChange;
+
+ private SystemSettingSwitchPreference mHide;
+ private SystemSettingSwitchPreference mVertical;
+
+ private int[] currentValue = new int[2];
+
+ @Override
+ public void onCreate(Bundle savedInstance) {
+ super.onCreate(savedInstance);
+ addPreferencesFromResource(R.xml.qs_tile_layout);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ mQsColumns = (CustomSeekBarPreference) findPreference(KEY_QS_COLUMN_PORTRAIT);
+ mQsColumns.setOnPreferenceChangeListener(this);
+
+ mQsRows = (CustomSeekBarPreference) findPreference(KEY_QS_ROW_PORTRAIT);
+ mQsRows.setOnPreferenceChangeListener(this);
+
+ mQqsRows = (CustomSeekBarPreference) findPreference(KEY_QQS_ROW_PORTRAIT);
+ mQqsRows.setOnPreferenceChangeListener(this);
+
+ mContext = getContext();
+
+ LayoutPreference preference = findPreference(KEY_APPLY_CHANGE_BUTTON);
+ mApplyChange = (Button) preference.findViewById(R.id.apply_change);
+ mApplyChange.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mApplyChange.isEnabled()) {
+ final int[] newValue = {
+ mQsRows.getValue() * 10 + mQsColumns.getValue(),
+ mQqsRows.getValue() * 10 + mQsColumns.getValue()
+ };
+ Settings.System.putIntForUser(getContentResolver(),
+ Settings.System.QS_LAYOUT, newValue[0], UserHandle.USER_CURRENT);
+ Settings.System.putIntForUser(getContentResolver(),
+ Settings.System.QQS_LAYOUT, newValue[1], UserHandle.USER_CURRENT);
+ if (QSLayoutUtils.updateLayout(mContext)) {
+ currentValue[0] = newValue[0];
+ currentValue[1] = newValue[1];
+ mApplyChange.setEnabled(false);
+ } else {
+ Settings.System.putIntForUser(getContentResolver(),
+ Settings.System.QS_LAYOUT, currentValue[0], UserHandle.USER_CURRENT);
+ Settings.System.putIntForUser(getContentResolver(),
+ Settings.System.QQS_LAYOUT, currentValue[1], UserHandle.USER_CURRENT);
+ Toast.makeText(mContext, R.string.qs_apply_change_failed, Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+ });
+
+ initPreference();
+
+ final boolean hideLabel = Settings.System.getIntForUser(getContentResolver(),
+ Settings.System.QS_TILE_LABEL_HIDE, 0, UserHandle.USER_CURRENT) == 1;
+
+ mHide = (SystemSettingSwitchPreference) findPreference(KEY_QS_HIDE_LABEL);
+ mHide.setOnPreferenceChangeListener(this);
+
+ mVertical = (SystemSettingSwitchPreference) findPreference(KEY_QS_VERTICAL_LAYOUT);
+ mVertical.setEnabled(!hideLabel);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mHide) {
+ boolean hideLabel = (Boolean) newValue;
+ mVertical.setEnabled(!hideLabel);
+ } else if (preference == mQsColumns) {
+ int qs_columns = Integer.parseInt(newValue.toString());
+ mApplyChange.setEnabled(
+ currentValue[0] != mQsRows.getValue() * 10 + qs_columns ||
+ currentValue[1] != mQqsRows.getValue() * 10 + qs_columns
+ );
+ } else if (preference == mQsRows) {
+ int qs_rows = Integer.parseInt(newValue.toString());
+ mQqsRows.setMax(qs_rows - 1);
+ if (mQqsRows.getValue() > qs_rows - 1) {
+ mQqsRows.setValue(qs_rows - 1);
+ }
+ mApplyChange.setEnabled(
+ currentValue[0] != qs_rows * 10 + mQsColumns.getValue() ||
+ currentValue[1] != mQqsRows.getValue() * 10 + mQsColumns.getValue()
+ );
+ } else if (preference == mQqsRows) {
+ int qqs_rows = Integer.parseInt(newValue.toString());
+ mApplyChange.setEnabled(
+ currentValue[0] != mQsRows.getValue() * 10 + mQsColumns.getValue() ||
+ currentValue[1] != qqs_rows * 10 + mQsColumns.getValue()
+ );
+ }
+ return true;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
+ }
+
+ private void initPreference() {
+ final int index_qs = Settings.System.getIntForUser(getContentResolver(),
+ Settings.System.QS_LAYOUT, 42, UserHandle.USER_CURRENT);
+ final int index_qqs = Settings.System.getIntForUser(getContentResolver(),
+ Settings.System.QQS_LAYOUT, 22, UserHandle.USER_CURRENT);
+ mQsColumns.setValue(index_qs % 10);
+ mQsRows.setValue(index_qs / 10);
+ mQqsRows.setValue(index_qqs / 10);
+ mQqsRows.setMax(mQsRows.getValue() - 1);
+ currentValue[0] = index_qs;
+ currentValue[1] = index_qqs;
+ }
+}