Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added SDL_IsAndroidTV()
  • Loading branch information
slouken committed Feb 6, 2018
1 parent 2b441ec commit 6ed184e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
Expand Up @@ -7,6 +7,7 @@

import android.app.*;
import android.content.*;
import android.content.res.Configuration;
import android.text.InputType;
import android.view.*;
import android.view.inputmethod.BaseInputConnection;
Expand Down Expand Up @@ -611,6 +612,17 @@ public static Context getContext() {
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();
}
Expand Down Expand Up @@ -1027,7 +1039,6 @@ public static String clipboardGetText() {
public static void clipboardSetText(String string) {
mClipboardHandler.clipboardSetText(string);
}

}

/**
Expand Down
5 changes: 5 additions & 0 deletions include/SDL_system.h
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/core/android/SDL_android.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -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
10 changes: 8 additions & 2 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 6ed184e

Please sign in to comment.