summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2018-08-21 11:23:47 -0700
committerSam Lantinga <slouken@libsdl.org>2018-08-21 11:23:47 -0700
commit72bca38da2c43e92fbd119480c915c254b95d0d9 (patch)
tree6584dac39586ec0f94263046d2fd5dace6f7567b
parent2949c96d41eb295c8d85918a2e35b7e021985906 (diff)
downloadsdl-72bca38da2c43e92fbd119480c915c254b95d0d9.tar.gz
Add SDL_IsTablet() to Android and iOS SDL.
-rw-r--r--android-project/app/src/main/java/org/libsdl/app/SDLActivity.java18
-rw-r--r--include/SDL_system.h9
-rw-r--r--src/core/android/SDL_android.c11
-rw-r--r--src/dynapi/SDL_dynapi_overrides.h1
-rw-r--r--src/dynapi/SDL_dynapi_procs.h3
-rw-r--r--src/video/uikit/SDL_uikitvideo.m11
6 files changed, 52 insertions, 1 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 6d745210f..a2df4a116 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
@@ -5,6 +5,7 @@ import java.io.InputStream;
import java.util.Arrays;
import java.util.Hashtable;
import java.lang.reflect.Method;
+import java.lang.Math;
import android.app.*;
import android.content.*;
@@ -779,6 +780,23 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
/**
* This method is called by SDL using JNI.
*/
+ public static boolean isTablet() {
+ DisplayMetrics metrics = new DisplayMetrics();
+ Activity sdlActivity = (Activity)getContext();
+ sdlActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+
+ double dWidthInches = metrics.widthPixels / (double)metrics.densityDpi;
+ double dHeightInches = metrics.heightPixels / (double)metrics.densityDpi;
+
+ double dDiagonal = Math.sqrt((dWidthInches * dWidthInches) + (dHeightInches * dHeightInches));
+
+ // If our diagonal size is seven inches or greater, we consider ourselves a tablet.
+ return (dDiagonal > 7.0);
+ }
+
+ /**
+ * This method is called by SDL using JNI.
+ */
public static boolean isChromebook() {
return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management");
}
diff --git a/include/SDL_system.h b/include/SDL_system.h
index 14b4dbeae..00eb7a475 100644
--- a/include/SDL_system.h
+++ b/include/SDL_system.h
@@ -174,6 +174,15 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
#endif /* __ANDROID__ */
+#if defined(__ANDROID__) || defined(__IPHONEOS__)
+
+/**
+ \brief Return true if the current device is a tablet.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
+
+#endif
+
/* Platform specific functions for WinRT */
#if defined(__WINRT__) && __WINRT__
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 7100dac34..159e6d401 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -232,6 +232,7 @@ static jmethodID midSetCustomCursor;
static jmethodID midSetSystemCursor;
static jmethodID midSupportsRelativeMouse;
static jmethodID midSetRelativeMouseEnabled;
+static jmethodID midIsTablet;
/* audio manager */
static jclass mAudioManagerClass;
@@ -354,13 +355,15 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
midSupportsRelativeMouse = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "supportsRelativeMouse", "()Z");
midSetRelativeMouseEnabled = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
+ midIsTablet = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "isTablet", "()Z");
+
if (!midGetNativeSurface ||
!midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
!midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
!midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
!midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
!midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled ||
- !midIsChromebook || !midIsDeXMode || !midManualBackButton) {
+ !midIsChromebook || !midIsDeXMode || !midManualBackButton || !midIsTablet) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
}
@@ -2048,6 +2051,12 @@ SDL_bool SDL_IsDeXMode(void)
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsDeXMode);
}
+SDL_bool SDL_IsTablet(void)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsTablet);
+}
+
void SDL_AndroidBackButton(void)
{
JNIEnv *env = Android_JNI_GetEnv();
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 100b1d063..db8c8e259 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -680,3 +680,4 @@
#define SDL_wcsdup SDL_wcsdup_REAL
#define SDL_GameControllerRumble SDL_GameControllerRumble_REAL
#define SDL_JoystickRumble SDL_JoystickRumble_REAL
+#define SDL_IsTablet SDL_IsTablet_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index c3983f89d..36342f097 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -722,3 +722,6 @@ SDL_DYNAPI_PROC(float,SDL_expf,(float a),(a),return)
SDL_DYNAPI_PROC(wchar_t*,SDL_wcsdup,(const wchar_t *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GameControllerRumble,(SDL_GameController *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_JoystickRumble,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
+#if defined(__ANDROID__) || defined(__IPHONEOS__)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
+#endif
diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m
index e74339f42..aec49a581 100644
--- a/src/video/uikit/SDL_uikitvideo.m
+++ b/src/video/uikit/SDL_uikitvideo.m
@@ -233,6 +233,17 @@ void SDL_NSLog(const char *text)
NSLog(@"%s", text);
}
+/*
+ * iOS Tablet detection
+ *
+ * This doesn't really have aything to do with the interfaces of the SDL video
+ * subsystem, but we need to stuff this into an Objective-C source code file.
+ */
+SDL_bool SDL_IsTablet(void)
+{
+ return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
+}
+
#endif /* SDL_VIDEO_DRIVER_UIKIT */
/* vi: set ts=4 sw=4 expandtab: */