Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[MOSYNC-2375] Android: Fixed bug that made runtime crash when rotatin…

…g the device and drawing using maSetClipRect. A test program is included in the issue MOSYNC-2375.
  • Loading branch information...
commit 9fa1cd19de5d16106adcbba862e08bc9385db69d 1 parent 3c40e46
Mikael Kindborg authored
View
24 ...ava/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncThread.java
@@ -586,6 +586,19 @@ public synchronized void updateSurfaceSize(int width, int height)
mCanvas = mDrawTargetScreen.mCanvas;
mBitmap = mDrawTargetScreen.mBitmap;
+ // Set/reset clip rect.
+ mClipLeft = 0;
+ mClipTop = 0;
+ mClipWidth = mWidth;
+ mClipHeight = mHeight;
+
+ // Set original clip rect.
+ // Save the clip state since we have a new canvas created.
+ // This initial save is needed for the clip rect stack to
+ // work correctly when calling restore clip rect.
+ mCanvas.save();
+ mCanvas.clipRect(mClipLeft, mClipTop, mClipWidth, mClipHeight, Region.Op.REPLACE);
+
updateScreen();
SYSLOG("mBitmap width:" + mBitmap.getWidth()
@@ -1122,17 +1135,10 @@ public ByteBuffer getBinaryResource(int handle)
void initSyscalls()
{
SYSLOG("initSyscalls");
- mUsingFrameBuffer = false;
- mClipLeft = 0;
- mClipTop = 0;
- mClipWidth = mWidth;
- mClipHeight = mHeight;
+ //Log.i("@@@@@", "initSyscalls");
- // Set original clip rect.
- // First we save the clip state.
- mCanvas.save();
- mCanvas.clipRect(mClipLeft, mClipTop, mClipWidth, mClipHeight, Region.Op.REPLACE);
+ mUsingFrameBuffer = false;
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAntiAlias(false);
View
54 .../java/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncView.java
@@ -34,7 +34,7 @@
public class MoSyncView extends SurfaceView implements SurfaceHolder.Callback
{
public SurfaceHolder mSurfaceHolder;
-
+
private Context mContext;
private MoSyncThread mMoSyncThread;
@@ -43,13 +43,13 @@
* @param context The Android Activity Context
* @param moSyncThread The thread in which the runtime is running
*/
- public MoSyncView(Context context, MoSyncThread moSyncThread)
+ public MoSyncView(Context context, MoSyncThread moSyncThread)
throws Exception
{
super(context);
-
+
SYSLOG("Constructor");
-
+
mContext = context;
mMoSyncThread = moSyncThread;
@@ -86,16 +86,16 @@ public MoSyncView(Context context, MoSyncThread moSyncThread)
default: Log.i("MoSync", "No hardware acceleration available");
}
*/
- mSurfaceHolder.addCallback(this);
-
+ mSurfaceHolder.addCallback(this);
+
setVisibility(VISIBLE);
-
+
setFocusableInTouchMode(true);
}
/**
- * Called during layout when the size of this view has changed.
- * If you were just added to the view hierarchy, you're called
+ * Called during layout when the size of this view has changed.
+ * If you were just added to the view hierarchy, you're called
* with the old values of 0.
* @param w Current width of this view.
* @param w h Current height of this view.
@@ -105,12 +105,12 @@ public MoSyncView(Context context, MoSyncThread moSyncThread)
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh)
{
- SYSLOG("onSizeChanged w:" + w + " h:" + h
+ SYSLOG("onSizeChanged w:" + w + " h:" + h
+ " oldw:" + oldw + " oldh:" + oldh);
-
+
super.onSizeChanged(w, h, oldw, oldh);
}
-
+
/**
* This function is called directly after a change to the surface.
*
@@ -123,16 +123,18 @@ public void onSizeChanged(int w, int h, int oldw, int oldh)
*/
@Override
public void surfaceChanged(
- SurfaceHolder holder,
- int format,
- int width,
+ SurfaceHolder holder,
+ int format,
+ int width,
int height)
{
SYSLOG("surfaceChanged");
-
+
+ //Log.i("@@@@@", "surfaceChanged");
+
// Allocate new screen buffer.
mMoSyncThread.updateSurfaceSize(width, height);
-
+
// Post screen changed event.
// TODO: Should this be done also initially, when the surface is
// first created, or only when it is changed after it has been created?
@@ -145,7 +147,7 @@ public void surfaceChanged(
}
/**
- * Function which is called by Android directly after the surface
+ * Function which is called by Android directly after the surface
* has been created.
*
* NOTE: Here we start the MoSync thread.
@@ -156,19 +158,23 @@ public void surfaceChanged(
public void surfaceCreated(SurfaceHolder holder)
{
SYSLOG("surfaceCreated");
-
+
+ //Log.i("@@@@@", "surfaceCreated");
+
if (!mMoSyncThread.isAlive())
{
- mMoSyncThread.updateSurfaceSize(getWidth(), getHeight());
+ //Log.i("@@@@@", "surfaceCreated 1");
mMoSyncThread.initSyscalls();
+ mMoSyncThread.updateSurfaceSize(getWidth(), getHeight());
mMoSyncThread.start();
}
else
{
+ //Log.i("@@@@@", "surfaceCreated 2");
mMoSyncThread.updateScreen();
}
}
-
+
/**
* Method that is called directly before the surface is destroyed.
*/
@@ -185,13 +191,13 @@ protected void onDraw(Canvas canvas)
}
protected void onFocusChanged(
- boolean gainFocus,
- int direction,
+ boolean gainFocus,
+ int direction,
Rect previouslyFocusedRect)
{
SYSLOG("onFocusChanged");
}
-
+
public boolean onTouchEvent(MotionEvent motionEvent)
{
return ((Activity) mContext).onTouchEvent(motionEvent);
Please sign in to comment.
Something went wrong with that request. Please try again.