doze: Adapt to S style
authorTheScarastic <warabhishek@gmail.com>
Wed, 6 Oct 2021 07:25:13 +0000 (07:25 +0000)
committerBruno Martins <bgcngm@gmail.com>
Thu, 13 Jan 2022 21:59:42 +0000 (22:59 +0100)
 * Use Theme.SubSettingsBase for theme
 * Replace PreferenceActivity with CollapsingToolbarBaseActivity
 * Add Titles to preference screen
 * Remove onOptionsItemSelected and where necessary move to activity

Change-Id: Ic879ce61d83a33da12829008a4336c8a23230d63
Signed-off-by: SamarV-121 <samarvispute121@pm.me>
Signed-off-by: Bruno Martins <bgcngm@gmail.com>
doze/AndroidManifest.xml
doze/res/layout/doze.xml [deleted file]
doze/res/xml/gesture_panel.xml
doze/src/org/lineageos/settings/doze/SamsungDozeActivity.java
doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
doze/src/org/lineageos/settings/doze/Utils.java

index 8e33bce786d29cc9cf75ef702d2d73849d8ba3ef..5d04b01845c185d7ee26a5fdb511f39af0c5c590 100644 (file)
@@ -32,7 +32,7 @@
         <activity
             android:name=".SamsungDozeActivity"
             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 (file)
index 941cdf6..0000000
+++ /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>
-
index e59de9c326c7bfe12f6f7f8c6d2cadb78c67e8af..e747d99606ad6a2b58fde7d05dc5d77d52fc8a61 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
      Copyright (C) 2015 The CyanogenMod Project
-                   2018-2019 The LineageOS Project
+                   2018-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.
      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"
index a7230548957322b55134a7e5814a9d0503649442..df518d973d8384eac6b4519e47ba824dd7b4c5ea 100644 (file)
 package org.lineageos.settings.doze;
 
 import android.os.Bundle;
-import android.preference.PreferenceActivity;
 
-public class SamsungDozeActivity extends PreferenceActivity {
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
+import com.android.settingslib.collapsingtoolbar.R;
+
+public class SamsungDozeActivity extends CollapsingToolbarBaseActivity {
 
     private static final String TAG = "samsung_doze";
 
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        getFragmentManager().beginTransaction().replace(android.R.id.content,
+        getFragmentManager().beginTransaction().replace(R.id.content_frame,
                 new SamsungDozeSettings(), TAG).commit();
     }
 }
index aaddb0caee5c966ee76e0ae723af5b18ddb3af9f..d452464595c804a336693c9435f8872ce98fd4b6 100644 (file)
 
 package org.lineageos.settings.doze;
 
-import android.app.ActionBar;
 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.Preference.OnPreferenceChangeListener;
 import androidx.preference.PreferenceFragment;
 import androidx.preference.SwitchPreference;
 
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
 import org.lineageos.internal.util.ScreenType;
 
 public class SamsungDozeSettings extends PreferenceFragment
-        implements CompoundButton.OnCheckedChangeListener, Preference.OnPreferenceChangeListener {
+        implements OnPreferenceChangeListener, OnMainSwitchChangeListener {
 
-    private TextView mTextView;
-    private View mSwitchBar;
+    private MainSwitchPreference mSwitchBar;
 
     private SwitchPreference mAlwaysOnDisplayPreference;
     private SwitchPreference mHandwavePreference;
@@ -50,11 +46,13 @@ public class SamsungDozeSettings extends PreferenceFragment
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         addPreferencesFromResource(R.xml.gesture_panel);
-        final ActionBar actionBar = getActivity().getActionBar();
-        actionBar.setDisplayHomeAsUpEnabled(true);
 
         boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
 
+        mSwitchBar = (MainSwitchPreference) findPreference(Utils.DOZE_ENABLE);
+        mSwitchBar.addOnSwitchChangeListener(this);
+        mSwitchBar.setChecked(dozeEnabled);
+
         mAlwaysOnDisplayPreference = findPreference(Utils.ALWAYS_ON_DISPLAY);
         mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
         mAlwaysOnDisplayPreference.setChecked(Utils.isAlwaysOnEnabled(getActivity()));
@@ -92,36 +90,6 @@ public class SamsungDozeSettings 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())) {
@@ -134,12 +102,11 @@ public class SamsungDozeSettings 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);
@@ -151,13 +118,4 @@ public class SamsungDozeSettings extends PreferenceFragment
         mPocketPreference.setEnabled(isChecked);
         mWakeOnGesturePreference.setEnabled(isChecked);
     }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        if (item.getItemId() == android.R.id.home) {
-            getActivity().onBackPressed();
-            return true;
-        }
-        return false;
-    }
 }
index 9478c89bd9d75b944d50c2816ed3b7f10257c180..1b78bed8d69a9bc4ef605f6f119fe7c7cd7dd59b 100644 (file)
@@ -35,7 +35,7 @@ public final class Utils {
     private static final boolean DEBUG = false;
 
     protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
-
+    protected static final String DOZE_ENABLE = "doze_enable";
     protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
     protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
     protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";