Flashlight Toggle - Bifunctional With Screen Light or Flash 1.0

Toggle flashlight by gesture.

  1. autormali
    Flashlight is triggered/toggled by profile with shake left-right gesture context but you can use any other context e.g. TapTap.

    The choice of which function is used (screen light or torch) depends on whether the display is unlocked or locked and screen is on or off.

    When:
    • display is locked and screen off - flash is being turned on/off by gesture. Optionally it can be turned off by quick setting tile.
    • display unlocked and screen on - screen light is being turned on/off by gesture. Tasker scene is used to illuminate the screen. Optionally it can be turned off by an icon in the center of scene. Screen light when is turned on sets display brightness to maximum and display timeout to 10 minutes (can be changed by user). Additionaly there is a slider to adjust display brightness placed at bottom of the scene.

    Descrtiption:
    Code (Text):
      Profile: Flashlight Toggle On Shake (1057)
        Event: Shake [ Axis:Left-Right Sensitivity:Medium Duration:Medium ]
        Enter: Flashlight Toggle (1039)
        <Is screen locked?>
        A1: Java Function [ Return:kgm Class Or Object:CONTEXT Function:getSystemService
        {KeyguardManager} (String) Param:keyguard Param: Param: Param: Param: Param: Param: ]
        <%locked returns true or false>
        A2: Java Function [ Return:%locked Class Or Object:kgm Function:inKeyguardRestrictedInputMode
        {boolean} () Param: Param: Param: Param: Param: Param: Param: ]
        A3: If [ %ToggleFlashlight ~ off ]
        <>
        A4: Vibrate Pattern [ Pattern:50,150,50,150 ]
        A5: Variable Set [ Name:%ToggleFlashlight To:on Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
        <Enable screen flashlight>
        A6: If [ %locked ~ false & %SCREEN ~ on ]
        <Store display timeout>
        A7: Variable Set [ Name:%LastTimeout To:%DTOUT Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
        A8: Display Timeout [ Secs:0 Mins:10 Hours:0 ]
        <Store brightness level>
        A9: Variable Set [ Name:%CurrentBrightness To:%BRIGHT Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
        A10: [X] Auto Brightness [ Set:Off ]
        A11: Display Timeout [ Secs:0 Mins:10 Hours:0 ]
        <➡️ Set here screen brightness at start of screen flashlight. Default 255 - maximum screen brightness. This variable is used  to set brightness slider position in the scene. Values accepted 0-255.>
        A12: Variable Set [ Name:%FlashScreenBrightness To:255 Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
        <Set brightness %FlashScreenBrightness value>
        A13: Perform Task [ Name:Set Brightness ↩️ Priority:%priority Parameter 1 (%par1):%FlashScreenBrightness Parameter 2 (%par2): Return Value Variable: Stop:Off Local Variable Passthrough:Off Limit Passthrough To: Reset Return Variable:Off Allow Overwrite Variables:Off ]
        <>
        A14: Show Scene [ Name:Flashlight Scn Display As:Activity, No Bar, No Status, No Nav Horizontal Position:100 Vertical Position:100 Animation:Scale Show Exit Button:Off Show Over Keyguard:On Continue Task Immediately:On ]
        <>
        A15: Stop [ With Error:Off Task: ]
        <Turn torch on>
        A16: Else If [ %locked ~ true & %SCREEN ~ off ]
        <>
        A17: Torch [ Set:On ]
        <>
        A18: Stop [ With Error:Off Task: ]
        A19: End If
        A20: Else
        <>
        A21: Vibrate Pattern [ Pattern:50,150 ]
        A22: Variable Set [ Name:%ToggleFlashlight To:off Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
        <Disable screen flashlight>
        A23: If [ %locked ~ false ]
        <❌>
        A24: Perform Task [ Name:Flashlight Destroy Scn Restore Settings Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off Local Variable Passthrough:Off Limit Passthrough To: Reset Return Variable:Off Allow Overwrite Variables:Off ]
        <Turn torch off>
        A25: Else If [ %locked ~ true ]
        <❌>
        A26: Torch [ Set:Off ]
        A27: End If
        A28: Variable Clear [ Name:%CurrentBrightness/%LastTimeout/%FlashScreenBrightness Pattern Matching:On Local Variables Only:Off Clear All Variables:Off ]
        A29: End If
    ***
        Profile: Flashlight Quick Setting Tile Off (659)
        Restore: no
        Event: Custom Setting [ Type:Secure Name:flashlight_enabled Value:0 ]
        Enter: Anon (871)
        <The profile and this task is activated and setting variable only - in the case you activated torch by shake and switched it off by quick setting tile. The name of setting flashlight_enabled appeared on Android 10. Below Android 10 the setting name is torch_enabled. Consider modify profile context if you're using phone with version below Android 10.>
        A1: Anchor
        A2: Variable Set [ Name:%ToggleFlashlight To:off Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
    ***
        Flashlight Destroy Scn Restore Settings (1056)
        A1: Destroy Scene [ Name:Flashlight Scn ]
        A2: Perform Task [ Name:SET Set Brightness ↩️ Priority:%priority Parameter 1 (%par1):%CurrentBrightness Parameter 2 (%par2): Return Value Variable: Stop:Off Local Variable Passthrough:Off Limit Passthrough To: Reset Return Variable:Off Allow Overwrite Variables:Off ]
        A3: Variable Set [ Name:%ToggleFlashlight To:off Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
        A4: [X] Auto Brightness [ Set:On ]
        A5: Display Timeout [ Secs:%LastTimeout Mins:0 Hours:0 ]
        A6: Variable Clear [ Name:%CurrentBrightness/%LastTimeout/%FlashScreenBrightness Pattern Matching:On Local Variables Only:Off Clear All Variables:Off ]
    ***
        Set Brightness ↩️ (1064)
        <Use this task to set the decided brightness level.
        You can (and must) still using the usual range: 0 - 255. Set %par1 to 0 -255.>
        A1: Anchor
        A2: Java Function [ Return:(PowerManager) pm Class Or Object:CONTEXT Function:getSystemService
        {Object} (String) Param:power Param: Param: Param: Param: Param: Param: ]
        <Minimum>
        A3: Java Function [ Return:%min Class Or Object:pm Function:getMinimumScreenBrightnessSetting
        {int} () Param: Param: Param: Param: Param: Param: Param: ]
        <Maximum>
        A4: Java Function [ Return:%max Class Or Object:pm Function:getMaximumScreenBrightnessSetting
        {int} () Param: Param: Param: Param: Param: Param: Param: ]
        A5: Variable Set [ Name:%math To:(%max - %min) / 255 Recurse Variables:Off Do Maths:On Append:Off Max Rounding Digits:1 ]
        A6: Variable Set [ Name:%new_value To:%math * %par1 Recurse Variables:Off Do Maths:On Append:Off Max Rounding Digits:1 ]
        A7: Variable Set [ Name:%new_value To:%min - 1 Recurse Variables:Off Do Maths:On Append:Off Max Rounding Digits:1 ] If [ %par1 < 1 ]
        A8: Variable Set [ Name:%new_value To:%max Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:1 ] If [ %par1 > 254 ]
        A9: Flash [ Text:Brightness set to: %new_value Long:Off ]
        <Set Brightness>
        A10: Custom Setting [ Type:System Name:screen_brightness Value:%new_value Use Root:On Read Setting To: ] If [ %par1 < 1 ]
        <Set Brightness>
        A11: Display Brightness [ Level:%new_value Disable Safeguard:Off Ignore Current Level:Off Immediate Effect:Off ] If [ %par1 > 0 ]
    ***
    Scene: Flashlight Scn
    P:1080x1848 L:-1x-1

    Orientation: Portrait
    Background Colour: #FFFFFFFF
    Action Bar Style: System
    Title: Flash
    Subtitle:
    Icon: null
    Tab Labels:

    Element: Image1/Image
    Geometry:
    P:427,761 250x250 L:427,761 250x250
    Content:
    Image: hl_ab_aaa_ext_io
    Alpha: 255
    Events:
    Click: 1060

    Element: Slider1/Slider
    Geometry:
    P:80,1350 900x250 L:77,1311 927x250
    Content:
    Orientation: Horizontal
    Min: 0
    Max: 255
    Default: %FlashScreenBrightness
    Show Indicators: Never
    Thumb Icon: hl_device_access_brightness_medium
    Events:
    ValueSelected: 723