MotoActions: 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

Co-authored-by: Erfan Abdi <erfangplus@gmail.com>
Change-Id: I87af15f5e165aa7bcd556eb2b716c0ce624ca4e7
This commit is contained in:
TheScarastic 2021-10-06 07:25:13 +00:00 committed by dianlujitao
parent 8a96ebc5a1
commit 860266e24f
9 changed files with 43 additions and 102 deletions

View File

@ -37,7 +37,7 @@
android:name=".DozePreferenceActivity" android:name=".DozePreferenceActivity"
android:exported="false" android:exported="false"
android:label="@string/ambient_display_gestures_title" android:label="@string/ambient_display_gestures_title"
android:theme="@style/Theme.Main"> android:theme="@style/Theme.SubSettingsBase">
<intent-filter> <intent-filter>
<action android:name="org.lineageos.settings.device.DOZE_SETTINGS" /> <action android:name="org.lineageos.settings.device.DOZE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
@ -48,7 +48,7 @@
android:name=".ActionsPreferenceActivity" android:name=".ActionsPreferenceActivity"
android:exported="false" android:exported="false"
android:label="@string/moto_gestures_panel_title" android:label="@string/moto_gestures_panel_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,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>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
Copyright (C) 2015-2016 The CyanogenMod Project 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" Licensed under the Apache License, Version 2.0 (the "License"
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -15,11 +15,12 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
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/actions_title">
<PreferenceCategory <PreferenceCategory
android:key="actions_key" android:key="actions_key">
android:title="@string/actions_title">
<SwitchPreference <SwitchPreference
android:key="gesture_camera_action" android:key="gesture_camera_action"

View File

@ -14,7 +14,18 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
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.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 <SwitchPreference
android:key="always_on_display" android:key="always_on_display"

View File

@ -18,16 +18,18 @@
package org.lineageos.settings.device; package org.lineageos.settings.device;
import android.os.Bundle; 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getFragmentManager() getFragmentManager()
.beginTransaction() .beginTransaction()
.replace(android.R.id.content, new ActionsPreferenceFragment()) .replace(R.id.content_frame, new ActionsPreferenceFragment())
.commit(); .commit();
} }
} }

View File

@ -17,7 +17,6 @@
package org.lineageos.settings.device; package org.lineageos.settings.device;
import android.app.ActionBar;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
@ -34,8 +33,6 @@ public class ActionsPreferenceFragment extends PreferenceFragment {
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.actions_panel); addPreferencesFromResource(R.xml.actions_panel);
final ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if (!CameraActivationSensor.hasSensor(getContext())) { if (!CameraActivationSensor.hasSensor(getContext())) {
PreferenceCategory category = findPreference(KEY_ACTIONS_CATEGORY); PreferenceCategory category = findPreference(KEY_ACTIONS_CATEGORY);

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2016 The CyanogenMod Project * 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,9 +18,11 @@
package org.lineageos.settings.device; package org.lineageos.settings.device;
import android.os.Bundle; 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"; private static final String TAG_DOZE = "doze";
@ -29,7 +31,7 @@ public class DozePreferenceActivity extends PreferenceActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getFragmentManager() getFragmentManager()
.beginTransaction() .beginTransaction()
.replace(android.R.id.content, new DozePreferenceFragment(), TAG_DOZE) .replace(R.id.content_frame, new DozePreferenceFragment(), TAG_DOZE)
.commit(); .commit();
} }
} }

View File

@ -17,7 +17,6 @@
package org.lineageos.settings.device; package org.lineageos.settings.device;
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;
@ -25,25 +24,20 @@ import android.app.DialogFragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; 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.Switch;
import android.widget.TextView;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragment; import androidx.preference.PreferenceFragment;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
public class DozePreferenceFragment extends PreferenceFragment import com.android.settingslib.widget.MainSwitchPreference;
implements OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener { import com.android.settingslib.widget.OnMainSwitchChangeListener;
private TextView mTextView; public class DozePreferenceFragment extends PreferenceFragment
private View mSwitchBar; implements Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
private MainSwitchPreference mSwitchBar;
private SwitchPreference mAlwaysOnDisplayPreference; private SwitchPreference mAlwaysOnDisplayPreference;
@ -54,8 +48,6 @@ public class DozePreferenceFragment extends PreferenceFragment
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.doze_panel); addPreferencesFromResource(R.xml.doze_panel);
final ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
SharedPreferences prefs = SharedPreferences prefs =
getActivity().getSharedPreferences("doze_panel", Activity.MODE_PRIVATE); getActivity().getSharedPreferences("doze_panel", Activity.MODE_PRIVATE);
@ -65,6 +57,10 @@ public class DozePreferenceFragment extends PreferenceFragment
boolean dozeEnabled = MotoActionsSettings.isDozeEnabled(getActivity()); boolean dozeEnabled = MotoActionsSettings.isDozeEnabled(getActivity());
mSwitchBar = (MainSwitchPreference) findPreference(MotoActionsSettings.DOZE_ENABLE);
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.setChecked(dozeEnabled);
mAlwaysOnDisplayPreference = findPreference(MotoActionsSettings.ALWAYS_ON_DISPLAY); mAlwaysOnDisplayPreference = findPreference(MotoActionsSettings.ALWAYS_ON_DISPLAY);
mAlwaysOnDisplayPreference.setEnabled(dozeEnabled); mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
mAlwaysOnDisplayPreference.setChecked(MotoActionsSettings.isAlwaysOnEnabled(getActivity())); 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 @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (MotoActionsSettings.ALWAYS_ON_DISPLAY.equals(preference.getKey())) { if (MotoActionsSettings.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
@ -132,11 +97,10 @@ public class DozePreferenceFragment extends PreferenceFragment
} }
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { public void onSwitchChanged(Switch switchView, boolean isChecked) {
MotoActionsSettings.enableDoze(getActivity(), isChecked); MotoActionsSettings.enableDoze(getActivity(), isChecked);
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); mSwitchBar.setChecked(isChecked);
mSwitchBar.setActivated(isChecked);
if (!isChecked) { if (!isChecked) {
MotoActionsSettings.enableAlwaysOn(getActivity(), false); MotoActionsSettings.enableAlwaysOn(getActivity(), false);
@ -149,15 +113,6 @@ public class DozePreferenceFragment extends PreferenceFragment
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

@ -43,6 +43,7 @@ public class MotoActionsSettings {
static final String GESTURE_PICK_UP_KEY = "gesture_pick_up"; static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
static final String GESTURE_POCKET_KEY = "gesture_pocket"; static final String GESTURE_POCKET_KEY = "gesture_pocket";
static final String DOZE_ENABLE = "doze_enable";
static final String ALWAYS_ON_DISPLAY = "always_on_display"; static final String ALWAYS_ON_DISPLAY = "always_on_display";
private final Context mContext; private final Context mContext;