CB-10879: Enable overlaysWebView on Android API 21+

This closes #77

This patch enables devices running Android API 21+ to have the status bar overlaying the WebView, i.e. `StatusBar.overlaysWebView(true)`. It lets any Android version call `StatusBar.overlaysWebView(false)` to disable the overlay, which is actually the default behavior on that platform.
This commit is contained in:
Andrea Lazzarotto 2017-02-26 20:11:07 +01:00 committed by Joe Bowser
parent d980145c98
commit 3f552ed734

View File

@ -142,6 +142,23 @@ public class StatusBar extends CordovaPlugin {
return true;
}
if ("overlaysWebView".equals(action)) {
if (Build.VERSION.SDK_INT >= 21) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setStatusBarTransparent(args.getBoolean(0));
} catch (JSONException ignore) {
LOG.e(TAG, "Invalid boolean argument");
}
}
});
return true;
}
else return args.getBoolean(0) == false;
}
return false;
}
@ -164,4 +181,21 @@ public class StatusBar extends CordovaPlugin {
}
}
}
private void setStatusBarTransparent(final boolean transparent) {
if (Build.VERSION.SDK_INT >= 21) {
final Window window = cordova.getActivity().getWindow();
if (transparent) {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.setStatusBarColor(Color.TRANSPARENT);
}
else {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_VISIBLE);
}
}
}
}