Merge change 1436 into donut
* changes: Density Compatibility mode for SurfaceView * use fixed size when requested. Otherwise, give the original size instead of scaled down size. * scale back the motion event to original size when surface view is using the orignal size.
This commit is contained in:
@@ -255,6 +255,23 @@ public class SurfaceView extends View {
|
|||||||
super.draw(canvas);
|
super.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||||
|
// SurfaceView uses pre-scaled size unless fixed size is requested. This hook
|
||||||
|
// scales the event back to the pre-scaled coordinates for such surface.
|
||||||
|
if (mRequestedWidth < 0 && mAppScale != 1.0f) {
|
||||||
|
MotionEvent scaledBack = MotionEvent.obtain(event);
|
||||||
|
scaledBack.scale(mAppScale);
|
||||||
|
try {
|
||||||
|
return super.dispatchTouchEvent(scaledBack);
|
||||||
|
} finally {
|
||||||
|
scaledBack.recycle();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return super.dispatchTouchEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dispatchDraw(Canvas canvas) {
|
protected void dispatchDraw(Canvas canvas) {
|
||||||
// if SKIP_DRAW is cleared, draw() has already punched a hole
|
// if SKIP_DRAW is cleared, draw() has already punched a hole
|
||||||
@@ -278,6 +295,12 @@ public class SurfaceView extends View {
|
|||||||
int myHeight = mRequestedHeight;
|
int myHeight = mRequestedHeight;
|
||||||
if (myHeight <= 0) myHeight = getHeight();
|
if (myHeight <= 0) myHeight = getHeight();
|
||||||
|
|
||||||
|
// Use original size for surface unless fixed size is requested.
|
||||||
|
if (mRequestedWidth <= 0) {
|
||||||
|
myWidth *= mAppScale;
|
||||||
|
myHeight *= mAppScale;
|
||||||
|
}
|
||||||
|
|
||||||
getLocationInWindow(mLocation);
|
getLocationInWindow(mLocation);
|
||||||
final boolean creating = mWindow == null;
|
final boolean creating = mWindow == null;
|
||||||
final boolean formatChanged = mFormat != mRequestedFormat;
|
final boolean formatChanged = mFormat != mRequestedFormat;
|
||||||
@@ -333,7 +356,7 @@ public class SurfaceView extends View {
|
|||||||
mSurfaceLock.lock();
|
mSurfaceLock.lock();
|
||||||
mDrawingStopped = !visible;
|
mDrawingStopped = !visible;
|
||||||
final int relayoutResult = mSession.relayout(
|
final int relayoutResult = mSession.relayout(
|
||||||
mWindow, mLayout, (int) (mWidth * mAppScale), (int) (mHeight * mAppScale),
|
mWindow, mLayout, mWidth, mHeight,
|
||||||
visible ? VISIBLE : GONE, false, mWinFrame, mContentInsets,
|
visible ? VISIBLE : GONE, false, mWinFrame, mContentInsets,
|
||||||
mVisibleInsets, mSurface);
|
mVisibleInsets, mSurface);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user