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: Ic879ce61d83a33da12829008a4336c8a23230d63
Signed-off-by: SamarV-121 <samarvispute121@pm.me>
Signed-off-by: Bruno Martins <bgcngm@gmail.com>
tirimbino
TheScarastic 3 years ago committed by Bruno Martins
parent 7b58426dbc
commit ba14751917
  1. 2
      doze/AndroidManifest.xml
  2. 28
      doze/res/layout/doze.xml
  3. 15
      doze/res/xml/gesture_panel.xml
  4. 8
      doze/src/org/lineageos/settings/doze/SamsungDozeActivity.java
  5. 66
      doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
  6. 2
      doze/src/org/lineageos/settings/doze/Utils.java

@ -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" />

@ -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>

@ -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.
@ -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"

@ -16,16 +16,18 @@
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();
}
}

@ -17,28 +17,24 @@
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;
}
}

@ -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";

Loading…
Cancel
Save