MotoActions: Adapt to S style lineage-19.0
authorTheScarastic <warabhishek@gmail.com>
Wed, 6 Oct 2021 07:25:13 +0000 (07:25 +0000)
committerdianlujitao <dianlujitao@lineageos.org>
Wed, 16 Feb 2022 15:23:41 +0000 (23:23 +0800)
 * Use Theme.SubSettingsBase for theme
 * Replace PreferenceActivity with CollapsingToolbarBaseActivity
 * Add Titles to preference screen
 * Remove onOptionsItemSelected and where necessary move to activity

Co-authored-by: Erfan Abdi <erfangplus@gmail.com>
Change-Id: I87af15f5e165aa7bcd556eb2b716c0ce624ca4e7

MotoActions/AndroidManifest.xml
MotoActions/res/layout/doze.xml [deleted file]
MotoActions/res/xml/actions_panel.xml
MotoActions/res/xml/doze_panel.xml
MotoActions/src/org/lineageos/settings/device/ActionsPreferenceActivity.java
MotoActions/src/org/lineageos/settings/device/ActionsPreferenceFragment.java
MotoActions/src/org/lineageos/settings/device/DozePreferenceActivity.java
MotoActions/src/org/lineageos/settings/device/DozePreferenceFragment.java
MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java

index 5d206d998b258d3a073f67edfc639770fb3d714a..5ae8f644332563d0cd510cc24c6bac04399c7aa8 100644 (file)
@@ -37,7 +37,7 @@
             android:name=".DozePreferenceActivity"
             android:exported="false"
             android:label="@string/ambient_display_gestures_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" />
@@ -48,7 +48,7 @@
             android:name=".ActionsPreferenceActivity"
             android:exported="false"
             android:label="@string/moto_gestures_panel_title"
-            android:theme="@style/Theme.Main">
+            android:theme="@style/Theme.SubSettingsBase">
             <intent-filter>
                 <action android:name="com.android.settings.action.IA_SETTINGS" />
             </intent-filter>
diff --git a/MotoActions/res/layout/doze.xml b/MotoActions/res/layout/doze.xml
deleted file mode 100644 (file)
index e9f3c0f..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:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
-
-    <include layout="@layout/switch_bar" />
-
-</LinearLayout>
-
index f366ea48540af3dd2fd8bbcb5e74bceb123cf103..c4ced85a027c8b16e8a153c99b41d144310c3693 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
      Copyright (C) 2015-2016 The CyanogenMod Project
-     Copyright (C) 2017 The LineageOS Project
+     Copyright (C) 2017,2022 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/actions_title">
 
     <PreferenceCategory
-        android:key="actions_key"
-        android:title="@string/actions_title">
+        android:key="actions_key">
 
         <SwitchPreference
             android:key="gesture_camera_action"
index 628810fbbe8161c2b7228e22f82050601adca53d..08333b87e85c619467f54810b3da7c6485b6cd49 100644 (file)
      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 2bb86efdd7118302b5e91c0522cc54340cb264c7..809b26ba7ed03bff39307c433066dd3c00927b89 100644 (file)
 package org.lineageos.settings.device;
 
 import android.os.Bundle;
-import android.preference.PreferenceActivity;
 
-public class ActionsPreferenceActivity extends PreferenceActivity {
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
+import com.android.settingslib.collapsingtoolbar.R;
+
+public class ActionsPreferenceActivity extends CollapsingToolbarBaseActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         getFragmentManager()
                 .beginTransaction()
-                .replace(android.R.id.content, new ActionsPreferenceFragment())
+                .replace(R.id.content_frame, new ActionsPreferenceFragment())
                 .commit();
     }
 }
index 7ee570c3a3c4b05d3fe3755f024aa1a3126ed689..ea83bb165523852fd793f0c9dfca02ee6db9cbea 100644 (file)
@@ -17,7 +17,6 @@
 
 package org.lineageos.settings.device;
 
-import android.app.ActionBar;
 import android.os.Bundle;
 import android.view.MenuItem;
 
