|
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 | + |
0 commit comments