|
16 | 16 | @NativePlugin()
|
17 | 17 | public class StatusBar extends Plugin {
|
18 | 18 |
|
| 19 | + private int currentStatusbarColor; |
| 20 | + |
| 21 | + public void load() { |
| 22 | + // save initial color of the status bar |
| 23 | + currentStatusbarColor = getActivity().getWindow().getStatusBarColor(); |
| 24 | + } |
| 25 | + |
19 | 26 | @PluginMethod()
|
20 | 27 | public void setStyle(final PluginCall call) {
|
21 | 28 | final String style = call.getString("style");
|
@@ -57,7 +64,10 @@ public void run() {
|
57 | 64 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
58 | 65 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
59 | 66 | try {
|
60 |
| - window.setStatusBarColor(Color.parseColor(color.toUpperCase())); |
| 67 | + final int parsedColor = Color.parseColor(color.toUpperCase()); |
| 68 | + window.setStatusBarColor(parsedColor); |
| 69 | + // update the local color field as well |
| 70 | + currentStatusbarColor = parsedColor; |
61 | 71 | call.success();
|
62 | 72 | } catch (IllegalArgumentException ex) {
|
63 | 73 | call.error("Invalid color provided. Must be a hex string (ex: #ff0000");
|
@@ -114,6 +124,38 @@ public void getInfo(final PluginCall call) {
|
114 | 124 | data.put("visible", (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) != View.SYSTEM_UI_FLAG_FULLSCREEN);
|
115 | 125 | data.put("style", style);
|
116 | 126 | data.put("color", String.format("#%06X", (0xFFFFFF & window.getStatusBarColor())));
|
| 127 | + data.put("overlays", (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); |
117 | 128 | call.resolve(data);
|
118 | 129 | }
|
| 130 | + |
| 131 | + @PluginMethod() |
| 132 | + public void setOverlaysWebView(final PluginCall call) { |
| 133 | + final Boolean overlays = call.getBoolean("overlay", true); |
| 134 | + getBridge().executeOnMainThread(new Runnable() { |
| 135 | + @Override |
| 136 | + public void run() { |
| 137 | + if (overlays) { |
| 138 | + // Sets the layout to a fullscreen one that does not hide the actual status bar, so the webview is displayed behind it. |
| 139 | + View decorView = getActivity().getWindow().getDecorView(); |
| 140 | + int uiOptions = decorView.getSystemUiVisibility(); |
| 141 | + uiOptions = uiOptions | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 142 | + decorView.setSystemUiVisibility(uiOptions); |
| 143 | + currentStatusbarColor = getActivity().getWindow().getStatusBarColor(); |
| 144 | + getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT); |
| 145 | + |
| 146 | + call.success(); |
| 147 | + } else { |
| 148 | + // Sets the layout to a normal one that displays the webview below the status bar. |
| 149 | + View decorView = getActivity().getWindow().getDecorView(); |
| 150 | + int uiOptions = decorView.getSystemUiVisibility(); |
| 151 | + uiOptions = uiOptions & ~View.SYSTEM_UI_FLAG_LAYOUT_STABLE & ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 152 | + decorView.setSystemUiVisibility(uiOptions); |
| 153 | + // recover the previous color of the status bar |
| 154 | + getActivity().getWindow().setStatusBarColor(currentStatusbarColor); |
| 155 | + |
| 156 | + call.success(); |
| 157 | + } |
| 158 | + } |
| 159 | + }); |
| 160 | + } |
119 | 161 | }
|
0 commit comments