Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c432380c authored by Mark Harman's avatar Mark Harman
Browse files

New BasicApplicationInterface.

parent 46b001b7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import java.util.TimerTask;
import net.sourceforge.opencamera.CameraController.CameraController;
import net.sourceforge.opencamera.CameraController.RawImage;
import net.sourceforge.opencamera.Preview.ApplicationInterface;
import net.sourceforge.opencamera.Preview.BasicApplicationInterface;
import net.sourceforge.opencamera.Preview.Preview;
import net.sourceforge.opencamera.Preview.VideoProfile;
import net.sourceforge.opencamera.UI.DrawPreview;
@@ -49,7 +50,7 @@ import android.widget.ImageButton;

/** Our implementation of ApplicationInterface, see there for details.
 */
public class MyApplicationInterface implements ApplicationInterface {
public class MyApplicationInterface extends BasicApplicationInterface {
	private static final String TAG = "MyApplicationInterface";

	// note, okay to change the order of enums in future versions, as getPhotoMode() does not rely on the order for the saved photo mode
+600 −0
Original line number Diff line number Diff line
package net.sourceforge.opencamera.Preview;

import java.util.Date;
import java.util.List;

import android.graphics.Canvas;
import android.location.Location;
import android.net.Uri;
import android.util.Pair;
import android.view.MotionEvent;

import net.sourceforge.opencamera.CameraController.CameraController;
import net.sourceforge.opencamera.CameraController.RawImage;

/** A partial implementation of ApplicationInterface that provides "default" implementations. So
 *  sub-classing this is easier than implementing ApplicationInterface directly - you only have to
 *  provide the unimplemented methods to get started, and can later override
 *  BasicApplicationInterface's methods as required.
 *  Note there is no need for your subclass of BasicApplicationInterface to call "super" methods -
 *  these are just default implementations that should be overridden as required.
 */
public abstract class BasicApplicationInterface implements ApplicationInterface {
	@Override
	public Location getLocation() {
		return null;
	}

	@Override
	public int getCameraIdPref() {
		return 0;
	}

	@Override
	public String getFlashPref() {
		return "flash_off";
	}

	@Override
	public String getFocusPref(boolean is_video) {
		return "focus_mode_continuous_picture";
	}

	@Override
	public boolean isVideoPref() {
		return false;
	}

	@Override
	public String getSceneModePref() {
		return CameraController.SCENE_MODE_DEFAULT;
	}

	@Override
	public String getColorEffectPref() {
		return CameraController.COLOR_EFFECT_DEFAULT;
	}

	@Override
	public String getWhiteBalancePref() {
		return CameraController.WHITE_BALANCE_DEFAULT;
	}

	@Override
	public int getWhiteBalanceTemperaturePref() {
		return 0;
	}

	@Override
	public String getAntiBandingPref() {
		return CameraController.ANTIBANDING_DEFAULT;
	}

	@Override
	public String getISOPref() {
		return CameraController.ISO_DEFAULT;
	}

	@Override
	public int getExposureCompensationPref() {
		return 0;
	}

	@Override
	public Pair<Integer, Integer> getCameraResolutionPref() {
		return null;
	}

	@Override
	public int getImageQualityPref() {
		return 90;
	}

	@Override
	public boolean getFaceDetectionPref() {
		return false;
	}

	@Override
	public String getVideoQualityPref() {
		return "";
	}

	@Override
	public boolean getVideoStabilizationPref() {
		return false;
	}

	@Override
	public boolean getForce4KPref() {
		return false;
	}

	@Override
	public String getVideoBitratePref() {
		return "default";
	}

	@Override
	public String getVideoFPSPref() {
		return "default";
	}

	@Override
	public float getVideoCaptureRateFactor() {
		return 1.0f;
	}

	@Override
	public boolean useVideoLogProfile() {
		return false;
	}

	@Override
	public float getVideoLogProfileStrength() {
		return 0;
	}

	@Override
	public long getVideoMaxDurationPref() {
		return 0;
	}

	@Override
	public int getVideoRestartTimesPref() {
		return 0;
	}

	@Override
	public VideoMaxFileSize getVideoMaxFileSizePref() throws NoFreeStorageException {
		VideoMaxFileSize video_max_filesize = new VideoMaxFileSize();
		video_max_filesize.max_filesize = 0;
		video_max_filesize.auto_restart = true;
		return video_max_filesize;
	}

	@Override
	public boolean getVideoFlashPref() {
		return false;
	}

	@Override
	public boolean getVideoLowPowerCheckPref() {
		return true;
	}

	@Override
	public String getPreviewSizePref() {
		return "preference_preview_size_wysiwyg";
	}

	@Override
	public String getPreviewRotationPref() {
		return "0";
	}

	@Override
	public String getLockOrientationPref() {
		return "none";
	}

	@Override
	public boolean getTouchCapturePref() {
		return false;
	}

	@Override
	public boolean getDoubleTapCapturePref() {
		return false;
	}

