[2/2] OmniControl: long press on power for flashlight from screen off

while we are here add resource config config_has_power_button
to hide long_press_power_torch preference for devices that dont have one

Change-Id: I3311ba558f8849115dc0d476a57f1a7bed978235
diff --git a/app/src/main/java/org/omnirom/control/ButtonSettingsFragment.kt b/app/src/main/java/org/omnirom/control/ButtonSettingsFragment.kt
index c872783..670f4f6 100644
--- a/app/src/main/java/org/omnirom/control/ButtonSettingsFragment.kt
+++ b/app/src/main/java/org/omnirom/control/ButtonSettingsFragment.kt
@@ -30,6 +30,7 @@
 class ButtonSettingsFragment : AbstractSettingsFragment() {
     private val CATEGORY_POWER = "button_power"
     private val KEY_ADVANCED_REBOOT = "advanced_reboot"
+    private val KEY_POWER_TORCH = "long_press_power_torch"
 
     override fun getFragmentTitle(): String {
         return resources.getString(R.string.button_settings_title)
@@ -61,6 +62,11 @@
                     // TODO
                 }
             }
+            val hasPowerMenu: Preference? = findPreference(KEY_POWER_TORCH)
+            if (hasPowerMenu != null) {
+                hasPowerMenu.isVisible =
+                resources.getBoolean(R.bool.config_has_power_button)
+            }
         }
     }
 
diff --git a/app/src/main/res/values/config.xml b/app/src/main/res/values/config.xml
index 6cddf27..efad539 100644
--- a/app/src/main/res/values/config.xml
+++ b/app/src/main/res/values/config.xml
@@ -3,4 +3,7 @@
     <integer name="grid_view_columns">1</integer>
     <bool name="config_show_battery_options">true</bool>
     <integer name="icon_shape_view_columns">20</integer>
+
+    <!-- power button support. Some devices do not have a power button -->
+    <bool name="config_has_power_button">true</bool>
 </resources>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b27786f..62d673c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -41,6 +41,8 @@
     <string name="global_actions_power_title">Power</string>
     <string name="global_actions_advanced_reboot_title">Enable advanced restart</string>
     <string name="global_actions_advanced_reboot_summary_new">Show more options in restart menu if not locked</string>
+    <string name="long_press_power_torch_title">Long press for flashlight</string>
+    <string name="long_press_power_torch_summary">Toggle flashlight when screen is off</string>
 
     <string name="device_settings_title">Device settings</string>
     <string name="device_settings_summary">Advanced device specific settings</string>
diff --git a/app/src/main/res/xml/button_settings_preferences.xml b/app/src/main/res/xml/button_settings_preferences.xml
index 2ebedbd..fdd4930 100644
--- a/app/src/main/res/xml/button_settings_preferences.xml
+++ b/app/src/main/res/xml/button_settings_preferences.xml
@@ -13,6 +13,12 @@
             android:summary="@string/global_actions_advanced_reboot_summary_new"
             android:defaultValue="false" />
 
+        <org.omnirom.omnilib.preference.SystemSettingSwitchPreference
+            android:key="long_press_power_torch"
+            android:title="@string/long_press_power_torch_title"
+            android:summary="@string/long_press_power_torch_summary"
+            android:defaultValue="false" />
+
     </PreferenceCategory>
 
 </PreferenceScreen>