mesmotronic / cordova-plugin-fullscreen

Plugin for Cordova (PhoneGap) to enable Android's various full screen modes
BSD 3-Clause "New" or "Revised" License
168 stars 56 forks source link

Fullscreen and resizable webview #41

Closed kilisio closed 4 years ago

kilisio commented 4 years ago

is it possible to toggle fullscreen on and off?

kilisio commented 4 years ago

My main reason for asking about fullscreen toggling is because when I enabled immersive mode and an input element came to focus, it would get hidden behind either the keyboard or the status barand also I needed my webview to resize based on my css. So i thought it would be better to control the fullscreen visibility manually, but i found a better hack. I modified the original plugin immersive mode function and commented out the layout flags.

    protected boolean immersiveMode()
    {
        if (!isImmersiveModeSupported())
        {
            context.error("Not supported");
            return false;
        }

        activity.runOnUiThread(new Runnable()
        {
            @Override
            public void run() 
            {
                try
                {
                    resetWindow();

                    final int uiOptions = 
                        // View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        // | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

                    // window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    decorView.setSystemUiVisibility(uiOptions);

                    decorView.setOnFocusChangeListener(new View.OnFocusChangeListener() 
                    {
                        @Override
                        public void onFocusChange(View v, boolean hasFocus) 
                        {
                            if (hasFocus)
                            {
                                decorView.setSystemUiVisibility(uiOptions);
                            }
                        }
                    });

                    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
                    {
                        @Override
                        public void onSystemUiVisibilityChange(int visibility) 
                        {
                            decorView.setSystemUiVisibility(uiOptions);
                        }
                    });

                    context.success();
                }
                catch (Exception e)
                {
                    context.error(e.getMessage());
                }
            }
        });

        return true;
    }

then simply added the plugin using my modified fork i.e

cordova plugin add https://github.com/kilisio/cordova-plugin-fullscreen.git#forked_dev

I dont know java, but it was a fun hacking and learning something new... thanks for the great plugin

neilrackett commented 4 years ago

Great to hear you found a solution!