	@Override
	public boolean getPausePreviewPref() {
		return false;
	}

	@Override
	public boolean getShowToastsPref() {
		return true;
	}

	@Override
	public boolean getShutterSoundPref() {
		return true;
	}

	@Override
	public boolean getStartupFocusPref() {
		return true;
	}

	@Override
	public long getTimerPref() {
		return 0;
	}

	@Override
	public String getRepeatPref() {
		return "1";
	}

	@Override
	public long getRepeatIntervalPref() {
		return 0;
	}

	@Override
	public boolean getGeotaggingPref() {
		return false;
	}

	@Override
	public boolean getRequireLocationPref() {
		return false;
	}

	@Override
	public boolean getRecordAudioPref() {
		return true;
	}

	@Override
	public String getRecordAudioChannelsPref() {
		return "audio_default";
	}

	@Override
	public String getRecordAudioSourcePref() {
		return "audio_src_camcorder";
	}

	@Override
	public int getZoomPref() {
		return 0;
	}

	@Override
	public double getCalibratedLevelAngle() {
		return 0;
	}

	@Override
	public boolean canTakeNewPhoto() {
		return true;
	}

	@Override
	public long getExposureTimePref() {
		return CameraController.EXPOSURE_TIME_DEFAULT;
	}

	@Override
	public float getFocusDistancePref(boolean is_target_distance) {
		return 0;
	}

	@Override
	public boolean isExpoBracketingPref() {
		return false;
	}

	@Override
	public int getExpoBracketingNImagesPref() {
		return 3;
	}

	@Override
	public double getExpoBracketingStopsPref() {
		return 2.0;
	}

	@Override
	public int getFocusBracketingNImagesPref() {
		return 3;
	}

	@Override
	public boolean getFocusBracketingAddInfinityPref() {
		return false;
	}

	@Override
	public boolean isFocusBracketingPref() {
		return false;
	}

	@Override
	public boolean isCameraBurstPref() {
		return false;
	}

	@Override
	public int getBurstNImages() {
		return 5;
	}

	@Override
	public boolean getBurstForNoiseReduction() {
		return false;
	}

	@Override
	public boolean getOptimiseAEForDROPref() {
		return false;
	}

	@Override
	public RawPref getRawPref() {
		return RawPref.RAWPREF_JPEG_ONLY;
	}

	@Override
	public int getMaxRawImages() {
		return 2;
	}

	@Override
	public boolean useCamera2FakeFlash() {
		return false;
	}

	@Override
	public boolean useCamera2FastBurst() {
		return true;
	}

	@Override
	public boolean usePhotoVideoRecording() {
		return true;
	}

	@Override
	public boolean isTestAlwaysFocus() {
		return false;
	}

	@Override
	public void cameraSetup() {

	}

	@Override
	public void touchEvent(MotionEvent event) {

	}

	@Override
	public void startingVideo() {

	}

	@Override
	public void startedVideo() {

	}

	@Override
	public void stoppingVideo() {

	}

	@Override
	public void stoppedVideo(int video_method, Uri uri, String filename) {

	}

	@Override
	public void onFailedStartPreview() {

	}

	@Override
	public void onCameraError() {

	}

	@Override
	public void onPhotoError() {

	}

	@Override
	public void onVideoInfo(int what, int extra) {

	}

	@Override
	public void onVideoError(int what, int extra) {

	}

	@Override
	public void onVideoRecordStartError(VideoProfile profile) {

	}

	@Override
	public void onVideoRecordStopError(VideoProfile profile) {

	}

	@Override
	public void onFailedReconnectError() {

	}

	@Override
	public void onFailedCreateVideoFileError() {

	}

	@Override
	public void hasPausedPreview(boolean paused) {

	}

	@Override
	public void cameraInOperation(boolean in_operation, boolean is_video) {

	}

	@Override
	public void turnFrontScreenFlashOn() {

	}

	@Override
	public void cameraClosed() {

	}

	@Override
	public void timerBeep(long remaining_time) {

	}

	@Override
	public void layoutUI() {

	}

	@Override
	public void multitouchZoom(int new_zoom) {

	}

	@Override
	public void setCameraIdPref(int cameraId) {

	}

	@Override
	public void setFlashPref(String flash_value) {

	}

	@Override
	public void setFocusPref(String focus_value, boolean is_video) {

	}

	@Override
	public void setVideoPref(boolean is_video) {

	}

	@Override
	public void setSceneModePref(String scene_mode) {

	}

	@Override
	public void clearSceneModePref() {

	}

	@Override
	public void setColorEffectPref(String color_effect) {

	}

	@Override
	public void clearColorEffectPref() {

	}

	@Override
	public void setWhiteBalancePref(String white_balance) {

	}

	@Override
	public void clearWhiteBalancePref() {

	}

	@Override
	public void setWhiteBalanceTemperaturePref(int white_balance_temperature) {

	}

	@Override
	public void setISOPref(String iso) {

	}

	@Override
	public void clearISOPref() {

	}

