mirror of
https://gitee.com/shuto/customCamera.git
synced 2026-05-02 00:07:24 +08:00
Mise en place d'un background dynamique passé depuis le JS.
This commit is contained in:
@@ -18,6 +18,7 @@ import java.io.IOException;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
public class CameraLauncher extends CordovaPlugin {
|
||||
|
||||
@@ -35,9 +36,23 @@ 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;
|
||||
}
|
||||
|
||||
Bundle imgBackground = new Bundle();
|
||||
imgBackground.putByteArray("imgBackgroundBase64", imgBackgroundBase64);
|
||||
intent.putExtras(imgBackground);
|
||||
|
||||
cordova.startActivityForResult((CordovaPlugin) this, intent, CameraLauncher.REQUEST_CODE);
|
||||
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/normal"
|
||||
android:id="@+id/background"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0.2"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/normal" />
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
@@ -12,11 +12,14 @@ import android.util.Log;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.Camera.PictureCallback;
|
||||
import android.hardware.Camera.ShutterCallback;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
@@ -57,11 +60,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);
|
||||
@@ -73,7 +72,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);
|
||||
}
|
||||
@@ -227,7 +226,7 @@ public class CameraActivity extends Activity {
|
||||
*/
|
||||
public void showMiniature(View view) {
|
||||
// Picture for the background.
|
||||
final ImageView imageView = (ImageView) findViewById(R.id.normal);
|
||||
final ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
// Button for show miniature picture.
|
||||
final Button miniature = (Button) view;
|
||||
|
||||
@@ -251,10 +250,7 @@ public class CameraActivity extends Activity {
|
||||
modeMiniature = false;
|
||||
|
||||
// resize miniature.
|
||||
LayoutParams paramsReagrandissement = (LayoutParams) imageView.getLayoutParams();
|
||||
paramsReagrandissement.width = -1;
|
||||
paramsReagrandissement.height = -1;
|
||||
imageView.setLayoutParams(paramsReagrandissement);
|
||||
setBackground();
|
||||
|
||||
// imageView.setAlpha(imageView.getAlpha());
|
||||
miniature.setVisibility(View.VISIBLE);
|
||||
@@ -395,4 +391,56 @@ 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.
|
||||
Bundle currentBundle = this.getIntent().getExtras();
|
||||
if (currentBundle != null) {
|
||||
// Get picture.
|
||||
byte[] imgBackgroundBase64 = currentBundle.getByteArray("imgBackgroundBase64");
|
||||
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.
|
||||
FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(widthBackground, heightBackground);
|
||||
if (heightBackground > displayHeightPx && widthBackground < displayWidthPx) {
|
||||
// Picture's height greater than device's height AND device's width greater than picture's width.
|
||||
paramsMiniature.width = (int) (displayHeightPx * widthBackground / heightBackground);
|
||||
paramsMiniature.height = (int) displayHeightPx;
|
||||
} else if (heightBackground < displayHeightPx && widthBackground > displayWidthPx) {
|
||||
// Picture's width greater than device's width AND device's height greater than picture's height.
|
||||
paramsMiniature.width = (int) displayWidthPx;
|
||||
paramsMiniature.height = (int) (displayWidthPx * heightBackground / widthBackground);
|
||||
} else if (heightBackground > displayHeightPx && widthBackground > displayWidthPx) {
|
||||
// Picture's width & Picture's height greater than device's width & device's height.
|
||||
if (heightBackground > widthBackground) {
|
||||
// Picture's height greater than Picture's width.
|
||||
paramsMiniature.width = (int) (displayHeightPx * widthBackground / heightBackground);
|
||||
paramsMiniature.height = (int) displayHeightPx;
|
||||
} else {
|
||||
// Picture's width greater than Picture's height.
|
||||
paramsMiniature.width = (int) displayWidthPx;
|
||||
paramsMiniature.height = (int) (displayWidthPx * heightBackground / widthBackground);
|
||||
}
|
||||
}
|
||||
|
||||
// set image at the view.
|
||||
ImageView imageView = (ImageView) findViewById(R.id.background);
|
||||
imageView.setImageBitmap(imgBackgroundBitmap);
|
||||
imageView.setLayoutParams(paramsMiniature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user