Skip to content

Commit

Permalink
MOSYNC-2730 Implemented MAW_EVENT_SCREEN_ORIENTATION_DID_CHANGE event…
Browse files Browse the repository at this point in the history
… on Android
  • Loading branch information
emmaTresanszki committed Feb 8, 2013
1 parent 157ef1f commit 95e9018
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 6 deletions.
1 change: 1 addition & 0 deletions libs/NativeUI/Screen.cpp
Expand Up @@ -118,6 +118,7 @@ namespace NativeUI
* Called just before the screen begins rotating.
* Subclasses may override this method to perform additional actions
* immediately prior to the rotation.
* Note: available only on iOS and WP.
*/
void Screen::orientationWillChange()
{
Expand Down
1 change: 1 addition & 0 deletions libs/NativeUI/Screen.h
Expand Up @@ -106,6 +106,7 @@ namespace NativeUI
* Called just before the screen begins rotating.
* Subclasses may override this method to perform additional actions
* immediately prior to the rotation.
* Note: available only on iOS and WP.
*/
virtual void orientationWillChange();

Expand Down
2 changes: 2 additions & 0 deletions runtimes/cpp/platforms/android/MoSyncBridge.cpp
Expand Up @@ -502,6 +502,8 @@ static void nativePostEvent(JNIEnv* env, jobject jthis, jintArray eventBuffer)
* intArray[4] - Handle to url data.
*
* WIDGET_EVENT_RATING_STAR_VALUE_CHANGED
*
* MAW_EVENT_SCREEN_ORIENTATION_DID_CHANGE
*/

// Allocate the widget event data structure.
Expand Down
Expand Up @@ -337,6 +337,17 @@ public void postSegmentedListItemClicked(int widgetHandle, int position, int ind
index);
}

/**
* Sends a screen orientation changed event.
* @param widgetHandle The screen widget that sends the event.
*/
public void postScreenOrientationChanged(int widgetHandle)
{
postWidgetEvent(
IX_WIDGET.MAW_EVENT_SCREEN_ORIENTATION_DID_CHANGE,
widgetHandle);
}

public static EventQueue getDefault()
{
return DEFAULT;
Expand Down
Expand Up @@ -3925,8 +3925,16 @@ else if (SCREEN_ORIENTATION_PORTRAIT == orientation)
}
else if (SCREEN_ORIENTATION_DYNAMIC == orientation)
{
maScreenSetOrientationHelper(
ActivityInfo.SCREEN_ORIENTATION_SENSOR);
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD )
{
maScreenSetOrientationHelper(
ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
else
{
maScreenSetOrientationHelper(
ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
}
else
{
Expand Down
Expand Up @@ -56,6 +56,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.Window;

Expand Down Expand Up @@ -105,6 +106,11 @@ public class MoSync extends Activity
private BroadcastReceiver mShutdownListener;
private boolean mEventTypeCloseHasBeenSent = false;
private MoSyncNFCForegroundUtil nfcForegroundHandler;
/**
* Keep the current screen rotation, and check it againts new
* values retrieved when configuration changes.
*/
private int mScreenRotation = Surface.ROTATION_0;

/**
* Sets screen and window properties.
Expand Down Expand Up @@ -219,9 +225,17 @@ else if(intent.getAction().equals(LocalNotificationsService.ACTION_NOTIFICATION_
@Override
public void onConfigurationChanged(Configuration newConfig)
{
Log.i("MoSync", "onConfigurationChanged");

SYSLOG("@@MoSync onConfigurationChanged");
super.onConfigurationChanged(newConfig);

SYSLOG("@@MoSync rotation = " + getWindowManager().getDefaultDisplay().getRotation());
if ( mScreenRotation != getWindowManager().getDefaultDisplay().getRotation() )
{
mScreenRotation = getWindowManager().getDefaultDisplay().getRotation();

EventQueue.getDefault().postScreenOrientationChanged(
mMoSyncThread.getCurrentScreen().getHandle());
}
}

@Override
Expand Down
Expand Up @@ -59,7 +59,8 @@ namespace OrientationTest
mOrientationLabel(NULL),
mSetOrientationDescriptionLabel(NULL),
mSetOrientationButton(NULL),
mOrientationOptionsListView(NULL)
mOrientationOptionsListView(NULL),
mOrientationChangesCount(0)
{
this->setTitle(SCREEN_TITLE);

Expand Down Expand Up @@ -397,6 +398,21 @@ namespace OrientationTest
case MA_SCREEN_ORIENTATION_LANDSCAPE_RIGHT:
orientationText = ORIENTATION_LANDSCAPE_RIGHT;
break;
default:
{
// maScreenGetCurrentOrientation is not yet implemented on Android.
mOrientationChangesCount ++;
if (mOrientationChangesCount > 0)
{
orientationText = "Orientation changed " +
MAUtil::integerToString(mOrientationChangesCount) + " times";
}
else
{
orientationText = "Orientation changed 1 time";
}
break;
}
}
return orientationText;
}
Expand Down
Expand Up @@ -192,6 +192,10 @@ namespace OrientationTest
* 3 - SCREEN_ORIENTATION_DYNAMIC
*/
int mSelectedOrientation;
/**
* Android only. Keep this until getOrientation is implemented.
*/
int mOrientationChangesCount;
};

} // namespace OrientationTest
Expand Down
2 changes: 1 addition & 1 deletion tools/idl2/NativeUI/WidgetEvent.idl
Expand Up @@ -353,7 +353,7 @@ group WidgetEvent "Widget event" {

/**
* Send by current screen after it finishes rotating.
* Platform: iOS and Windows Phone 7.1
* Platform: iOS, Android and Windows Phone 7.1
*/
SCREEN_ORIENTATION_DID_CHANGE = 24;

Expand Down

0 comments on commit 95e9018

Please sign in to comment.