Skip to content
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

Closed
jdepypere opened this issue Apr 4, 2016 · 12 comments
Closed

Camera flipped on non-default screen orientation #576

jdepypere opened this issue Apr 4, 2016 · 12 comments

Comments

@jdepypere
Copy link

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.

@srowen
Copy link
Contributor

srowen commented Apr 4, 2016

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
Copy link

carl1990 commented Apr 15, 2016

+1
I face to same problem.

I dot know the core.jar version
My app run on device: LG Nexues 5x and android Version is 6.0,
the activity set android:screenOrientation="portrait"
but,the capture preview is Opposite direction

for example this iamge
device-2016-04-15-184843

the computer screen should be up on keyboard

@tqlmorepassion
Copy link

@carl1990 你解决了吗?官方推荐的兼容方案是什么。

@douyn
Copy link

douyn commented May 25, 2016

同胞们好,我也遇到这个问题,在6.0一下画面都是正常的,但是在6.0画面就是倒的

@tqlmorepassion
Copy link

@douyn 你确定是6.0?还只是5X?

@douyn
Copy link

douyn commented May 25, 2016

@tqlmorepassion 只有一台6.0的手机,确实是 nexus 5x,最近在做6.0适配测试出的问题。刚好看到这里也有这个问题。我想问一下是只有6.0 里边只有5x才有这个问题吗,英文看不太懂啊

@tqlmorepassion
Copy link

@douyn 好像我查了查isu,就5X吧,然后有人说解决方案也没有帖出来,https://github.com/tqlmorepassion/zxing-android
这个是我之前的解决方案,你可以参考一下。

@douyn
Copy link

douyn commented May 25, 2016

@tqlmorepassion 只用修改下面的那句代码,其他的不做处理是吧,我去试一下效果,谢谢

if (Build.MODEL.equals("Nexus 5X")) {//兼容5x旋转270度
camera.setDisplayOrientation(270);
} else {
camera.setDisplayOrientation(90);
}

@tqlmorepassion
Copy link

@douyn 对头~

@GuoJinyu
Copy link

GuoJinyu commented Dec 15, 2016

@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.
So the key to solve this problem is catching this event and resetting camera parameters.
I give one solution,it may not be a perfect one,but it is workable。

  1. add inner clase in CaptureActivity.class
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();

@KrasnayaPloshchad
Copy link
Contributor

This bug must be fixed along with #111

@KrasnayaPloshchad
Copy link
Contributor

@srowen This bug seems fixed in Barcode Scanner+, however I hope you can also fix in Barcode Scanner (not plus).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

8 participants
@srowen @jdepypere @carl1990 @tqlmorepassion @GuoJinyu @KrasnayaPloshchad @douyn and others