Share My Creation Block Phone Screen from turned off

Name: TDScreenOnOFF
Version: 1

This solution gives the user the possibility tu override the phone screen off timeout. The settings values will not affected (Button btAn). After override the button color turns yellow. After doing his actions while the screen is on the user is able to reset back to the standard settings screen timeout (Button btClose) the button color turns back to blue.

NOTICE!
Do not forget to reset the override back because screen on means to consumpt battery energy. Reset is done by clicking button btAn again or closing the App with button btClose. Do not close the App with the phones navigation bar.

Find the needed code here and put it in an Activity Project in the Activity Main:

Code Main Activity:
#Region  Project Attributes
    #ApplicationLabel: TDScreenOnOff
    #VersionCode: 1
    #VersionName: TDScreenOnOFF
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Private xui As XUI
End Sub

Sub Globals
    Private PWS As PhoneWakeState
    Private statusAn As Boolean = False
    Private btAn As Label
    Private btClose As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Activity.Title = "TDScreenON: Bildschirm immer an?"
End Sub


Private Sub btClose_Click
    ' reset screen on to phone standard
    PWS.ReleaseKeepAlive
    ' close all activities
    Dim jo As JavaObject
    jo.InitializeContext
    jo.RunMethod("finishAffinity", Null)
End Sub

Private Sub btAn_Click
    ' toogle status
    statusAn = Not(statusAn)
    
    If statusAn Then
        ' disable phone standard screen timeout
        PWS.KeepAlive(True)
        ' set button param
        btAn.Color = Colors.yellow
        btAn.TextColor=Colors.black
        btAn.Text = "Bleibt immer an!"
    Else
        ' enable phone standard screen timeout
        PWS.ReleaseKeepAlive
        ' set button param
        btAn.Color = Colors.blue
        btAn.TextColor=Colors.white
        btAn.Text = "Ja, immer anschalten."
    End If
End Sub

You need a layout file called "layout.bal" with two buttons btAn and btClose. An you must activate the phone-library.
 
Top