android.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright (c) 2006-2014 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "android.h"
  21. #ifdef LOVE_ANDROID
  22. #include "SDL.h"
  23. #include "jni.h"
  24. namespace love
  25. {
  26. namespace android
  27. {
  28. double getScreenScale()
  29. {
  30. JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
  31. jclass activity = (jclass) SDL_AndroidGetActivity();
  32. jmethodID getMetrics = env->GetStaticMethodID(activity, "getMetrics", "()Landroid/util/DisplayMetrics;");
  33. jobject metrics = env->CallStaticObjectMethod(activity, getMetrics);
  34. jclass metricsClass = env->GetObjectClass(metrics);
  35. double result = env->GetFloatField(metrics, env->GetFieldID(metricsClass, "density", "F"));
  36. env->DeleteLocalRef (metricsClass);
  37. env->DeleteLocalRef (metrics);
  38. env->DeleteLocalRef (activity);
  39. return result;
  40. }
  41. } // android
  42. } // love
  43. #endif // LOVE_ANDROID