Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Several classes in android manifest.

Several classes in android manifest.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 1 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexorleon
    wrote on 20 May 2016, 03:18 last edited by
    #1

    Hello!
    I wanted to hide ActionBar in android.

    // java code
    if(getSupportActionBar().isShowing()) {
    
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    
        getSupportActionBar().hide();
    } else {
        getSupportActionBar().show();
    }
    

    To test this code, I created an empty project "Blanck Activity" in Android Studio. I added code to the button. Works great.
    Now the implementation in Qt.

    // main.cpp
    QAndroidJniObject::callStaticMethod<void>("AndroidBar", "hideNavigationBar");
    
    // AndroidBar.java
    import android.view.View;
    import android.util.Log;
    
    public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity
    {
        private static final String TAG = AndroidBar.class.getSimpleName();
    
        public static void hideNavigationBar() {
    
            Log.d(TAG, "Hide navigation bar");
    
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }
    

    But there is an error:
    non-static method getWindow() cannot be referenced from a static context

    Then I decided to create a separate class.

    // AndroidBar.java
    import android.util.Log;
    
    public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity
    {
        private static final String TAG = AndroidBar.class.getSimpleName();
    
        public static void hideNavigationBar() {
    
            Log.d(TAG, "Hide navigation bar");
    
            MyTest test = new MyTest();
            test.hideBar();
    
            test = null;
        }
    }
    
    // MyTest.java
    import android.view.View;
    import android.util.Log;
    
    public class MyTest extends org.qtproject.qt5.android.bindings.QtActivity
    {
        private String TAG = AndroidBar.class.getSimpleName();
    
        public void hideBar() {
    
            Log.d(TAG, "Hide bar");
    
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }
    

    No errors, but the method is not called. In the Android Studio it works.

    // .pro
    android {
        QT += androidextras
        ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
        OTHER_FILES += android/AndroidManifest.xml \
        android/src/AndroidBar.java \
        android/src/MyTest.java
    }
    
    // AndroidManifest.xml
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication">
            <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" 
    				  android:label="@string/app_name" 
    				  android:name="org.qtproject.qt5.android.bindings.QtActivity"
    				  android:screenOrientation="landscape">
    

    How to add this class to the project? Or are there other solutions?

    A 1 Reply Last reply 9 Jun 2016, 05:00
    0
    • A Alexorleon
      20 May 2016, 03:18

      Hello!
      I wanted to hide ActionBar in android.

      // java code
      if(getSupportActionBar().isShowing()) {
      
          View decorView = getWindow().getDecorView();
          int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
          decorView.setSystemUiVisibility(uiOptions);
      
          getSupportActionBar().hide();
      } else {
          getSupportActionBar().show();
      }
      

      To test this code, I created an empty project "Blanck Activity" in Android Studio. I added code to the button. Works great.
      Now the implementation in Qt.

      // main.cpp
      QAndroidJniObject::callStaticMethod<void>("AndroidBar", "hideNavigationBar");
      
      // AndroidBar.java
      import android.view.View;
      import android.util.Log;
      
      public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity
      {
          private static final String TAG = AndroidBar.class.getSimpleName();
      
          public static void hideNavigationBar() {
      
              Log.d(TAG, "Hide navigation bar");
      
              View decorView = getWindow().getDecorView();
              int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
              decorView.setSystemUiVisibility(uiOptions);
          }
      }
      

      But there is an error:
      non-static method getWindow() cannot be referenced from a static context

      Then I decided to create a separate class.

      // AndroidBar.java
      import android.util.Log;
      
      public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity
      {
          private static final String TAG = AndroidBar.class.getSimpleName();
      
          public static void hideNavigationBar() {
      
              Log.d(TAG, "Hide navigation bar");
      
              MyTest test = new MyTest();
              test.hideBar();
      
              test = null;
          }
      }
      
      // MyTest.java
      import android.view.View;
      import android.util.Log;
      
      public class MyTest extends org.qtproject.qt5.android.bindings.QtActivity
      {
          private String TAG = AndroidBar.class.getSimpleName();
      
          public void hideBar() {
      
              Log.d(TAG, "Hide bar");
      
              View decorView = getWindow().getDecorView();
              int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
              decorView.setSystemUiVisibility(uiOptions);
          }
      }
      

      No errors, but the method is not called. In the Android Studio it works.

      // .pro
      android {
          QT += androidextras
          ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
          OTHER_FILES += android/AndroidManifest.xml \
          android/src/AndroidBar.java \
          android/src/MyTest.java
      }
      
      // AndroidManifest.xml
      <application android:icon="@drawable/icon" android:label="@string/app_name" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication">
              <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" 
      				  android:label="@string/app_name" 
      				  android:name="org.qtproject.qt5.android.bindings.QtActivity"
      				  android:screenOrientation="landscape">
      

      How to add this class to the project? Or are there other solutions?

      A Offline
      A Offline
      Alexorleon
      wrote on 9 Jun 2016, 05:00 last edited by
      #2

      Create a new activity in your andrdoid/src folder subclassing QtActivity.
      In this article, all explained in detail - https://www.kdab.com/qt-android-episode-7/.
      At the end of the article there is the source code.

      Add method in the class MyActivity.

      @Override
          public void onWindowFocusChanged(boolean hasFocus)
          {
              Log.d("BLABLA", "Window focus changed");
              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);
          }
      

      Do not forget about it:

      import android.os.Build;
      import android.view.View;
      import android.util.Log;
      

      It works on version 4.4.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved