Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eab1c5d5 authored by Sam Mortimer's avatar Sam Mortimer Committed by Michael Bestas
Browse files

[3/3] Torch long press power: add auto-off function

Change-Id: I701cd239a355c6e4ddbed858262d89e21c5b8fae
parent e8a2f896
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -322,4 +322,20 @@
        <item>8</item>
        <item>9</item>
    </string-array>

    <string-array name="torch_long_press_power_timeout_entries">
        <item>@string/auto_power_save_never</item>
        <item>1 minute</item>
        <item>2 minutes</item>
        <item>5 minutes</item>
        <item>10 minutes</item>
    </string-array>

    <string-array name="torch_long_press_power_timeout_values" translatable="false">
        <item>0</item>
        <item>60</item>
        <item>120</item>
        <item>300</item>
        <item>600</item>
    </string-array>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -259,6 +259,7 @@

    <string name="torch_long_press_power_gesture_title">Long press for torch</string>
    <string name="torch_long_press_power_gesture_desc">Activate the torch by long pressing the power button while the display is off</string>
    <string name="torch_long_press_power_timeout_title">Automatically turn torch off</string>

    <!-- Profiles -->
    <string name="profile_menu_delete_title">Delete</string>
+9 −0
Original line number Diff line number Diff line
@@ -99,6 +99,15 @@
            android:defaultValue="false"
            cm:requiresConfig="@*android:bool/config_supportLongPressPowerWhenNonInteractive" />

        <ListPreference
            android:key="torch_long_press_power_timeout"
            android:dialogTitle="@string/torch_long_press_power_timeout_title"
            android:title="@string/torch_long_press_power_timeout_title"
            android:entries="@array/torch_long_press_power_timeout_entries"
            android:entryValues="@array/torch_long_press_power_timeout_values"
            android:dependency="torch_long_press_power_gesture"
            android:persistent="false" />

    </PreferenceCategory>

    <PreferenceCategory
+12 −0
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
    private static final String KEY_VOLUME_CONTROL_RING_STREAM = "volume_keys_control_ring_stream";
    private static final String KEY_TORCH_LONG_PRESS_POWER_GESTURE =
            "torch_long_press_power_gesture";
    private static final String KEY_TORCH_LONG_PRESS_POWER_TIMEOUT =
            "torch_long_press_power_timeout";

    private static final String CATEGORY_POWER = "power_key";
    private static final String CATEGORY_HOME = "home_key";
@@ -152,6 +154,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
    private SwitchPreference mPowerEndCall;
    private SwitchPreference mHomeAnswerCall;
    private SwitchPreference mTorchLongPressPowerGesture;
    private ListPreference mTorchLongPressPowerTimeout;

    private PreferenceCategory mNavigationPreferencesCat;

@@ -213,6 +216,10 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
        // Long press power while display is off to activate torchlight
        mTorchLongPressPowerGesture =
                (SwitchPreference) findPreference(KEY_TORCH_LONG_PRESS_POWER_GESTURE);
        final int torchLongPressPowerTimeout = CMSettings.System.getInt(resolver,
                CMSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, 0);
        mTorchLongPressPowerTimeout = initList(KEY_TORCH_LONG_PRESS_POWER_TIMEOUT,
                torchLongPressPowerTimeout);

        // Home button answers calls.
        mHomeAnswerCall = (SwitchPreference) findPreference(KEY_HOME_ANSWER_CALL);
@@ -288,6 +295,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
            }
            if (!QSUtils.deviceSupportsFlashLight(getActivity())) {
                powerCategory.removePreference(mTorchLongPressPowerGesture);
                powerCategory.removePreference(mTorchLongPressPowerTimeout);
            }
        } else {
            prefScreen.removePreference(powerCategory);
@@ -634,6 +642,10 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
            CMSettings.Secure.putString(getContentResolver(),
                    CMSettings.Secure.RECENTS_LONG_PRESS_ACTIVITY, putString);
            return true;
        } else if (preference == mTorchLongPressPowerTimeout) {
            handleListChange(mTorchLongPressPowerTimeout, newValue,
                    CMSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT);
            return true;
        }
        return false;
    }