Skip to content

Commit 6a9fff6

Browse files
committed
New API's to control device sleep behaviour: 'enableWakeLock', 'disableWakeLock'
1 parent c365773 commit 6a9fff6

8 files changed

Lines changed: 145 additions & 78 deletions

File tree

inspector/an-inspector/ForgeModule/bin/AndroidManifest.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,67 @@
1-
package io.trigger.forge.android.modules.display;
2-
3-
import com.google.gson.JsonArray;
4-
5-
import io.trigger.forge.android.core.ForgeApp;
6-
import io.trigger.forge.android.core.ForgeParam;
7-
import io.trigger.forge.android.core.ForgeTask;
8-
import android.content.pm.ActivityInfo;
9-
import android.graphics.Color;
10-
import android.os.Build;
11-
import android.view.Window;
12-
import android.view.WindowManager;
13-
14-
public class API {
15-
public static void orientation_forcePortrait(final ForgeTask task) {
16-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
17-
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
18-
} else {
19-
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
20-
}
21-
if (task != null) {
22-
task.success();
23-
}
24-
}
25-
26-
public static void orientation_forceLandscape(final ForgeTask task) {
27-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
28-
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
29-
} else {
30-
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
31-
}
32-
if (task != null) {
33-
task.success();
34-
}
35-
}
36-
37-
public static void orientation_allowAny(final ForgeTask task) {
38-
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
39-
if (task != null) {
40-
task.success();
41-
}
42-
}
43-
public static void setStatusBarColor(final ForgeTask task, @ForgeParam("color") final JsonArray colorArray) {
44-
if (colorArray.size() != 3) {
45-
task.error("invalid color array, expecting: [r, g, b]");
46-
return;
47-
}
48-
int color = Color.rgb(colorArray.get(0).getAsInt(), colorArray.get(1).getAsInt(), colorArray.get(2).getAsInt());
49-
Util.setStatusBarColor(color);
50-
task.success();
51-
}
52-
}
53-
1+
package io.trigger.forge.android.modules.display;
2+
3+
import com.google.gson.JsonArray;
4+
5+
import io.trigger.forge.android.core.ForgeApp;
6+
import io.trigger.forge.android.core.ForgeParam;
7+
import io.trigger.forge.android.core.ForgeTask;
8+
import android.content.pm.ActivityInfo;
9+
import android.graphics.Color;
10+
import android.os.Build;
11+
import android.view.Window;
12+
import android.view.WindowManager;
13+
14+
public class API {
15+
public static void orientation_forcePortrait(final ForgeTask task) {
16+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
17+
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
18+
} else {
19+
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
20+
}
21+
if (task != null) {
22+
task.success();
23+
}
24+
}
25+
26+
public static void orientation_forceLandscape(final ForgeTask task) {
27+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
28+
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
29+
} else {
30+
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
31+
}
32+
if (task != null) {
33+
task.success();
34+
}
35+
}
36+
37+
public static void orientation_allowAny(final ForgeTask task) {
38+
ForgeApp.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
39+
if (task != null) {
40+
task.success();
41+
}
42+
}
43+
public static void setStatusBarColor(final ForgeTask task, @ForgeParam("color") final JsonArray colorArray) {
44+
if (colorArray.size() != 3) {
45+
task.error("invalid color array, expecting: [r, g, b]");
46+
return;
47+
}
48+
int color = Color.rgb(colorArray.get(0).getAsInt(), colorArray.get(1).getAsInt(), colorArray.get(2).getAsInt());
49+
Util.setStatusBarColor(color);
50+
task.success();
51+
}
52+
public static void setWakeLock(final ForgeTask task, @ForgeParam("enabled") final boolean enabled) {
53+
task.performUI(new Runnable() {
54+
@Override
55+
public void run() {
56+
if (enabled) {
57+
ForgeApp.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
58+
} else {
59+
ForgeApp.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
60+
}
61+
}
62+
});
63+
task.success();
64+
}
65+
}
66+
67+

