Skip to content

Instantly share code, notes, and snippets.

@NetguruGist
Created November 9, 2015 08:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NetguruGist/54d62bc6e625e34ffe66 to your computer and use it in GitHub Desktop.
Save NetguruGist/54d62bc6e625e34ffe66 to your computer and use it in GitHub Desktop.
augmented1 java
public class CameraViewActivity extends Activity implements
SurfaceHolder.Callback,OnLocationChangedListener,OnAzimuthChangedListener{
private Camera mCamera;
private SurfaceHolder mSurfaceHolder;
private boolean isCameraviewOn = false;
private AugmentedPOI mPoi;
private double mAzimuthReal = 0;
private double mAzimuthTeoretical = 0;
private static double AZIMUTH_ACCURACY = 5;
private double mMyLatitude = 0;
private double mMyLongitude = 0;
private MyCurrentAzimuth myCurrentAzimuth;
private MyCurrentLocation myCurrentLocation;
TextView descriptionTextView;
ImageView pointerIcon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_view);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setupListeners();
setupLayout();
setAugmentedRealityPoint();
}
/**Here is the place where you can setup your points of interest. In our example we will stick to just one but you can extend algorithm to work with DB etc. **/
private void setAugmentedRealityPoint() {
poi = new AugmentedPOI(
"Kościół Mariacki",
"Kościół Mariacki w Krakowie",
50.06169631,
19.93919566
);
}
public double calculateTeoreticalAzimuth() {
....
}
private List<Double> calculateAzimuthAccuracy(double azimuth) {
....
}
private boolean isBetween(double minAngle, double maxAngle, double azimuth) {
....
}
private void updateDescription() {
descriptionTextView.setText(mPoi.getPoiName() + " azimuthTeoretical "
+ mAzimuthTeoretical + " azimuthReal " + mAzimuthReal + " latitude "
+ mMyLatitude + " longitude " + mMyLongitude);
}
@Override
public void getCurrentLocation(Location location) {
....
}
@Override
public void onAzimuthChanged(float azimuthChangedFrom, float azimuthChangedTo) {
....
}
private void setupListeners() {
myCurrentLocation = new MyCurrentLocation(this);
myCurrentLocation.buildGoogleApiClient(this);
myCurrentLocation.start();
myCurrentAzimuth = new MyCurrentAzimuth(this, this);
myCurrentAzimuth.start();
}
private void setupLayout() {
descriptionTextView = (TextView) findViewById(R.id.cameraTextView);
getWindow().setFormat(PixelFormat.UNKNOWN);
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.cameraview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if (isCameraviewOn) {
mCamera.stopPreview();
isCameraviewOn = false;
}
if (mCamera != null) {
try {
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
isCameraviewOn = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
mCamera.setDisplayOrientation(90);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
isCameraviewOn = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment