9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2026-05-02 00:07:24 +08:00
Issue#30
This commit is contained in:
ChristopheBoucaut
2014-12-29 12:22:28 +01:00
8 changed files with 663 additions and 718 deletions
+1 -5
View File
@@ -78,12 +78,8 @@ public class CameraLauncher extends CordovaPlugin {
);
break;
case CameraLauncher.RESULT_SUCCESS:
String pathPicture = intent.getStringExtra("pathPicture");
try {
File fl = new File(pathPicture);
byte[] ret = loadFile(fl);
byte[] output = Base64.encode(ret, Base64.NO_WRAP);
byte[] output = Base64.encode(TransferBigData.getImgTaken(), Base64.NO_WRAP);
String js_out = new String(output);
this.callbackContext.success(js_out);
@@ -19,9 +19,7 @@
<ImageView
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_height="fill_parent"
android:alpha="0.2"
android:scaleType="fitXY" />
@@ -33,30 +31,21 @@
android:layout_alignParentTop="true"
android:gravity="bottom" >
<LinearLayout
android:id="@+id/buttonMiniatureAndPhoto"
<Button
android:id="@+id/miniature"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="bottom" >
android:onClick="buttonMiniature"
android:text="@string/miniature" />
<Button
android:id="@+id/miniature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:onClick="showMiniature"
android:text="@string/miniature" />
<Button
android:id="@+id/capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="takePhoto"
android:text="@string/capture" />
</LinearLayout>
<Button
android:id="@+id/capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="takePhoto"
android:text="@string/capture" />
<org.geneanet.customcamera.VerticalSeekBar
android:id="@+id/switchOpacity"
@@ -94,6 +83,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="acceptPhoto"
android:text="@string/acceptePicture" />
<Button
@@ -101,6 +91,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="declinePhoto"
android:text="@string/declinePicture" />
</LinearLayout>
File diff suppressed because it is too large Load Diff
@@ -1,81 +1,90 @@
package org.geneanet.customcamera;
import java.io.IOException;
import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
/**
* Interface between the view and the camera.
*/
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
public class CameraPreview extends SurfaceView implements
SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
private SurfaceHolder myHolder;
private Camera myCamera;
/**
* Constructor
* @override
*/
public CameraPreview(Context context, Camera camera) {
super(context);
/**
* Constructor.
*
* @override
*/
public CameraPreview(Context context, Camera camera) {
super(context);
// assign camera
mCamera = camera;
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
// assign camera
myCamera = camera;
myHolder = getHolder();
myHolder.addCallback(this);
myHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
/**
* When the view is created.
*
* @override.
*/
public void surfaceCreated(SurfaceHolder holder) {
try {
// Reset preview start camera.
myCamera.setPreviewCallback(null);
myCamera.setPreviewDisplay(holder);
// Start link between the view and the camera.
myCamera.startPreview();
} catch (IOException e) {
Log.e("customCamera", "Error setting camera preview to create surface: "
+ e.getMessage());
}
}
/**
* When the view is changed.
*
* @override.
*/
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// check if the surface exist.
if (myHolder.getSurface() == null) {
return;
}
/**
* When the view is created.
* @override.
*/
public void surfaceCreated(SurfaceHolder holder) {
try {
// Reset preview start camera.
mCamera.setPreviewCallback(null);
mCamera.setPreviewDisplay(holder);
// Start link between the view and the camera.
mCamera.startPreview();
} catch (IOException e) {
Log.e("customCamera", "Error setting camera preview to create surface: " + e.getMessage());
}
try {
// stop current instance.
myCamera.setPreviewCallback(null);
myCamera.stopPreview();
} catch (Exception e) {
Log.e("customCamera",
"Error setting camera preview at null: " + e.getMessage());
}
/**
* When the view is changed.
* @override.
*/
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// check if the surface exist.
if (mHolder.getSurface() == null){
return;
}
try {
// stop current instance.
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
} catch (Exception e) {
Log.e("customCamera", "Error setting camera preview at null: " + e.getMessage());
}
try {
// Start new link between the view and the camera.
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
} catch (Exception e) {
Log.e("error", "Error starting camera preview with mHolder: " + e.getMessage());
}
try {
// Start new link between the view and the camera.
myCamera.setPreviewDisplay(myHolder);
myCamera.startPreview();
} catch (Exception e) {
Log.e("error",
"Error starting camera preview with myHolder: " + e.getMessage());
}
}
/**
* To destroy the surface of the preview.
* @override
*/
public void surfaceDestroyed(SurfaceHolder holder) {}
/**
* To destroy the surface of the preview.
*
* @override
*/
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
@@ -1,7 +1,5 @@
package org.geneanet.customcamera;
import org.geneanet.customcamera.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -11,35 +9,50 @@ import android.os.Bundle;
import android.util.Log;
import android.view.View;
import org.geneanet.customcamera.R;
/**
* Just to test application.
*/
public class MainActivity extends Activity {
Camera mCamera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Camera myCamera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* Start the camera.
*
* @param view The current view.
*/
public void startCamera(View view) {
if (this.checkCameraHardware(this)) {
Intent intent = new Intent(this, CameraActivity.class);
startActivity(intent);
finish();
} else {
Log.d("customCamera", "No camera hardware detected.");
}
public void startCamera(View view) {
if(this.checkCameraHardware(this)){
Intent intent = new Intent(this, CameraActivity.class);
startActivity(intent);
finish();
}
else {
Log.d("customCamera", "No camera hardware detected.");
}
}
private boolean checkCameraHardware(Context context) {
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) || Camera.getNumberOfCameras() > 0) {
return true;
} else {
return false;
}
}
/**
* Check if the device has cameras.
*
* @param context Context of the application.
*
* @return boolean True if the device has cameras. Else, return false.
*/
private boolean checkCameraHardware(Context context) {
if (context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)
|| Camera.getNumberOfCameras() > 0) {
return true;
} else {
return false;
}
}
}
@@ -7,45 +7,46 @@ import android.util.Log;
* Manage camera resource.
*/
public class ManagerCamera {
protected static Camera mCamera = null;
// Constant to define differents orientations for the devices.
public final static int PORTRAIT = 0;
public final static int LANDSCAPE = 1;
public final static int PORTRAIT_INVERSED = 2;
public final static int LANDSCAPE_INVERSED = 3;
protected static Camera mCamera = null;
/**
* A safe way to get an instance of the Camera object.
* @return Camera | null
*/
public static Camera getCameraInstance() {
// If camera is already instanced and available, return this resource.
if (ManagerCamera.mCamera != null) {
return ManagerCamera.mCamera;
}
// Constant to define different orientations for the devices.
public static final int PORTRAIT = 0;
public static final int LANDSCAPE = 1;
public static final int PORTRAIT_INVERSED = 2;
public static final int LANDSCAPE_INVERSED = 3;
// Start back camera.
Camera c = null;
try {
c = Camera.open(0);
} catch (RuntimeException e) {
Log.e("customCamera", "Can't open the camera back.");
}
ManagerCamera.mCamera = c;
return c; // returns null if camera is unavailable
/**
* A safe way to get an instance of the Camera object.
*
* @return Camera | null
*/
public static Camera getCameraInstance() {
// If camera is already instanced and available, return this resource.
if (ManagerCamera.mCamera != null) {
return ManagerCamera.mCamera;
}
/**
* To release the camera.
*/
public static void clearCameraAccess() {
if (ManagerCamera.mCamera != null) {
ManagerCamera.mCamera.stopPreview();
ManagerCamera.mCamera.release();
ManagerCamera.mCamera = null;
}
// Start back camera.
Camera cam = null;
try {
cam = Camera.open(0);
} catch (RuntimeException e) {
Log.e("customCamera", "Can't open the camera back.");
}
ManagerCamera.mCamera = cam;
return cam; // returns null if camera is unavailable
}
/**
* To release the camera.
*/
public static void clearCameraAccess() {
if (ManagerCamera.mCamera != null) {
ManagerCamera.mCamera.stopPreview();
ManagerCamera.mCamera.release();
ManagerCamera.mCamera = null;
}
}
}
@@ -4,21 +4,42 @@ package org.geneanet.customcamera;
* Use to transfer big data between activities.
*/
public class TransferBigData {
protected static byte[] imgBackgroundBase64 = null;
protected static byte[] imgBackgroundBase64 = null;
protected static byte[] imgTaken = null;
/**
* Get bytes to represent background picture.
* @return byte[]
*/
public static byte[] getImgBackgroundBase64() {
return TransferBigData.imgBackgroundBase64;
}
/**
* Get bytes to represent background picture.
*
* @return byte[]
*/
public static byte[] getImgBackgroundBase64() {
return TransferBigData.imgBackgroundBase64;
}
/**
* Set bytes to represent background picture.
* @param byte[] imgBackgroundBase64
*/
public static void setImgBackgroundBase64(byte[] imgBackgroundBase64) {
TransferBigData.imgBackgroundBase64 = imgBackgroundBase64;
}
/**
* Set bytes to represent background picture.
*
* @param byte[] imgBackgroundBase64
*/
public static void setImgBackgroundBase64(byte[] imgBackgroundBase64) {
TransferBigData.imgBackgroundBase64 = imgBackgroundBase64;
}
/**
* Get bytes to represent picture taken.
*
* @return byte[]
*/
public static byte[] getImgTaken() {
return TransferBigData.imgTaken;
}
/**
* Set bytes to represent picture taken.
*
* @param byte[] imgTaken
*/
public static void setImgTaken(byte[] imgTaken) {
TransferBigData.imgTaken = imgTaken;
}
}
@@ -10,56 +10,59 @@ import android.widget.SeekBar;
* Widget for opacity bar.
*/
public class VerticalSeekBar extends SeekBar {
/**
* Constructor
* @override
*/
public VerticalSeekBar(Context context) {
super(context);
/**
* Constructor.
*
* @override
*/
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onSizeChanged(int width, int height, int oldw, int oldh) {
super.onSizeChanged(height, width, oldh, oldw);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas canvas) {
canvas.rotate(-90);
canvas.translate(-getHeight(), 0);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(), 0);
super.onDraw(c);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
return true;
}
}