How to activate Immersive Full-Screen Mode in android 4.4

2,873 views
Skip to first unread message

Mibo

unread,
Dec 9, 2013, 11:22:35 AM12/9/13
to andro...@googlegroups.com
Hi!

I have created a Qt project that now runs on a Nexus 7 device. However, the design is made for the resolution 1280x800 and the bottom navigation bar makes the available screen space less than 1280 and messes up the design layout.

In Android 4.4 there is something called Immersive Full-Screen Mode (https://developer.android.com/training/system-ui/immersive.html

This mode can remove the bottom navigation bar.

To activate it I tested a quick solution by adding the function in the QtActivity.java file (the generated file). 

Added in the function onWindowFocusChanged(boolean hasFocus)
if (hasFocus) {
        decorView
.setSystemUiVisibility(
               
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);}

But It doesn't work at all in the Qt-application. (Well nothing seem to work there Log.d("TEST","message") do not seem to get printed out either).

The code works in a hello world android example on same device.

Do anyone know any solution to this? Are there a way to get into this full screen mode without editing the java files?

Mibo

unread,
Dec 10, 2013, 6:09:03 AM12/10/13
to andro...@googlegroups.com
Found a temporary solution and posting it in case others want to know.

In the file (that is located in the installation folder):
C:\Qt\Qt5.2.0_android\5.2.0-rc1\android_armv7\src\android\java\src\org\qtproject\qt5\android\bindings\QtActivity.java

In the function:

    @Override
    public void onWindowFocusChanged(boolean hasFocus)
    {


I added:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(

Ian Moreira

unread,
Dec 10, 2013, 9:46:58 AM12/10/13
to andro...@googlegroups.com
Hey! Thanks a lot for finding this solution! My app is working perfectly now. :)


--
You received this message because you are subscribed to the Google Groups "android-qt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-qt+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mibo

unread,
Dec 11, 2013, 8:28:20 AM12/11/13
to andro...@googlegroups.com

I found out a better way of doing this.

1. Add the ANDROID_PACKAGE_SOURCE_DIR = ./android/ in the Qt project file

2. Copy all files from the android templates located the Qt install directory (in my case C:\Qt\Qt5.2.0_android\5.2.0-rc1\android_armv7\src\android\java) and put them in your android folder (overwrite existing files).

3. Remove all files that are identical to the template files (keep the files you edit/create for your project)
in my case I deleted all files except these:
./android/AndroidManifest.xml
./android/src/org/qtproject/qt5/android/bindings/StartActivity.java

4. StartActivity.java is a new file and it looks like this in my case, it turns on the immersive mode and the call the super class. It extends the QtActivity class that will handle other calls necessary.

StartActivity.java
---- start ----

package org.qtproject.qt5.android.bindings;

 

import org.qtproject.qt5.android.bindings.QtActivity;

 

import android.os.Build;

import android.view.View;

import android.util.Log;

 

public class StartActivity extends QtActivity

{

 

    public StartActivity(){}

 

    @Override

    public void onWindowFocusChanged(boolean hasFocus)

    {

               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {  

                       if (hasFocus) {

                               Log.d("SCREEN","IMMERSIVE MODE ACTIVE");

                               getWindow().getDecorView().setSystemUiVisibility(

                                              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);}

               }

       

        if (!QtApplication.invokeDelegate(hasFocus).invoked)

            super.onWindowFocusChanged(hasFocus);

 

       

    }

 

}

 

---- end ----


5. In the AndroidManifest.xml I edit the activity class to be StartActivity instead of QtActivity

        <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
                  android:name="org.qtproject.qt5.android.bindings.StartActivity"

 

By doing this step you do not have to change the template file.

This solution will be project specific.






Den måndagen den 9:e december 2013 kl. 17:22:35 UTC+1 skrev Mibo:
Reply all
Reply to author
Forward
0 new messages