Skip to content

Commit

Permalink
doze: Adapt to S style
Browse files Browse the repository at this point in the history
 * 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>
  • Loading branch information
TheScarastic authored and bgcngm committed Jan 13, 2022
1 parent 7b58426 commit ba14751
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 89 deletions.
2 changes: 1 addition & 1 deletion doze/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
28 changes: 0 additions & 28 deletions doze/res/layout/doze.xml

This file was deleted.

15 changes: 13 additions & 2 deletions doze/res/xml/gesture_panel.xml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions doze/src/org/lineageos/settings/doze/SamsungDozeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
66 changes: 12 additions & 54 deletions doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
Expand Down Expand Up @@ -92,36 +90,6 @@ public void onResume() {
}
}

@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())) {
Expand All @@ -134,12 +102,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}

@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);
Expand All @@ -151,13 +118,4 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
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;
}
}
2 changes: 1 addition & 1 deletion doze/src/org/lineageos/settings/doze/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit ba14751

Please sign in to comment.