Skip to content

Commit

Permalink
Merge remote-tracking branch 'github_origin/ThreeThreeOne' into githu…
Browse files Browse the repository at this point in the history
…b_sandbox_threethreeone
  • Loading branch information
spiridon-alexandru committed Jun 25, 2013
2 parents 6eb640d + 10c76bf commit c9f27b3
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 37 deletions.
4 changes: 2 additions & 2 deletions libs/NativeUI/WidgetUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace NativeUI
MAUtil::Vector<Listener*>& vector,
Listener* listener)
{
if (listener == NULL)
if (!listener)
{
return;
}
Expand All @@ -85,7 +85,7 @@ namespace NativeUI
MAUtil::Vector<Listener*>& vector,
Listener* listener)
{
if (listener == NULL)
if (!listener)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ - (CGPoint) pointUsingOrientation:(CGPoint) originalPoint
returnedPoint.x = width - originalPoint.x;
returnedPoint.y = height - originalPoint.y;
break;
case MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT:
case MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT:
returnedPoint.x = originalPoint.y;
returnedPoint.y = width - originalPoint.x;
break;
case MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT:
case MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT:
returnedPoint.x = height - originalPoint.y;
returnedPoint.y = originalPoint.x;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ -(int) setSupportedOrientations:(const int) orientations
UIInterfaceOrientationMaskPortrait : mSupportedOrientations;
mSupportedOrientations |= mAllowedScreenOrientations &MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN ?
UIInterfaceOrientationMaskPortraitUpsideDown : mSupportedOrientations;
// MoSync landscape left/right concept is the opposite of the native ios landscape left/right.
mSupportedOrientations |= mAllowedScreenOrientations & MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT ?
UIInterfaceOrientationMaskLandscapeLeft : mSupportedOrientations;
UIInterfaceOrientationMaskLandscapeRight : mSupportedOrientations;
mSupportedOrientations |= mAllowedScreenOrientations & MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT?
UIInterfaceOrientationMaskLandscapeRight : mSupportedOrientations;
UIInterfaceOrientationMaskLandscapeLeft : mSupportedOrientations;
return MA_SCREEN_ORIENTATION_RES_OK;
}
}
Expand Down Expand Up @@ -143,11 +144,12 @@ -(bool) isInterfaceOrientationSupported:(UIInterfaceOrientation) orientation
case UIInterfaceOrientationPortraitUpsideDown:
returnValue = [self isPortraitUpsideDownModeSupported];
break;
// MoSync landscape left/right concept is the opposite of the native ios landscape left/right.
case UIInterfaceOrientationLandscapeLeft:
returnValue = [self isLandscapeLeftModeSupported];
returnValue = [self isLandscapeRightModeSupported];
break;
case UIInterfaceOrientationLandscapeRight:
returnValue = [self isLandscapeRightModeSupported];
returnValue = [self isLandscapeLeftModeSupported];
break;
}
return returnValue;
Expand Down Expand Up @@ -232,11 +234,12 @@ -(int) getCurrentScreenOrientation
case UIInterfaceOrientationPortraitUpsideDown:
returnValue = MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN;
break;
// MoSync landscape left/right concept is the opposite of the native ios landscape left/right.
case UIInterfaceOrientationLandscapeLeft:
returnValue = MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT;
returnValue = MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT;
break;
case UIInterfaceOrientationLandscapeRight:
returnValue = MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT;
returnValue = MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,28 @@ protected int setSupportedOrientation(int orientation)
// Store supported orientation flag.
mSupportedOrientations = orientation;

Boolean isLandscape = false;
Boolean isPortrait = false;

if (((orientation & MA_SCREEN_ORIENTATION_PORTRAIT_UP)
== MA_SCREEN_ORIENTATION_PORTRAIT_UP) ||
((orientation & MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN)
== MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN))
{
isPortrait = true;
}

if (((orientation & MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT)
== MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT) ||
((orientation & MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT)
== MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT))
{
isLandscape = true;
}

