Cherish: Refactor qs tiles layout fragment
Signed-off-by: cjh1249131356 <cjh1249131356@gmail.com> Signed-off-by: minaripenguin <minaripenguin@users.noreply.github.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
20
res/layout/qs_tile_apply_change_button.xml
Normal file
20
res/layout/qs_tile_apply_change_button.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/apply_change"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="20dp"
|
||||
android:enabled="false"
|
||||
android:text="@string/qs_apply_change_button_title"
|
||||
android:textAllCaps="false"
|
||||
style="@style/ActionPrimaryButton" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -611,23 +611,21 @@
|
||||
<string name="qs_reflected">Reflected</string>
|
||||
<string name="qs_surround">Surround</string>
|
||||
<string name="qs_thin">ThinLine</string>
|
||||
|
||||
<!-- QS tiles layout direction: vertical or horizontal -->
|
||||
<string name="qs_tile_layout_category_title">Tile layout</string>
|
||||
<string name="qs_tile_layout_title">Title Alignment</string>
|
||||
<string name="qs_tile_layout_summary">Enable for centered layout.</string>
|
||||
|
||||
<!-- QS tiles title visibility -->
|
||||
<string name="qs_tile_title_visibility_title">Hide tile titles</string>
|
||||
<string name="qs_tile_title_visibility_summary">Toggle to hide tile titles</string>
|
||||
|
||||
<!-- QS tiles layout -->
|
||||
<string name="qs_layout_category_title">Tiles layout</string>
|
||||
<string name="qs_tile_label_hide_title">Hide label</string>
|
||||
<string name="qs_tile_label_hide_summary">Only show icon in tile</string>
|
||||
<string name="qs_tile_label_size_title">Label text size</string>
|
||||
<string name="qs_columns_portrait_title">Columns (portrait)</string>
|
||||
<string name="qs_columns_landscape_title">Columns (landscape)</string>
|
||||
<!-- QS tiles layout -->
|
||||
<string name="qs_layout_category_title">Quick Settings layout</string>
|
||||
<string name="qs_tile_layout_title">QS tiles layout</string>
|
||||
<string name="qs_tile_layout_summary">Customize tiles layout in QS panel</string>
|
||||
<string name="qs_tiles_layout_category">Tiles layout</string>
|
||||
<string name="qs_rows_portrait_title">Rows (Portrait)</string>
|
||||
<string name="qqs_rows_portrait_title">Rows (Quick QS portrait)</string>
|
||||
<string name="qs_columns_portrait_title">Columns (Portrait)</string>
|
||||
<string name="qs_apply_change_button_title">Apply change</string>
|
||||
<string name="qs_apply_change_failed">Failed to apply change</string>
|
||||
<string name="qs_tile_hide_label_title">Hide labels</string>
|
||||
<string name="qs_tile_hide_label_summary">Show only icon for QS tiles</string>
|
||||
<string name="qs_tile_vertical_layout_title">Vertical layout</string>
|
||||
<string name="qs_tile_vertical_layout_summary">Enable vertical layout for QS tiles</string>
|
||||
|
||||
<!-- Power menu Animations -->
|
||||
<string name="power_menu_animation_title">Power menu animation</string>
|
||||
|
||||
@@ -96,43 +96,12 @@
|
||||
android:key="qs_layout_category"
|
||||
android:title="@string/qs_layout_category_title">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="qs_tile_label_hide"
|
||||
android:title="@string/qs_tile_label_hide_title"
|
||||
android:summary="@string/qs_tile_label_hide_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="qs_tile_label_size"
|
||||
android:title="@string/qs_tile_label_size_title"
|
||||
android:max="15"
|
||||
settings:min="10"
|
||||
settings:interval="1"
|
||||
settings:units="sp"
|
||||
android:defaultValue="14" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="qs_tile_vertical_layout"
|
||||
android:title="@string/qs_tile_layout_title"
|
||||
android:summary="@string/qs_tile_layout_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="qs_layout_columns"
|
||||
android:title="@string/qs_columns_portrait_title"
|
||||
android:max="5"
|
||||
settings:min="2"
|
||||
settings:interval="1"
|
||||
android:defaultValue="2" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="qs_layout_columns_landscape"
|
||||
android:title="@string/qs_columns_landscape_title"
|
||||
android:max="6"
|
||||
settings:min="2"
|
||||
settings:interval="1"
|
||||
android:defaultValue="4" />
|
||||
<Preference
|
||||
android:key="qs_tile_layout"
|
||||
android:icon="@drawable/ic_qs_tile"
|
||||
android:title="@string/qs_tile_layout_title"
|
||||
android:summary="@string/qs_tile_layout_summary"
|
||||
android:fragment="com.cherish.settings.fragments.QsTileLayoutSettings" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
49
res/xml/qs_tile_layout.xml
Normal file
49
res/xml/qs_tile_layout.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/qs_tile_layout_title">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="qs_tile_label_hide"
|
||||
android:title="@string/qs_tile_hide_label_title"
|
||||
android:summary="@string/qs_tile_hide_label_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="qs_tile_vertical_layout"
|
||||
android:title="@string/qs_tile_vertical_layout_title"
|
||||
android:summary="@string/qs_tile_vertical_layout_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="tiles_layout"
|
||||
android:title="@string/qs_tiles_layout_category">
|
||||
|
||||
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||
android:key="qs_layout_columns"
|
||||
android:title="@string/qs_columns_portrait_title"
|
||||
android:defaultValue="2"
|
||||
android:max="6"
|
||||
settings:min="2" />
|
||||
|
||||
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||
android:key="qs_layout_rows"
|
||||
android:title="@string/qs_rows_portrait_title"
|
||||
android:defaultValue="4"
|
||||
android:max="6"
|
||||
settings:min="2" />
|
||||
|
||||
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||
android:key="qqs_layout_rows"
|
||||
android:title="@string/qqs_rows_portrait_title"
|
||||
android:defaultValue="2"
|
||||
android:max="5"
|
||||
settings:min="1" />
|
||||
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
android:key="apply_change_button"
|
||||
android:layout="@layout/qs_tile_apply_change_button" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
171
src/com/cherish/settings/fragments/QsTileLayoutSettings.java
Normal file
171
src/com/cherish/settings/fragments/QsTileLayoutSettings.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user