sdm660-common: DeviceDoze: Adapt to S style

* Use Theme.SubSettingsBase for theme
     * Replace PreferenceActivity with CollapsingToolbarBaseActivity
     * Remove onOptionsItemSelected and where neccessary move to activity

Co-authored-by: pix106 <sbordenave@gmail.com>
Signed-off-by: pix106 <sbordenave@gmail.com>
This commit is contained in:
TheScarastic 2021-12-04 10:09:23 +01:00 committed by pix106
parent 97dbafb607
commit 467ccc1c47
10 changed files with 26 additions and 199 deletions

View file

@ -15,7 +15,6 @@ android_app {
privileged: true, privileged: true,
static_libs: [ static_libs: [
"androidx.preference_preference",
"org.lineageos.settings.resources", "org.lineageos.settings.resources",
], ],

View file

@ -51,7 +51,7 @@
android:name=".DozeSettingsActivity" android:name=".DozeSettingsActivity"
android:exported="false" android:exported="false"
android:label="@string/ambient_display_title" android:label="@string/ambient_display_title"
android:theme="@style/Theme.Main"> android:theme="@style/Theme.SubSettingsBase">
<intent-filter> <intent-filter>
<action android:name="com.android.settings.action.IA_SETTINGS" /> <action android:name="com.android.settings.action.IA_SETTINGS" />
</intent-filter> </intent-filter>

View file

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018-2020 The Xiaomi-SDM660 Project
https://github.com/xiaomi-sdm660
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<include layout="@layout/switch_bar" />
</LinearLayout>

View file

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018-2020 The Xiaomi-SDM660 Project
https://github.com/xiaomi-sdm660
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switch_bar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@drawable/switchbar_background"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:clickable="true"
android:gravity="center">
<TextView android:id="@+id/switch_text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:paddingStart="56dp"
android:maxLines="2"
android:ellipsize="end"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textSize="16sp"
android:textAlignment="viewStart" />
<Switch
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@null"
android:theme="@style/Theme.Main.SwitchBar.Switch" />
</LinearLayout>

View file

@ -28,6 +28,7 @@
<!-- Ambient Display --> <!-- Ambient Display -->
<string name="ambient_display_title">Ambient Display</string> <string name="ambient_display_title">Ambient Display</string>
<string name="ambient_enable">Enable</string>
<!-- Tilt sensor --> <!-- Tilt sensor -->
<string name="tilt_sensor_title">Tilt Sensor Gestures</string> <string name="tilt_sensor_title">Tilt Sensor Gestures</string>

View file

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018-2020 The Xiaomi-SDM660 Project
https://github.com/xiaomi-sdm660
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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<style name="Theme.Main" parent="@android:style/Theme.DeviceDefault.Settings">
<item name="dialogPreferenceStyle">@style/Theme.Main.DialogPreferenceStyle</item>
<item name="preferenceCategoryStyle">@style/Theme.Main.PreferenceCategoryStyle</item>
<item name="preferenceFragmentStyle">@style/Theme.Main.PreferenceFragmentStyle</item>
<item name="preferenceStyle">@style/Theme.Main.PreferenceStyle</item>
<item name="preferenceTheme">@style/Theme.Main.PreferenceTheme</item>
<item name="switchPreferenceStyle">@style/Theme.Main.SwitchPreferenceStyle</item>
</style>
<style name="Theme.Main.DialogPreferenceStyle" parent="@style/Theme.Main.PreferenceStyle">
</style>
<style name="Theme.Main.PreferenceCategoryStyle" parent="@*android:style/Preference.DeviceDefault.Category">
<item name="allowDividerAbove">true</item>
<item name="allowDividerBelow">true</item>
<item name="android:layout">@layout/preference_category_material_settings</item>
</style>
<style name="Theme.Main.PreferenceFragmentStyle" parent="@*android:style/PreferenceFragment.Material">
<item name="allowDividerAfterLastItem">false</item>
</style>
<style name="Theme.Main.PreferenceStyle" parent="@*android:style/Preference.DeviceDefault">
<item name="allowDividerAbove">false</item>
<item name="allowDividerBelow">true</item>
<item name="singleLineTitle">false</item>
<item name="android:layout">@layout/preference_material_settings</item>
</style>
<style name="Theme.Main.PreferenceTheme">
</style>
<style name="Theme.Main.SwitchPreferenceStyle" parent="@style/Theme.Main.PreferenceStyle">
<item name="widgetLayout">@*android:layout/preference_widget_switch</item>
</style>
<style name="Theme.Main.SwitchBar" parent="@android:style/ThemeOverlay.Material.ActionBar">
</style>
<style name="Theme.Main.SwitchBar.Switch">
<item name="android:trackTint">@color/switchbar_switch_track_tint</item>
<item name="android:thumbTint">@color/switchbar_switch_thumb_tint</item>
</style>
</resources>

View file

@ -16,7 +16,14 @@
limitations under the License. limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/ambient_display_title">
<com.android.settingslib.widget.MainSwitchPreference
android:defaultValue="false"
android:key="doze_enable"
android:title="@string/ambient_enable" />
<PreferenceCategory <PreferenceCategory
android:key="tilt_sensor" android:key="tilt_sensor"

View file

@ -19,9 +19,10 @@
package com.advanced.settings.doze; package com.advanced.settings.doze;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
import com.android.settingslib.collapsingtoolbar.R;
public class DozeSettingsActivity extends PreferenceActivity { public class DozeSettingsActivity extends CollapsingToolbarBaseActivity {
private static final String TAG_DOZE = "doze"; private static final String TAG_DOZE = "doze";
@ -29,7 +30,7 @@ public class DozeSettingsActivity extends PreferenceActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, getFragmentManager().beginTransaction().replace(R.id.content_frame,
new DozeSettingsFragment(), TAG_DOZE).commit(); new DozeSettingsFragment(), TAG_DOZE).commit();
} }
} }