inspector/ios-inspector/ForgeModule/ForgeModule.xcodeproj/project.pbxproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
B31B6D4515C13D5200854074 /* Project object */ = {
150150
isa = PBXProject;
151151
attributes = {
152-
LastUpgradeCheck = 0600;
152+
LastUpgradeCheck = 0820;
153153
ORGANIZATIONNAME = "Trigger Corp";
154154
};
155155
buildConfigurationList = B31B6D4815C13D5200854074 /* Build configuration list for PBXProject "ForgeModule" */;
@@ -211,13 +211,16 @@
211211
CLANG_WARN_CONSTANT_CONVERSION = YES;
212212
CLANG_WARN_EMPTY_BODY = YES;
213213
CLANG_WARN_ENUM_CONVERSION = YES;
214+
CLANG_WARN_INFINITE_RECURSION = YES;
214215
CLANG_WARN_INT_CONVERSION = YES;
216+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
215217
CLANG_WARN_UNREACHABLE_CODE = YES;
216218
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
217219
COPY_PHASE_STRIP = NO;
218220
ENABLE_STRICT_OBJC_MSGSEND = YES;
219221
GCC_C_LANGUAGE_STANDARD = gnu99;
220222
GCC_DYNAMIC_NO_PIC = NO;
223+
GCC_NO_COMMON_BLOCKS = YES;
221224
GCC_OPTIMIZATION_LEVEL = 0;
222225
GCC_PREPROCESSOR_DEFINITIONS = (
223226
"DEBUG=1",
@@ -231,7 +234,7 @@
231234
GCC_WARN_UNINITIALIZED_AUTOS = YES;
232235
GCC_WARN_UNUSED_FUNCTION = YES;
233236
GCC_WARN_UNUSED_VARIABLE = YES;
234-
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
237+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
235238
ONLY_ACTIVE_ARCH = YES;
236239
SDKROOT = iphoneos;
237240
VALID_ARCHS = "armv7 armv7s arm64 i386 x86_64";
@@ -248,20 +251,23 @@
248251
CLANG_WARN_CONSTANT_CONVERSION = YES;
249252
CLANG_WARN_EMPTY_BODY = YES;
250253
CLANG_WARN_ENUM_CONVERSION = YES;
254+
CLANG_WARN_INFINITE_RECURSION = YES;
251255
CLANG_WARN_INT_CONVERSION = YES;
256+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
252257
CLANG_WARN_UNREACHABLE_CODE = YES;
253258
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
254259
COPY_PHASE_STRIP = YES;
255260
ENABLE_STRICT_OBJC_MSGSEND = YES;
256261
GCC_C_LANGUAGE_STANDARD = gnu99;
262+
GCC_NO_COMMON_BLOCKS = YES;
257263
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
258264
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
259265
GCC_WARN_ABOUT_RETURN_TYPE = YES;
260266
GCC_WARN_UNDECLARED_SELECTOR = YES;
261267
GCC_WARN_UNINITIALIZED_AUTOS = YES;
262268
GCC_WARN_UNUSED_FUNCTION = YES;
263269
GCC_WARN_UNUSED_VARIABLE = YES;
264-
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
270+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
265271
SDKROOT = iphoneos;
266272
VALIDATE_PRODUCT = YES;
267273
VALID_ARCHS = "armv7 armv7s arm64 i386 x86_64";

inspector/ios-inspector/ForgeModule/display/display_API.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ + (void)orientation_allowAny:(ForgeTask*)task {
2626
[task success:nil];
2727
}
2828

29+
+ (void)setWakeLock:(ForgeTask*)task enabled:(NSNumber*)enabled{
30+
[[UIApplication sharedApplication] setIdleTimerDisabled:[enabled boolValue]];
31+
[task success:nil];
32+
}
33+
2934
@end

module/docs/index.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
================================
33

44
The ``forge.display`` namespace allows you to control how your app will be displayed as the device is moved
5-
around.
5+
around.
66

77
The default is to allow for any orientation, with the content being re-drawn as the screen is rotated.
88

@@ -11,19 +11,19 @@ The default is to allow for any orientation, with the content being re-drawn as
1111
###Fullscreen
1212

1313
Android, iOS 5 & 6
14-
: If set to true, the system statusbar will be hidden: your app will run completely fullscreen on the device.
14+
: If set to true, the system statusbar will be hidden: your app will run completely fullscreen on the device.
1515

1616
iOS 7+
1717
: * `not-fullscreen`: equivalent to non-fullscreen operation on iOS 5 or 6; the statusbar is shown and has a background which can be customised with the [topbar](/modules/topbar/current/) module.
18-
* `no-statusbar`: equivalent to fullscreen operation on iOS 5 or 6: the statusbar is not shown at all
19-
* `webview-under-statusbar`: your app covers the full screen (as with `no-statusbar`), but the statusbar information is shown floating over it with a higher z-index.
18+
* `no-statusbar`: equivalent to fullscreen operation on iOS 5 or 6: the statusbar is not shown at all
19+
* `webview-under-statusbar`: your app covers the full screen (as with `no-statusbar`), but the statusbar information is shown floating over it with a higher z-index.
2020

2121
###Orientations
2222

2323
iPhone, iPad, Android
2424
: Set the default orientation lock on a per platform basis.
2525
These options can be set to any of `"any"`, `"portrait"` or `"landscape"` to limit the orientations usable by the app.
26-
26+
2727
###Statusbar
2828

2929
Background Color
@@ -57,4 +57,16 @@ limitations while your app is running with the following API.
5757
!platforms: Android 5.0+
5858
!param: color `array` an array of three integers in the range [0,255] that make up the RGB color of the topbar. For example, opaque red is [255, 0, 0].
5959
!param: success `function(value)` callback to be invoked when no errors occur
60-
!param: error `function(content)` called with details of any error which may occur
60+
!param: error `function(content)` called with details of any error which may occur
61+
62+
!method: forge.display.enableWakeLock(success, error)
63+
!description: Prevent the device from entering sleep mode and disabling the display when your app is active.
64+
!platforms: iOS, Android
65+
!param: success `function(value)` callback to be invoked when no errors occur
66+
!param: error `function(content)` called with details of any error which may occur
67+
68+
!method: forge.display.disableWakeLock(success, error)
69+
!description: Remove any active wake lock preventing the device from entering sleep mode when your app is active.
70+
!platforms: iOS, Android
71+
!param: success `function(value)` callback to be invoked when no errors occur
72+
!param: error `function(content)` called with details of any error which may occur

module/javascript/module.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ forge['display'] = {
1010
forge.internal.call("display.orientation_allowAny", {}, success, error);
1111
}
1212
},
13+
'enableWakeLock': function (success, error) {
14+
forge.internal.call("display.setWakeLock", {enabled: true}, success, error);
15+
},
16+
'disableWakeLock': function (success, error) {
17+
forge.internal.call("display.setWakeLock", {enabled: false}, success, error);
18+
},
1319
'setStatusBarColor': function (color, success, error) {
1420
forge.internal.call("display.setStatusBarColor", {color: color}, success, error);
1521
}
16-
};
22+
};