	@Override
	public void setExposureCompensationPref(int exposure) {

	}

	@Override
	public void clearExposureCompensationPref() {

	}

	@Override
	public void setCameraResolutionPref(int width, int height) {

	}

	@Override
	public void setVideoQualityPref(String video_quality) {

	}

	@Override
	public void setZoomPref(int zoom) {

	}

	@Override
	public void setExposureTimePref(long exposure_time) {

	}

	@Override
	public void clearExposureTimePref() {

	}

	@Override
	public void setFocusDistancePref(float focus_distance, boolean is_target_distance) {

	}

	@Override
	public void onDrawPreview(Canvas canvas) {

	}

	@Override
	public boolean onBurstPictureTaken(List<byte[]> images, Date current_date) {
		return false;
	}

	@Override
	public boolean onRawPictureTaken(RawImage raw_image, Date current_date) {
		return false;
	}

	@Override
	public void onCaptureStarted() {

	}

	@Override
	public void onPictureCompleted() {

	}

	@Override
	public void onContinuousFocusMove(boolean start) {

	}
}
+5 −5
Original line number Diff line number Diff line
@@ -6,18 +6,18 @@ Open Camera is compiled using Android Studio. (Versions 1.34 or earlier were com
Source Control
==============

The Git repository is available at https://sourceforge.net/p/opencamera/code/ . Note that I work with the auto crlf turned off (otherwise it converts all the Linux line endings into Windows format). If you want to work on the source, please check out the latest version from the repository.
The Git repository is available at https://sourceforge.net/p/opencamera/code/ . Note that I work with the auto crlf turned off (otherwise it converts all the Linux line endings into Windows format). If you want to work on the source (especially if you want to contribute), please check out the latest version from the repository. If you are forking to build a separate application, again the Git repository has the latest code, but taking a source archive corresponding to a released version of Open Camera ( https://sourceforge.net/projects/opencamera/files/ ) may be more stable.

General advice
==============

If you want to build an application using the Open Camera source code, there are various levels you might like to do this at.

CameraController: The classes in the CameraController/ folder encapsultate the Android camera API (both the original, and Android 5's Camera2 API). So one level is to use these classes, to build a new application. These classes are still fairly low level (and you'll still have to do work such as setting up things like the camera preview), but avoid having to deal with Android's camera API directly. They combine the 2 camera APIs under a single interface (though some features are Camera2 specific). They also encapsulate code that covers driver specific behaviours (or driver bug workarounds!), to hide this from the outside world.
CameraController: The classes in the CameraController/ folder encapsultate the Android camera API (both the original, and the Camera2 API introduced in Android 5). So one level is to use these classes, to build a new application. These classes are still fairly low level (and you'll still have to do work such as setting up things like the camera preview), but avoid having to deal with Android's camera API directly. They combine the 2 camera APIs under a single interface (though some features are Camera2 specific). They also encapsulate code that covers driver specific behaviours (or driver bug workarounds!), to hide this from the outside world.

Preview: At a higher level, you might want to take the classes in Preview/ as well as CameraController/. Note the Preview class is a bit of a misnomer - as well as the camera preview, it also includes much of the functionality required to operate the camera. This level would provide you with a camera, but still leave you to define all the higher level parts of the application, such as user-interface, preferences, image processing and saving. As well as controlling the Preview by calling its methods, an instance of ApplicationInterface must be supplied, to allow the Preview to communicate to the application. (As an alternative, you may prefer to start with Open Camera's MyApplicationInterface as a sample, and modify it to your needs.)
Preview: At a higher level, you might want to take the classes in Preview/ as well as CameraController/. Note the Preview class is a bit of a misnomer - as well as the camera preview, it also includes much of the functionality required to operate the camera. This level would provide you with a camera, but still leave you to define all the higher level parts of the application, such as user-interface, preferences, image processing and saving. As well as controlling the Preview by calling its methods, an instance of ApplicationInterface must be supplied, to allow the Preview to communicate to the application. It is recommended to subclass BasicApplicationInterface, which provides a dummy default implementation of many of the methods. (As an alternative, you may prefer to start with Open Camera's MyApplicationInterface as a sample, and modify it to your needs.)

Application: You might prefer to use Open Camera in its entirety, as an Activity within your application (or possibly converting the MainActivity to a fragment). Consider whether Open Camera's Settings should be unified with the settings in your application. All accesses to SharedPreferences use the PreferencesKeys class to find the keys.
Application: You might prefer to use Open Camera in its entirety, as an Activity within your application (or possibly converting the MainActivity to a fragment). Consider whether Open Camera's Settings should be unified with the settings in your application. Accesses to SharedPreferences use the PreferencesKeys class to find the keys.

Licence
=======
@@ -30,4 +30,4 @@ Homepage: http://opencamera.org.uk/

Google Play download: https://play.google.com/store/apps/details?id=net.sourceforge.opencamera

Mark Harman 26 November 2016
Mark Harman 9 September 2018