@@ -34,8 +33,6 @@ public class ActionsPreferenceFragment extends PreferenceFragment {
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         addPreferencesFromResource(R.xml.actions_panel);
-        final ActionBar actionBar = getActivity().getActionBar();
-        actionBar.setDisplayHomeAsUpEnabled(true);
 
         if (!CameraActivationSensor.hasSensor(getContext())) {
             PreferenceCategory category = findPreference(KEY_ACTIONS_CATEGORY);
index aad612606aa1b0e67582d9d1c5dac901433556e6..8332ab4c9a6ead035c68c5fde45afdb0df9d8da7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2015-2016 The CyanogenMod Project
- *               2017 The LineageOS Project
+ *               2017,2022 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.
 package org.lineageos.settings.device;
 
 import android.os.Bundle;
-import android.preference.PreferenceActivity;
 
-public class DozePreferenceActivity extends PreferenceActivity {
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
+import com.android.settingslib.collapsingtoolbar.R;
+
+public class DozePreferenceActivity extends CollapsingToolbarBaseActivity {
 
     private static final String TAG_DOZE = "doze";
 
@@ -29,7 +31,7 @@ public class DozePreferenceActivity extends PreferenceActivity {
         super.onCreate(savedInstanceState);
         getFragmentManager()
                 .beginTransaction()
-                .replace(android.R.id.content, new DozePreferenceFragment(), TAG_DOZE)
+                .replace(R.id.content_frame, new DozePreferenceFragment(), TAG_DOZE)
                 .commit();
     }
 }
index 58f22afa3a715ef0a1b408064b189d385ee69472..525019c0711f4cf859e4e4ecce57e6676a748cd4 100644 (file)
@@ -17,7 +17,6 @@
 
 package org.lineageos.settings.device;
 
-import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
@@ -25,25 +24,20 @@ import android.app.DialogFragment;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.os.Bundle;
-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.PreferenceCategory;
 import androidx.preference.PreferenceFragment;
 import androidx.preference.SwitchPreference;
 
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
 public class DozePreferenceFragment extends PreferenceFragment
-        implements OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
+        implements Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
 
-    private TextView mTextView;
-    private View mSwitchBar;
+    private MainSwitchPreference mSwitchBar;
 
     private SwitchPreference mAlwaysOnDisplayPreference;
 
@@ -54,8 +48,6 @@ public class DozePreferenceFragment extends PreferenceFragment
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         addPreferencesFromResource(R.xml.doze_panel);
-        final ActionBar actionBar = getActivity().getActionBar();
-        actionBar.setDisplayHomeAsUpEnabled(true);
 
         SharedPreferences prefs =
                 getActivity().getSharedPreferences("doze_panel", Activity.MODE_PRIVATE);
@@ -65,6 +57,10 @@ public class DozePreferenceFragment extends PreferenceFragment
 
         boolean dozeEnabled = MotoActionsSettings.isDozeEnabled(getActivity());
 
+        mSwitchBar = (MainSwitchPreference) findPreference(MotoActionsSettings.DOZE_ENABLE);
+        mSwitchBar.addOnSwitchChangeListener(this);
+        mSwitchBar.setChecked(dozeEnabled);
+
         mAlwaysOnDisplayPreference = findPreference(MotoActionsSettings.ALWAYS_ON_DISPLAY);
         mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
         mAlwaysOnDisplayPreference.setChecked(MotoActionsSettings.isAlwaysOnEnabled(getActivity()));
@@ -91,37 +87,6 @@ public class DozePreferenceFragment 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 = MotoActionsSettings.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 (MotoActionsSettings.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
@@ -132,11 +97,10 @@ public class DozePreferenceFragment extends PreferenceFragment
     }
 
     @Override
-    public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+    public void onSwitchChanged(Switch switchView, boolean isChecked) {
         MotoActionsSettings.enableDoze(getActivity(), isChecked);
 
-        mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
-        mSwitchBar.setActivated(isChecked);
+        mSwitchBar.setChecked(isChecked);
 
         if (!isChecked) {
             MotoActionsSettings.enableAlwaysOn(getActivity(), false);
@@ -149,15 +113,6 @@ public class DozePreferenceFragment extends PreferenceFragment
         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 {
         @Override
         public Dialog onCreateDialog(Bundle savedInstanceState) {
index d1e2e50076b126ffa97d1aa6b34392043acf927a..5f654fd73ef45d3a841a70047066288e01d38436 100644 (file)
@@ -43,6 +43,7 @@ public class MotoActionsSettings {
     static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
     static final String GESTURE_POCKET_KEY = "gesture_pocket";
 
+    static final String DOZE_ENABLE = "doze_enable";
     static final String ALWAYS_ON_DISPLAY = "always_on_display";
 
     private final Context mContext;