1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

Added Android support for screen orientation control

This commit is contained in:
jules 2016-01-13 12:05:29 +00:00
parent 668d9c5f69
commit 99052af8bc
9 changed files with 62 additions and 15 deletions

View file

@ -691,7 +691,7 @@ public class JuceAppActivity extends Activity
int format, int width, int height);
}
public NativeSurfaceView createNativeSurfaceView(long nativeSurfacePtr)
public NativeSurfaceView createNativeSurfaceView (long nativeSurfacePtr)
{
return new NativeSurfaceView (this, nativeSurfacePtr);
}
@ -1041,23 +1041,24 @@ public class JuceAppActivity extends Activity
return null;
java.lang.reflect.Method method;
try {
try
{
method = obj.getClass().getMethod ("getProperty", String.class);
} catch (SecurityException e) {
return null;
} catch (NoSuchMethodException e) {
return null;
}
catch (SecurityException e) { return null; }
catch (NoSuchMethodException e) { return null; }
if (method == null)
return null;
try {
try
{
return (String) method.invoke (obj, property);
} catch (java.lang.IllegalArgumentException e) {
} catch (java.lang.IllegalAccessException e) {
} catch (java.lang.reflect.InvocationTargetException e) {
}
catch (java.lang.IllegalArgumentException e) {}
catch (java.lang.IllegalAccessException e) {}
catch (java.lang.reflect.InvocationTargetException e) {}
return null;
}
@ -1093,5 +1094,4 @@ public class JuceAppActivity extends Activity
{
return new JuceThread(host);
}
}

View file

@ -266,6 +266,7 @@ extern AndroidSystem android;
METHOD (createNativeSurfaceView, "createNativeSurfaceView", "(J)L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$NativeSurfaceView;") \
METHOD (postMessage, "postMessage", "(J)V") \
METHOD (finish, "finish", "()V") \
METHOD (setRequestedOrientation,"setRequestedOrientation", "(I)V") \
METHOD (getClipboardContent, "getClipboardContent", "()Ljava/lang/String;") \
METHOD (setClipboardContent, "setClipboardContent", "(Ljava/lang/String;)V") \
METHOD (excludeClipRegion, "excludeClipRegion", "(Landroid/graphics/Canvas;FFFF)V") \

View file

@ -386,10 +386,14 @@ void Desktop::setKioskModeComponent (Component* componentToUse, const bool allow
//==============================================================================
void Desktop::setOrientationsEnabled (const int newOrientations)
{
// Dodgy set of flags being passed here! Make sure you specify at least one permitted orientation.
jassert (newOrientations != 0 && (newOrientations & ~allOrientations) == 0);
if (allowedOrientations != newOrientations)
{
// Dodgy set of flags being passed here! Make sure you specify at least one permitted orientation.
jassert (newOrientations != 0 && (newOrientations & ~allOrientations) == 0);
allowedOrientations = newOrientations;
allowedOrientations = newOrientations;
allowedOrientationsChanged();
}
}
bool Desktop::isOrientationEnabled (const DisplayOrientation orientation) const noexcept

View file

@ -429,6 +429,8 @@ private:
bool kioskModeReentrant;
int allowedOrientations;
void allowedOrientationsChanged();
float masterScaleFactor;
ComponentAnimator animator;

View file

@ -728,6 +728,38 @@ void Desktop::setKioskComponent (Component* kioskModeComponent, bool enableOrDis
// TODO
}
//==============================================================================
static jint getAndroidOrientationFlag (int orientations) noexcept
{
enum
{
SCREEN_ORIENTATION_LANDSCAPE = 0,
SCREEN_ORIENTATION_PORTRAIT = 1,
SCREEN_ORIENTATION_USER = 2,
SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8,
SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9,
SCREEN_ORIENTATION_USER_LANDSCAPE = 11,
SCREEN_ORIENTATION_USER_PORTRAIT = 12,
};
switch (orientations)
{
case Desktop::upright: return (jint) SCREEN_ORIENTATION_PORTRAIT;
case Desktop::upsideDown: return (jint) SCREEN_ORIENTATION_REVERSE_PORTRAIT;
case Desktop::upright + Desktop::upsideDown: return (jint) SCREEN_ORIENTATION_USER_PORTRAIT;
case Desktop::rotatedAntiClockwise: return (jint) SCREEN_ORIENTATION_LANDSCAPE;
case Desktop::rotatedClockwise: return (jint) SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
case Desktop::rotatedClockwise + Desktop::rotatedAntiClockwise: return (jint) SCREEN_ORIENTATION_USER_LANDSCAPE;
default: return (jint) SCREEN_ORIENTATION_USER;
}
}
void Desktop::allowedOrientationsChanged()
{
android.activity.callVoidMethod (JuceAppActivity.setRequestedOrientation,
getAndroidOrientationFlag (allowedOrientations));
}
//==============================================================================
bool juce_areThereAnyAlwaysOnTopWindows()
{
@ -764,7 +796,7 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, setScreenSize, void, (JNIEnv
//==============================================================================
Image juce_createIconForFile (const File& file)
{
return Image::null;
return Image();
}
//==============================================================================

View file

@ -1023,6 +1023,8 @@ void Desktop::setKioskComponent (Component* kioskModeComp, bool enableOrDisable,
}
}
void Desktop::allowedOrientationsChanged() {}
//==============================================================================
void UIViewComponentPeer::repaint (const Rectangle<int>& area)
{

View file

@ -3746,6 +3746,8 @@ void Desktop::setKioskComponent (Component* comp, bool enableOrDisable, bool /*
comp->setBounds (getDisplays().getMainDisplay().totalArea);
}
void Desktop::allowedOrientationsChanged() {}
//==============================================================================
ComponentPeer* Component::createNewPeer (int styleFlags, void* nativeWindowToAttachTo)
{

View file

@ -2006,6 +2006,8 @@ void Desktop::setKioskComponent (Component* kioskComp, bool shouldBeEnabled, boo
#endif
}
void Desktop::allowedOrientationsChanged() {}
//==============================================================================
ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
{

View file

@ -3311,6 +3311,8 @@ void Desktop::setKioskComponent (Component* kioskModeComp, bool enableOrDisable,
kioskModeComp->setBounds (getDisplays().getMainDisplay().totalArea);
}
void Desktop::allowedOrientationsChanged() {}
//==============================================================================
struct MonitorInfo
{