Skip to content

Commit

Permalink
Merge pull request #3 from KillerInk/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
Theliel authored Dec 14, 2017
2 parents 5f4fb76 + 91ab97d commit 36579dc
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 647 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/lge/hardware/LGCameraRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ public LGCameraRef(int cameraid, int hwlvl)
private void init_classes() throws ClassNotFoundException, NoSuchMethodException {
CLASS_LGCAMERA = Class.forName("com.lge.hardware.LGCamera");
CLASS_LGPARAMETERS = Class.forName("com.lge.hardware.LGCamera$LGParameters");
METHOD_getCamera = CLASS_LGCAMERA.getMethod("getCamera",null);
METHOD_getLGParameters = CLASS_LGCAMERA.getMethod("getLGParameters",null);
METHOD_LGParameters_getParameters = CLASS_LGPARAMETERS.getMethod("getParameters", null);
METHOD_getCamera = CLASS_LGCAMERA.getMethod("getCamera");
METHOD_getLGParameters = CLASS_LGCAMERA.getMethod("getLGParameters");
METHOD_LGParameters_getParameters = CLASS_LGPARAMETERS.getMethod("getParameters");
}

//public android.hardware.Camera getCamera() { }

public Camera getCamera()
{
try {
return (Camera) METHOD_getCamera.invoke(lgCamera,null);
return (Camera) METHOD_getCamera.invoke(lgCamera);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ protected void saveDng(byte[] data, File file)
task.setFilePath(file, SettingsManager.getInstance().GetWriteExternal());
task.setBytesTosave(data,ImageSaveTask.RAW10);
task.setLocation(cameraUiWrapper.getActivityInterface().getLocationManager().getCurrentLocation());
task.setOpcode2(SettingsManager.getInstance().getOpcode2());
task.setOpcode3(SettingsManager.getInstance().getOpcode3());
ImageManager.putImageSaveTask(task);
}
}
19 changes: 15 additions & 4 deletions app/src/main/java/freed/cam/apis/camera2/Camera2Fragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,46 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume");
if (textureView.isAttachedToWindow() && PreviewSurfaceRdy)
startCamera();
}

@Override
public void onPause() {
super.onPause();
Log.d(TAG, "onPause");
stopPreview();
stopCamera();
}

@Override
public void onCameraOpen(final String message)
{
Log.d(TAG, "onCameraOpen, initCamera");
mBackgroundHandler.initCamera();
}

@Override
public void onCameraClose(String message)
{
Log.d(TAG, "onCameraClose");
cameraIsOpen = false;
mProcessor.kill();
super.onCameraClose(message);
}

@Override
public void onPreviewOpen(String message) {
parametersHandler.setManualSettingsToParameters();
Log.d(TAG, "onPreviewOpen");
//workaround, that seem to kill front camera when switching picformat
if (!SettingsManager.getInstance().getIsFrontCamera())
parametersHandler.setManualSettingsToParameters();
}

@Override
public void onPreviewClose(String message) {

Log.d(TAG, "onPreviewClose");
}

