CB-9513 Allow to show/hide status bar in fullscreen mode. This closes #42

This commit is contained in:
Vladimir Kotikov 2015-12-29 10:27:43 +03:00
parent d853f828d6
commit a4a1065c4f

View File

@ -23,6 +23,7 @@ import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@ -76,6 +77,7 @@ public class StatusBar extends CordovaPlugin {
Log.v(TAG, "Executing action: " + action);
final Activity activity = this.cordova.getActivity();
final Window window = activity.getWindow();
if ("_ready".equals(action)) {
boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
@ -86,6 +88,17 @@ public class StatusBar extends CordovaPlugin {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we
// use KitKat here to be aligned with "Fullscreen" preference
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiOptions = window.getDecorView().getSystemUiVisibility();
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
return;
}
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
@ -96,6 +109,17 @@ public class StatusBar extends CordovaPlugin {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we
// use KitKat here to be aligned with "Fullscreen" preference
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiOptions = window.getDecorView().getSystemUiVisibility()
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
return;
}
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});