9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2026-05-02 00:07:24 +08:00
Issue#9
This commit is contained in:
Tboy70
2014-11-28 17:16:00 +01:00
3 changed files with 82 additions and 30 deletions
@@ -9,7 +9,6 @@
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</FrameLayout>
<FrameLayout
@@ -23,7 +22,6 @@
android:alpha="0.2"
android:scaleType="fitXY"
android:src="@drawable/normal" />
</FrameLayout>
<GridLayout
@@ -33,16 +31,24 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/miniature"
<RelativeLayout
android:id="@+id/miniature_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:onClick="showMiniature"
android:text="@string/miniature" />
android:layout_height="match_parent" >
<Button
android:id="@+id/miniature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:onClick="showMiniature"
android:text="@string/miniature" />
</RelativeLayout>
<Button
android:id="@+id/capture"
@@ -67,9 +73,7 @@
android:progressDrawable="@drawable/custom_opacity_bar"
android:secondaryProgress="7"
android:thumb="@drawable/thumb" />
</LinearLayout>
</GridLayout>
<GridLayout
@@ -99,9 +103,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/declinePicture" />
</LinearLayout>
</GridLayout>
</RelativeLayout>
@@ -6,11 +6,12 @@
<string name="action_settings">Settings</string>
<string name="title_activity_camera_activity">CameraActivityNative</string>
<string name="start_custom_camera">Start Custom Camera</string>
<string name="capture">Capture</string>
<string name="todo">TODO</string>
<string name="sss">sss</string>
<string name="miniature">Miniature</string>
<string name="capture">Photo</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="acceptePicture">Accepter Photo</string>
<string name="declinePicture">Refuser Photo</string>
</resources>
@@ -7,8 +7,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import android.util.Log;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
@@ -29,6 +27,7 @@ import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -41,6 +40,11 @@ public class CameraActivity extends Activity {
*/
private boolean modeMiniature = false;
/**
* Enable when a photo is taken
*/
private boolean photoTaken = false;
/**
* Camera resource.
*/
@@ -227,21 +231,15 @@ public class CameraActivity extends Activity {
*/
public void showMiniature(View view) {
// Picture for the background.
final ImageView imageView = (ImageView) findViewById(R.id.normal);
ImageView imageView = (ImageView) findViewById(R.id.normal);
// Button for show miniature picture.
final Button miniature = (Button) view;
// if it's not miniature mode.
if (!modeMiniature) {
modeMiniature = true;
// Set new size for miniature layout.
FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(imageView.getWidth()/4, imageView.getHeight()/4);
paramsMiniature.gravity = Gravity.BOTTOM;
imageView.setLayoutParams(paramsMiniature);
// Set current opacity for the miniature.
// imageView.setAlpha(imageView.getAlpha());
setParamsMiniature(imageView, true);
// Hide the miniature button.
miniature.setVisibility(View.INVISIBLE);
@@ -249,7 +247,7 @@ public class CameraActivity extends Activity {
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
modeMiniature = false;
ImageView imageView = (ImageView) findViewById(R.id.normal);
// resize miniature.
LayoutParams paramsReagrandissement = (LayoutParams) imageView.getLayoutParams();
paramsReagrandissement.width = -1;
@@ -320,6 +318,7 @@ public class CameraActivity extends Activity {
*/
public void onPictureTaken(final byte[] data, Camera camera) {
// Show buttons to accept or decline the picture.
final LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto);
keepPhoto.setVisibility(View.VISIBLE);
Button accept = (Button)findViewById(R.id.accept);
@@ -329,6 +328,21 @@ public class CameraActivity extends Activity {
final Button photo = (Button)findViewById(R.id.capture);
photo.setVisibility(View.INVISIBLE);
// Put button miniature at the top of the page
final Button miniature = (Button)findViewById(R.id.miniature);
final LayoutParams params = (RelativeLayout.LayoutParams)miniature.getLayoutParams();
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
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.normal);
setParamsMiniature(imageView, false);
}
// Stop link between view and camera to start the preview picture.
mCamera.stopPreview();
@@ -337,6 +351,7 @@ public class CameraActivity extends Activity {
@Override
public void onClick(View v) {
try {
photoTaken = false;
// Get path picture to storage.
String pathPicture = Environment.getExternalStorageDirectory().getPath()+"/"+Environment.DIRECTORY_DCIM+"/Camera/";
pathPicture = pathPicture+String.format("%d.jpeg", System.currentTimeMillis());
@@ -359,14 +374,24 @@ public class CameraActivity extends Activity {
decline.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
keepPhoto.setVisibility(View.INVISIBLE);
photo.setVisibility(View.VISIBLE);
mCamera.startPreview();
photoTaken = false;
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
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.normal);
setParamsMiniature(imageView, false);
}
keepPhoto.setVisibility(View.INVISIBLE);
photo.setVisibility(View.VISIBLE);
mCamera.startPreview();
}
});
};
};
// Start capture picture.
mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
@@ -389,10 +414,34 @@ public class CameraActivity extends Activity {
return true;
}
/**
* When the back button is pressed
*/
@Override
public void onBackPressed() {
this.setResult(3);
this.finish();
}
/**
* 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);
}
}