diff --git a/modules/juce_gui_basics/components/juce_Desktop.h b/modules/juce_gui_basics/components/juce_Desktop.h index 3677263296..502ca0fd97 100644 --- a/modules/juce_gui_basics/components/juce_Desktop.h +++ b/modules/juce_gui_basics/components/juce_Desktop.h @@ -289,13 +289,13 @@ public: void beginDragAutoRepeat (int millisecondsBetweenCallbacks); //============================================================================== - /** In a tablet device which can be turned around, this is used to inidicate the orientation. */ + /** In a tablet/mobile device which can be turned around, this is used to indicate the orientation. */ enum DisplayOrientation { - upright = 1, /**< Indicates that the display is the normal way up. */ - upsideDown = 2, /**< Indicates that the display is upside-down. */ - rotatedClockwise = 4, /**< Indicates that the display is turned 90 degrees clockwise from its upright position. */ - rotatedAntiClockwise = 8, /**< Indicates that the display is turned 90 degrees anti-clockwise from its upright position. */ + upright = 1, /**< Indicates that the device is the normal way up. */ + upsideDown = 2, /**< Indicates that the device is upside-down. */ + rotatedClockwise = 4, /**< Indicates that the device is turned 90 degrees clockwise from its upright position. */ + rotatedAntiClockwise = 8, /**< Indicates that the device is turned 90 degrees anti-clockwise from its upright position. */ allOrientations = 1 + 2 + 4 + 8 /**< A combination of all the orientation values */ }; diff --git a/modules/juce_gui_basics/native/juce_android_Windowing.cpp b/modules/juce_gui_basics/native/juce_android_Windowing.cpp index 9ae74bb91d..c6f92403ac 100644 --- a/modules/juce_gui_basics/native/juce_android_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_android_Windowing.cpp @@ -678,6 +678,18 @@ ComponentPeer* Component::createNewPeer (int styleFlags, void*) } //============================================================================== +#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + METHOD (getRotation, "getRotation", "()I") + +DECLARE_JNI_CLASS (Display, "android/view/Display"); +#undef JNI_CLASS_MEMBERS + +#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + METHOD (getDefaultDisplay, "getDefaultDisplay", "()Landroid/view/Display;") + +DECLARE_JNI_CLASS (WindowManager, "android/view/WindowManager"); +#undef JNI_CLASS_MEMBERS + bool Desktop::canUseSemiTransparentWindows() noexcept { return true; @@ -690,7 +702,37 @@ double Desktop::getDefaultMasterScale() Desktop::DisplayOrientation Desktop::getCurrentOrientation() const { - // TODO + enum + { + ROTATION_0 = 0, + ROTATION_90 = 1, + ROTATION_180 = 2, + ROTATION_270 = 3 + }; + + JNIEnv* env = getEnv(); + LocalRef windowServiceString (javaString ("window")); + LocalRef windowManager = LocalRef (env->CallObjectMethod (android.activity, JuceAppActivity.getSystemService, windowServiceString.get())); + + if (windowManager.get() != 0) + { + LocalRef display = LocalRef (env->CallObjectMethod (windowManager, WindowManager.getDefaultDisplay)); + + if (display.get() != 0) + { + int rotation = env->CallIntMethod (display, Display.getRotation); + + switch (rotation) + { + case ROTATION_0: return upright; + case ROTATION_90: return rotatedAntiClockwise; + case ROTATION_180: return upsideDown; + case ROTATION_270: return rotatedClockwise; + } + } + } + + jassertfalse; return upright; }