+++ /dev/null
-<?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>
-
<?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"
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;
@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()));
}
}
- @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())) {
}
@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);
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;
- }
}