Trigger.io可以访问KitKat的“沉浸式”模式吗?

时间:2014-04-01 13:44:02

标签: android trigger.io android-4.4-kitkat

我正在使用Trigger.io开发一个应用程序,我对Android 4.4中添加的“沉浸模式”感兴趣,以允许用户隐藏本机UI栏。

我尝试使用display模块的“全屏”选项,但这似乎仅限于隐藏顶部栏。

Trigger.io是否有任何触发新“沉浸模式”的本机命令?

如果没有,是否可以通过编写自定义模块将此标志公开给JavaScript?

1 个答案:

答案 0 :(得分:1)

查看trigger.io display v2.3模块的source code,全屏配置选项仅隐藏状态栏(顶部栏)。

要隐藏导航栏(Android 4.0)或使用沉浸式全屏模式(Android 4.4),您需要编写本机(自定义)模块。

对于沉浸式模式,您可以添加以下代码,以检测并将沉浸式模式切换到本机模块,该模块改编自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();
        }
    });
}