From 57e88ab477b8743cc08aee786e9efcdabeb72deb Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Tue, 16 Dec 2014 16:08:44 +0100 Subject: [PATCH 1/4] Refacto du code -> mise en variable d'instance --- .../res/layout/activity_camera_view.xml | 2 +- .../geneanet/customcamera/CameraActivity.java | 61 +++++++++++++------ 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/android/customCamera/res/layout/activity_camera_view.xml b/src/android/customCamera/res/layout/activity_camera_view.xml index 542df23..5da06d8 100644 --- a/src/android/customCamera/res/layout/activity_camera_view.xml +++ b/src/android/customCamera/res/layout/activity_camera_view.xml @@ -93,7 +93,7 @@ diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 1ee7552..c8d723c 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -63,6 +63,21 @@ public class CameraActivity extends Activity { * Distance between fingers for the zoom */ private static float distanceBetweenFingers; + + /** + * The seekBar for the opacity + */ + private SeekBar switchOpacity; + + /** + * The seekBar for the zoom + */ + private SeekBar zoomLevel; + + /** + * Parameters of the camera + */ + private Camera.Parameters params; @Override protected void onCreate(Bundle savedInstanceState) { @@ -74,11 +89,11 @@ public class CameraActivity extends Activity { this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_camera_view); - + setBackground(); // The opacity bar - SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); + switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); // Event on change opacity. switchOpacity.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @@ -143,23 +158,23 @@ public class CameraActivity extends Activity { preview.addView(mPreview); // The zoom bar progress - final Camera.Parameters params = mCamera.getParameters(); - final SeekBar niveauZoom = (SeekBar) findViewById(R.id.niveauZoom); + params = mCamera.getParameters(); + zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); int maxZoom = params.getMaxZoom(); final int zoom = params.getZoom(); - niveauZoom.setMax(maxZoom); - niveauZoom.setProgress(zoom); - niveauZoom.setVisibility(View.VISIBLE); + zoomLevel.setMax(maxZoom); + zoomLevel.setProgress(zoom); + zoomLevel.setVisibility(View.VISIBLE); // Event on change zoom with the bar. - niveauZoom.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { + zoomLevel.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); + zoomLevel.setProgress(newZoom); params.setZoom(newZoom); mCamera.setParameters(params); } @@ -186,7 +201,7 @@ public class CameraActivity extends Activity { @Override public boolean onTouchEvent(MotionEvent event) { if (!photoTaken) { - Camera.Parameters params = mCamera.getParameters(); + params = mCamera.getParameters(); int action = event.getAction(); if (event.getPointerCount() > 1) { @@ -259,10 +274,10 @@ public class CameraActivity extends Activity { * @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); + zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); + zoomLevel.setMax(maxZoom); + zoomLevel.setProgress(zoom*2); + zoomLevel.setVisibility(View.VISIBLE); } /** @@ -403,8 +418,8 @@ public class CameraActivity extends Activity { photo.setVisibility(View.INVISIBLE); // Hide the zoom progressBar - final SeekBar niveauZoom = (SeekBar) findViewById(R.id.niveauZoom); - niveauZoom.setVisibility(View.INVISIBLE); + zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); + zoomLevel.setVisibility(View.INVISIBLE); // Put button miniature at the top of the page final Button miniature = (Button)findViewById(R.id.miniature); @@ -493,7 +508,7 @@ public class CameraActivity extends Activity { keepPhoto.setVisibility(View.INVISIBLE); photo.setVisibility(View.VISIBLE); - niveauZoom.setVisibility(View.VISIBLE); + zoomLevel.setVisibility(View.VISIBLE); mCamera.startPreview(); } }); @@ -624,4 +639,16 @@ public class CameraActivity extends Activity { imageView.setLayoutParams(paramsMiniature); } } + + @Override + protected void onSaveInstanceState(Bundle outState) { + // TODO Auto-generated method stub + super.onSaveInstanceState(outState); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + // TODO Auto-generated method stub + super.onRestoreInstanceState(savedInstanceState); + } } From 6a8795d1951fdd655f9bc96715380d36b8c8dfa4 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Wed, 17 Dec 2014 15:55:53 +0100 Subject: [PATCH 2/4] Maintien de la photo quand on tourne l'appareil --- .../res/layout/activity_camera_view.xml | 5 + .../geneanet/customcamera/CameraActivity.java | 167 +++++++++++++----- 2 files changed, 131 insertions(+), 41 deletions(-) diff --git a/src/android/customCamera/res/layout/activity_camera_view.xml b/src/android/customCamera/res/layout/activity_camera_view.xml index 5da06d8..045b79f 100644 --- a/src/android/customCamera/res/layout/activity_camera_view.xml +++ b/src/android/customCamera/res/layout/activity_camera_view.xml @@ -11,6 +11,11 @@ android:layout_alignParentTop="true" > + + 4f) + opt.inSampleSize = 4; + else if (res > 3f) + opt.inSampleSize = 2; + + // Preview from camera + storedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length,opt); // Event started after accept picture. accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - try { - BitmapFactory.Options opt; - opt = new BitmapFactory.Options(); - // Temp storage to use for decoding - opt.inTempStorage = new byte[16 * 1024]; - Parameters parameters = mCamera.getParameters(); - Size size = parameters.getPictureSize(); - - int height = size.height; - int width = size.width; - float res = (width * height) / 1024000; - - // Return a smaller image for now - if (res > 4f) - opt.inSampleSize = 4; - else if (res > 3f) - opt.inSampleSize = 2; - - // Preview from camera - Bitmap storedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length,opt); - + try { // Matrix to perform rotation Matrix mat = new Matrix(); float redirect = redirectPhotoInGallery(); @@ -502,7 +523,7 @@ public class CameraActivity extends Activity { // If mode miniature and photo is declined, the miniature goes back to the bottom if (modeMiniature) { - ImageView imageView = (ImageView) findViewById(R.id.background); + imageView = (ImageView) findViewById(R.id.background); setParamsMiniature(imageView, false); } @@ -632,7 +653,7 @@ public class CameraActivity extends Activity { } // set image at the view. - ImageView imageView = (ImageView) findViewById(R.id.background); + imageView = (ImageView) findViewById(R.id.background); imageView.setImageBitmap(imgBackgroundBitmap); paramsMiniature.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); @@ -642,13 +663,77 @@ public class CameraActivity extends Activity { @Override protected void onSaveInstanceState(Bundle outState) { - // TODO Auto-generated method stub - super.onSaveInstanceState(outState); + outState.putBoolean("modeMiniature", modeMiniature); + outState.putBoolean("photoTaken", photoTaken); + outState.putParcelable("storedBitmap", storedBitmap); + super.onSaveInstanceState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { - // TODO Auto-generated method stub - super.onRestoreInstanceState(savedInstanceState); + // We get the last value of modeMiniature + modeMiniature = savedInstanceState.getBoolean("modeMiniature"); + // We get the last value of photoTaken + photoTaken = savedInstanceState.getBoolean("photoTaken"); + storedBitmap = savedInstanceState.getParcelable("storedBitmap"); + + // If the miniature is on when we rotate + if (modeMiniature) { + imageView = (ImageView) findViewById(R.id.background); + setParamsMiniature(imageView, false); + modeMiniature = false; + } + + if (photoTaken) { + // Matrix to perform rotation + Matrix mat = new Matrix(); + mat.postRotate(270); + + // Creation of the bitmap + storedBitmap = Bitmap.createBitmap(storedBitmap, 0, 0, storedBitmap.getWidth(), storedBitmap.getHeight(), mat, true); + Bitmap newBitmap = resizeAfterRotate(storedBitmap); + ImageView photoResized = (ImageView) findViewById(R.id.photoResized); + photoResized.setImageBitmap(newBitmap); + imageView = (ImageView) findViewById(R.id.background); + preview.setVisibility(View.INVISIBLE); + } + + super.onRestoreInstanceState(savedInstanceState); + } + + /** + * Resize the bitmap saved when you rotate the device. + * + * @param Bitmap bitmap The original bitmap + * + * @return the new bitmap. + */ + protected Bitmap resizeAfterRotate(Bitmap bitmap){ + // Initialize the new bitmap resized + Bitmap newBitmap = null; + + // 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) (bitmap.getWidth() * displayMetrics.density); + int heightBackground = (int) (bitmap.getHeight() * displayMetrics.density); + + // Change size ImageView. + float ratioX = (float) displayWidthPx / (float) widthBackground; + float ratioY = (float) displayHeightPx / (float) heightBackground; + if (ratioX < ratioY && ratioX < 1) { + System.out.println("OK"); + newBitmap = Bitmap.createScaledBitmap(bitmap, (int) displayWidthPx, (int) (ratioX * heightBackground), false); + } else if (ratioX >= ratioY && ratioY < 1) { + System.out.println("OK2"); + newBitmap = Bitmap.createScaledBitmap(bitmap, (int) (ratioY * widthBackground), (int) displayHeightPx, false); + } + + return newBitmap; } } From 0528bd1a8d9e42a9a2f0be161723530b3109ba7f Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Wed, 17 Dec 2014 16:29:44 +0100 Subject: [PATCH 3/4] Maintien de la photo quand on tourne l'appareil --- .../src/org/geneanet/customcamera/CameraActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index ed5924b..7d0be2d 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -727,10 +727,8 @@ public class CameraActivity extends Activity { float ratioX = (float) displayWidthPx / (float) widthBackground; float ratioY = (float) displayHeightPx / (float) heightBackground; if (ratioX < ratioY && ratioX < 1) { - System.out.println("OK"); newBitmap = Bitmap.createScaledBitmap(bitmap, (int) displayWidthPx, (int) (ratioX * heightBackground), false); } else if (ratioX >= ratioY && ratioY < 1) { - System.out.println("OK2"); newBitmap = Bitmap.createScaledBitmap(bitmap, (int) (ratioY * widthBackground), (int) displayHeightPx, false); } From c40645a2cd851170634ae6a9b1e7f4517ae9ba68 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Fri, 19 Dec 2014 15:27:55 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Gerer=20la=20rotation=20des=20images=20+=20?= =?UTF-8?q?lock=20de=20l'ecran=20disponible.=20Refactoriqation=20pr=C3=A9v?= =?UTF-8?q?ue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/layout/activity_camera_view.xml | 33 +- .../geneanet/customcamera/CameraActivity.java | 1426 +++++++++-------- 2 files changed, 778 insertions(+), 681 deletions(-) diff --git a/src/android/customCamera/res/layout/activity_camera_view.xml b/src/android/customCamera/res/layout/activity_camera_view.xml index 045b79f..dda2f5f 100644 --- a/src/android/customCamera/res/layout/activity_camera_view.xml +++ b/src/android/customCamera/res/layout/activity_camera_view.xml @@ -33,21 +33,30 @@ android:layout_alignParentTop="true" android:gravity="bottom" > -