mirror of
https://gitee.com/shuto/customCamera.git
synced 2026-05-02 00:07:24 +08:00
Merge branch 'master' into issue#6
Conflicts: src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java
This commit is contained in:
@@ -16,7 +16,6 @@ import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
|
||||
public class CameraLauncher extends CordovaPlugin {
|
||||
@@ -35,9 +34,20 @@ public class CameraLauncher extends CordovaPlugin {
|
||||
|
||||
Intent intent = new Intent(this.cordova.getActivity(), CameraActivity.class);
|
||||
|
||||
Bundle imgBackgroundBase64 = new Bundle();
|
||||
imgBackgroundBase64.putString("imgBackgroundBase64", args.getString(0));
|
||||
intent.putExtras(imgBackgroundBase64);
|
||||
byte[] imgBackgroundBase64;
|
||||
try {
|
||||
imgBackgroundBase64 = Base64.decode(args.getString(0), Base64.NO_WRAP);
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.callbackContext.error(
|
||||
generateError(
|
||||
CameraLauncher.RESULT_ERROR,
|
||||
"Error decode base64 picture."
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
TransferBigData.setImgBackgroundBase64(imgBackgroundBase64);
|
||||
|
||||
cordova.startActivityForResult((CordovaPlugin) this, intent, CameraLauncher.REQUEST_CODE);
|
||||
|
||||
|
||||
@@ -11,20 +11,14 @@
|
||||
android:layout_alignParentTop="true" >
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
<ImageView
|
||||
android:id="@+id/background"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/normal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0.2"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/normal" />
|
||||
</FrameLayout>
|
||||
android:layout_alignParentTop="true"
|
||||
android:alpha="0.2"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/beforePhoto"
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.hardware.Camera.ShutterCallback;
|
||||
import android.hardware.Camera.Size;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
@@ -33,6 +34,7 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
@@ -73,11 +75,7 @@ public class CameraActivity extends Activity {
|
||||
|
||||
setContentView(R.layout.activity_camera_view);
|
||||
|
||||
// Get the base64 picture for the background only if it's exist.
|
||||
Bundle currentBundle = this.getIntent().getExtras();
|
||||
if (currentBundle != null) {
|
||||
String imgBackgroundBase64 = currentBundle.getString("imgBackgroundBase64");
|
||||
}
|
||||
setBackground();
|
||||
|
||||
// The opacity bar
|
||||
SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity);
|
||||
@@ -89,7 +87,7 @@ public class CameraActivity extends Activity {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
|
||||
progress = progresValue;
|
||||
ImageView imageView = (ImageView) findViewById(R.id.normal);
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
float newOpacity = (float) (0.2+progress*0.1);
|
||||
imageView.setAlpha(newOpacity);
|
||||
}
|
||||
@@ -119,7 +117,7 @@ public class CameraActivity extends Activity {
|
||||
// Change camera orientation function of the device's default orientation.
|
||||
if (defaultOrientation == 1 || defaultOrientation == 2) {
|
||||
int orientation;
|
||||
switch(defaultDisplay.getRotation()){
|
||||
switch (defaultDisplay.getRotation()) {
|
||||
case 0 :
|
||||
orientation = (defaultOrientation == 1) ? 90 : 0;
|
||||
mCamera.setDisplayOrientation(orientation);
|
||||
@@ -260,7 +258,7 @@ public class CameraActivity extends Activity {
|
||||
* @param maxZoom int the max zoom of the device
|
||||
* @param zoom int the current zoom
|
||||
*/
|
||||
private void setZoomProgress(int maxZoom, int zoom){
|
||||
private void setZoomProgress(int maxZoom, int zoom) {
|
||||
SeekBar niveauZoom = (SeekBar) findViewById(R.id.niveauZoom);
|
||||
niveauZoom.setMax(maxZoom);
|
||||
niveauZoom.setProgress(zoom*2);
|
||||
@@ -291,13 +289,7 @@ public class CameraActivity extends Activity {
|
||||
*/
|
||||
public void showMiniature(View view) {
|
||||
// Picture for the background.
|
||||
ImageView imageView = (ImageView) findViewById(R.id.normal);
|
||||
if (!photoTaken) {
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_END);
|
||||
}
|
||||
else {
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_START);
|
||||
}
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
// Button for show miniature picture.
|
||||
final Button miniature = (Button) view;
|
||||
|
||||
@@ -313,14 +305,11 @@ public class CameraActivity extends Activity {
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
modeMiniature = false;
|
||||
ImageView imageView = (ImageView) findViewById(R.id.normal);
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
// resize miniature.
|
||||
LayoutParams paramsReagrandissement = (LayoutParams) imageView.getLayoutParams();
|
||||
imageView.setClickable(false);
|
||||
paramsReagrandissement.width = -1;
|
||||
paramsReagrandissement.height = -1;
|
||||
imageView.setLayoutParams(paramsReagrandissement);
|
||||
setBackground();
|
||||
|
||||
miniature.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
@@ -333,17 +322,16 @@ public class CameraActivity extends Activity {
|
||||
* @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){
|
||||
public void setParamsMiniature(ImageView imageView, boolean resize) {
|
||||
RelativeLayout.LayoutParams paramsMiniature = new RelativeLayout.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;
|
||||
if (!photoTaken) {
|
||||
paramsMiniature.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
|
||||
}else {
|
||||
paramsMiniature.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
|
||||
}
|
||||
imageView.setLayoutParams(paramsMiniature);
|
||||
}
|
||||
@@ -427,9 +415,8 @@ public class CameraActivity extends Activity {
|
||||
photoTaken = true;
|
||||
|
||||
// If miniature mode when photo is taken, the miniature goes to the top
|
||||
if(modeMiniature){
|
||||
ImageView imageView = (ImageView) findViewById(R.id.normal);
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_START);
|
||||
if (modeMiniature) {
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
setParamsMiniature(imageView, false);
|
||||
}
|
||||
|
||||
@@ -499,9 +486,8 @@ public class CameraActivity extends Activity {
|
||||
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);
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_END);
|
||||
if (modeMiniature) {
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
setParamsMiniature(imageView, false);
|
||||
}
|
||||
|
||||
@@ -596,4 +582,46 @@ public class CameraActivity extends Activity {
|
||||
this.setResult(3);
|
||||
this.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* To set background in the view.
|
||||
*/
|
||||
protected void setBackground() {
|
||||
// Get the base64 picture for the background only if it's exist.
|
||||
byte[] imgBackgroundBase64 = TransferBigData.getImgBackgroundBase64();
|
||||
if (imgBackgroundBase64 != null) {
|
||||
// Get picture.
|
||||
Bitmap imgBackgroundBitmap = BitmapFactory.decodeByteArray(imgBackgroundBase64, 0, imgBackgroundBase64.length);
|
||||
|
||||
// Get sizes screen.
|
||||
Display defaultDisplay = getWindowManager().getDefaultDisplay();
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
defaultDisplay.getMetrics(displayMetrics);
|
||||
int displayWidthPx = (int) displayMetrics.widthPixels;
|
||||
int displayHeightPx = (int) displayMetrics.heightPixels;
|
||||
|
||||
// Get sizes picture.
|
||||
int widthBackground = (int) (imgBackgroundBitmap.getWidth() * displayMetrics.density);
|
||||
int heightBackground = (int) (imgBackgroundBitmap.getHeight() * displayMetrics.density);
|
||||
|
||||
// Change size ImageView.
|
||||
RelativeLayout.LayoutParams paramsMiniature = new RelativeLayout.LayoutParams(widthBackground, heightBackground);
|
||||
float ratioX = (float) displayWidthPx / (float) widthBackground;
|
||||
float ratioY = (float) displayHeightPx / (float) heightBackground;
|
||||
if (ratioX < ratioY && ratioX < 1) {
|
||||
paramsMiniature.width = (int) displayWidthPx;
|
||||
paramsMiniature.height = (int) (ratioX * heightBackground);
|
||||
} else if (ratioX >= ratioY && ratioY < 1) {
|
||||
paramsMiniature.width = (int) (ratioY * widthBackground);
|
||||
paramsMiniature.height = (int) displayHeightPx;
|
||||
}
|
||||
|
||||
// set image at the view.
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
imageView.setImageBitmap(imgBackgroundBitmap);
|
||||
|
||||
paramsMiniature.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
|
||||
imageView.setLayoutParams(paramsMiniature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
/**
|
||||
* Use to transfer big data between activities.
|
||||
*/
|
||||
public class TransferBigData {
|
||||
protected static byte[] imgBackgroundBase64 = null;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user