diff options
| author | TheScarastic <warabhishek@gmail.com> | 2021-10-06 07:25:13 +0000 |
|---|---|---|
| committer | Bruno Martins <bgcngm@gmail.com> | 2022-02-15 14:20:03 +0000 |
| commit | d0f72b11001839c5074e8bf3adf947467be6e79c (patch) | |
| tree | 15bdf11d5ee21ff1edb73e4dca433e658ae175db | |
| parent | 689e9f46918ac962e8cd4ead5639059ff4bec67e (diff) | |
pro1: doze: Adapt to S style
* Use Theme.SubSettingsBase for theme
* Replace PreferenceActivity with CollapsingToolbarBaseActivity
* Add Titles to preference screen
* Remove onOptionsItemSelected and where necessary move to activity
Change-Id: I87af15f5e165aa7bcd556eb2b716c0ce624ca4e7
| -rw-r--r-- | doze/AndroidManifest.xml | 2 | ||||
| -rw-r--r-- | doze/res/layout/doze.xml | 28 | ||||
| -rw-r--r-- | doze/res/xml/doze_settings.xml | 15 | ||||
| -rw-r--r-- | doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java | 10 | ||||
| -rw-r--r-- | doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java | 66 | ||||
| -rw-r--r-- | doze/src/org/lineageos/settings/doze/Utils.java | 4 |
6 files changed, 35 insertions, 90 deletions
diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml index 7ecf978..f880f70 100644 --- a/doze/AndroidManifest.xml +++ b/doze/AndroidManifest.xml @@ -48,7 +48,7 @@ <activity android:name=".DozeSettingsActivity" android:label="@string/ambient_display_title" - android:theme="@style/Theme.Main"> + android:theme="@style/Theme.SubSettingsBase"> <intent-filter> <action android:name="org.lineageos.settings.device.DOZE_SETTINGS" /> <category android:name="android.intent.category.DEFAULT" /> diff --git a/doze/res/layout/doze.xml b/doze/res/layout/doze.xml deleted file mode 100644 index 941cdf6..0000000 --- a/doze/res/layout/doze.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* -** Copyright 2014, The Android Open Source 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. -*/ ---> - -<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> - diff --git a/doze/res/xml/doze_settings.xml b/doze/res/xml/doze_settings.xml index 21f5d09..da95bac 100644 --- a/doze/res/xml/doze_settings.xml +++ b/doze/res/xml/doze_settings.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2015 The CyanogenMod Project - 2018-2019 The LineageOS Project + 2018-2019,2021 The LineageOS Project Licensed under the Apache License, Version 2.0 (the "License" you may not use this file except in compliance with the License. @@ -15,7 +15,18 @@ See the License for the specific language governing permissions and 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.TopIntroPreference + android:key="doze_top_intro" + android:title="@string/ambient_display_enable_summary"/> + + <com.android.settingslib.widget.MainSwitchPreference + android:defaultValue="false" + android:key="doze_enable" + android:title="@string/ambient_display_enable_title" /> <SwitchPreference android:key="always_on_display" diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java b/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java index 1591b2c..213f0b4 100644 --- a/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java +++ b/doze/src/org/lineageos/settings/doze/DozeSettingsActivity.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2015-2016 The CyanogenMod Project - * 2017 The LineageOS Project + * 2017,2021 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,11 @@ package org.lineageos.settings.doze; import android.os.Bundle; -import android.preference.PreferenceActivity; -public class DozeSettingsActivity extends PreferenceActivity { +import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; +import com.android.settingslib.collapsingtoolbar.R; + +public class DozeSettingsActivity extends CollapsingToolbarBaseActivity { private static final String TAG_DOZE = "doze"; @@ -28,7 +30,7 @@ public class DozeSettingsActivity extends PreferenceActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getFragmentManager().beginTransaction().replace(android.R.id.content, + getFragmentManager().beginTransaction().replace(R.id.content_frame, new DozeSettingsFragment(), TAG_DOZE).commit(); } } diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java index df98037..954ae28 100644 --- a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java +++ b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2015 The CyanogenMod Project - * 2017-2019 The LineageOS Project + * 2017-2019,2021 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.lineageos.settings.doze; -import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -27,24 +26,20 @@ import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; -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.TextView; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragment; import androidx.preference.SwitchPreference; +import com.android.settingslib.widget.MainSwitchPreference; +import com.android.settingslib.widget.OnMainSwitchChangeListener; + public class DozeSettingsFragment extends PreferenceFragment - implements CompoundButton.OnCheckedChangeListener, Preference.OnPreferenceChangeListener { + implements OnMainSwitchChangeListener, Preference.OnPreferenceChangeListener { - private TextView mTextView; - private View mSwitchBar; + private MainSwitchPreference mSwitchBar; private SwitchPreference mAlwaysOnDisplayPreference; @@ -56,8 +51,6 @@ public class DozeSettingsFragment extends PreferenceFragment @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.doze_settings); - final ActionBar actionBar = getActivity().getActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE); @@ -67,6 +60,10 @@ public class DozeSettingsFragment extends PreferenceFragment boolean dozeEnabled = Utils.isDozeEnabled(getActivity()); + mSwitchBar = (MainSwitchPreference) findPreference(Utils.DOZE_ENABLE); + mSwitchBar.addOnSwitchChangeListener(this); + mSwitchBar.setChecked(dozeEnabled); + mAlwaysOnDisplayPreference = (SwitchPreference) findPreference(Utils.ALWAYS_ON_DISPLAY); mAlwaysOnDisplayPreference.setEnabled(dozeEnabled); mAlwaysOnDisplayPreference.setChecked(Utils.isAlwaysOnEnabled(getActivity())); @@ -100,35 +97,6 @@ public class DozeSettingsFragment extends PreferenceFragment } @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 public boolean onPreferenceChange(Preference preference, Object newValue) { if (Utils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) { Utils.enableAlwaysOn(getActivity(), (Boolean) newValue); @@ -140,12 +108,11 @@ public class DozeSettingsFragment extends PreferenceFragment } @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { + public void onSwitchChanged(Switch switchView, boolean isChecked) { Utils.enableDoze(getActivity(), isChecked); Utils.checkDozeService(getActivity()); - mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); - mSwitchBar.setActivated(isChecked); + mSwitchBar.setChecked(isChecked); if (!isChecked) { Utils.enableAlwaysOn(getActivity(), false); @@ -157,15 +124,6 @@ public class DozeSettingsFragment extends PreferenceFragment mPocketPreference.setEnabled(isChecked); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - getActivity().onBackPressed(); - return true; - } - return false; - } - private static class HelpDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java index a4b6fb9..7bb66ea 100644 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ b/doze/src/org/lineageos/settings/doze/Utils.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2015 The CyanogenMod Project - * 2017-2019 The LineageOS Project + * 2017-2019,2021 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,8 @@ public final class Utils { private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; + protected static final String DOZE_ENABLE = "doze_enable"; + protected static final String ALWAYS_ON_DISPLAY = "always_on_display"; protected static final String CATEG_TILT_SENSOR = "tilt_sensor"; |
