zenfone6: Import OmniDisplayManager
From android-10 branch and add 2 commits
https://gerrit.omnirom.org/c/android_packages_apps_OmniDisplayManager/+/37671
https://gerrit.omnirom.org/c/android_packages_apps_OmniDisplayManager/+/37672/1
Change-Id: Ic6d450bbf3a27fb46f5e0029f035315551ef3c3b
diff --git a/OmniDisplayManager/Android.mk b/OmniDisplayManager/Android.mk
new file mode 100644
index 0000000..ba28cbd
--- /dev/null
+++ b/OmniDisplayManager/Android.mk
@@ -0,0 +1,43 @@
+# Copyright (C) 2018 The OmniROM Project
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := OmniDisplayManager
+LOCAL_CERTIFICATE := platform
+LOCAL_PRIVILEGED_MODULE := true
+LOCAL_PRIVATE_PLATFORM_APIS := true
+LOCAL_MODULE_TAGS := optional
+LOCAL_USE_AAPT2 := true
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+LOCAL_STATIC_ANDROID_LIBRARIES := \
+ androidx.core_core \
+ androidx.preference_preference
+
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
+LOCAL_AAPT_FLAGS := --auto-add-overlay
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_DEX_PREOPT := false
+
+include packages/apps/OmniLib/common.mk
+
+include $(BUILD_PACKAGE)
diff --git a/OmniDisplayManager/AndroidManifest.xml b/OmniDisplayManager/AndroidManifest.xml
new file mode 100644
index 0000000..02edc69
--- /dev/null
+++ b/OmniDisplayManager/AndroidManifest.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+Copyright (C) 2017 The OmniROM Project
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.omnirom.omnidisplaymanager"
+ android:versionCode="1"
+ android:versionName="1.0"
+ android:sharedUserId="android.uid.system" >
+
+ <uses-sdk
+ android:minSdkVersion="28"
+ android:targetSdkVersion="28" />
+
+ <uses-permission android:name="android.permission.HARDWARE_TEST" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
+ <application
+ android:label="@string/app_name"
+ android:icon="@drawable/omnirom_logo"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:name="org.omnirom.omnidisplaymanager.ColorSettingsActivity"
+ android:label="@string/app_name"
+ android:launchMode="singleInstance" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ <receiver android:name="org.omnirom.omnidisplaymanager.Startup" >
+ <intent-filter android:priority="100" >
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+ </receiver>
+
+ <service
+ android:name=".DisplayManagerTileService"
+ android:icon="@drawable/ic_settings_displaymanager"
+ android:label="@string/display_manager_tile"
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
+ <intent-filter>
+ <action
+ android:name="android.service.quicksettings.action.QS_TILE"/>
+ </intent-filter>
+ </service>
+
+ <service
+ android:name=".ReadingModeTileService"
+ android:icon="@drawable/ic_tile_reading_mode"
+ android:label="@string/reading_mode_title"
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
+ <intent-filter>
+ <action
+ android:name="android.service.quicksettings.action.QS_TILE"/>
+ </intent-filter>
+ </service>
+ </application>
+</manifest>
diff --git a/OmniDisplayManager/proguard.flags b/OmniDisplayManager/proguard.flags
new file mode 100644
index 0000000..276720f
--- /dev/null
+++ b/OmniDisplayManager/proguard.flags
@@ -0,0 +1,3 @@
+# This is a configuration file for ProGuard.
+# http://proguard.sourceforge.net/index.html#manual/usage.html
+
diff --git a/OmniDisplayManager/res/drawable-nodpi/header_image.jpeg b/OmniDisplayManager/res/drawable-nodpi/header_image.jpeg
new file mode 100644
index 0000000..b97f849
--- /dev/null
+++ b/OmniDisplayManager/res/drawable-nodpi/header_image.jpeg
Binary files differ
diff --git a/OmniDisplayManager/res/drawable/ic_settings_backup_restore.xml b/OmniDisplayManager/res/drawable/ic_settings_backup_restore.xml
new file mode 100644
index 0000000..1276fda
--- /dev/null
+++ b/OmniDisplayManager/res/drawable/ic_settings_backup_restore.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="24dp"
+ android:width="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+ <path android:fillColor="@android:color/white"
+ android:pathData="M12,3A9,9 0 0,0 3,12H0L4,16L8,12H5A7,7 0 0,1 12,5A7,7 0 0,1 19,12A7,7 0 0,1 12,19C10.5,19 9.09,18.5 7.94,17.7L6.5,19.14C8.04,20.3 9.94,21 12,21A9,9 0 0,0 21,12A9,9 0 0,0 12,3M14,12A2,2 0 0,0 12,10A2,2 0 0,0 10,12A2,2 0 0,0 12,14A2,2 0 0,0 14,12Z" />
+</vector>
diff --git a/OmniDisplayManager/res/drawable/ic_settings_displaymanager.xml b/OmniDisplayManager/res/drawable/ic_settings_displaymanager.xml
new file mode 100644
index 0000000..125dd8e
--- /dev/null
+++ b/OmniDisplayManager/res/drawable/ic_settings_displaymanager.xml
@@ -0,0 +1,13 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:fillColor="#ffffff"
+ android:pathData="M9,1C7.9,1 7,1.9 7,3L7,6L9,6L9,4L19,4L19,20L9,20L9,18L7,18L7,21C7,22.1 7.9,23 9,23L19,23C20.1,23 21,22.1 21,21L21,3C21,1.9 20.1,1 19,1L9,1zM9.2012,7.2773C9.2172,7.2882 9.2333,7.299 9.25,7.3086C9.2496,7.3064 9.2504,7.3049 9.25,7.3027C9.2334,7.2948 9.2179,7.285 9.2012,7.2773zM7.8906,7.7676C7.8889,7.7679 7.8865,7.7692 7.8848,7.7695C7.8991,7.7699 7.9152,7.7692 7.9297,7.7695C7.9162,7.7684 7.9023,7.7653 7.8906,7.7676zM10.4492,8.3516C10.4479,8.3522 10.4466,8.3529 10.4453,8.3535C10.4497,8.357 10.4546,8.3598 10.459,8.3633C10.4563,8.359 10.4519,8.3559 10.4492,8.3516zM6.4961,9.0586C6.4955,9.0621 6.4948,9.0625 6.4941,9.0664C6.4935,9.0673 6.4945,9.0725 6.4941,9.0742C6.5031,9.0765 6.513,9.0783 6.5195,9.0801C6.513,9.0725 6.5041,9.0667 6.4961,9.0586zM6.6172,12.7051C6.6172,12.7012 6.6142,12.713 6.6133,12.7168C6.6132,12.7189 6.6133,12.7206 6.6133,12.7227C6.6144,12.7172 6.6172,12.7107 6.6172,12.7051zM6.7227,13.0742C6.7256,13.0779 6.7275,13.0823 6.7305,13.0859C6.7481,13.1073 6.7344,13.0887 6.7363,13.0898C6.7336,13.0861 6.7325,13.0804 6.7285,13.0781C6.7265,13.077 6.7247,13.0754 6.7227,13.0742zM6.2578,14.2461C6.2575,14.2474 6.2562,14.2486 6.2559,14.25C6.2574,14.2491 6.2579,14.2481 6.2598,14.248L6.2578,14.2461zM8.2695,14.5508C8.2869,14.5431 8.2327,14.5637 8.2148,14.5703C8.2324,14.5627 8.2439,14.5638 8.2559,14.5586C8.2648,14.5548 8.2581,14.5558 8.2695,14.5508z"/>
+ <path
+ android:fillColor="#ffffff"
+ android:pathData="m7.7662,6.299c-3.1036,0 -5.6203,2.5166 -5.6203,5.6203 0,3.1036 2.5166,5.6203 5.6203,5.6203 0.5183,0 0.9367,-0.4184 0.9367,-0.9367 0,-0.2435 -0.0937,-0.4621 -0.2435,-0.6307 -0.1436,-0.1624 -0.2373,-0.3809 -0.2373,-0.6182 0,-0.5183 0.4184,-0.9367 0.9367,-0.9367l1.1053,0c1.7235,0 3.1224,-1.3988 3.1224,-3.1224 0,-2.7602 -2.5166,-4.9958 -5.6203,-4.9958zM4.3316,11.9193c-0.5183,0 -0.9367,-0.4184 -0.9367,-0.9367 0,-0.5183 0.4184,-0.9367 0.9367,-0.9367 0.5183,0 0.9367,0.4184 0.9367,0.9367 0,0.5183 -0.4184,0.9367 -0.9367,0.9367zM6.205,9.4214c-0.5183,0 -0.9367,-0.4184 -0.9367,-0.9367 0,-0.5183 0.4184,-0.9367 0.9367,-0.9367 0.5183,0 0.9367,0.4184 0.9367,0.9367 0,0.5183 -0.4184,0.9367 -0.9367,0.9367zM9.3274,9.4214c-0.5183,0 -0.9367,-0.4184 -0.9367,-0.9367 0,-0.5183 0.4184,-0.9367 0.9367,-0.9367 0.5183,0 0.9367,0.4184 0.9367,0.9367 0,0.5183 -0.4184,0.9367 -0.9367,0.9367zM11.2008,11.9193c-0.5183,0 -0.9367,-0.4184 -0.9367,-0.9367 0,-0.5183 0.4184,-0.9367 0.9367,-0.9367 0.5183,0 0.9367,0.4184 0.9367,0.9367 0,0.5183 -0.4184,0.9367 -0.9367,0.9367z"/>
+</vector>
diff --git a/OmniDisplayManager/res/drawable/ic_tile_reading_mode.xml b/OmniDisplayManager/res/drawable/ic_tile_reading_mode.xml
new file mode 100644
index 0000000..5846419
--- /dev/null
+++ b/OmniDisplayManager/res/drawable/ic_tile_reading_mode.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="24dp"
+ android:width="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+ <path android:fillColor="#ffffff"
+ android:pathData="M21,5C19.89,4.65 18.67,4.5 17.5,4.5C15.55,4.5 13.45,4.9 12,6C10.55,4.9 8.45,4.5 6.5,4.5C4.55,4.5 2.45,4.9 1,6V20.65C1,20.9 1.25,21.15 1.5,21.15C1.6,21.15 1.65,21.1 1.75,21.1C3.1,20.45 5.05,20 6.5,20C8.45,20 10.55,20.4 12,21.5C13.35,20.65 15.8,20 17.5,20C19.15,20 20.85,20.3 22.25,21.05C22.35,21.1 22.4,21.1 22.5,21.1C22.75,21.1 23,20.85 23,20.6V6C22.4,5.55 21.75,5.25 21,5M21,18.5C19.9,18.15 18.7,18 17.5,18C15.8,18 13.35,18.65 12,19.5V8C13.35,7.15 15.8,6.5 17.5,6.5C18.7,6.5 19.9,6.65 21,7V18.5Z" />
+</vector>
diff --git a/OmniDisplayManager/res/drawable/omnirom_logo.xml b/OmniDisplayManager/res/drawable/omnirom_logo.xml
new file mode 100644
index 0000000..079afe6
--- /dev/null
+++ b/OmniDisplayManager/res/drawable/omnirom_logo.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2017 The OmniROM 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.
+*/
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp"
+ android:height="48dp"
+ android:viewportWidth="512.000000"
+ android:viewportHeight="512.000000">
+
+ <group
+ android:translateY="512.000000"
+ android:scaleX="0.100000"
+ android:scaleY="-0.100000">
+ <path
+ android:fillColor="#a1c729"
+ android:strokeWidth="1"
+ android:pathData="M1425 4703 c-526 -71 -929 -439 -1041 -953 -18 -80 -19 -149 -19 -1200 0 -1051 1
+-1120 19 -1200 104 -475 461 -832 936 -936 80 -18 150 -19 1230 -19 1080 0 1150 1
+1230 19 475 104 832 461 936 936 18 80 19 149 19 1200 0 1051 -1 1120 -19 1200
+-102 468 -444 816 -916 933 -84 21 -102 21 -1215 23 -621 1 -1143 0 -1160 -3z
+m2248 -578 c183 -39 350 -170 433 -342 66 -136 64 -102 62 -1243 l-3 -1030 -70 97
+c-134 186 -378 410 -571 524 -41 24 -74 47 -74 51 0 5 65 122 143 261 79 138 149
+262 155 273 10 20 7 24 -46 52 l-57 31 -159 -280 c-87 -153 -161 -279 -165 -279 -3
+0 -39 14 -80 30 -394 161 -889 172 -1301 29 -63 -22 -122 -43 -132 -46 -12 -4 -49
+54 -169 265 l-154 271 -57 -31 c-53 -28 -56 -32 -46 -52 6 -11 73 -131 150 -265 76
+-134 138 -246 138 -250 0 -3 -38 -28 -84 -54 -134 -78 -252 -172 -386 -306 -69 -70
+-156 -170 -195 -224 l-70 -97 -3 1030 c-2 1141 -4 1107 62 1243 82 170 249 303 428
+342 96 21 2153 21 2251 0z m-1880 -2429 c104 -43 127 -180 42 -255 -61 -53 -139
+-53 -201 1 -128 112 2 320 159 254z m1630 0 c104 -43 127 -180 42 -255 -61 -53
+-139 -53 -201 1 -128 112 2 320 159 254z" />
+ </group>
+</vector>
diff --git a/OmniDisplayManager/res/layout/header_layout.xml b/OmniDisplayManager/res/layout/header_layout.xml
new file mode 100644
index 0000000..3022b5c
--- /dev/null
+++ b/OmniDisplayManager/res/layout/header_layout.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 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:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="24dp"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:scaleType="centerCrop"
+ android:src="@drawable/header_image" />
+
+</LinearLayout>
diff --git a/OmniDisplayManager/res/layout/layout_preference_frame.xml b/OmniDisplayManager/res/layout/layout_preference_frame.xml
new file mode 100644
index 0000000..eec3d7a
--- /dev/null
+++ b/OmniDisplayManager/res/layout/layout_preference_frame.xml
@@ -0,0 +1,18 @@
+<!--
+ Copyright (C) 2015 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.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
diff --git a/OmniDisplayManager/res/values/config.xml b/OmniDisplayManager/res/values/config.xml
new file mode 100644
index 0000000..e991aac
--- /dev/null
+++ b/OmniDisplayManager/res/values/config.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The OmniROM Project
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <bool name="display_mode_support">false</bool>
+ <bool name="color_balance_support">false</bool>
+</resources>
diff --git a/OmniDisplayManager/res/values/custom_arrays.xml b/OmniDisplayManager/res/values/custom_arrays.xml
new file mode 100644
index 0000000..818fbd3
--- /dev/null
+++ b/OmniDisplayManager/res/values/custom_arrays.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (C) 2013 The OmniROM Project
+
+ Parts Copyright (C) 2012-2013 The CyanogenMod Project
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string-array name="adaptive_backlight_entries" translatable="false">
+ <item>@string/adaptive_backlight_low</item>
+ <item>@string/adaptive_backlight_medium</item>
+ <item>@string/adaptive_backlight_hight</item>
+ <item>@string/adaptive_backlight_auto</item>
+ </string-array>
+
+ <string-array name="adaptive_backlight_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ </string-array>
+</resources>
diff --git a/OmniDisplayManager/res/values/custom_strings.xml b/OmniDisplayManager/res/values/custom_strings.xml
new file mode 100644
index 0000000..0aa3811
--- /dev/null
+++ b/OmniDisplayManager/res/values/custom_strings.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The OmniROM Project
+
+ Parts Copyright (C) 2012-2013 The CyanogenMod Project
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="app_name">Omni Display Management</string>
+ <string name="title">Display colors</string>
+ <string name="display_settings_title">Display</string>
+ <string name="color_balance_title">Color balance</string>
+ <string name="display_management_mode">Display mode</string>
+ <string name="sunlight_enhancement_title">Sunlight Enhancement</string>
+ <string name="adaptive_backlight_title">Adaptive Backlight</string>
+ <string name="adaptive_backlight_low">Low</string>
+ <string name="adaptive_backlight_medium">Medium</string>
+ <string name="adaptive_backlight_hight">Hight</string>
+ <string name="adaptive_backlight_auto">Auto</string>
+ <string name="reading_mode_title">Reading mode</string>
+ <string name="hue_title">Hue</string>
+ <string name="saturation_title">Saturation</string>
+ <string name="intensity_title">Intensity</string>
+ <string name="contrast_title">Contrast</string>
+ <string name="reset">Reset</string>
+ <string name="display_manager_tile">Display colors</string>
+</resources>
diff --git a/OmniDisplayManager/res/values/styles.xml b/OmniDisplayManager/res/values/styles.xml
new file mode 100644
index 0000000..ae909bd
--- /dev/null
+++ b/OmniDisplayManager/res/values/styles.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014-2017 The OmniROM 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.
+-->
+<resources>
+ <style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Settings">
+ <item name="preferenceTheme">@style/PreferenceTheme</item>
+ </style>
+
+ <style name="PreferenceTheme" parent="@style/PreferenceThemeOverlay.SettingsBase">
+ </style>
+</resources>
diff --git a/OmniDisplayManager/res/xml/display_management_settings.xml b/OmniDisplayManager/res/xml/display_management_settings.xml
new file mode 100644
index 0000000..2c248f9
--- /dev/null
+++ b/OmniDisplayManager/res/xml/display_management_settings.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2014-2016 The OmniROM 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/title">
+
+ <org.omnirom.omnidisplaymanager.preferences.LayoutPreference
+ android:key="header"
+ android:layout="@layout/header_layout"
+ android:selectable="false"/>
+
+ <org.omnirom.omnidisplaymanager.preferences.ColorBalancePreference
+ android:key="color_balance"
+ android:title="@string/color_balance_title"
+ android:dependency="reading_mode" />
+
+ <org.omnirom.omnidisplaymanager.preferences.PictureAdjustmentPreference
+ android:key="hue_value"
+ adjustmentType="hue"
+ android:title="@string/hue_title" />
+
+ <org.omnirom.omnidisplaymanager.preferences.PictureAdjustmentPreference
+ android:key="saturation_value"
+ adjustmentType="saturation"
+ android:title="@string/saturation_title" />
+
+ <org.omnirom.omnidisplaymanager.preferences.PictureAdjustmentPreference
+ android:key="intensity_value"
+ adjustmentType="intensity"
+ android:title="@string/intensity_title" />
+
+ <org.omnirom.omnidisplaymanager.preferences.PictureAdjustmentPreference
+ android:key="contrast_value"
+ adjustmentType="contrast"
+ android:title="@string/contrast_title" />
+
+ <org.omnirom.omnidisplaymanager.preferences.SunlightVisibilityPreference
+ android:key="sunlight_enhancement"
+ android:title="@string/sunlight_enhancement_title" />
+
+ <ListPreference
+ android:key="display_management_mode"
+ android:title="@string/display_management_mode"
+ android:summary="%s"
+ android:persistent="false" />
+
+ <SwitchPreference
+ android:key="reading_mode"
+ android:title="@string/reading_mode_title"
+ android:disableDependentsState="true" />
+</PreferenceScreen>
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ColorSettings.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ColorSettings.java
new file mode 100644
index 0000000..1a26643
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ColorSettings.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package org.omnirom.omnidisplaymanager;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.opengl.Matrix;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+import androidx.preference.PreferenceFragment;
+import androidx.preference.SwitchPreference;
+import android.os.ServiceManager;
+import android.provider.Settings;
+import android.provider.SearchIndexableResource;
+import android.util.SparseArray;
+import android.util.Slog;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.util.omni.DeviceUtils;
+
+import com.qti.snapdragon.sdk.display.ModeInfo;
+
+import org.omnirom.omnidisplaymanager.preferences.ColorBalancePreference;
+import org.omnirom.omnidisplaymanager.preferences.SunlightVisibilityPreference;
+import org.omnirom.omnidisplaymanager.preferences.PictureAdjustmentPreference;
+
+import java.util.List;
+import java.util.Arrays;
+
+public class ColorSettings extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
+ private static final String TAG = "DisplaySettings";
+ private ListPreference mDisplayMode;
+ private ListPreference mAdaptiveBacklightMode;
+ private SwitchPreference mReadingMode;
+
+ private static final String PREF_DISPLAY_MODE = "display_management_mode";
+ private static final String PREF_COLOR_BALANCE = "color_balance";
+ private static final String PREF_SVI = "sunlight_enhancement";
+ public static final String PREF_READING_MODE = "reading_mode";
+
+ private static final int LEVEL_COLOR_MATRIX_READING = 201;
+
+ private static final SparseArray<float[]> mColorMatrix = new SparseArray<>(3);
+ private static final int SURFACE_FLINGER_TRANSACTION_COLOR_MATRIX = 1015;
+ private static final float[][] mTempColorMatrix = new float[2][16];
+
+ private static final int MENU_RESET = Menu.FIRST;
+
+ /**
+ * Matrix and offset used for converting color to grayscale.
+ * Copied from com.android.server.accessibility.DisplayAdjustmentUtils.MATRIX_GRAYSCALE
+ */
+ private static final float[] MATRIX_GRAYSCALE = new float[] {
+ .2126f, .2126f, .2126f, 0,
+ .7152f, .7152f, .7152f, 0,
+ .0722f, .0722f, .0722f, 0,
+ 0, 0, 0, 1
+ };
+
+ /** Full color matrix and offset */
+ private static final float[] MATRIX_NORMAL = new float[] {
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1
+ };
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.display_management_settings, rootKey);
+ if (!DisplayManagement.isFeatureSupported(DisplayManagement.FEATURE_COLOR_BALANCE) ||
+ !getResources().getBoolean(R.bool.color_balance_support)) {
+ Preference pref = getPreferenceScreen().findPreference(PREF_COLOR_BALANCE);
+ if (pref != null) {
+ getPreferenceScreen().removePreference(pref);
+ }
+ }
+
+ if (!DisplayManagement.isFeatureSupported(DisplayManagement.FEATURE_SUNLIGHT_VISBILITY_IMPROVEMENT)) {
+ Preference pref = getPreferenceScreen().findPreference(PREF_SVI);
+ if (pref != null) {
+ getPreferenceScreen().removePreference(pref);
+ }
+ }
+
+ if (!DisplayManagement.isFeatureSupported(DisplayManagement.FEATURE_COLOR_MODE_SELECTION) ||
+ !getResources().getBoolean(R.bool.display_mode_support)) {
+ Preference pref = getPreferenceScreen().findPreference(PREF_DISPLAY_MODE);
+ if (pref != null) {
+ getPreferenceScreen().removePreference(pref);
+ }
+ } else {
+ mDisplayMode = (ListPreference) findPreference(PREF_DISPLAY_MODE);
+ mDisplayMode.setOnPreferenceChangeListener(this);
+
+ ModeInfo[] modes = DisplayManagement.getModes();
+ if (modes != null) {
+ CharSequence[] entries = new CharSequence[modes.length];
+ CharSequence[] entryValues = new CharSequence[modes.length];
+ for (int i = 0; i < modes.length; i++) {
+ entries[i] = modes[i].getName();
+ entryValues[i] = String.valueOf(modes[i].getId());
+ }
+
+ mDisplayMode.setEntries(entries);
+ mDisplayMode.setEntryValues(entryValues);
+ mDisplayMode.setValueIndex(DisplayManagement.getActiveMode());
+ }
+ }
+
+ mReadingMode = (SwitchPreference) findPreference(PREF_READING_MODE);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(Preference preference) {
+ if (preference == mReadingMode) {
+ boolean checked = ((SwitchPreference)preference).isChecked();
+ setReadingMode(checked);
+ return true;
+ }
+ return super.onPreferenceTreeClick(preference);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mDisplayMode) {
+ int val = Integer.parseInt((String) newValue);
+ int index = mDisplayMode.findIndexOfValue((String) newValue);
+ DisplayManagement.setMode(index);
+ mDisplayMode.setSummary(mDisplayMode.getEntries()[index]);
+ return true;
+ }
+ return false;
+ }
+
+ public static void setReadingMode(boolean state) {
+ setColorMatrix(LEVEL_COLOR_MATRIX_READING,
+ state ? MATRIX_GRAYSCALE : MATRIX_NORMAL);
+ }
+
+ public static void setColorMatrix(int level, float[] value) {
+ if (value != null && value.length != 16) {
+ throw new IllegalArgumentException("Expected length: 16 (4x4 matrix)"
+ + ", actual length: " + value.length);
+ }
+
+ synchronized (mColorMatrix) {
+ final float[] oldValue = mColorMatrix.get(level);
+ if (!Arrays.equals(oldValue, value)) {
+ if (value == null) {
+ mColorMatrix.remove(level);
+ } else if (oldValue == null) {
+ mColorMatrix.put(level, Arrays.copyOf(value, value.length));
+ } else {
+ System.arraycopy(value, 0, oldValue, 0, value.length);
+ }
+
+ // Update the current color transform.
+ applyColorMatrix(computeColorMatrixLocked());
+ }
+ }
+ }
+
+ private static void applyColorMatrix(float[] m) {
+ final IBinder flinger = ServiceManager.getService("SurfaceFlinger");
+ if (flinger != null) {
+ final Parcel data = Parcel.obtain();
+ data.writeInterfaceToken("android.ui.ISurfaceComposer");
+ if (m != null) {
+ data.writeInt(1);
+ for (int i = 0; i < 16; i++) {
+ data.writeFloat(m[i]);
+ }
+ } else {
+ data.writeInt(0);
+ }
+ try {
+ flinger.transact(SURFACE_FLINGER_TRANSACTION_COLOR_MATRIX, data, null, 0);
+ } catch (RemoteException ex) {
+ Slog.e(TAG, "Failed to set color transform", ex);
+ } finally {
+ data.recycle();
+ }
+ }
+ }
+
+ private static float[] computeColorMatrixLocked() {
+ final int count = mColorMatrix.size();
+ if (count == 0) {
+ return null;
+ }
+
+ final float[][] result = mTempColorMatrix;
+ Matrix.setIdentityM(result[0], 0);
+ for (int i = 0; i < count; i++) {
+ float[] rhs = mColorMatrix.valueAt(i);
+ Matrix.multiplyMM(result[(i + 1) % 2], 0, result[i % 2], 0, rhs, 0);
+ }
+ return result[count % 2];
+ }
+
+ private void resetToDefaults() {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ SharedPreferences.Editor editor = sharedPrefs.edit();
+ editor.remove(DisplayManagement.KEY_CONTRAST_VALUE);
+ editor.remove(DisplayManagement.KEY_HUE_VALUE);
+ editor.remove(DisplayManagement.KEY_INTENSITY_VALUE);
+ editor.remove(DisplayManagement.KEY_SATURATION_VALUE);
+ editor.remove(DisplayManagement.KEY_COLOR_BALANCE);
+ editor.remove(DisplayManagement.KEY_SUNLIGHT_VISIBILITY);
+ editor.commit();
+
+ for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
+ Preference p = getPreferenceScreen().getPreference(i);
+ if (p instanceof PictureAdjustmentPreference) {
+ ((PictureAdjustmentPreference)p).resetToDefaults();
+ }
+ if (p instanceof ColorBalancePreference) {
+ ((ColorBalancePreference)p).resetToDefaults();
+ }
+ if (p instanceof SunlightVisibilityPreference) {
+ ((SunlightVisibilityPreference)p).resetToDefaults();
+ }
+ }
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ menu.add(0, MENU_RESET, 0, R.string.reset)
+ .setIcon(R.drawable.ic_settings_backup_restore)
+ .setAlphabeticShortcut('r')
+ .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case MENU_RESET:
+ resetToDefaults();
+ return true;
+ }
+ return false;
+ }
+}
+
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ColorSettingsActivity.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ColorSettingsActivity.java
new file mode 100644
index 0000000..57c12c0
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ColorSettingsActivity.java
@@ -0,0 +1,67 @@
+/*
+* Copyright (C) 2018 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.omnirom.omnidisplaymanager;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import androidx.preference.PreferenceFragment;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+public class ColorSettingsActivity extends Activity {
+
+ private ColorSettings mColorSettingsFragment;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setTitle(getResources().getString(R.string.title));
+
+ Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
+ if (fragment == null) {
+ mColorSettingsFragment = new ColorSettings();
+ getFragmentManager().beginTransaction()
+ .add(android.R.id.content, mColorSettingsFragment)
+ .commit();
+ } else {
+ mColorSettingsFragment = (ColorSettings) fragment;
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ default:
+ break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/DisplayManagement.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/DisplayManagement.java
new file mode 100644
index 0000000..7f1b5d1
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/DisplayManagement.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package org.omnirom.omnidisplaymanager;
+
+import android.os.SystemProperties;
+import android.util.Log;
+
+import com.qti.service.colorservice.IColorServiceImpl;
+import com.qti.snapdragon.sdk.display.ModeInfo;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class DisplayManagement {
+
+ private static IColorServiceImpl mColorService;
+ public static final String TAG = "DisplayManagement";
+ private static boolean isDisplayManagementSupported;
+
+ public static final int FEATURE_COLOR_BALANCE = 0;
+ public static final int FEATURE_COLOR_MODE_SELECTION = 1;
+ public static final int FEATURE_COLOR_MODE_MANAGEMENT = 2;
+ public static final int FEATURE_ADAPTIVE_BACKLIGHT = 3;
+ public static final int FEATURE_GLOBAL_PICTURE_ADJUSTMENT = 4;
+ public static final int FEATURE_MEMORY_COLOR_ADJUSTMENT = 5;
+ public static final int FEATURE_SUNLIGHT_VISBILITY_IMPROVEMENT = 6;
+
+ public static final String KEY_CONTRAST_VALUE = "contrast_value";
+ public static final String KEY_HUE_VALUE = "hue_value";
+ public static final String KEY_INTENSITY_VALUE = "intensity_value";
+ public static final String KEY_SATURATION_VALUE = "saturation_value";
+ public static final String KEY_COLOR_BALANCE = "color_balance";
+ public static final String KEY_SUNLIGHT_VISIBILITY = "sunlight_enhancement";
+
+ private static Map<String, String> mDefaultValues = new HashMap();
+
+ private static void init(){
+ if (mColorService == null) {
+ try {
+ mColorService = new IColorServiceImpl();
+ mColorService.native_init();
+ isDisplayManagementSupported = true;
+ saveDefaults();
+ } catch (Throwable t) {
+ // Ignore, DisplayEngineService not available.
+ Log.e(TAG, "init", t);
+ }
+ }
+ }
+
+ public static int getActiveMode() {
+ try {
+ int defaultMode = getColorService().native_getDefaultMode(0);
+ return defaultMode;
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static ModeInfo[] getModes() {
+ try {
+ ModeInfo[] modes = getColorService().native_getModes(0, 2);
+ return modes;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void setMode(int modeId) {
+ try {
+ getColorService().native_setActiveMode(0, modeId);
+ } catch (Exception e) {
+ }
+ }
+
+ public static boolean isFeatureSupported(int featId) {
+ try {
+ int supported = getColorService().native_isFeatureSupported(0, featId);
+ return supported > 0;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public static int getColorBalance() {
+ try {
+ int balanceValue = getColorService().native_getColorBalance(0);
+ return balanceValue;
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static void setColorBalance(int newValue) {
+ try {
+ getColorService().native_setColorBalance(0, newValue);
+ } catch (Exception e) {
+ }
+ }
+
+ public static int getSVI() {
+ try {
+ return getColorService().native_getSVI(0);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static int getRangeSVIStrength(int index) {
+ try {
+ return getColorService().native_getRangeSVI(0, index);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static void setSVI(int newValue) {
+ try {
+ getColorService().native_setSVI(0, newValue);
+ } catch (Exception e) {
+ }
+ }
+
+ public static int getBacklightQualityLevel() {
+ try {
+ return getColorService().native_getBacklightQualityLevel(0);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static void setBacklightQualityLevel(int index) {
+ try {
+ getColorService().native_setBacklightQualityLevel(0, index);
+ } catch (Exception e) {
+ }
+ }
+
+ public static int[] getRangePAParameter() {
+ try {
+ return getColorService().native_getRangePAParameter(0);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static int[] getPAParameters() {
+ try {
+ int[] v = getColorService().native_getPAParameters(0);
+ return v;
+ } catch (Exception e) {
+ return new int[] {0, 0, 0, 0, 0, 0};
+ }
+ }
+
+ public static void setPAParameters(int displayId, int flag, int hue, int saturation, int intensity, int contrast, int satThreshold){
+ try {
+ getColorService().native_setPAParameters(displayId, flag, hue, saturation, intensity, contrast, satThreshold);
+ } catch (Exception e) {
+ }
+ }
+
+ public static String getDefaultValue(String key) {
+ return mDefaultValues.get(key);
+ }
+
+ private static IColorServiceImpl getColorService() {
+ if (mColorService == null) {
+ init();
+ }
+ return mColorService;
+ }
+
+ private static void saveDefaults() {
+ if (mDefaultValues.size() == 0) {
+ mDefaultValues.put(KEY_CONTRAST_VALUE, "100");
+ mDefaultValues.put(KEY_HUE_VALUE, "180");
+ mDefaultValues.put(KEY_INTENSITY_VALUE, "100");
+ mDefaultValues.put(KEY_SATURATION_VALUE, "50");
+ mDefaultValues.put(KEY_COLOR_BALANCE, "0");
+ mDefaultValues.put(KEY_SUNLIGHT_VISIBILITY, "-1");
+ Log.i(TAG, "defaults = " + mDefaultValues);
+ }
+ }
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/DisplayManagerTileService.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/DisplayManagerTileService.java
new file mode 100644
index 0000000..8273d81
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/DisplayManagerTileService.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.omnidisplaymanager;
+
+import android.content.Intent;
+import android.service.quicksettings.TileService;
+
+
+public class DisplayManagerTileService extends TileService {
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public void onTileAdded() {
+ super.onTileAdded();
+ }
+
+ @Override
+ public void onTileRemoved() {
+ super.onTileRemoved();
+ }
+
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+ }
+
+ @Override
+ public void onStopListening() {
+ super.onStopListening();
+ }
+
+ @Override
+ public void onClick() {
+ super.onClick();
+ sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
+ Intent startIntent = new Intent(this, ColorSettingsActivity.class);
+ startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(startIntent);
+ }
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/IColorServiceImpl.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/IColorServiceImpl.java
new file mode 100644
index 0000000..0aad32d
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/IColorServiceImpl.java
@@ -0,0 +1,96 @@
+/*
+* Copyright (C) 2018 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+package com.qti.service.colorservice;
+
+import android.util.Log;
+import java.util.Hashtable;
+
+import com.qti.snapdragon.sdk.display.ModeInfo;
+
+public class IColorServiceImpl {
+ private static final String TAG = "DeviceParts";
+
+ public native int native_createNewMode(int i, String str, int i2, long j, int i3);
+
+ public native int native_createNewModeAllFeatures(int i, String str, int i2);
+
+ public native void native_deinit();
+
+ public native int native_deleteMode(int i, int i2);
+
+ public native int native_disableMemoryColorConfiguration(int i, int i2);
+
+ public native long[] native_getActiveMode(int i);
+
+ public native int native_getAdaptiveBacklightScale(int i);
+
+ public native int native_getBacklightQualityLevel(int i);
+
+ public native int native_getColorBalance(int i);
+
+ public native int native_getDefaultMode(int i);
+
+ public native int[] native_getMemoryColorParameters(int i, int i2);
+
+ public native ModeInfo[] native_getModes(int i, int i2);
+
+ public native int native_getNumberOfModes(int i, int i2);
+
+ public native int[] native_getPAParameters(int i);
+
+ public native int[] native_getRangeMemoryColorParameter(int i, int i2);
+
+ public native int[] native_getRangePAParameter(int i);
+
+ public native int native_getRangeSVI(int i, int i2);
+
+ public native int native_getSVI(int i);
+
+ public native int native_init();
+
+ public native int native_isActiveFeatureOn(int i, int i2);
+
+ public native int native_isFeatureSupported(int i, int i2);
+
+ public native int native_modifyMode(int i, int i2, String str, int i3, long j, int i4);
+
+ public native int native_modifyModeAllFeatures(int i, int i2, String str, int i3);
+
+ public native int native_setActiveFeatureControl(int i, int i2, int i3);
+
+ public native int native_setActiveMode(int i, int i2);
+
+ public native int native_setBacklightQualityLevel(int i, int i2);
+
+ public native int native_setColorBalance(int i, int i2);
+
+ public native int native_setDefaultMode(int i, int i2);
+
+ public native int native_setMemoryColorParameters(int i, int i2, int i3, int i4, int i5);
+
+ public native int native_setPAParameters(int i, int i2, int i3, int i4, int i5, int i6, int i7);
+
+ public native int native_setSVI(int i, int i2);
+
+ public IColorServiceImpl() {
+ System.loadLibrary("sdm-disp-apis");
+ System.loadLibrary("sd_sdk_display");
+ }
+
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ModeInfo.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ModeInfo.java
new file mode 100644
index 0000000..5563756
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ModeInfo.java
@@ -0,0 +1,66 @@
+/*
+* Copyright (C) 2018 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+package com.qti.snapdragon.sdk.display;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.os.Parcelable.Creator;
+
+public class ModeInfo implements Parcelable {
+ public static final Creator<ModeInfo> CREATOR = new Creator<ModeInfo>() {
+ public ModeInfo createFromParcel(Parcel inParcel) {
+ return new ModeInfo(inParcel.readInt(), inParcel.readString(), inParcel.readInt());
+ }
+
+ public ModeInfo[] newArray(int size) {
+ return new ModeInfo[size];
+ }
+ };
+ private int id = -1;
+ private int modeType = 0;
+ private String name = null;
+
+ public ModeInfo(int pId, String pName, int pType) {
+ id = pId;
+ name = pName;
+ modeType = pType;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getModeType() {
+ return modeType;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel destParcel, int flags) {
+ destParcel.writeInt(id);
+ destParcel.writeString(name);
+ destParcel.writeInt(modeType);
+ }
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ReadingModeTileService.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ReadingModeTileService.java
new file mode 100644
index 0000000..34521f4
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/ReadingModeTileService.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.omnidisplaymanager;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.service.quicksettings.TileService;
+import androidx.preference.PreferenceManager;
+
+
+public class ReadingModeTileService extends TileService {
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public void onTileAdded() {
+ super.onTileAdded();
+ }
+
+ @Override
+ public void onTileRemoved() {
+ super.onTileRemoved();
+ }
+
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+ }
+
+ @Override
+ public void onStopListening() {
+ super.onStopListening();
+ }
+
+ @Override
+ public void onClick() {
+ super.onClick();
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+ if (sharedPrefs.getBoolean(ColorSettings.PREF_READING_MODE, false)) {
+ ColorSettings.setReadingMode(false);
+ sharedPrefs.edit().putBoolean(ColorSettings.PREF_READING_MODE, false).commit();
+ } else {
+ ColorSettings.setReadingMode(true);
+ sharedPrefs.edit().putBoolean(ColorSettings.PREF_READING_MODE, true).commit();
+ }
+ }
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/Startup.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/Startup.java
new file mode 100644
index 0000000..b08e322
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/Startup.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.omnidisplaymanager;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import androidx.preference.PreferenceManager;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+public class Startup extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(final Context context, final Intent bootintent) {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+ int[] currentValue = DisplayManagement.getPAParameters();
+
+ int contrast = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_CONTRAST_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_CONTRAST_VALUE)));
+ int hue = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_HUE_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_HUE_VALUE)));
+ int intensity = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_INTENSITY_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_INTENSITY_VALUE)));
+ int saturation = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_SATURATION_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_SATURATION_VALUE)));
+ DisplayManagement.setPAParameters(0, currentValue[0], hue, saturation, intensity, contrast, currentValue[5]);
+
+ if (context.getResources().getBoolean(R.bool.color_balance_support)) {
+ int colorBalance = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_COLOR_BALANCE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_COLOR_BALANCE)));
+ DisplayManagement.setColorBalance(colorBalance);
+ }
+
+ // always reset on reboot
+ sharedPrefs.edit().putBoolean(ColorSettings.PREF_READING_MODE, false).commit();
+ }
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/ColorBalancePreference.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/ColorBalancePreference.java
new file mode 100644
index 0000000..ce98b25
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/ColorBalancePreference.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.omnidisplaymanager.preferences;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.SharedPreferences;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceViewHolder;
+import android.database.ContentObserver;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.Button;
+import android.os.Bundle;
+import android.util.Log;
+import android.os.Vibrator;
+
+import org.omnirom.omnidisplaymanager.DisplayManagement;
+import org.omnirom.omnidisplaymanager.R;
+
+public class ColorBalancePreference extends Preference implements
+ SeekBar.OnSeekBarChangeListener {
+
+ private SeekBar mSeekBar;
+ private int mOldStrength;
+ private int mMinValue;
+ private int mMaxValue;
+ private static final String TAG = "ColorBalancePreference";
+
+ public ColorBalancePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mMinValue = 0;
+ mMaxValue = 100;
+
+ setLayoutResource(R.layout.preference_seek_bar);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ mOldStrength = getValue();
+ mSeekBar = (SeekBar) holder.findViewById(R.id.seekbar);
+ mSeekBar.setMax(mMaxValue - mMinValue);
+ mSeekBar.setProgress(mOldStrength - mMinValue);
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ public int getValue() {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ return Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_COLOR_BALANCE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_COLOR_BALANCE)));
+ }
+
+ private void setValue(String newValue, boolean withFeedback) {
+ DisplayManagement.setColorBalance(Integer.parseInt(newValue));
+ SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
+ editor.putString(DisplayManagement.KEY_COLOR_BALANCE, newValue);
+ editor.commit();
+ }
+
+
+ public void onProgressChanged(SeekBar seekBar, int progress,
+ boolean fromTouch) {
+ setValue(String.valueOf(progress + mMinValue), true);
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // NA
+ }
+
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // NA
+ }
+
+ public void resetToDefaults() {
+ mSeekBar.setProgress(Integer.valueOf(DisplayManagement.getDefaultValue(DisplayManagement.KEY_COLOR_BALANCE)), true);
+ }
+}
+
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/LayoutPreference.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/LayoutPreference.java
new file mode 100644
index 0000000..cfd82c8
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/LayoutPreference.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+package org.omnirom.omnidisplaymanager.preferences;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import androidx.annotation.VisibleForTesting;
+import androidx.core.content.res.TypedArrayUtils;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+
+import org.omnirom.omnidisplaymanager.R;
+
+public class LayoutPreference extends Preference {
+
+ private final View.OnClickListener mClickListener = v -> performClick(v);
+ private boolean mAllowDividerAbove;
+ private boolean mAllowDividerBelow;
+
+ @VisibleForTesting
+ View mRootView;
+
+ public LayoutPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context, attrs, 0 /* defStyleAttr */);
+ }
+
+ public LayoutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init(context, attrs, defStyleAttr);
+ }
+
+ public LayoutPreference(Context context, int resource) {
+ this(context, LayoutInflater.from(context).inflate(resource, null, false));
+ }
+
+ public LayoutPreference(Context context, View view) {
+ super(context);
+ setView(view);
+ }
+
+ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Preference);
+ mAllowDividerAbove = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerAbove,
+ R.styleable.Preference_allowDividerAbove, false);
+ mAllowDividerBelow = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerBelow,
+ R.styleable.Preference_allowDividerBelow, false);
+ a.recycle();
+
+ a = context.obtainStyledAttributes(
+ attrs, com.android.internal.R.styleable.Preference, defStyleAttr, 0);
+ int layoutResource = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
+ 0);
+ if (layoutResource == 0) {
+ throw new IllegalArgumentException("LayoutPreference requires a layout to be defined");
+ }
+ a.recycle();
+
+ // Need to create view now so that findViewById can be called immediately.
+ final View view = LayoutInflater.from(getContext())
+ .inflate(layoutResource, null, false);
+ setView(view);
+ }
+
+ private void setView(View view) {
+ setLayoutResource(R.layout.layout_preference_frame);
+ mRootView = view;
+ setShouldDisableView(false);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ holder.itemView.setOnClickListener(mClickListener);
+
+ final boolean selectable = isSelectable();
+ holder.itemView.setFocusable(selectable);
+ holder.itemView.setClickable(selectable);
+ holder.setDividerAllowedAbove(mAllowDividerAbove);
+ holder.setDividerAllowedBelow(mAllowDividerBelow);
+
+ FrameLayout layout = (FrameLayout) holder.itemView;
+ layout.removeAllViews();
+ ViewGroup parent = (ViewGroup) mRootView.getParent();
+ if (parent != null) {
+ parent.removeView(mRootView);
+ }
+ layout.addView(mRootView);
+ }
+
+ public <T extends View> T findViewById(int id) {
+ return mRootView.findViewById(id);
+ }
+
+}
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/PictureAdjustmentPreference.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/PictureAdjustmentPreference.java
new file mode 100644
index 0000000..050cfc5
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/PictureAdjustmentPreference.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2018 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.omnidisplaymanager.preferences;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.SharedPreferences;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceViewHolder;
+import android.database.ContentObserver;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.Button;
+import android.os.Bundle;
+import android.util.Log;
+
+import org.omnirom.omnidisplaymanager.DisplayManagement;
+import org.omnirom.omnidisplaymanager.R;
+
+import java.util.Arrays;
+
+public class PictureAdjustmentPreference extends Preference implements
+ SeekBar.OnSeekBarChangeListener {
+
+ private SeekBar mSeekBar;
+ private int mOldStrength;
+ private int mMinValue;
+ private int mMaxValue;
+ private PictureAdjustment currentAdjustment;
+
+ public PictureAdjustmentPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ int[] ranges = DisplayManagement.getRangePAParameter();
+ Log.i("ranges", Arrays.toString(ranges));
+ if (ranges != null && ranges.length > 0) {
+ mMinValue = ranges[currentAdjustment.minRangeIndex];
+ mMaxValue = ranges[currentAdjustment.maxRangeIndex];
+ } else {
+ mMinValue = 0;
+ mMaxValue = 0;
+ }
+
+ setLayoutResource(R.layout.preference_seek_bar);
+ }
+
+ private void init(AttributeSet attrs) {
+ String ajustmentType = attrs.getAttributeValue(null, "adjustmentType");
+ switch (ajustmentType) {
+ case "contrast":
+ currentAdjustment = new PictureAdjustment(6, 7, 4, DisplayManagement.KEY_CONTRAST_VALUE);
+ break;
+ case "hue":
+ currentAdjustment = new PictureAdjustment(0, 1, 1, DisplayManagement.KEY_HUE_VALUE);
+ break;
+ case "intensity":
+ currentAdjustment = new PictureAdjustment(4, 5, 3, DisplayManagement.KEY_INTENSITY_VALUE);
+ break;
+ case "saturation":
+ currentAdjustment = new PictureAdjustment(2, 3, 2, DisplayManagement.KEY_SATURATION_VALUE);
+ break;
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ mOldStrength = getValue();
+ mSeekBar = (SeekBar) holder.findViewById(R.id.seekbar);
+ mSeekBar.setMax(mMaxValue - mMinValue);
+ mSeekBar.setProgress(mOldStrength - mMinValue);
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ public int getValue() {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ return Integer.valueOf(sharedPrefs.getString(currentAdjustment.preferenceKey,
+ DisplayManagement.getDefaultValue(currentAdjustment.preferenceKey)));
+ }
+
+ private void setValue(String newValue) {
+ int[] currentValue = DisplayManagement.getPAParameters();
+
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ int contrast = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_CONTRAST_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_CONTRAST_VALUE)));
+ int hue = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_HUE_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_HUE_VALUE)));
+ int intensity = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_INTENSITY_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_INTENSITY_VALUE)));
+ int saturation = Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_SATURATION_VALUE,
+ DisplayManagement.getDefaultValue(DisplayManagement.KEY_SATURATION_VALUE)));
+
+ switch (currentAdjustment.preferenceKey) {
+ case DisplayManagement.KEY_CONTRAST_VALUE:
+ DisplayManagement.setPAParameters(0, currentValue[0], hue, saturation, intensity, Integer.parseInt(newValue), currentValue[5]);
+ break;
+ case DisplayManagement.KEY_HUE_VALUE:
+ DisplayManagement.setPAParameters(0, currentValue[0], Integer.parseInt(newValue), saturation, intensity, contrast, currentValue[5]);
+ break;
+ case DisplayManagement.KEY_INTENSITY_VALUE:
+ DisplayManagement.setPAParameters(0, currentValue[0], hue, saturation, Integer.parseInt(newValue), contrast, currentValue[5]);
+ break;
+ case DisplayManagement.KEY_SATURATION_VALUE:
+ DisplayManagement.setPAParameters(0, currentValue[0], hue, Integer.parseInt(newValue), intensity, contrast, currentValue[5]);
+ break;
+ }
+
+ SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
+ editor.putString(currentAdjustment.preferenceKey, newValue);
+ editor.commit();
+ }
+
+ public void onProgressChanged(SeekBar seekBar, int progress,
+ boolean fromTouch) {
+ setValue(String.valueOf(progress + mMinValue));
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // NA
+ }
+
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // NA
+ }
+
+ public void resetToDefaults() {
+ mSeekBar.setProgress(Integer.valueOf(DisplayManagement.getDefaultValue(currentAdjustment.preferenceKey)), true);
+ }
+
+ public class PictureAdjustment {
+ public int minRangeIndex;
+ public int maxRangeIndex;
+ public int parameterIndex;
+ public String preferenceKey;
+
+ public PictureAdjustment(int min, int max, int param, String key) {
+ minRangeIndex = min;
+ maxRangeIndex = max;
+ parameterIndex = param;
+ preferenceKey = key;
+ }
+ }
+}
+
+
diff --git a/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/SunlightVisibilityPreference.java b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/SunlightVisibilityPreference.java
new file mode 100644
index 0000000..ecb9204
--- /dev/null
+++ b/OmniDisplayManager/src/org/omnirom/omnidisplaymanager/preferences/SunlightVisibilityPreference.java
@@ -0,0 +1,95 @@
+/*
+* Copyright (C) 2018 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.omnirom.omnidisplaymanager.preferences;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.SharedPreferences;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceViewHolder;
+import android.database.ContentObserver;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.Button;
+import android.os.Bundle;
+import android.util.Log;
+import android.os.Vibrator;
+
+import org.omnirom.omnidisplaymanager.DisplayManagement;
+import org.omnirom.omnidisplaymanager.R;
+
+public class SunlightVisibilityPreference extends Preference implements
+ SeekBar.OnSeekBarChangeListener {
+
+ private SeekBar mSeekBar;
+ private int mOldStrength;
+ private int mMinValue;
+ private int mMaxValue;
+
+ public SunlightVisibilityPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mMinValue = DisplayManagement.getRangeSVIStrength(0);
+ mMaxValue = DisplayManagement.getRangeSVIStrength(1);
+
+ setLayoutResource(R.layout.preference_seek_bar);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ mOldStrength = getValue();
+ mSeekBar = (SeekBar) holder.findViewById(R.id.seekbar);
+ mSeekBar.setMax(mMaxValue - mMinValue);
+ mSeekBar.setProgress(mOldStrength - mMinValue);
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ public int getValue() {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ return Integer.valueOf(sharedPrefs.getString(DisplayManagement.KEY_SUNLIGHT_VISIBILITY, DisplayManagement.getDefaultValue(DisplayManagement.KEY_SUNLIGHT_VISIBILITY)));
+ }
+
+ private void setValue(String newValue) {
+ DisplayManagement.setSVI(Integer.parseInt(newValue));
+ SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
+ editor.putString(DisplayManagement.KEY_SUNLIGHT_VISIBILITY, newValue);
+ editor.commit();
+ }
+
+ public void onProgressChanged(SeekBar seekBar, int progress,
+ boolean fromTouch) {
+ setValue(String.valueOf(progress + mMinValue));
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // NA
+ }
+
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // NA
+ }
+
+ public void resetToDefaults() {
+ mSeekBar.setProgress(Integer.valueOf(DisplayManagement.getDefaultValue(DisplayManagement.KEY_SUNLIGHT_VISIBILITY)), true);
+ }
+}
+