The orientation of Samsung Galaxy S camera bug

If you made something related with camera with Samsung Galaxy S based on Android SDK, you must meet lots of problems. (I hope you don't meet such a case ...)
Changing camera parameter is one of them.

If you change the orientation of the camera screen of Galaxy S. looks like;
parameters.set("orientation", "portrait");
(Sure, the default orientation is completely nonsense, this is why you try to do it.)

The screen is suddenly filled with noise and mispositioned.

You should override onMeasure function like the below codes;
// this functions is for correcting the screen position of Galaxy S.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
WindowManager w = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display d = w.getDefaultDisplay();
int dwidth = d.getWidth();
int dheight = d.getHeight();

if (dwidth < dheight)
{
setMeasuredDimension(dwidth + 200, dheight); // HACK: to stretch the portrait view so that the camera preview fills the screen
ViewGroup.LayoutParams lp = getLayoutParams();
if (lp.getClass() == FrameLayout.LayoutParams.class)
((FrameLayout.LayoutParams)lp).gravity = Gravity.CENTER_HORIZONTAL;
else if (lp.getClass() == LinearLayout.LayoutParams.class)
((LinearLayout.LayoutParams)lp).gravity = Gravity.CENTER_HORIZONTAL;
else if (lp.getClass() == RelativeLayout.LayoutParams.class)
((RelativeLayout.LayoutParams)lp).addRule(RelativeLayout.CENTER_HORIZONTAL);
setLayoutParams(lp);
}
else
{
setMeasuredDimension(dwidth, dheight);
}
getHolder().setFixedSize(dwidth, dheight);
} // onMeasure()

And add it
<activity android:name=".CameraLayer" android:label="@string/app_name" android:screenOrientation="portrait"/>
to AndroidManifest.xml

Now, you can avoid the problem, but it can't be a radical solution because of the frozen orientation of the camera.

I think Samsung ..., they need to re-think themselves.

이 블로그의 인기 게시물

둘 중 누군가 그녀를 죽였다, 범인 해설

[MAC OS X] mds_stores 100% CPU usage

tips more on unity ...