mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-09 04:30:09 +00:00
Android: Implemented Desktop::getCurrentOrientation() for Android
This commit is contained in:
parent
dcfec9de3b
commit
4ea8c871b8
2 changed files with 48 additions and 6 deletions
|
|
@ -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 */
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<jstring> windowServiceString (javaString ("window"));
|
||||
LocalRef<jobject> windowManager = LocalRef<jobject> (env->CallObjectMethod (android.activity, JuceAppActivity.getSystemService, windowServiceString.get()));
|
||||
|
||||
if (windowManager.get() != 0)
|
||||
{
|
||||
LocalRef<jobject> display = LocalRef<jobject> (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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue