From da5bdbbaca5e3daa5478fc14c55e54b10dc6afaf Mon Sep 17 00:00:00 2001 From: AdrianDC Date: Mon, 23 Oct 2017 14:38:48 -0300 Subject: [PATCH] sanders: LineageActions: Upgrade to Oreo Settings UI * Attach to appropriate Settings pages * Hide divider lines to match Settings UI styles * Apply On/Off text on the switch bar toggle * Implement AOSP Settings preference layouts for indentation * Depends on android_packages_resources_devicesettings: "DeviceSettings: Import Oreo Settings layouts" Ib3f670b19c7e728b97fd76efe04bcc2f69008b06 * Partially based upon commit "Bring DozeSettings up to date" I0850f7d9558a14f739f752f76002db993381a0e5 by Steve Kondik for the SwitchBar integration but using native themes Change-Id: Ic5b8335aafc9ce876ed90a25045398e39515e484 Signed-off-by: Adrian DC Signed-off-by: jhenrique09 --- LineageActions/AndroidManifest.xml | 14 +- .../res/drawable/ic_settings_doze.xml | 4 +- .../res/drawable/ic_settings_fingerprint.xml | 4 +- .../res/drawable/ic_settings_gestures.xml | 4 +- .../ic_settings_screen_off_gestures.xml | 4 +- .../res/drawable/switchbar_background.xml | 20 +++ LineageActions/res/layout/doze.xml | 27 ++++ LineageActions/res/layout/fp_gesture.xml | 27 ++++ LineageActions/res/layout/switch_bar.xml | 48 +++++++ LineageActions/res/values/styles.xml | 35 ++++- LineageActions/res/xml/doze_panel.xml | 12 +- LineageActions/res/xml/fp_gesture_panel.xml | 24 +--- LineageActions/res/xml/main_panel.xml | 24 ++-- .../settings/device/DozeSettings.java | 65 --------- .../settings/device/DozeSettingsActivity.java | 33 +++++ .../settings/device/DozeSettingsFragment.java | 110 +++++++++++++++ .../settings/device/FPGestureSettings.java | 58 -------- .../device/FPGestureSettingsActivity.java | 33 +++++ .../device/FPGestureSettingsFragment.java | 128 ++++++++++++++++++ .../device/GestureSettingsActivity.java | 33 +++++ ...ings.java => GestureSettingsFragment.java} | 35 ++--- .../ScreenOffGestureSettingsActivity.java | 32 +++++ ... => ScreenOffGestureSettingsFragment.java} | 35 ++--- 23 files changed, 590 insertions(+), 219 deletions(-) create mode 100644 LineageActions/res/drawable/switchbar_background.xml create mode 100644 LineageActions/res/layout/doze.xml create mode 100644 LineageActions/res/layout/fp_gesture.xml create mode 100644 LineageActions/res/layout/switch_bar.xml delete mode 100644 LineageActions/src/org/lineageos/settings/device/DozeSettings.java create mode 100644 LineageActions/src/org/lineageos/settings/device/DozeSettingsActivity.java create mode 100644 LineageActions/src/org/lineageos/settings/device/DozeSettingsFragment.java delete mode 100644 LineageActions/src/org/lineageos/settings/device/FPGestureSettings.java create mode 100644 LineageActions/src/org/lineageos/settings/device/FPGestureSettingsActivity.java create mode 100644 LineageActions/src/org/lineageos/settings/device/FPGestureSettingsFragment.java create mode 100644 LineageActions/src/org/lineageos/settings/device/GestureSettingsActivity.java rename LineageActions/src/org/lineageos/settings/device/{GestureSettings.java => GestureSettingsFragment.java} (76%) create mode 100644 LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsActivity.java rename LineageActions/src/org/lineageos/settings/device/{ScreenOffGestureSettings.java => ScreenOffGestureSettingsFragment.java} (65%) diff --git a/LineageActions/AndroidManifest.xml b/LineageActions/AndroidManifest.xml index 37de0e0..a94c1f2 100644 --- a/LineageActions/AndroidManifest.xml +++ b/LineageActions/AndroidManifest.xml @@ -14,6 +14,10 @@ + + @@ -49,7 +53,7 @@ android:summary="@string/device_gestures_summary" android:theme="@style/LineageActions"> - + diff --git a/LineageActions/res/drawable/ic_settings_doze.xml b/LineageActions/res/drawable/ic_settings_doze.xml index 1cbb485..04d2846 100644 --- a/LineageActions/res/drawable/ic_settings_doze.xml +++ b/LineageActions/res/drawable/ic_settings_doze.xml @@ -4,14 +4,14 @@ android:height="24dp" android:viewportWidth="1000.000000" android:viewportHeight="1000.000000" - android:tint="?android:attr/colorAccent"> + android:tint="?android:attr/colorControlNormal"> - + android:tint="?android:attr/colorControlNormal"> + diff --git a/LineageActions/res/drawable/ic_settings_gestures.xml b/LineageActions/res/drawable/ic_settings_gestures.xml index a49a8d7..2d74c58 100644 --- a/LineageActions/res/drawable/ic_settings_gestures.xml +++ b/LineageActions/res/drawable/ic_settings_gestures.xml @@ -19,10 +19,10 @@ android:height="24dp" android:viewportWidth="24" android:viewportHeight="24" - android:tint="?android:attr/colorAccent"> + android:tint="?android:attr/colorControlNormal"> + android:tint="?android:attr/colorControlNormal"> diff --git a/LineageActions/res/drawable/switchbar_background.xml b/LineageActions/res/drawable/switchbar_background.xml new file mode 100644 index 0000000..314ed12 --- /dev/null +++ b/LineageActions/res/drawable/switchbar_background.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/LineageActions/res/layout/doze.xml b/LineageActions/res/layout/doze.xml new file mode 100644 index 0000000..a7ce3e0 --- /dev/null +++ b/LineageActions/res/layout/doze.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/LineageActions/res/layout/fp_gesture.xml b/LineageActions/res/layout/fp_gesture.xml new file mode 100644 index 0000000..a7ce3e0 --- /dev/null +++ b/LineageActions/res/layout/fp_gesture.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/LineageActions/res/layout/switch_bar.xml b/LineageActions/res/layout/switch_bar.xml new file mode 100644 index 0000000..201920b --- /dev/null +++ b/LineageActions/res/layout/switch_bar.xml @@ -0,0 +1,48 @@ + + + + + + + + + + diff --git a/LineageActions/res/values/styles.xml b/LineageActions/res/values/styles.xml index 2c8a3d1..561c0b2 100644 --- a/LineageActions/res/values/styles.xml +++ b/LineageActions/res/values/styles.xml @@ -16,14 +16,43 @@ limitations under the License. --> + - - + + + + + + + + + + + + diff --git a/LineageActions/res/xml/doze_panel.xml b/LineageActions/res/xml/doze_panel.xml index d50cd73..6363b99 100644 --- a/LineageActions/res/xml/doze_panel.xml +++ b/LineageActions/res/xml/doze_panel.xml @@ -17,24 +17,16 @@ - - + android:summary="@string/pick_up_gesture_summary" /> + android:summary="@string/hand_wave_gesture_summary" /> diff --git a/LineageActions/res/xml/fp_gesture_panel.xml b/LineageActions/res/xml/fp_gesture_panel.xml index 63a9c84..1be62f3 100644 --- a/LineageActions/res/xml/fp_gesture_panel.xml +++ b/LineageActions/res/xml/fp_gesture_panel.xml @@ -15,31 +15,17 @@ - - - - + + - - + android:targetClass="org.lineageos.settings.device.GestureSettingsActivity" /> + - - + android:targetClass="org.lineageos.settings.device.DozeSettingsActivity" /> + - - + android:targetClass="org.lineageos.settings.device.FPGestureSettingsActivity" /> + - - + android:targetClass="org.lineageos.settings.device.ScreenOffGestureSettingsActivity" /> + diff --git a/LineageActions/src/org/lineageos/settings/device/DozeSettings.java b/LineageActions/src/org/lineageos/settings/device/DozeSettings.java deleted file mode 100644 index 4f54250..0000000 --- a/LineageActions/src/org/lineageos/settings/device/DozeSettings.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017 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. - * 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. - */ - -package org.lineageos.settings.device; - -import android.os.Bundle; -import android.preference.PreferenceActivity; -import android.provider.Settings; -import android.preference.Preference; -import android.preference.PreferenceCategory; -import android.preference.SwitchPreference; -import android.view.MenuItem; - -public class DozeSettings extends PreferenceActivity { - - - private static final String KEY_AMBIENT_DISPLAY_ENABLE = "doze_enabled"; - - private SwitchPreference mAmbientDisplayPreference; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.doze_panel); - getActionBar().setDisplayHomeAsUpEnabled(true); - boolean dozeEnabled = LineageActionsSettings.isDozeEnabled(getContentResolver()); - mAmbientDisplayPreference = (SwitchPreference) findPreference(KEY_AMBIENT_DISPLAY_ENABLE); - // Read from DOZE_ENABLED secure setting - mAmbientDisplayPreference.setChecked(dozeEnabled); - mAmbientDisplayPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - boolean enable = (boolean) newValue; - return enableDoze(enable); - } - }); - } - - private boolean enableDoze(boolean enable) { - return Settings.Secure.putInt(getContentResolver(), - Settings.Secure.DOZE_ENABLED, enable ? 1 : 0); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } -} diff --git a/LineageActions/src/org/lineageos/settings/device/DozeSettingsActivity.java b/LineageActions/src/org/lineageos/settings/device/DozeSettingsActivity.java new file mode 100644 index 0000000..2893658 --- /dev/null +++ b/LineageActions/src/org/lineageos/settings/device/DozeSettingsActivity.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 The CyanogenMod 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. + */ + +package org.lineageos.settings.device; + +import android.os.Bundle; + +import android.preference.PreferenceActivity; + +public class DozeSettingsActivity extends PreferenceActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState == null){ + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new DozeSettingsFragment()).commit(); + } + } +} diff --git a/LineageActions/src/org/lineageos/settings/device/DozeSettingsFragment.java b/LineageActions/src/org/lineageos/settings/device/DozeSettingsFragment.java new file mode 100644 index 0000000..547d803 --- /dev/null +++ b/LineageActions/src/org/lineageos/settings/device/DozeSettingsFragment.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017 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. + * 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. + */ + +package org.lineageos.settings.device; + +import android.app.ActionBar; +import android.os.Bundle; +import android.support.v14.preference.PreferenceFragment; +import android.provider.Settings; +import android.support.v7.preference.Preference; +import android.support.v14.preference.SwitchPreference; +import android.view.MenuItem; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.Switch; +import android.widget.TextView; + +public class DozeSettingsFragment extends PreferenceFragment { + + private SwitchPreference mHandwavePreference; + private SwitchPreference mPickupPreference; + + private TextView mSwitchBarText; + private Switch mAmbientDisplaySwitch; + + private String KEY_GESTURE_HAND_WAVE = "gesture_hand_wave"; + private String KEY_GESTURE_PICK_UP = "gesture_pick_up"; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + ActionBar actionbar = getActivity().getActionBar(); + actionbar.setDisplayHomeAsUpEnabled(true); + actionbar.setTitle(R.string.ambient_display_title); + } + + @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); + + View switchBar = view.findViewById(R.id.switch_bar); + mAmbientDisplaySwitch = (Switch) switchBar.findViewById(android.R.id.switch_widget); + mAmbientDisplaySwitch.setChecked(LineageActionsSettings.isDozeEnabled(getActivity().getContentResolver())); + mAmbientDisplaySwitch.setOnCheckedChangeListener(mAmbientDisplayPrefListener); + + switchBar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mAmbientDisplaySwitch.toggle(); + } + }); + + mSwitchBarText = switchBar.findViewById(R.id.switch_text); + mSwitchBarText.setText(LineageActionsSettings.isDozeEnabled(getActivity().getContentResolver()) ? R.string.switch_bar_on : + R.string.switch_bar_off); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.doze_panel); + boolean dozeEnabled = LineageActionsSettings.isDozeEnabled(getActivity().getContentResolver()); + mHandwavePreference = (SwitchPreference) findPreference(KEY_GESTURE_HAND_WAVE); + mPickupPreference = (SwitchPreference) findPreference(KEY_GESTURE_PICK_UP); + updatePrefs(dozeEnabled); + } + + private CompoundButton.OnCheckedChangeListener mAmbientDisplayPrefListener = + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean enable) { + if (enableDoze(enable)) { + updatePrefs(enable); + mSwitchBarText.setText(enable ? R.string.switch_bar_on : R.string.switch_bar_off); + } + } + }; + + private void updatePrefs(boolean enabled){ + mHandwavePreference.setEnabled(enabled); + mPickupPreference.setEnabled(enabled); + } + + private boolean enableDoze(boolean enable) { + return Settings.Secure.putInt(getActivity().getContentResolver(), + Settings.Secure.DOZE_ENABLED, enable ? 1 : 0); + } +} diff --git a/LineageActions/src/org/lineageos/settings/device/FPGestureSettings.java b/LineageActions/src/org/lineageos/settings/device/FPGestureSettings.java deleted file mode 100644 index b4a64bb..0000000 --- a/LineageActions/src/org/lineageos/settings/device/FPGestureSettings.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2016 The CyanogenMod 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. - */ - -package org.lineageos.settings.device; - -import android.os.Bundle; -import android.content.Context; -import android.preference.PreferenceCategory; -import android.preference.SwitchPreference; -import android.hardware.fingerprint.FingerprintManager; -import android.preference.PreferenceActivity; -import android.view.MenuItem; - -public class FPGestureSettings extends PreferenceActivity { - - private SwitchPreference mFPScreenOffGesture; - private PreferenceCategory mFPScreenOffCategory; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.fp_gesture_panel); - getActionBar().setDisplayHomeAsUpEnabled(true); - mFPScreenOffGesture = (SwitchPreference) findPreference("fp_home_scr_off"); - mFPScreenOffCategory = (PreferenceCategory) findPreference("fp_keys_scr_off"); - boolean hasEnrolledFingerprints = hasEnrolledFingerprints(); - mFPScreenOffGesture.setEnabled(!hasEnrolledFingerprints); - mFPScreenOffCategory.setEnabled(!hasEnrolledFingerprints); - } - - private boolean hasEnrolledFingerprints(){ - FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE); - return fingerprintManager.hasEnrolledFingerprints(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - -} diff --git a/LineageActions/src/org/lineageos/settings/device/FPGestureSettingsActivity.java b/LineageActions/src/org/lineageos/settings/device/FPGestureSettingsActivity.java new file mode 100644 index 0000000..afc424f --- /dev/null +++ b/LineageActions/src/org/lineageos/settings/device/FPGestureSettingsActivity.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 The CyanogenMod 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. + */ + +package org.lineageos.settings.device; + +import android.os.Bundle; + +import android.preference.PreferenceActivity; + +public class FPGestureSettingsActivity extends PreferenceActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState == null){ + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new FPGestureSettingsFragment()).commit(); + } + } +} diff --git a/LineageActions/src/org/lineageos/settings/device/FPGestureSettingsFragment.java b/LineageActions/src/org/lineageos/settings/device/FPGestureSettingsFragment.java new file mode 100644 index 0000000..4f6a22b --- /dev/null +++ b/LineageActions/src/org/lineageos/settings/device/FPGestureSettingsFragment.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2016 The CyanogenMod 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. + */ + +package org.lineageos.settings.device; + +import android.app.ActionBar; +import android.os.Bundle; +import android.content.Context; +import android.content.SharedPreferences.Editor; +import android.preference.PreferenceManager; +import android.support.v7.preference.PreferenceCategory; +import android.support.v14.preference.SwitchPreference; +import android.hardware.fingerprint.FingerprintManager; +import android.support.v14.preference.PreferenceFragment; +import android.view.MenuItem; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.Switch; +import android.widget.TextView; + +import org.lineageos.settings.device.actions.Constants; + +import static org.lineageos.settings.device.actions.Constants.FP_HOME_KEY; +import static org.lineageos.settings.device.actions.Constants.FP_HOME_KEY_OFF; + +public class FPGestureSettingsFragment extends PreferenceFragment { + + private SwitchPreference mFPScreenOffGesture; + private PreferenceCategory mFPScreenOffCategory; + private PreferenceCategory mFPScreenOnCategory; + + private TextView mSwitchBarText; + private Switch mFPGestureSwitch; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + ActionBar actionbar = getActivity().getActionBar(); + actionbar.setDisplayHomeAsUpEnabled(true); + actionbar.setTitle(R.string.fingerprint_gestures_title); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final View view = LayoutInflater.from(getContext()).inflate(R.layout.fp_gesture, container, false); + ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); + return view; + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + View switchBar = view.findViewById(R.id.switch_bar); + mFPGestureSwitch = (Switch) switchBar.findViewById(android.R.id.switch_widget); + mFPGestureSwitch.setChecked(isFPGestureEnabled()); + mFPGestureSwitch.setOnCheckedChangeListener(mFPGesturePrefListener); + + switchBar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mFPGestureSwitch.toggle(); + } + }); + + mSwitchBarText = switchBar.findViewById(R.id.switch_text); + mSwitchBarText.setText(isFPGestureEnabled() ? R.string.switch_bar_on : + R.string.switch_bar_off); + } + + private void updatePrefs(boolean enabled){ + Editor prefEditor = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit(); + prefEditor.putBoolean(FP_HOME_KEY, enabled); + prefEditor.apply(); + mFPScreenOnCategory.setEnabled(enabled); + mFPScreenOffGesture.setEnabled(enabled); + mFPScreenOffCategory.setEnabled(enabled); + if(enabled){ + boolean hasEnrolledFingerprints = hasEnrolledFingerprints(); + mFPScreenOffGesture.setEnabled(!hasEnrolledFingerprints); + mFPScreenOffCategory.setEnabled(!hasEnrolledFingerprints); + } + } + + private boolean isFPGestureEnabled(){ + return Constants.isPreferenceEnabled(getActivity(), FP_HOME_KEY); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.fp_gesture_panel); + mFPScreenOffGesture = (SwitchPreference) findPreference(FP_HOME_KEY_OFF); + mFPScreenOffCategory = (PreferenceCategory) findPreference("fp_keys_scr_off"); + mFPScreenOnCategory = (PreferenceCategory) findPreference("fp_keys_scr_on"); + updatePrefs(isFPGestureEnabled()); + } + + private CompoundButton.OnCheckedChangeListener mFPGesturePrefListener = + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean enable) { + updatePrefs(enable); + mSwitchBarText.setText(enable ? R.string.switch_bar_on : R.string.switch_bar_off); + } + }; + + private boolean hasEnrolledFingerprints(){ + FingerprintManager fingerprintManager = (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE); + return fingerprintManager.hasEnrolledFingerprints(); + } + +} diff --git a/LineageActions/src/org/lineageos/settings/device/GestureSettingsActivity.java b/LineageActions/src/org/lineageos/settings/device/GestureSettingsActivity.java new file mode 100644 index 0000000..40c3291 --- /dev/null +++ b/LineageActions/src/org/lineageos/settings/device/GestureSettingsActivity.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 The CyanogenMod 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. + */ + +package org.lineageos.settings.device; + +import android.os.Bundle; + +import android.preference.PreferenceActivity; + +public class GestureSettingsActivity extends PreferenceActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState == null){ + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new GestureSettingsFragment()).commit(); + } + } +} diff --git a/LineageActions/src/org/lineageos/settings/device/GestureSettings.java b/LineageActions/src/org/lineageos/settings/device/GestureSettingsFragment.java similarity index 76% rename from LineageActions/src/org/lineageos/settings/device/GestureSettings.java rename to LineageActions/src/org/lineageos/settings/device/GestureSettingsFragment.java index f92f167..c4f7ecf 100644 --- a/LineageActions/src/org/lineageos/settings/device/GestureSettings.java +++ b/LineageActions/src/org/lineageos/settings/device/GestureSettingsFragment.java @@ -22,32 +22,36 @@ import android.os.Bundle; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.preference.PreferenceActivity; -import android.preference.PreferenceCategory; -import android.preference.Preference; -import android.preference.Preference.OnPreferenceClickListener; -import android.preference.SwitchPreference; +import android.support.v14.preference.PreferenceFragment; +import android.support.v7.preference.PreferenceCategory; +import android.support.v7.preference.Preference; +import android.support.v7.preference.Preference.OnPreferenceClickListener; +import android.support.v14.preference.SwitchPreference; import android.view.MenuItem; -public class GestureSettings extends PreferenceActivity { +public class GestureSettingsFragment extends PreferenceFragment { private SwitchPreference mFlipPref; private NotificationManager mNotificationManager; private boolean mFlipClick = false; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.actions_panel); - getActionBar().setDisplayHomeAsUpEnabled(true); - mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE); mFlipPref = (SwitchPreference) findPreference("gesture_flip_to_mute"); mFlipPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { if (!mNotificationManager.isNotificationPolicyAccessGranted()) { mFlipPref.setChecked(false); - new AlertDialog.Builder(GestureSettings.this) + new AlertDialog.Builder(getActivity()) .setTitle(getString(R.string.flip_to_mute_title)) .setMessage(getString(R.string.dnd_access)) .setNegativeButton(android.R.string.cancel, null) @@ -77,13 +81,4 @@ public class GestureSettings extends PreferenceActivity { } } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - } diff --git a/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsActivity.java b/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsActivity.java new file mode 100644 index 0000000..f2c886a --- /dev/null +++ b/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsActivity.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 The CyanogenMod 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. + */ + +package org.lineageos.settings.device; + +import android.os.Bundle; + +import android.preference.PreferenceActivity; + +public class ScreenOffGestureSettingsActivity extends PreferenceActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState == null){ + getFragmentManager().beginTransaction() + .replace(android.R.id.content, new ScreenOffGestureSettingsFragment()).commit(); + } + } +} diff --git a/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettings.java b/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsFragment.java similarity index 65% rename from LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettings.java rename to LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsFragment.java index 107c914..cf98eba 100644 --- a/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettings.java +++ b/LineageActions/src/org/lineageos/settings/device/ScreenOffGestureSettingsFragment.java @@ -18,54 +18,49 @@ package org.lineageos.settings.device; import android.os.Bundle; import android.provider.Settings; -import android.preference.Preference; -import android.preference.SwitchPreference; -import android.preference.PreferenceActivity; +import android.support.v7.preference.Preference; +import android.support.v14.preference.SwitchPreference; +import android.support.v14.preference.PreferenceFragment; import android.view.MenuItem; import static android.provider.Settings.Secure.DOUBLE_TAP_TO_WAKE; import static org.lineageos.settings.device.actions.Constants.KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK; -public class ScreenOffGestureSettings extends PreferenceActivity { +public class ScreenOffGestureSettingsFragment extends PreferenceFragment { private SwitchPreference mTapToWake; private SwitchPreference mHapticFeedback; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.screen_off_gesture_panel); - getActionBar().setDisplayHomeAsUpEnabled(true); mTapToWake = (SwitchPreference) findPreference("tap_to_wake"); - mTapToWake.setChecked(Settings.Secure.getInt(getContentResolver(), DOUBLE_TAP_TO_WAKE, 0) == 1); + mTapToWake.setChecked(Settings.Secure.getInt(getActivity().getContentResolver(), DOUBLE_TAP_TO_WAKE, 0) == 1); mTapToWake.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object objValue) { boolean value = (Boolean) objValue; - Settings.Secure.putInt(getContentResolver(), DOUBLE_TAP_TO_WAKE, value ? 1 : 0); + Settings.Secure.putInt(getActivity().getContentResolver(), DOUBLE_TAP_TO_WAKE, value ? 1 : 0); return true; } }); mHapticFeedback = (SwitchPreference) findPreference("haptic_feedback"); - mHapticFeedback.setChecked(Settings.System.getInt(getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, 1) == 1); + mHapticFeedback.setChecked(Settings.System.getInt(getActivity().getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, 1) == 1); mHapticFeedback.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object objValue) { boolean value = (Boolean) objValue; - Settings.System.putInt(getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, value ? 1 : 0); + Settings.System.putInt(getActivity().getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, value ? 1 : 0); return true; } }); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - }