From 6d0ea5b8c892344e6049b6c3d613ed93db33296d Mon Sep 17 00:00:00 2001 From: Zhao Wei Liew Date: Wed, 7 Sep 2016 18:20:51 +0800 Subject: [PATCH] samsung: doze: Integrate with Settings Bring this up to speed on the Settings changes in N: * Use support libs for preferences * Hook up to Settings drawer through SettingsDrawerActivity Change-Id: I9365b3ebd1bbfed2936302e30da50e3f9af06665 --- doze/Android.mk | 21 ++++++++++++ doze/AndroidManifest.xml | 4 +-- doze/proguard.flags | 6 ++++ doze/res/values/styles.xml | 21 ++++++++++++ .../settings/device/SamsungDozeActivity.java | 34 +++++++++++++++++++ .../device/TouchscreenGestureSettings.java | 19 +++++------ 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 doze/res/values/styles.xml create mode 100644 doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java diff --git a/doze/Android.mk b/doze/Android.mk index 015d8019..07b7cac0 100644 --- a/doze/Android.mk +++ b/doze/Android.mk @@ -10,10 +10,31 @@ LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true LOCAL_STATIC_JAVA_LIBRARIES := \ + android-support-v14-preference \ + android-support-v7-appcompat \ + android-support-v7-preference \ + android-support-v7-recyclerview \ org.cyanogenmod.platform.internal LOCAL_PROGUARD_FLAG_FILES := proguard.flags +LOCAL_RESOURCE_DIR := \ + $(LOCAL_PATH)/res \ + frameworks/support/v14/preference/res \ + frameworks/support/v7/appcompat/res \ + frameworks/support/v7/preference/res \ + frameworks/support/v7/recyclerview/res + +LOCAL_AAPT_FLAGS := --auto-add-overlay \ + --extra-packages android.support.v14.preference:android.support.v7.appcompat:android.support.v7.preference:android.support.v7.recyclerview + +ifneq ($(INCREMENTAL_BUILDS),) + LOCAL_PROGUARD_ENABLED := disabled + LOCAL_JACK_ENABLED := incremental +endif + +include frameworks/base/packages/SettingsLib/common.mk + include $(BUILD_PACKAGE) include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml index fe2cfe46..b14e9e03 100644 --- a/doze/AndroidManifest.xml +++ b/doze/AndroidManifest.xml @@ -30,9 +30,9 @@ + android:theme="@style/SamsungDozeSettings"> diff --git a/doze/proguard.flags b/doze/proguard.flags index 3bb1f2c2..0a629417 100644 --- a/doze/proguard.flags +++ b/doze/proguard.flags @@ -1,3 +1,9 @@ -keep class com.cyanogenmod.settings.device.* { *; } + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keep class ** extends android.support.v14.preference.PreferenceFragment diff --git a/doze/res/values/styles.xml b/doze/res/values/styles.xml new file mode 100644 index 00000000..69e4ff38 --- /dev/null +++ b/doze/res/values/styles.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java b/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java new file mode 100644 index 00000000..45ac5305 --- /dev/null +++ b/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java @@ -0,0 +1,34 @@ +/* + * 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 com.cyanogenmod.settings.device; + +import android.app.Fragment; +import android.app.FragmentTransaction; +import android.os.Bundle; + +import com.android.settingslib.drawer.SettingsDrawerActivity; + +public class SamsungDozeActivity extends SettingsDrawerActivity { + + private static final String TAG = "samsung_doze"; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getFragmentManager().beginTransaction().replace(R.id.content_frame, + new TouchscreenGestureSettings(), TAG).commit(); + } +} diff --git a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java index 30bbcf42..c9ffce0a 100644 --- a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java +++ b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java @@ -17,14 +17,14 @@ package com.cyanogenmod.settings.device; import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceActivity; -import android.preference.SwitchPreference; +import android.support.v14.preference.PreferenceFragment; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.Preference; import android.provider.Settings; import org.cyanogenmod.internal.util.ScreenType; -public class TouchscreenGestureSettings extends PreferenceActivity { +public class TouchscreenGestureSettings extends PreferenceFragment { private static final String KEY_AMBIENT_DISPLAY_ENABLE = "ambient_display_enable"; private static final String KEY_HAND_WAVE = "gesture_hand_wave"; @@ -37,8 +37,7 @@ public class TouchscreenGestureSettings extends PreferenceActivity { private SwitchPreference mProximityWakePreference; @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.gesture_panel); boolean dozeEnabled = isDozeEnabled(); mAmbientDisplayPreference = @@ -59,22 +58,22 @@ public class TouchscreenGestureSettings extends PreferenceActivity { } @Override - protected void onResume() { + public void onResume() { super.onResume(); // If running on a phone, remove padding around the listview - if (!ScreenType.isTablet(this)) { + if (!ScreenType.isTablet(getContext())) { getListView().setPadding(0, 0, 0, 0); } } private boolean enableDoze(boolean enable) { - return Settings.Secure.putInt(getContentResolver(), + return Settings.Secure.putInt(getContext().getContentResolver(), Settings.Secure.DOZE_ENABLED, enable ? 1 : 0); } private boolean isDozeEnabled() { - return Settings.Secure.getInt(getContentResolver(), + return Settings.Secure.getInt(getContext().getContentResolver(), Settings.Secure.DOZE_ENABLED, 1) != 0; }