module/manifest.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"changes": "* New Config Option for Android 5.0+: `statusbar.background-color`\n* New API for Android 5.0+: `setStatusBarColor`",
2+
"changes": "* New API's to control device sleep behaviour: `enableWakeLock`, `disableWakeLock`",
33
"description": "Configure display behaviour, like rotation and fullscreen, for your app.\n\nThis module also let you programmatically access and set device specific display options.",
4-
"min_platform_version": "v2.1.0",
4+
"min_platform_version": "v2.5.1",
55
"namespace": "display",
6-
"platform_version": "v2.2.0",
7-
"version": "2.5"
8-
}
6+
"platform_version": "v2.5.1",
7+
"version": "2.6"
8+
}

module/tests/interactive.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1+
/* global module, forge, asyncTest, askQuestion, ok, start */
2+
13
module("forge.display");
24

35
if (forge.is.mobile()) {
6+
asyncTest("Wake lock enabled", 1, function() {
7+
forge.display.enableWakeLock(function () {
8+
askQuestion("Does the app go to sleep?", {
9+
Yes: function () {
10+
ok(false, "User claims failure");
11+
start();
12+
}, No: function () {
13+
ok(true, "User claims success");
14+
start();
15+
}
16+
});
17+
}, function (e) {
18+
ok(false, "Error: " + JSON.stringify(e));
19+
});
20+
});
21+
22+
asyncTest("Wake lock disabled", 1, function() {
23+
forge.display.disableWakeLock(function () {
24+
askQuestion("Does the app go to sleep?", {
25+
Yes: function () {
26+
ok(true, "User claims success");
27+
start();
28+
}, No: function () {
29+
ok(false, "User claims failure");
30+
start();
31+
}
32+
});
33+
}, function (e) {
34+
ok(false, "Error: " + JSON.stringify(e));
35+
});
36+
});
37+
438
asyncTest("Initial orientation", 1, function() {
539
askQuestion("Does the app rotate freely?", {Yes: function () {
640
ok(true, "User claims success");

0 commit comments

Comments
 (0)