9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2024-10-06 18:32:07 +08:00

Merge branch 'master' into issue#2

Conflicts:
	src/android/customCamera/res/layout/activity_camera_view.xml
	src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java
This commit is contained in:
Christophe BOUCAUT 2014-12-08 09:44:57 +01:00
commit 1779457b65
3 changed files with 252 additions and 133 deletions

View File

@ -9,79 +9,75 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" > android:layout_alignParentTop="true" >
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" > android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView <ImageView
android:id="@+id/background" android:id="@+id/background"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:alpha="0.2" android:alpha="0.2"
android:scaleType="fitXY" /> android:scaleType="centerInside"
android:src="@drawable/normal" />
</FrameLayout> </FrameLayout>
<GridLayout <LinearLayout
android:id="@+id/beforePhoto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:columnCount="4" > android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="bottom" >
<LinearLayout <Button
android:layout_width="fill_parent" android:id="@+id/miniature"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:orientation="horizontal" > android:layout_height="wrap_content"
android:layout_weight="0.2"
android:onClick="showMiniature"
android:text="@string/miniature" />
<Button <Button
android:id="@+id/miniature" android:id="@+id/capture"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_weight="1"
android:onClick="showMiniature" android:onClick="takePhoto"
android:text="@string/miniature" /> android:text="@string/capture" />
<Button <org.geneanet.customcamera.VerticalSeekBar
android:id="@+id/capture" android:id="@+id/switchOpacity"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="300dp"
android:layout_gravity="bottom" android:layout_gravity="center_vertical"
android:layout_weight="0.74" android:layout_weight="0"
android:text="@string/capture" android:alpha="0.6"
android:onClick="takePhoto" /> android:max="7"
android:maxHeight="13dp"
android:minHeight="0dp"
android:progress="0"
android:progressDrawable="@drawable/custom_opacity_bar"
android:secondaryProgress="7"
android:thumb="@drawable/thumb"
android:thumbOffset="-0.9px" />
</LinearLayout>
<org.geneanet.customcamera.VerticalSeekBar <FrameLayout
android:id="@+id/switchOpacity" android:id="@+id/afterPhoto"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_gravity="center_vertical|right"
android:layout_weight="0"
android:alpha="0.6"
android:max="7"
android:maxHeight="13dp"
android:minHeight="0dp"
android:progress="0"
android:progressDrawable="@drawable/custom_opacity_bar"
android:secondaryProgress="7"
android:thumb="@drawable/thumb" />
</LinearLayout>
</GridLayout>
<GridLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" >
android:columnCount="2" >
<LinearLayout <LinearLayout
android:id="@+id/keepPhoto" android:id="@+id/keepPhoto"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:alpha="0.6" android:alpha="0.8"
android:background="@color/black" android:background="@color/black"
android:visibility="invisible" > android:visibility="invisible" >
@ -91,16 +87,21 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/acceptePicture" /> android:text="@string/acceptePicture" />
<Button <Button
android:id="@+id/decline" android:id="@+id/decline"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/declinePicture" /> android:text="@string/declinePicture" />
</LinearLayout> </LinearLayout>
</GridLayout> </FrameLayout>
<SeekBar
android:id="@+id/niveauZoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
</RelativeLayout> </RelativeLayout>

View File

@ -6,11 +6,12 @@
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="title_activity_camera_activity">CameraActivityNative</string> <string name="title_activity_camera_activity">CameraActivityNative</string>
<string name="start_custom_camera">Start Custom Camera</string> <string name="start_custom_camera">Start Custom Camera</string>
<string name="capture">Capture</string>
<string name="todo">TODO</string> <string name="todo">TODO</string>
<string name="sss">sss</string> <string name="sss">sss</string>
<string name="miniature">Miniature</string> <string name="miniature">Miniature</string>
<string name="capture">Photo</string> <string name="capture">Photo</string>
<string name="BoutonMiniature">Ceci est le bouton permettant d\'afficher une miniature</string> <string name="BoutonMiniature">Ceci est le bouton permettant d\'afficher une miniature</string>
<string name="descImage">Il s\'agit de l\'image de fond de l\'appareil photo</string> <string name="descImage">Il s\'agit de l\'image de fond de l\'appareil photo</string>
<string name="acceptePicture">Accepter Photo</string>
<string name="declinePicture">Refuser Photo</string>
</resources> </resources>

