Added SDL_IsAndroidTV()
authorSam Lantinga <slouken@libsdl.org>
Tue, 06 Feb 2018 15:03:35 -0800
changeset 118448e2ca40e07f3
parent 11843 bbe75e4fc57e
child 11845 cf80a56f6d8d
Added SDL_IsAndroidTV()
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
include/SDL_system.h
src/core/android/SDL_android.c
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Feb 05 11:40:39 2018 -0800
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Feb 06 15:03:35 2018 -0800
     1.3 @@ -7,6 +7,7 @@
     1.4  
     1.5  import android.app.*;
     1.6  import android.content.*;
     1.7 +import android.content.res.Configuration;
     1.8  import android.text.InputType;
     1.9  import android.view.*;
    1.10  import android.view.inputmethod.BaseInputConnection;
    1.11 @@ -611,6 +612,17 @@
    1.12          return SDL.getContext();
    1.13      }
    1.14  
    1.15 +    /**
    1.16 +     * This method is called by SDL using JNI.
    1.17 +     */
    1.18 +    public static boolean isAndroidTV() {
    1.19 +        UiModeManager uiModeManager = (UiModeManager) getContext().getSystemService(UI_MODE_SERVICE);
    1.20 +        return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION);
    1.21 +    }
    1.22 +
    1.23 +    /**
    1.24 +     * This method is called by SDL using JNI.
    1.25 +     */
    1.26      public static DisplayMetrics getDisplayDPI() {
    1.27          return getContext().getResources().getDisplayMetrics();
    1.28      }
    1.29 @@ -1027,7 +1039,6 @@
    1.30      public static void clipboardSetText(String string) {
    1.31          mClipboardHandler.clipboardSetText(string);
    1.32      }
    1.33 -
    1.34  }
    1.35  
    1.36  /**
     2.1 --- a/include/SDL_system.h	Mon Feb 05 11:40:39 2018 -0800
     2.2 +++ b/include/SDL_system.h	Tue Feb 06 15:03:35 2018 -0800
     2.3 @@ -109,6 +109,11 @@
     2.4  extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);
     2.5  
     2.6  /**
     2.7 +   \brief Return true if the application is running on Android TV
     2.8 + */
     2.9 +extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
    2.10 +
    2.11 +/**
    2.12     See the official Android developer guide for more information:
    2.13     http://developer.android.com/guide/topics/data/data-storage.html
    2.14  */
     3.1 --- a/src/core/android/SDL_android.c	Mon Feb 05 11:40:39 2018 -0800
     3.2 +++ b/src/core/android/SDL_android.c	Tue Feb 06 15:03:35 2018 -0800
     3.3 @@ -211,6 +211,7 @@
     3.4  static jmethodID midSetActivityTitle;
     3.5  static jmethodID midSetOrientation;
     3.6  static jmethodID midGetContext;
     3.7 +static jmethodID midIsAndroidTV;
     3.8  static jmethodID midInputGetInputDeviceIds;
     3.9  static jmethodID midSendMessage;
    3.10  static jmethodID midShowTextInput;
    3.11 @@ -305,6 +306,8 @@
    3.12                                  "setOrientation","(IIZLjava/lang/String;)V");
    3.13      midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.14                                  "getContext","()Landroid/content/Context;");
    3.15 +    midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.16 +                                "isAndroidTV","()Z");
    3.17      midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.18                                  "inputGetInputDeviceIds", "(I)[I");
    3.19      midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.20 @@ -326,9 +329,10 @@
    3.21                                  "getManifestEnvironmentVariables", "()Z");
    3.22  
    3.23      midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
    3.24 +    midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
    3.25  
    3.26      if (!midGetNativeSurface ||
    3.27 -       !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
    3.28 +       !midSetActivityTitle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
    3.29         !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
    3.30         !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
    3.31         !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables|| !midGetDisplayDPI) {
    3.32 @@ -1993,6 +1997,12 @@
    3.33      return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
    3.34  }
    3.35  
    3.36 +SDL_bool SDL_IsAndroidTV(void)
    3.37 +{
    3.38 +    JNIEnv *env = Android_JNI_GetEnv();
    3.39 +    return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsAndroidTV);
    3.40 +}
    3.41 +
    3.42  const char * SDL_AndroidGetInternalStoragePath(void)
    3.43  {
    3.44      static char *s_AndroidInternalFilesPath = NULL;
     4.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Mon Feb 05 11:40:39 2018 -0800
     4.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Feb 06 15:03:35 2018 -0800
     4.3 @@ -665,3 +665,5 @@
     4.4  #define SDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution_REAL
     4.5  #define SDL_RenderGetMetalLayer SDL_RenderGetMetalLayer_REAL
     4.6  #define SDL_RenderGetMetalCommandEncoder SDL_RenderGetMetalCommandEncoder_REAL
     4.7 +#define SDL_IsAndroidTV SDL_IsAndroidTV_REAL
     4.8 +#define SDL_WinRTGetDeviceFamily SDL_WinRTGetDeviceFamily_REAL
     5.1 --- a/src/dynapi/SDL_dynapi_procs.h	Mon Feb 05 11:40:39 2018 -0800
     5.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Tue Feb 06 15:03:35 2018 -0800
     5.3 @@ -69,12 +69,12 @@
     5.4  SDL_DYNAPI_PROC(IDirect3DDevice9*,SDL_RenderGetD3D9Device,(SDL_Renderer *a),(a),return)
     5.5  #endif
     5.6  
     5.7 -#if defined(__IPHONEOS__) && __IPHONEOS__
     5.8 +#ifdef __IPHONEOS__
     5.9  SDL_DYNAPI_PROC(int,SDL_iPhoneSetAnimationCallback,(SDL_Window *a, int b, void c, void *d),(a,b,c,d),return)
    5.10  SDL_DYNAPI_PROC(void,SDL_iPhoneSetEventPump,(SDL_bool a),(a),)
    5.11  #endif
    5.12  
    5.13 -#if defined(__ANDROID__) && __ANDROID__
    5.14 +#ifdef __ANDROID__
    5.15  SDL_DYNAPI_PROC(void*,SDL_AndroidGetJNIEnv,(void),(),return)
    5.16  SDL_DYNAPI_PROC(void*,SDL_AndroidGetActivity,(void),(),return)
    5.17  SDL_DYNAPI_PROC(const char*,SDL_AndroidGetInternalStoragePath,(void),(),return)
    5.18 @@ -699,3 +699,9 @@
    5.19  SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionModeForResolution,(int a, int b),(a,b),return)
    5.20  SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalLayer,(SDL_Renderer *a),(a),return)
    5.21  SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalCommandEncoder,(SDL_Renderer *a),(a),return)
    5.22 +#ifdef __WINRT__
    5.23 +SDL_DYNAPI_PROC(SDL_WinRT_DeviceFamily,SDL_WinRTGetDeviceFamily,(void),(),return)
    5.24 +#endif
    5.25 +#ifdef __ANDROID__
    5.26 +SDL_DYNAPI_PROC(SDL_bool,SDL_IsAndroidTV,(void),(),return)
    5.27 +#endif