If you think the Android project geoar-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/**
* Copyright 2012 52North Initiative for Geospatial Open Source Software GmbH
*/*www.java2s.com*/
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package org.n52.geoar.tracking.camera;
import java.util.ArrayList;
import java.util.List;
import org.n52.geoar.GeoARApplication;
import org.n52.geoar.view.geoar.Settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.hardware.Camera.Size;
/**
* This class sums up all relevant camera parameters and also informs listeners
* of changed parameters. Data gets updated by {@link CameraView}
*
* @author Holger Hopmann
*
*/publicclass RealityCamera {
privatestaticfinal String CAMERA_HEIGHT_PREF = "cameraHeight";
publicinterface CameraUpdateListener {
void onCameraUpdate();
}
publicstaticfloat height = 1.6f; // "usage height", distance between
// ground and device
publicstaticfloat fovY = 42.5f;
// Viewport of camera preview
publicstaticint cameraViewportWidth;
publicstaticint cameraViewportHeight;
privatestaticboolean hasViewportSize = false;
privatestatic List<CameraUpdateListener> listeners = new ArrayList<CameraUpdateListener>();
publicstaticfloat aspect;
publicstaticvoid addCameraUpdateListener(CameraUpdateListener listener) {
listeners.add(listener);
}
publicstaticvoid removeCameraUpdateListener(CameraUpdateListener listener) {
listeners.remove(listener);
}
privatestaticvoid onUpdate() {
for (CameraUpdateListener listener : listeners) {
listener.onCameraUpdate();
}
}
publicstaticvoid setFovY(float fov) {
boolean changed = RealityCamera.fovY != fov;
RealityCamera.fovY = fov;
if (changed)
onUpdate();
}
publicstaticvoid setViewportSize(Size size) {
setViewportSize(size.width, size.height);
}
publicstaticvoid setViewportSize(int width, int height) {
boolean changed = cameraViewportHeight != height
|| cameraViewportWidth != width;
cameraViewportHeight = height;
cameraViewportWidth = width;
RealityCamera.aspect = width / (float) height;
hasViewportSize = true;
if (changed)
onUpdate();
}
publicstaticboolean hasViewportSize() {
return hasViewportSize;
}
@Deprecated
publicstaticvoid setAspect(float aspect) {
// RealityCamera.aspect = aspect;
}
publicstaticvoid changeHeight(float inc) {
height += inc;
onUpdate();
}
publicstaticvoid setHeight(float height) {
RealityCamera.height = height;
onUpdate();
}
publicstaticvoid saveState() {
SharedPreferences preferences = GeoARApplication.applicationContext
.getSharedPreferences(GeoARApplication.PREFERENCES_FILE,
Context.MODE_PRIVATE);
Editor editor = preferences.edit();
editor.putFloat(CAMERA_HEIGHT_PREF, RealityCamera.height);
editor.commit();
}
publicstaticvoid restoreState() {
SharedPreferences prefs = GeoARApplication.applicationContext
.getSharedPreferences(GeoARApplication.PREFERENCES_FILE,
Context.MODE_PRIVATE);
RealityCamera.setHeight(prefs.getFloat(CAMERA_HEIGHT_PREF, 1.6f));
}
}