sm6150-common: parts: Adapt to S style
* Use Theme.SubSettingsBase for theme * Replace PreferenceActivity with CollapsingToolbarBaseActivity * Add Titles to prefernce screen * Remove onOptionsItemSelected and where neccessary move to activity Change-Id: I25f6dce7cf202487898facfa66e57ced86a85594
This commit is contained in:
parent
81eed3a59a
commit
ffc917c1e3
@ -48,7 +48,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".doze.DozeSettingsActivity"
|
android:name=".doze.DozeSettingsActivity"
|
||||||
android:label="@string/ambient_display_title"
|
android:label="@string/ambient_display_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" />
|
||||||
|
@ -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>
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
|
<!-- Ambient settings -->
|
||||||
|
<string name="ambient_enable">Use ambient display</string>
|
||||||
|
|
||||||
<string name="doze_brightness_title">Always on brightness</string>
|
<string name="doze_brightness_title">Always on brightness</string>
|
||||||
<string name="doze_brightness_summary">%s mode is enabled</string>
|
<string name="doze_brightness_summary">%s mode is enabled</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -15,7 +15,14 @@
|
|||||||
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.MainSwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="doze_enable"
|
||||||
|
android:title="@string/ambient_enable" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="always_on_display"
|
android:key="always_on_display"
|
||||||
|
@ -18,9 +18,11 @@
|
|||||||
package org.lineageos.settings.doze;
|
package org.lineageos.settings.doze;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
|
|
||||||
public class DozeSettingsActivity extends PreferenceActivity {
|
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
|
||||||
|
import com.android.settingslib.collapsingtoolbar.R;
|
||||||
|
|
||||||
|
public class DozeSettingsActivity extends CollapsingToolbarBaseActivity {
|
||||||
private static final String TAG_DOZE = "doze";
|
private static final String TAG_DOZE = "doze";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,7 +31,7 @@ public class DozeSettingsActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
getFragmentManager()
|
getFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(android.R.id.content, new DozeSettingsFragment(), TAG_DOZE)
|
.replace(R.id.content_frame, new DozeSettingsFragment(), TAG_DOZE)
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package org.lineageos.settings.doze;
|
package org.lineageos.settings.doze;
|
||||||
|
|
||||||
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;
|
||||||
@ -27,13 +26,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
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.Switch;
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||||
@ -41,13 +34,15 @@ import androidx.preference.PreferenceCategory;
|
|||||||
import androidx.preference.PreferenceFragment;
|
import androidx.preference.PreferenceFragment;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
import org.lineageos.settings.R;
|
import org.lineageos.settings.R;
|
||||||
import org.lineageos.settings.utils.FileUtils;
|
import org.lineageos.settings.utils.FileUtils;
|
||||||
|
|
||||||
public class DozeSettingsFragment extends PreferenceFragment
|
public class DozeSettingsFragment extends PreferenceFragment
|
||||||
implements OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
|
implements OnPreferenceChangeListener, OnMainSwitchChangeListener {
|
||||||
private TextView mTextView;
|
private MainSwitchPreference mSwitchBar;
|
||||||
private View mSwitchBar;
|
|
||||||
|
|
||||||
private SwitchPreference mAlwaysOnDisplayPreference;
|
private SwitchPreference mAlwaysOnDisplayPreference;
|
||||||
private ListPreference mDozeBrightnessPreference;
|
private ListPreference mDozeBrightnessPreference;
|
||||||
@ -61,8 +56,6 @@ public class DozeSettingsFragment extends PreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
addPreferencesFromResource(R.xml.doze_settings);
|
addPreferencesFromResource(R.xml.doze_settings);
|
||||||
final ActionBar actionBar = getActivity().getActionBar();
|
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
|
|
||||||
SharedPreferences prefs =
|
SharedPreferences prefs =
|
||||||
getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
|
getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
|
||||||
@ -72,6 +65,10 @@ public class DozeSettingsFragment extends PreferenceFragment
|
|||||||
|
|
||||||
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());
|
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());
|
||||||
|
|
||||||
|
mSwitchBar = (MainSwitchPreference) findPreference(DozeUtils.DOZE_ENABLE);
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.setChecked(dozeEnabled);
|
||||||
|
|
||||||
mAlwaysOnDisplayPreference = (SwitchPreference) findPreference(DozeUtils.ALWAYS_ON_DISPLAY);
|
mAlwaysOnDisplayPreference = (SwitchPreference) findPreference(DozeUtils.ALWAYS_ON_DISPLAY);
|
||||||
mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
|
mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
|
||||||
mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity()));
|
mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity()));
|
||||||
@ -126,36 +123,6 @@ public class DozeSettingsFragment 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 = DozeUtils.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 (DozeUtils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
|
if (DozeUtils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
|
||||||
@ -184,12 +151,11 @@ public class DozeSettingsFragment extends PreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
DozeUtils.enableDoze(getActivity(), isChecked);
|
DozeUtils.enableDoze(getActivity(), isChecked);
|
||||||
DozeUtils.checkDozeService(getActivity());
|
DozeUtils.checkDozeService(getActivity());
|
||||||
|
|
||||||
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
|
mSwitchBar.setChecked(isChecked);
|
||||||
mSwitchBar.setActivated(isChecked);
|
|
||||||
|
|
||||||
if (!isChecked) {
|
if (!isChecked) {
|
||||||
DozeUtils.enableAlwaysOn(getActivity(), false);
|
DozeUtils.enableAlwaysOn(getActivity(), false);
|
||||||
@ -209,15 +175,6 @@ public class DozeSettingsFragment 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class HelpDialogFragment extends DialogFragment {
|
private static class HelpDialogFragment extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
@ -43,6 +43,7 @@ public final class DozeUtils {
|
|||||||
|
|
||||||
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
|
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
|
||||||
|
|
||||||
|
protected static final String DOZE_ENABLE = "doze_enable";
|
||||||
protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
|
protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
|
||||||
protected static final String DOZE_BRIGHTNESS_KEY = "doze_brightness";
|
protected static final String DOZE_BRIGHTNESS_KEY = "doze_brightness";
|
||||||
protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
|
protected static final String WAKE_ON_GESTURE_KEY = "wake_on_gesture";
|
||||||
|
Loading…
Reference in New Issue
Block a user