@Override
Expand Down Expand Up @@ -206,16 +214,19 @@ protected void handleBackgroundMessage(Message message) {
switch (message.what)
{
case MSG_START_CAMERA:
if (!cameraIsOpen)
if (!cameraIsOpen) {
Log.d(TAG, "Start Camera");
cameraIsOpen = cameraHolder.OpenCamera(SettingsManager.getInstance().GetCurrentCamera());
} else
Log.d(TAG, "Camera is already open");
break;
case MSG_STOP_CAMERA:
Log.d(TAG, "Stop Camera");
cameraHolder.CloseCamera();
cameraIsOpen = false;
break;
case MSG_RESTART_CAMERA:
Log.d(TAG, "Stop Camera");
Log.d(TAG, "Restart Camera");
cameraHolder.CloseCamera();
cameraIsOpen = false;
if (!cameraIsOpen)
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/freed/cam/apis/camera2/CameraHolderApi2.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public boolean OpenCamera(int camera)

} catch (CameraAccessException ex) {
Log.WriteEx(ex);
if (mCameraDevice != null) {
mCameraDevice.close();
mCameraDevice = null;
}
return false;
}
return true;
Expand Down Expand Up @@ -342,8 +346,9 @@ public void onDisconnected(@NonNull CameraDevice cameraDevice)
{
Log.d(TAG,"Camera Disconnected");
// mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
if (mCameraDevice != null) {
mCameraDevice.close();
}
if (UIHandler != null)
UIHandler.post(new Runnable() {
@Override
Expand All @@ -358,6 +363,11 @@ public void onError(@NonNull CameraDevice cameraDevice, final int error)
{
Log.d(TAG, "Camera Error" + error);
// mCameraOpenCloseLock.release();
if (mCameraDevice != null) {
mCameraDevice.close();
mCameraDevice = null;

}
errorRecieved = true;
UIHandler.post(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import freed.image.ImageManager;
import freed.image.ImageSaveTask;
import freed.image.ImageTaskDngConverter;
import freed.settings.SettingsManager;
import freed.utils.Log;

/**
Expand Down Expand Up @@ -303,6 +304,8 @@ private void process_rawWithDngConverter(Image image, int rawFormat,File file) {
saveTask.setDngProfile(prof);
saveTask.setFilePath(file, externalSD);
saveTask.setOrientation(orientation);
saveTask.setOpcode2(SettingsManager.getInstance().getOpcode2());
saveTask.setOpcode3(SettingsManager.getInstance().getOpcode3());
ImageManager.putImageSaveTask(saveTask);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ public void DestroyModule()
Log.d(TAG, "DestroyModule");
cameraHolder.captureSessionHandler.CloseCaptureSession();
cameraUiWrapper.getFocusPeakProcessor().kill();
if (rawReader != null){
rawReader.close();
rawReader = null;
}
if (jpegReader != null){
jpegReader.close();
jpegReader = null;
}
}

@Override
Expand All @@ -128,6 +136,7 @@ public void DoWork()
mBackgroundHandler.post(TakePicture);
else if (isWorking)
{
Log.d(TAG, "cancel capture");
cameraHolder.captureSessionHandler.cancelCapture();
finishCapture();
changeCaptureState(CaptureStates.image_capture_stop);
Expand All @@ -145,66 +154,61 @@ public void startPreview() {
int orientationToSet = (360 +cameraUiWrapper.getActivityInterface().getOrientation() + sensorOrientation)%360;
if (SettingsManager.get(Settings.orientationHack).getBoolean())
orientationToSet = (360 +cameraUiWrapper.getActivityInterface().getOrientation() + sensorOrientation+180)%360;
Log.d(TAG, "orientation to set :" +orientationToSet);
cameraHolder.captureSessionHandler.SetParameter(CaptureRequest.JPEG_ORIENTATION, orientationToSet);

// Here, we create a CameraCaptureSession for camera preview

try {
Size previewSize = cameraHolder.getSizeForPreviewDependingOnImageSize(ImageFormat.YUV_420_888, mImageWidth, mImageHeight);
if (cameraUiWrapper.getFocusPeakProcessor() != null)
{
cameraUiWrapper.getFocusPeakProcessor().kill();
}
int orientation = 0;
switch (sensorOrientation)
{
case 90:
orientation = 0;
break;
case 180:
orientation =90;
break;
case 270: orientation = 180;
break;
case 0: orientation = 270;
break;
}
final int w = previewSize.getWidth();
final int h = previewSize.getHeight();
final int or = orientation;
mainHandler.post(new Runnable() {
@Override
public void run() {
cameraHolder.captureSessionHandler.SetTextureViewSize(w, h,or,or+180,false);
}
});

SurfaceTexture texture = cameraHolder.captureSessionHandler.getSurfaceTexture();
texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
Surface previewsurface = new Surface(texture);

cameraUiWrapper.getFocusPeakProcessor().Reset(previewSize.getWidth(), previewSize.getHeight());
cameraUiWrapper.getFocusPeakProcessor().setOutputSurface(previewsurface);
Surface camerasurface = cameraUiWrapper.getFocusPeakProcessor().getInputSurface();
cameraHolder.captureSessionHandler.AddSurface(camerasurface,true);

if (jpegReader != null)
cameraHolder.captureSessionHandler.AddSurface(jpegReader.getSurface(),false);
if (rawReader != null)
cameraHolder.captureSessionHandler.AddSurface(rawReader.getSurface(),false);

cameraHolder.captureSessionHandler.CreateCaptureSession();

cameraHolder.captureSessionHandler.createImageCaptureRequestBuilder();
if (jpegReader != null)
cameraHolder.captureSessionHandler.setImageCaptureSurface(jpegReader.getSurface());
if (rawReader != null)
cameraHolder.captureSessionHandler.setImageCaptureSurface(rawReader.getSurface());
Size previewSize = cameraHolder.getSizeForPreviewDependingOnImageSize(ImageFormat.YUV_420_888, mImageWidth, mImageHeight);
if (cameraUiWrapper.getFocusPeakProcessor() != null)
{
cameraUiWrapper.getFocusPeakProcessor().kill();
}
catch(Exception ex)
int orientation = 0;
switch (sensorOrientation)
{
Log.WriteEx(ex);
case 90:
orientation = 0;
break;
case 180:
orientation =90;
break;
case 270: orientation = 180;
break;
case 0: orientation = 270;
break;
}
final int w = previewSize.getWidth();
final int h = previewSize.getHeight();
final int or = orientation;
mainHandler.post(new Runnable() {
@Override
public void run() {
cameraHolder.captureSessionHandler.SetTextureViewSize(w, h,or,or+180,false);
}
});

SurfaceTexture texture = cameraHolder.captureSessionHandler.getSurfaceTexture();
texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
Surface previewsurface = new Surface(texture);

cameraUiWrapper.getFocusPeakProcessor().Reset(previewSize.getWidth(), previewSize.getHeight());
cameraUiWrapper.getFocusPeakProcessor().setOutputSurface(previewsurface);
Surface camerasurface = cameraUiWrapper.getFocusPeakProcessor().getInputSurface();
cameraHolder.captureSessionHandler.AddSurface(camerasurface,true);

if (jpegReader != null)
cameraHolder.captureSessionHandler.AddSurface(jpegReader.getSurface(),false);
if (rawReader != null)
cameraHolder.captureSessionHandler.AddSurface(rawReader.getSurface(),false);

cameraHolder.captureSessionHandler.CreateCaptureSession();

cameraHolder.captureSessionHandler.createImageCaptureRequestBuilder();
if (jpegReader != null)
cameraHolder.captureSessionHandler.setImageCaptureSurface(jpegReader.getSurface());
if (rawReader != null)
cameraHolder.captureSessionHandler.setImageCaptureSurface(rawReader.getSurface());
if (parameterHandler.get(Settings.M_Burst) != null)
parameterHandler.get(Settings.M_Burst).fireStringValueChanged(parameterHandler.get(Settings.M_Burst).GetStringValue());
cameraUiWrapper.onPreviewOpen("");
Expand Down Expand Up @@ -278,8 +282,10 @@ else if (picFormat.equals(SettingsManager.getInstance().getResString(R.string.pi

}
else {
if (rawReader != null)
if (rawReader != null) {
rawReader.close();
rawReader = null;
}
rawReader = null;
captureDng = false;
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/freed/cam/ui/CameraUiSlidePagerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public void setCameraFragment(CameraFragmentAbstract cameraFragment)
this.cameraFragment = cameraFragment;
settingsMenuFragment.setCameraToUi(cameraFragment);
cameraUiFragment.setCameraToUi(cameraFragment);

if (cameraFragment != null)
cameraFragment.getModuleHandler().ModuleHasChanged(cameraFragment.getModuleHandler().getCurrentModuleName());
}

public void updateScreenSlideFile(List<FileHolder> files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public boolean isRunning()

public ShutterAnimationHandler(Looper looper, Resources resources,ShutterButton shutterButton)
{

super(looper);
halfsize = resources.getDimensionPixelSize(R.dimen.cameraui_shuttericon_size) /2;
uiHandler = new UIHandler(Looper.getMainLooper());
this.shutterButton = shutterButton;
//used to draw green timer inside the shutter button
Expand Down Expand Up @@ -174,7 +176,6 @@ public void stopShutterTimer() {
private void run()
{
calcstartTime = System.nanoTime();
halfsize = shutterButton.getWidth()/2;
MAX_SHUTTER_OPEN = (shutterButton.getWidth() - 100) / 2;
SHUTTER_OPEN_STEP = (MAX_SHUTTER_OPEN) / MAXFRAMES;
MAX_RECORDING_OPEN = shutterButton.getWidth() /4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.troop.freedcam.R;

import freed.cam.apis.basecamera.CameraWrapperInterface;
import freed.cam.apis.basecamera.modules.ModuleChangedEvent;
import freed.cam.apis.basecamera.modules.ModuleHandlerAbstract;
import freed.cam.apis.basecamera.modules.ModuleHandlerAbstract.CaptureStates;
import freed.settings.Settings;
Expand All @@ -41,7 +42,7 @@
/**
* Created by troop on 20.06.2015.
*/
public class ShutterButton extends android.support.v7.widget.AppCompatButton implements ModuleHandlerAbstract.CaptureStateChanged {
public class ShutterButton extends android.support.v7.widget.AppCompatButton implements ModuleHandlerAbstract.CaptureStateChanged, ModuleChangedEvent {
private CameraWrapperInterface cameraUiWrapper;

private final String TAG = ShutterButton.class.getSimpleName();
Expand All @@ -53,9 +54,11 @@ public class ShutterButton extends android.support.v7.widget.AppCompatButton imp
* Starts a background thread and its {@link Handler}.
*/
private void startBackgroundThread() {
mBackgroundThread = new HandlerThread("ShutterDraw");
mBackgroundThread.start();
animationHandler = new ShutterAnimationHandler(mBackgroundThread.getLooper(),getResources(),this);
if (mBackgroundThread == null || !mBackgroundThread.isAlive()) {
mBackgroundThread = new HandlerThread("ShutterDraw");
mBackgroundThread.start();
animationHandler = new ShutterAnimationHandler(mBackgroundThread.getLooper(), getResources(), this);
}
}

/**
Expand Down Expand Up @@ -103,6 +106,7 @@ protected void onDetachedFromWindow() {

private void init(Context context) {

startBackgroundThread();
//set background img that get then overdrawn
setBackgroundResource(R.drawable.shutter5);

Expand Down Expand Up @@ -139,9 +143,12 @@ public void SetCameraUIWrapper(CameraWrapperInterface cameraUiWrapper, UserMessa
if (cameraUiWrapper.getModuleHandler() == null)
return;
this.cameraUiWrapper = cameraUiWrapper;
cameraUiWrapper.getModuleHandler().addListner(this);
cameraUiWrapper.getModuleHandler().setWorkListner(this);
if(cameraUiWrapper.getModuleHandler().getCurrentModule() != null)
if(cameraUiWrapper.getModuleHandler().getCurrentModule() != null) {
onCaptureStateChanged(cameraUiWrapper.getModuleHandler().getCurrentModule().getCurrentCaptureState());

}
Log.d(this.TAG, "Set cameraUiWrapper to ShutterButton");
}

Expand Down Expand Up @@ -207,4 +214,10 @@ protected void onDraw(Canvas canvas)
animationHandler.onDraw(canvas);
}

@Override
public void onModuleChanged(String module) {
if(cameraUiWrapper.getModuleHandler().getCurrentModule() != null) {
onCaptureStateChanged(cameraUiWrapper.getModuleHandler().getCurrentModule().getCurrentCaptureState());
}
}
}
Loading

0 comments on commit 36579dc

Please sign in to comment.