// Set to FULL_SENSOR or SENSOR.
if ( orientation == MA_SCREEN_ORIENTATION_DYNAMIC )
if ( (isLandscape && isPortrait) ||
(orientation == MA_SCREEN_ORIENTATION_DYNAMIC) )
{
setOrientation(
ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class MoSync extends Activity
* values retrieved when configuration changes.
*/
private static int mScreenRotation = Surface.ROTATION_0;
private static int mConfigOrientation = Configuration.ORIENTATION_PORTRAIT;

/**
* Sets screen and window properties.
Expand Down Expand Up @@ -311,13 +312,18 @@ public void onConfigurationChanged(Configuration newConfig)

SYSLOG("@@MoSync rotation = " + newRotation);

// Has the rotation changed?
if (mScreenRotation != newRotation)
int newConfigOrientation = getResources().getConfiguration().orientation;

// Has the rotation or orientation changed?
if ((mScreenRotation != newRotation) ||
(mConfigOrientation != newConfigOrientation))
{
// Save current rotation.
// Save current rotation and config orientation.
mScreenRotation = newRotation;
mConfigOrientation = newConfigOrientation;

int screenOrientation = getScreenOrientation();

// Post rotation event.
ScreenWidget screen = mMoSyncThread.getUnconvertedCurrentScreen();
if (null != screen)
Expand Down Expand Up @@ -362,24 +368,47 @@ public void onConfigurationChanged(Configuration newConfig)
}

/**
* Get the screen orientation based on latest rotation.
* Get the screen orientation based on latest rotation and config orientation.
* @return
*/
public static int getScreenOrientation()
{
switch(mScreenRotation)
{
case Surface.ROTATION_0:
return MA_SCREEN_ORIENTATION_PORTRAIT_UP;
case Surface.ROTATION_180:
return MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN;
case Surface.ROTATION_270:
return MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT;
case Surface.ROTATION_90:
return MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT;
final Activity activity = MoSyncThread.getInstance().getActivity();

int configOrientation = activity.getResources().getConfiguration().orientation;

int screenOrientation;

switch (configOrientation)
{
case Configuration.ORIENTATION_PORTRAIT:
if(mScreenRotation == Surface.ROTATION_90 ||
mScreenRotation == Surface.ROTATION_180)
{
screenOrientation = MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN;
}
else
{
screenOrientation = MA_SCREEN_ORIENTATION_PORTRAIT_UP;
}
break;
case Configuration.ORIENTATION_LANDSCAPE:
if(mScreenRotation == android.view.Surface.ROTATION_0 ||
mScreenRotation == android.view.Surface.ROTATION_90)
{
screenOrientation = MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT;
}
else
{
screenOrientation = MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT;
}
break;
default:
return MA_SCREEN_ORIENTATION_PORTRAIT_UP;
screenOrientation = MA_SCREEN_ORIENTATION_PORTRAIT_UP;
break;
}

return screenOrientation;
}

@Override
Expand Down
26 changes: 15 additions & 11 deletions tools/idl2/Modules/orientation.idl
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
group OrientationConstants "Orientation constants" {
constset int MA_SCREEN_ORIENTATION_ {
/// The device is in portrait mode - the standard vertical orientation.
PORTRAIT_UP = 0x1;

/// The device is in the opposite direction from normal portrait (MA_SCREEN_ORIENTATION_PORTRAIT_UP).
// Note: not available on Windows Phone.
PORTRAIT_UPSIDE_DOWN = 0x2;

/// The device is in portrait mode, based on sensor. Depending on user rotation,
/// #MA_SCREEN_ORIENTATION_PORTRAIT_UP or #MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN will be used.
/// Value equals: #MA_SCREEN_ORIENTATION_PORTRAIT_UP | #MA_SCREEN_ORIENTATION_PORTRAIT_UPSIDE_DOWN.
PORTRAIT = 0x3;
/// The device is in portrait mode, with the device held upright and the home button on
/// the bottom.
PORTRAIT_UP = 0x1;
/// The device is in portrait mode but upside down, with the device held upright and the
/// home button at the top.
// Note: not available on Windows Phone.
PORTRAIT_UPSIDE_DOWN = 0x2;
/// The device is in landscape mode, with the device held upright and the home button on
/// the left side.

/// The device is in landscape mode, with the device tilted to the left from the normal portrait.
// mode (MA_SCREEN_ORIENTATION_PORTRAIT_UP).
LANDSCAPE_LEFT = 0x4;
/// The device is in landscape mode, with the device held upright and the home button on
/// the right side.

/// The device is in landscape mode, with the device tilted to the right from the normal portrait.
// mode (MA_SCREEN_ORIENTATION_PORTRAIT_UP).
LANDSCAPE_RIGHT = 0x8;

/// The device is in landscape mode, based on sensor. Depending on user rotation,
/// #MA_SCREEN_ORIENTATION_LANDSCAPE_LEFT or #MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT will be used.
LANDSCAPE = 0xC;

/// Screen orientation is based on device sensor.
/// Value equals: #MA_SCREEN_ORIENTATION_PORTRAIT| #MA_SCREEN_ORIENTATION_LANDSCAPE.
DYNAMIC = 0xF;
Expand Down

0 comments on commit c9f27b3

Please sign in to comment.