-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera flipped on non-default screen orientation #576
Comments
Yeah I have seen this too, not sure why it happens. It's OK in both orientations at startup but rotating doesn't alter the camera orientation. If you'd like to look into it, open a PR here with suggestions. |
@carl1990 你解决了吗?官方推荐的兼容方案是什么。 |
同胞们好,我也遇到这个问题,在6.0一下画面都是正常的,但是在6.0画面就是倒的 |
@douyn 你确定是6.0?还只是5X? |
@tqlmorepassion 只有一台6.0的手机,确实是 nexus 5x,最近在做6.0适配测试出的问题。刚好看到这里也有这个问题。我想问一下是只有6.0 里边只有5x才有这个问题吗,英文看不太懂啊 |
@douyn 好像我查了查isu,就5X吧,然后有人说解决方案也没有帖出来,https://github.com/tqlmorepassion/zxing-android |
@tqlmorepassion 只用修改下面的那句代码,其他的不做处理是吧,我去试一下效果,谢谢 if (Build.MODEL.equals("Nexus 5X")) {//兼容5x旋转270度 |
@douyn 对头~ |
@srowen I debugged the code, and found that when rotating the screen such as 180 degree, the activity did not invoke the onResume() method, so camera parameters were not been resetting, so we often got wrong surface preview when rotating.
private class MyOrientationDetector extends OrientationEventListener {
private int lastOrientation = -1;
MyOrientationDetector(Context context) {
super(context);
}
void setLastOrientation(int rotation) {
switch (rotation) {
case Surface.ROTATION_90:
lastOrientation = 270;
break;
case Surface.ROTATION_270:
lastOrientation = 90;
break;
default:
lastOrientation = -1;
}
}
@Override
public void onOrientationChanged(int orientation) {
Log.d(TAG, "orientation:" + orientation);
if (orientation > 45 && orientation < 135) {
orientation = 90;
} else if (orientation > 225 && orientation < 315) {
orientation = 270;
} else {
orientation = -1;
}
if ((orientation == 90 && lastOrientation == 270) || (orientation == 270 && lastOrientation == 90)) {
Log.i(TAG, "orientation:" + orientation + "lastOrientation:" + lastOrientation);
Intent intent = getIntent();
finish();
startActivity(intent);
lastOrientation = orientation;
Log.i(TAG, "SUCCESS");
}
}
} 2.add in onCreate() myOrientationDetector = new MyOrientationDetector(this);
myOrientationDetector.setLastOrientation(getWindowManager().getDefaultDisplay().getRotation()); 3.add in orientation setting of onResume() if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
setRequestedOrientation(getCurrentOrientation());
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
myOrientationDetector.enable();
} 4.add in onPause() myOrientationDetector.disable(); |
This bug must be fixed along with #111 |
@srowen This bug seems fixed in Barcode Scanner+, however I hope you can also fix in Barcode Scanner (not plus). |
I'm running version 4.7.5 of the Android application but there are some orientation issues. When the screen is locked on the default orientation, everything is fine. but when disabling the 'No automatic rotation'-option and rotating the screen, the image will be rotated around the long axis of the phone (making up right, but left remaining left). I've tested this on three different devices running both Lollipop and Marshmallow (Samsung XCover on 5.1.1, Nexus 5 on 6.0.1 and Moto X Play on 6.0)
I'm aware of many other bug reports, but from those that I've checked they are about an issue on the default orientation.
The text was updated successfully, but these errors were encountered: