[PATCH] Hint for SYSTEM_UI_FLAG_LOW_PROFILE on android

Here is a small patch that adds support of android’s
SYSTEM_UI_FLAG_LOW_PROFILE that makes games look more immersive.

Regards, Alexey.
-------------- next part --------------

HG changeset patch

User stopiccot <@Alexey_Petruchik>

Date 1406141828 -10800

Node ID 0597ac969fec6c62baa0e4bc449b68f51b2d9e0e

Parent 6d059ed9b6cafdeb276802426880715f2b296a7f

Hint for SYSTEM_UI_FLAG_LOW_PROFILE on android

diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
— a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -85,8 +85,15 @@

     // Set up the surface
     mSurface = new SDLSurface(getApplication());+
  •    nativeAddHintCallback(SDL_HINT_ANDROID_USE_UI_LOW_PROFILE, new SDLHintCallback() {
    
  •        @Override
    
  •        public void callback(String name, String oldValue, String newValue) {
    
  •            updateLowProfileSettings(newValue);
    
  •        }
    
  •    });
    
  •    if(Build.VERSION.SDK_INT >= 12) {
    
  •    if (Build.VERSION.SDK_INT >= 12) {
           mJoystickHandler = new SDLJoystickHandler_API12();
       }
       else {
    

@@ -112,9 +119,9 @@
Log.v(“SDL”, “onResume()”);
super.onResume();
SDLActivity.handleResume();

  •    updateLowProfileSettings(nativeGetHint(SDL_HINT_ANDROID_USE_UI_LOW_PROFILE));
    
    }
  • @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    @@ -202,6 +209,19 @@
    mSingleton.finish();
    }
  • private static final String SDL_HINT_ANDROID_USE_UI_LOW_PROFILE = “SDL_ANDROID_USE_UI_LOW_PROFILE”;
  • void updateLowProfileSettings(String value) {
  •    if ("1".equals(value)) {
    
  •        runOnUiThread(new Runnable() {
    
  •            @Override
    
  •            public void run() {
    
  •                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    
  •            }
    
  •        });
    
  •    }
    
  • }
 // Messages from the SDLMain thread
 static final int COMMAND_CHANGE_TITLE = 1;

@@ -298,7 +318,14 @@
int is_accelerometer, int nbuttons,
int naxes, int nhats, int nballs);
public static native int nativeRemoveJoystick(int device_id);
+

  • interface SDLHintCallback {
  •    void callback(String name, String oldValue, String newValue);
    
  • }
  • public static native String nativeGetHint(String name);
  • public static native void nativeAddHintCallback(String name, SDLHintCallback callback);
 /**
  * This method is called by SDL using JNI.

diff --git a/include/SDL_hints.h b/include/SDL_hints.h
— a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -477,6 +477,11 @@
*/
#define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION “SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION”

  • /**
    • \brief If set to 1, sets UI_LOW_PROFILE setting for SDLActivity
  • */
    +#define SDL_HINT_ANDROID_USE_UI_LOW_PROFILE “SDL_ANDROID_USE_UI_LOW_PROFILE”

/**

  • \brief An enumeration of hint priorities
    diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
    — a/src/core/android/SDL_android.c
    +++ b/src/core/android/SDL_android.c
    @@ -396,6 +396,32 @@
    return result;
    }

+void Android_JNI_HintCallback(void *userdata, const char *name, const char *oldValue, const char *newValue) {

  • JNIEnv *env = Android_JNI_GetEnv();
  • jobject callback = (jobject)userdata;
  • jclass cls = (*env)->GetObjectClass(env, callback);
  • jmethodID method = (*env)->GetMethodID(env, cls, “callback”, “(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V”);
  • jstring javaName = (*env)->NewStringUTF(env, name);
  • jstring javaOldValue = (*env)->NewStringUTF(env, oldValue);
  • jstring javaNewValue = (*env)->NewStringUTF(env, newValue);
  • (*env)->CallVoidMethod(env, callback, method, javaName, javaOldValue, javaNewValue);
  • (*env)->DeleteLocalRef(env, javaName);
  • (*env)->DeleteLocalRef(env, javaOldValue);
  • (*env)->DeleteLocalRef(env, javaNewValue);
    +}

+void Java_org_libsdl_app_SDLActivity_nativeAddHintCallback(JNIEnv* env, jclass cls, jstring name, jobject callback) {

  • const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
  • SDL_AddHintCallback(utfname, Android_JNI_HintCallback, (*env)->NewGlobalRef(env, callback));
  • (*env)->ReleaseStringUTFChars(env, name, utfname);
    +}

/*******************************************************************************
Functions called by SDL into Java
*******************************************************************************/

Thanks, I’m keeping this to add after the 2.0.4 release (as well as a few
other patches in the queue).

2014-07-23 16:01 GMT-03:00 Alexey Petruchik <alexey.petruchik at gmail.com>:> Here is a small patch that adds support of android’s

SYSTEM_UI_FLAG_LOW_PROFILE that makes games look more immersive.

Regards, Alexey.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

Funny thing is that 2.0.4 announcement was the reason why I finally sent
this patchOn Thu, Jul 24, 2014 at 4:31 PM, Gabriel Jacobo wrote:

Thanks, I’m keeping this to add after the 2.0.4 release (as well as a few
other patches in the queue).

2014-07-23 16:01 GMT-03:00 Alexey Petruchik <@Alexey_Petruchik>:

Here is a small patch that adds support of android’s
SYSTEM_UI_FLAG_LOW_PROFILE that makes games look more immersive.

Regards, Alexey.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org