From 6ed184ec69716425c8bdc03042882881f1165ad1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 6 Feb 2018 15:03:35 -0800 Subject: [PATCH] Added SDL_IsAndroidTV() --- .../src/main/java/org/libsdl/app/SDLActivity.java | 13 ++++++++++++- include/SDL_system.h | 5 +++++ src/core/android/SDL_android.c | 12 +++++++++++- src/dynapi/SDL_dynapi_overrides.h | 2 ++ src/dynapi/SDL_dynapi_procs.h | 10 ++++++++-- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index b91c6139d..a3fcbe73c 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -7,6 +7,7 @@ import java.lang.reflect.Method; import android.app.*; import android.content.*; +import android.content.res.Configuration; import android.text.InputType; import android.view.*; import android.view.inputmethod.BaseInputConnection; @@ -611,6 +612,17 @@ public class SDLActivity extends Activity { return SDL.getContext(); } + /** + * This method is called by SDL using JNI. + */ + public static boolean isAndroidTV() { + UiModeManager uiModeManager = (UiModeManager) getContext().getSystemService(UI_MODE_SERVICE); + return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION); + } + + /** + * This method is called by SDL using JNI. + */ public static DisplayMetrics getDisplayDPI() { return getContext().getResources().getDisplayMetrics(); } @@ -1027,7 +1039,6 @@ public class SDLActivity extends Activity { public static void clipboardSetText(String string) { mClipboardHandler.clipboardSetText(string); } - } /** diff --git a/include/SDL_system.h b/include/SDL_system.h index 383f2c382..7b776fdf1 100644 --- a/include/SDL_system.h +++ b/include/SDL_system.h @@ -108,6 +108,11 @@ extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void); */ extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void); +/** + \brief Return true if the application is running on Android TV + */ +extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void); + /** See the official Android developer guide for more information: http://developer.android.com/guide/topics/data/data-storage.html diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index e907b7918..f09f91840 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -211,6 +211,7 @@ static jmethodID midGetNativeSurface; static jmethodID midSetActivityTitle; static jmethodID midSetOrientation; static jmethodID midGetContext; +static jmethodID midIsAndroidTV; static jmethodID midInputGetInputDeviceIds; static jmethodID midSendMessage; static jmethodID midShowTextInput; @@ -305,6 +306,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c "setOrientation","(IIZLjava/lang/String;)V"); midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getContext","()Landroid/content/Context;"); + midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, + "isAndroidTV","()Z"); midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "inputGetInputDeviceIds", "(I)[I"); midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, @@ -326,9 +329,10 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c "getManifestEnvironmentVariables", "()Z"); midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;"); + midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;"); if (!midGetNativeSurface || - !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds || + !midSetActivityTitle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds || !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || !midClipboardSetText || !midClipboardGetText || !midClipboardHasText || !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables|| !midGetDisplayDPI) { @@ -1993,6 +1997,12 @@ void *SDL_AndroidGetActivity(void) return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext); } +SDL_bool SDL_IsAndroidTV(void) +{ + JNIEnv *env = Android_JNI_GetEnv(); + return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsAndroidTV); +} + const char * SDL_AndroidGetInternalStoragePath(void) { static char *s_AndroidInternalFilesPath = NULL; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index b7d31bc58..b1240ef0d 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -665,3 +665,5 @@ #define SDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution_REAL #define SDL_RenderGetMetalLayer SDL_RenderGetMetalLayer_REAL #define SDL_RenderGetMetalCommandEncoder SDL_RenderGetMetalCommandEncoder_REAL +#define SDL_IsAndroidTV SDL_IsAndroidTV_REAL +#define SDL_WinRTGetDeviceFamily SDL_WinRTGetDeviceFamily_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 121b7450e..146d47981 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -69,12 +69,12 @@ SDL_DYNAPI_PROC(int,SDL_Direct3D9GetAdapterIndex,(int a),(a),return) SDL_DYNAPI_PROC(IDirect3DDevice9*,SDL_RenderGetD3D9Device,(SDL_Renderer *a),(a),return) #endif -#if defined(__IPHONEOS__) && __IPHONEOS__ +#ifdef __IPHONEOS__ SDL_DYNAPI_PROC(int,SDL_iPhoneSetAnimationCallback,(SDL_Window *a, int b, void c, void *d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_iPhoneSetEventPump,(SDL_bool a),(a),) #endif -#if defined(__ANDROID__) && __ANDROID__ +#ifdef __ANDROID__ SDL_DYNAPI_PROC(void*,SDL_AndroidGetJNIEnv,(void),(),return) SDL_DYNAPI_PROC(void*,SDL_AndroidGetActivity,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_AndroidGetInternalStoragePath,(void),(),return) @@ -699,3 +699,9 @@ SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionMode,(void),(),retur SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionModeForResolution,(int a, int b),(a,b),return) SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalLayer,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalCommandEncoder,(SDL_Renderer *a),(a),return) +#ifdef __WINRT__ +SDL_DYNAPI_PROC(SDL_WinRT_DeviceFamily,SDL_WinRTGetDeviceFamily,(void),(),return) +#endif +#ifdef __ANDROID__ +SDL_DYNAPI_PROC(SDL_bool,SDL_IsAndroidTV,(void),(),return) +#endif