round Camera Orientation - Android android.hardware

Android examples for android.hardware:Camera Orientation

Description

round Camera Orientation

Demo Code

import android.view.OrientationEventListener;

public class Main {

  public static final int ORIENTATION_HYSTERESIS = 5;

  public static int roundOrientation(int orientation, int orientationHistory) {
    boolean changeOrientation = false;
    if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
      changeOrientation = true;// w  ww  .j  a va  2 s  .c o  m
    } else {
      int dist = Math.abs(orientation - orientationHistory);
      dist = Math.min(dist, 360 - dist);
      changeOrientation = (dist >= 45 + ORIENTATION_HYSTERESIS);
    }
    if (changeOrientation) {
      return ((orientation + 45) / 90 * 90) % 360;
    }
    return orientationHistory;
  }

}

Related Tutorials