View file

@ -18,7 +18,6 @@
package com.advanced.settings.doze; package com.advanced.settings.doze;
import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -31,19 +30,15 @@ import androidx.preference.SwitchPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.Preference.OnPreferenceChangeListener; import androidx.preference.Preference.OnPreferenceChangeListener;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView;
import com.android.settingslib.widget.MainSwitchPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener, public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener,
CompoundButton.OnCheckedChangeListener { OnMainSwitchChangeListener {
private TextView mTextView; private MainSwitchPreference mSwitchBar;
private View mSwitchBar;
private SwitchPreference mPickUpPreference; private SwitchPreference mPickUpPreference;
private SwitchPreference mRaiseToWakePreference; private SwitchPreference mRaiseToWakePreference;
@ -53,8 +48,6 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.doze_settings); addPreferencesFromResource(R.xml.doze_settings);
final ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings", SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings",
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
@ -64,6 +57,10 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
boolean dozeEnabled = Utils.isDozeEnabled(getActivity()); boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
mSwitchBar = (MainSwitchPreference) findPreference(Utils.DOZE_ENABLE);
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.setChecked(dozeEnabled);
PreferenceCategory proximitySensorCategory = PreferenceCategory proximitySensorCategory =
(PreferenceCategory) getPreferenceScreen().findPreference(Utils.CATEG_PROX_SENSOR); (PreferenceCategory) getPreferenceScreen().findPreference(Utils.CATEG_PROX_SENSOR);
@ -97,35 +94,6 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
} }
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false);
((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
mTextView = view.findViewById(R.id.switch_text);
mTextView.setText(getString(dozeEnabled ?
R.string.switch_bar_on : R.string.switch_bar_off));
mSwitchBar = view.findViewById(R.id.switch_bar);
Switch switchWidget = mSwitchBar.findViewById(android.R.id.switch_widget);
switchWidget.setChecked(dozeEnabled);
switchWidget.setOnCheckedChangeListener(this);
mSwitchBar.setActivated(dozeEnabled);
mSwitchBar.setOnClickListener(v -> {
switchWidget.setChecked(!switchWidget.isChecked());
mSwitchBar.setActivated(switchWidget.isChecked());
});
}
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue); Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
@ -138,12 +106,11 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
} }
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { public void onSwitchChanged(Switch switchView, boolean isChecked) {
Utils.enableDoze(getActivity(), isChecked); Utils.enableDoze(getActivity(), isChecked);
Utils.checkDozeService(getActivity()); Utils.checkDozeService(getActivity());
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); mSwitchBar.setChecked(isChecked);
mSwitchBar.setActivated(isChecked);
mPickUpPreference.setEnabled(isChecked); mPickUpPreference.setEnabled(isChecked);
mRaiseToWakePreference.setEnabled(isChecked); mRaiseToWakePreference.setEnabled(isChecked);
@ -151,15 +118,6 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
mPocketPreference.setEnabled(isChecked); mPocketPreference.setEnabled(isChecked);
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
getActivity().onBackPressed();
return true;
}
return false;
}
public static class HelpDialogFragment extends DialogFragment { public static class HelpDialogFragment extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {

View file

@ -37,6 +37,7 @@ public final class Utils {
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
protected static final String DOZE_ENABLE = "doze_enable";
protected static final String CATEG_PROX_SENSOR = "proximity_sensor"; protected static final String CATEG_PROX_SENSOR = "proximity_sensor";
protected static final String CATEG_TILT_SENSOR = "tilt_sensor"; protected static final String CATEG_TILT_SENSOR = "tilt_sensor";