View File

@ -7,8 +7,6 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import android.util.Log;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -44,10 +42,20 @@ public class CameraActivity extends Activity {
*/ */
private boolean modeMiniature = false; private boolean modeMiniature = false;
/**
* Enable when a photo is taken
*/
private boolean photoTaken = false;
/** /**
* Camera resource. * Camera resource.
*/ */
private Camera mCamera = null; private Camera mCamera = null;
/**
* Distance between fingers for the zoom
*/
private static float distanceBetweenFingers;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -125,7 +133,36 @@ public class CameraActivity extends Activity {
// Assign the render camera to the view // Assign the render camera to the view
CameraPreview mPreview = new CameraPreview(this, mCamera); CameraPreview mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview); preview.addView(mPreview);
// The zoom bar progress
final Camera.Parameters params = mCamera.getParameters();
final SeekBar niveauZoom = (SeekBar) findViewById(R.id.niveauZoom);
int maxZoom = params.getMaxZoom();
final int zoom = params.getZoom();
niveauZoom.setMax(maxZoom);
niveauZoom.setProgress(zoom);
niveauZoom.setVisibility(View.VISIBLE);
// Event on change zoom with the bar.
niveauZoom.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progress = progresValue;
int newZoom = (int)(zoom+progress);
niveauZoom.setProgress(newZoom);
params.setZoom(newZoom);
mCamera.setParameters(params);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
} }
/** /**
@ -141,72 +178,28 @@ public class CameraActivity extends Activity {
// Event on touch screen to call the manager of the zoom & the auto focus. // Event on touch screen to call the manager of the zoom & the auto focus.
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
Camera.Parameters params = mCamera.getParameters(); if (!photoTaken) {
int action = event.getAction(); Camera.Parameters params = mCamera.getParameters();
int action = event.getAction();
if (event.getPointerCount() > 1) {
// If we touch with more than one finger if (event.getPointerCount() > 1) {
float distanceBetweenFingers = 0; // If we touch with more than one finger
if (action == MotionEvent.ACTION_POINTER_UP) { if (action == MotionEvent.ACTION_POINTER_2_DOWN) {
distanceBetweenFingers = getFingerSpacing(event); distanceBetweenFingers = getFingerSpacing(event);
} else if (action == MotionEvent.ACTION_MOVE && params.isZoomSupported()) { } else if (action == MotionEvent.ACTION_MOVE && params.isZoomSupported()) {
mCamera.cancelAutoFocus(); mCamera.cancelAutoFocus();
handleZoom(event, params, distanceBetweenFingers); handleZoom(event, params, distanceBetweenFingers);
} }
} else { } else {
// If we touch with one finger -> auto-focus // If we touch with one finger -> auto-focus
if (action == MotionEvent.ACTION_UP) { if (action == MotionEvent.ACTION_UP) {
handleFocus(event, params); handleFocus(event, params);
} }
}
} }
return true; return true;
} }
/**
* Manage the zoom.
*
* @param MotionEvent event Current event which start this action.
* @param Parameters params Camera's parameter.
* @param float distanceBetweenFingers Distance between two fingers.
*/
private void handleZoom(MotionEvent event, Camera.Parameters params, float distanceBetweenFingers) {
// take zoom max for the camera hardware.
int maxZoom = params.getMaxZoom();
// current value for the zoom.
int zoom = params.getZoom();
// new distance between fingers.
float newDist = getFingerSpacing(event);
if (newDist > distanceBetweenFingers) {
//zoom in
if (zoom < maxZoom/2)
zoom+=2;
} else if (newDist < distanceBetweenFingers) {
//zoom out
if (zoom > 0)
zoom-=2;
}
distanceBetweenFingers = newDist;
params.setZoom(zoom);
mCamera.setParameters(params);
}
/**
* Manage the focus.
*
* @param MotionEvent event Current event which start this action.
* @param Parameters params Camera's parameter.
*/
public void handleFocus(MotionEvent event, Camera.Parameters params) {
List<String> supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean b, Camera camera) {}
});
}
}
/** /**
* Determine the space between the first two fingers. * Determine the space between the first two fingers.
* *
@ -220,27 +213,90 @@ public class CameraActivity extends Activity {
return (float) Math.sqrt(x * x + y * y); return (float) Math.sqrt(x * x + y * y);
} }
/**
* Manage the zoom.
*
* @param MotionEvent event Current event which start this action.
* @param Parameters params Camera's parameter.
* @param float distanceBetweenFingers Distance between two fingers.
*/
private void handleZoom(MotionEvent event, Camera.Parameters params, float distanceBetweenFingers) {
// take zoom max for the camera hardware.
int maxZoom = params.getMaxZoom();
// current value for the zoom.
int zoom = params.getZoom();
setZoomProgress(maxZoom, zoom);
// new distance between fingers.
float newDist = getFingerSpacing(event);
if (newDist > distanceBetweenFingers) {
//zoom in
if (zoom < maxZoom) {
zoom++;
}
} else if (newDist < distanceBetweenFingers) {
//zoom out
if (zoom > 0) {
zoom--;
}
}
distanceBetweenFingers = newDist;
params.setZoom(zoom);
mCamera.setParameters(params);
}
/**
* To set the seekBar zoom with the pinchZoom
*
* @param maxZoom int the max zoom of the device
* @param zoom int the current zoom
*/
private void setZoomProgress(int maxZoom, int zoom){
SeekBar niveauZoom = (SeekBar) findViewById(R.id.niveauZoom);
niveauZoom.setMax(maxZoom);
niveauZoom.setProgress(zoom*2);
niveauZoom.setVisibility(View.VISIBLE);
}
/**
* Manage the focus.
*
* @param MotionEvent event Current event which start this action.
* @param Parameters params Camera's parameter.
*/
public void handleFocus(MotionEvent event, Camera.Parameters params) {
if (photoTaken == false) {
List<String> supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean b, Camera camera) {}
});
}
}
}
/** /**
* Display the miniature. * Display the miniature.
* @param View view Current view. * @param View view Current view.
*/ */
public void showMiniature(View view) { public void showMiniature(View view) {
// Picture for the background. // Picture for the background.
final ImageView imageView = (ImageView) findViewById(R.id.background); ImageView imageView = (ImageView) findViewById(R.id.background);
if (!photoTaken) {
imageView.setScaleType(ImageView.ScaleType.FIT_END);
}
else {
imageView.setScaleType(ImageView.ScaleType.FIT_START);
}
// Button for show miniature picture. // Button for show miniature picture.
final Button miniature = (Button) view; final Button miniature = (Button) view;
// if it's not miniature mode. // if it's not miniature mode.
if (!modeMiniature) { if (!modeMiniature) {
modeMiniature = true; modeMiniature = true;
// Set new size for miniature layout. // Set new size for miniature layout.
FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(imageView.getWidth()/4, imageView.getHeight()/4); setParamsMiniature(imageView, true);
paramsMiniature.gravity = Gravity.BOTTOM;
imageView.setLayoutParams(paramsMiniature);
// Set current opacity for the miniature.
// imageView.setAlpha(imageView.getAlpha());
// Hide the miniature button. // Hide the miniature button.
miniature.setVisibility(View.INVISIBLE); miniature.setVisibility(View.INVISIBLE);
@ -248,17 +304,44 @@ public class CameraActivity extends Activity {
imageView.setOnClickListener(new View.OnClickListener() { imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
modeMiniature = false; modeMiniature = false;
ImageView imageView = (ImageView) findViewById(R.id.background);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
// resize miniature. // resize miniature.
setBackground(); setBackground();
// imageView.setAlpha(imageView.getAlpha()); LayoutParams paramsReagrandissement = (LayoutParams) imageView.getLayoutParams();
imageView.setClickable(false);
paramsReagrandissement.width = -1;
paramsReagrandissement.height = -1;
imageView.setLayoutParams(paramsReagrandissement);
miniature.setVisibility(View.VISIBLE); miniature.setVisibility(View.VISIBLE);
} }
}); });
} }
} }
/**
* Set the size and the gravity of the miniature function of photo is taken or not.
*
* @param ImageView imageView Reference to the background image.
* @param Boolean Resize Should we resize or not ? Only when click on "miniature"
*/
public void setParamsMiniature(ImageView imageView, boolean resize){
FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(imageView.getWidth(), imageView.getHeight());
if (resize == true){
paramsMiniature.width = imageView.getWidth()/4;
paramsMiniature.height = imageView.getHeight()/4;
}
if (!photoTaken){
paramsMiniature.gravity = Gravity.BOTTOM;
}
else {
paramsMiniature.gravity = Gravity.TOP;
}
imageView.setLayoutParams(paramsMiniature);
}
/** /**
* Method to get the device default orientation. * Method to get the device default orientation.
* *
@ -324,6 +407,25 @@ public class CameraActivity extends Activity {
// Hide the capture button. // Hide the capture button.
final Button photo = (Button)findViewById(R.id.capture); final Button photo = (Button)findViewById(R.id.capture);
photo.setVisibility(View.INVISIBLE); photo.setVisibility(View.INVISIBLE);
// Hide the zoom progressBar
final SeekBar niveauZoom = (SeekBar) findViewById(R.id.niveauZoom);
niveauZoom.setVisibility(View.INVISIBLE);
// Put button miniature at the top of the page
final Button miniature = (Button)findViewById(R.id.miniature);
final LayoutParams params = (LinearLayout.LayoutParams)miniature.getLayoutParams();
((LinearLayout.LayoutParams) params).gravity = Gravity.TOP;
miniature.setLayoutParams(params);
photoTaken = true;
// If miniature mode when photo is taken, the miniature goes to the top
if(modeMiniature){
ImageView imageView = (ImageView) findViewById(R.id.background);
imageView.setScaleType(ImageView.ScaleType.FIT_START);
setParamsMiniature(imageView, false);
}
// Stop link between view and camera to start the preview picture. // Stop link between view and camera to start the preview picture.
mCamera.stopPreview(); mCamera.stopPreview();
@ -333,6 +435,7 @@ public class CameraActivity extends Activity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
try { try {
photoTaken = false;
// Get path picture to storage. // Get path picture to storage.
String pathPicture = Environment.getExternalStorageDirectory().getPath()+"/"+Environment.DIRECTORY_DCIM+"/Camera/"; String pathPicture = Environment.getExternalStorageDirectory().getPath()+"/"+Environment.DIRECTORY_DCIM+"/Camera/";
pathPicture = pathPicture+String.format("%d.jpeg", System.currentTimeMillis()); pathPicture = pathPicture+String.format("%d.jpeg", System.currentTimeMillis());
@ -355,14 +458,25 @@ public class CameraActivity extends Activity {
decline.setOnClickListener(new View.OnClickListener() { decline.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
keepPhoto.setVisibility(View.INVISIBLE); photoTaken = false;
photo.setVisibility(View.VISIBLE); ((LinearLayout.LayoutParams) params).gravity = Gravity.BOTTOM;
mCamera.startPreview(); miniature.setLayoutParams(params);
// If mode miniature and photo is declined, the miniature goes back to the bottom
if(modeMiniature) {
ImageView imageView = (ImageView) findViewById(R.id.background);
imageView.setScaleType(ImageView.ScaleType.FIT_END);
setParamsMiniature(imageView, false);
}
keepPhoto.setVisibility(View.INVISIBLE);
photo.setVisibility(View.VISIBLE);
niveauZoom.setVisibility(View.VISIBLE);
mCamera.startPreview();
} }
}); });
}; };
}; };
// Start capture picture. // Start capture picture.
mCamera.takePicture(shutterCallback, rawCallback, jpegCallback); mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
} }
@ -385,7 +499,10 @@ public class CameraActivity extends Activity {
return true; return true;
} }
/**
* When the back button is pressed
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
this.setResult(3); this.setResult(3);