-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathWDDT.MobileTools.pas
More file actions
69 lines (57 loc) · 1.6 KB
/
Copy pathWDDT.MobileTools.pas
File metadata and controls
69 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
unit WDDT.MobileTools;
interface
uses
System.SysUtils
{$IFDEF ANDROID},
FMX.Helpers.Android,
Androidapi.JNI.App,
Androidapi.Helpers,
Androidapi.JNI.GraphicsContentViewText
{$ENDIF};
type
TMobileTools = class
protected
class function GetKeepScreenOn: Boolean; static;
class procedure SetKeepScreenOn(Value: Boolean); static;
public
class property KeepScreenOn: Boolean read GetKeepScreenOn write SetKeepScreenOn;
end;
implementation
{ TMobileTools }
class function TMobileTools.GetKeepScreenOn: Boolean;
begin
{$IFDEF ANDROID}
var FlagsResult: Integer;
CallInUIThreadAndWaitFinishing(
procedure
begin
FlagsResult := TAndroidHelper.Activity.getWindow.getAttributes.flags;
end);
Result := (FlagsResult and TJWindowManager_LayoutParams.JavaClass.FLAG_KEEP_SCREEN_ON) <> 0;
{$ELSE}
Result := False;
{$ENDIF}
end;
// Solution is based on <https://stackoverflow.com/questions/34802583/wanting-to-keep-the-screen-on-in-delphi-app-on-android>
class procedure TMobileTools.SetKeepScreenOn(Value: Boolean);
begin
{$IFDEF ANDROID}
var PerformProc: TCallBack;
if Value then
PerformProc :=
procedure
begin
TAndroidHelper.Activity.getWindow.addFlags(
TJWindowManager_LayoutParams.JavaClass.FLAG_KEEP_SCREEN_ON);
end
else
PerformProc :=
procedure
begin
TAndroidHelper.Activity.getWindow.clearFlags(
TJWindowManager_LayoutParams.JavaClass.FLAG_KEEP_SCREEN_ON);
end;
CallInUIThreadAndWaitFinishing(PerformProc);
{$ENDIF}
end;
end.