Вопрос

I'm developing an app using Trigger.io, and I'm interested in the "Immersive mode" which was added in Android 4.4 to allow users to hide the native UI bars.

I've tried using the display module's "Full Screen" option, but that seems limited to hiding the top bar.

Does Trigger.io have any native commands which trigger the new "Immersive mode"?

If not, is it possible to expose this flag to JavaScript by writing a custom module?

Это было полезно?

Решение

Looking at the trigger.io display v2.3 module's source code, the fullscreen config option hides the status bar (top bar) only.

To hide the Navigation Bar (Android 4.0) or to use the Immersive Full-Screen Mode (Android 4.4) you will need to write a native (custom) module.

For Immersive mode, you could add the following code which detects and toggles immersive mode to a native module which was adapted from the Android BasicImmersiveMode Sample

public static void toggleHideyBar(final ForgeTask task) {
    task.performUI(new Runnable() {
        public void run() {
            // The UI options currently enabled are represented by a bitfield.
            // getSystemUiVisibility() gives us that bitfield.
            int uiOptions = ForgeApp.getActivity().getWindow().getDecorView().getSystemUiVisibility();
            int newUiOptions = uiOptions;
            boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
            if (isImmersiveModeEnabled) {
                ForgeLog.d("Turning immersive mode mode off.");
            } else {
                ForgeLog.d("Turning immersive mode mode on.");
            }

            // Navigation bar hiding:  Backwards compatible to ICS.
            if (Build.VERSION.SDK_INT >= 14) {
                newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            }

            // Status bar hiding: Backwards compatible to Jellybean
            if (Build.VERSION.SDK_INT >= 16) {
                newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
            }

            // Immersive mode: Backward compatible to KitKat.
            // Note that this flag doesn't do anything by itself, it only augments the behavior
            // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
            // all three flags are being toggled together.
            // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
            // Sticky immersive mode differs in that it makes the navigation and status bars
            // semi-transparent, and the UI flag does not get cleared when the user interacts with
            // the screen.
            if (Build.VERSION.SDK_INT >= 18) {
                newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }

            ForgeApp.getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
            task.success();
        }
    });
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top