diff --git a/ScanDemoExample/build/intermediates/dex-cache/cache.xml b/ScanDemoExample/build/intermediates/dex-cache/cache.xml
index 29211b53..f19df12c 100644
--- a/ScanDemoExample/build/intermediates/dex-cache/cache.xml
+++ b/ScanDemoExample/build/intermediates/dex-cache/cache.xml
@@ -2,31 +2,31 @@
-
-
+ sha1="2c91c949a45a21cdecf26e03951e46c7beec9ad8">
+
-
-
+ sha1="705ffc2c856ea563f08d87cc59e797eb37c69e3f">
+
-
-
+ sha1="81d42bf983a8741f4888a6e333e454e4a5e0eeb7">
+
-
+ sha1="1ca346c89899db689554b90d197c36ee298bd2e3">
-
+ -
+
+
diff --git a/ScanDemoExample/scanlibrary/build.gradle b/ScanDemoExample/scanlibrary/build.gradle
index 9d5ac633..e0937103 100644
--- a/ScanDemoExample/scanlibrary/build.gradle
+++ b/ScanDemoExample/scanlibrary/build.gradle
@@ -29,4 +29,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
+ //Library for Image View That have Ability to zoom...
+ compile 'com.davemorrissey.labs:subsampling-scale-image-view:2.3.0'
}
diff --git a/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/ScanFragment.java b/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/ScanFragment.java
index e34f8b99..b14dcc2c 100644
--- a/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/ScanFragment.java
+++ b/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/ScanFragment.java
@@ -26,6 +26,8 @@
import android.widget.ImageView;
import android.widget.Toast;
+import com.davemorrissey.labs.subscaleview.ScaleImageView;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -60,10 +62,8 @@ public class ScanFragment extends Fragment {
private Map points;
private boolean isCropMode = false;
- private boolean isPointsDownScaled = false;
private int previousOreantation = -1;
- private boolean isOreantationChanged = false;
// ===========================================================
// Constructors
@@ -98,12 +98,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
int currentOreantation = Utils.getScreenOrientation(getActivity());
if (previousOreantation == -1) {
previousOreantation = currentOreantation;
- isOreantationChanged = false;
- } else if (previousOreantation == currentOreantation) {
- isOreantationChanged = false;
- } else {
- previousOreantation = currentOreantation;
- isOreantationChanged = true;
+ } else if (previousOreantation != currentOreantation) {
+ points = null;
}
if (takenPhotoLocation == null) {
@@ -111,6 +107,9 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
} else {
if (documentBitmap != null) {
viewHolder.sourceImageView.setImageBitmap(documentBitmap);
+ viewHolder.sourceImageView.setVisibility(View.INVISIBLE);
+ viewHolder.scaleImageView.setImageBitmap(documentBitmap);
+ viewHolder.scaleImageView.setVisibility(View.VISIBLE);
}
}
@@ -128,9 +127,8 @@ public void run() {
layoutParams.gravity = Gravity.CENTER;
viewHolder.polygonView.setLayoutParams(layoutParams);
- if (isOreantationChanged) {
+ if (points == null) {
points = getOutlinePoints(tempBitmap);
- isPointsDownScaled = true;
}
viewHolder.polygonView.setPoints(points);
}
@@ -158,13 +156,17 @@ public void onSaveInstanceState(Bundle outState) {
}
private MenuItem cropBtn;
+ private MenuItem rotateBtn;
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.scan_menu, menu);
cropBtn = menu.findItem(R.id.crop);
+ rotateBtn = menu.findItem(R.id.rotate);
+
cropBtn.setVisible(!isCropMode);
+ rotateBtn.setVisible(!isCropMode);
super.onCreateOptionsMenu(menu, inflater);
}
@@ -178,6 +180,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
} else if (item.getItemId() == R.id.done) {
onDoneButtonClicked();
return true;
+ } else if (item.getItemId() == R.id.rotate) {
+ onRotateButtonClicked();
+ return true;
}
return super.onOptionsItemSelected(item);
}
@@ -203,28 +208,50 @@ private void releaseAllBitmaps() {
private void onCropButtonClicked() {
cropBtn.setVisible(false);
+ rotateBtn.setVisible(false);
isCropMode = true;
Bitmap scaledBitmap = scaleBitmap(takenPhotoBitmap, viewHolder.sourceFrame.getWidth(), viewHolder.sourceFrame.getHeight());
viewHolder.sourceImageView.setImageBitmap(scaledBitmap);
-
- if (!isPointsDownScaled) downScalePoints(points, takenPhotoBitmap, scaledBitmap.getWidth(), scaledBitmap.getHeight());
- isPointsDownScaled = true;
- viewHolder.polygonView.setPoints(points);
+ viewHolder.sourceImageView.setVisibility(View.VISIBLE);
+ viewHolder.scaleImageView.setVisibility(View.GONE);
Bitmap tempBitmap = ((BitmapDrawable) viewHolder.sourceImageView.getDrawable()).getBitmap();
viewHolder.polygonView.setVisibility(View.VISIBLE);
+
+ points = getEdgePoints(tempBitmap);
+
+ viewHolder.polygonView.setPoints(points);
int padding = (int) getResources().getDimension(R.dimen.scanPadding);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(tempBitmap.getWidth() + 2 * padding, tempBitmap.getHeight() + 2 * padding);
layoutParams.gravity = Gravity.CENTER;
viewHolder.polygonView.setLayoutParams(layoutParams);
}
+ private void onRotateButtonClicked() {
+ Bitmap takenPhotoBitmapTmp = Utils.rotateBitmap(takenPhotoBitmap, -90);
+ takenPhotoBitmap.recycle();
+ takenPhotoBitmap = takenPhotoBitmapTmp;
+
+ Bitmap documentBitmapTmp = Utils.rotateBitmap(documentBitmap, -90);
+ documentBitmap.recycle();
+ documentBitmap = documentBitmapTmp;
+
+ Bitmap scaledBitmap = scaleBitmap(documentBitmap, viewHolder.sourceFrame.getWidth(), viewHolder.sourceFrame.getHeight());
+ viewHolder.sourceImageView.setImageBitmap(scaledBitmap);
+ viewHolder.sourceImageView.setVisibility(View.INVISIBLE);
+ viewHolder.scaleImageView.setImageBitmap(scaledBitmap);
+ viewHolder.scaleImageView.setVisibility(View.VISIBLE);
+// Bitmap tempBitmap = ((BitmapDrawable) viewHolder.sourceImageView.getDrawable()).getBitmap();
+ points = getOutlinePoints(viewHolder.sourceFrame);
+ }
+
private void onDoneButtonClicked() {
if (isCropMode) {
isCropMode = false;
cropBtn.setVisible(true);
+ rotateBtn.setVisible(true);
Map points = viewHolder.polygonView.getPoints();
if (isScanPointsValid(points)) {
@@ -392,6 +419,15 @@ private static Map getOutlinePoints(Bitmap tempBitmap) {
return outlinePoints;
}
+ private static Map getOutlinePoints(View view) {
+ Map outlinePoints = new HashMap<>();
+ outlinePoints.put(0, new PointF(0, 0));
+ outlinePoints.put(1, new PointF(view.getWidth(), 0));
+ outlinePoints.put(2, new PointF(0, view.getHeight()));
+ outlinePoints.put(3, new PointF(view.getWidth(), view.getHeight()));
+ return outlinePoints;
+ }
+
private static Map orderedValidEdgePoints(Bitmap tempBitmap, List pointFs) {
Map orderedPoints = PolygonView.getOrderedPoints(pointFs);
if (!PolygonView.isValidShape(orderedPoints)) {
@@ -431,9 +467,12 @@ protected void dismissDialog() {
private void onDocumentFromBitmapTaskFinished(DocumentFromBitmapTaskResult result) {
documentBitmap = result.bitmap;
points = result.points;
- isPointsDownScaled = false;
- viewHolder.sourceImageView.setImageBitmap(scaleBitmap(documentBitmap, viewHolder.sourceFrame.getWidth(), viewHolder.sourceFrame.getHeight()));
+ Bitmap scaledBitmap = scaleBitmap(documentBitmap, viewHolder.sourceFrame.getWidth(), viewHolder.sourceFrame.getHeight());
+ viewHolder.sourceImageView.setImageBitmap(scaledBitmap);
+ viewHolder.sourceImageView.setVisibility(View.INVISIBLE);
+ viewHolder.scaleImageView.setImageBitmap(scaledBitmap);
+ viewHolder.scaleImageView.setVisibility(View.VISIBLE);
viewHolder.polygonView.setVisibility(View.GONE);
}
@@ -463,6 +502,7 @@ protected void onPreExecute() {
@Override
protected DocumentFromBitmapTaskResult doInBackground(Void... params) {
+ System.gc();
DocumentFromBitmapTaskResult result = new DocumentFromBitmapTaskResult();
if (points != null) {
@@ -491,11 +531,13 @@ private static class DocumentFromBitmapTaskResult {
private static class ViewHolder {
private ImageView sourceImageView;
+ private ScaleImageView scaleImageView;
private FrameLayout sourceFrame;
private PolygonView polygonView;
void prepare(View parent) {
sourceImageView = (ImageView) parent.findViewById(R.id.sourceImageView);
+ scaleImageView = (ScaleImageView) parent.findViewById(R.id.scaleImage);
sourceFrame = (FrameLayout) parent.findViewById(R.id.sourceFrame);
polygonView = (PolygonView) parent.findViewById(R.id.polygonView);
}
diff --git a/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/Utils.java b/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/Utils.java
index 1faf536c..58eab8a5 100644
--- a/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/Utils.java
+++ b/ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/Utils.java
@@ -2,6 +2,8 @@
import android.app.Activity;
import android.content.pm.ActivityInfo;
+import android.graphics.Bitmap;
+import android.graphics.Matrix;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface;
@@ -77,4 +79,11 @@ public static int getScreenOrientation(Activity activity) {
return orientation;
}
+ public static Bitmap rotateBitmap(Bitmap source, float angle) {
+ System.gc();
+ Matrix matrix = new Matrix();
+ matrix.postRotate(angle);
+ return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
+ }
+
}
\ No newline at end of file
diff --git a/ScanDemoExample/scanlibrary/src/main/res/drawable-hdpi/ic_rotate_90_degrees_ccw_white_24dp.png b/ScanDemoExample/scanlibrary/src/main/res/drawable-hdpi/ic_rotate_90_degrees_ccw_white_24dp.png
new file mode 100644
index 00000000..729423ce
Binary files /dev/null and b/ScanDemoExample/scanlibrary/src/main/res/drawable-hdpi/ic_rotate_90_degrees_ccw_white_24dp.png differ
diff --git a/ScanDemoExample/scanlibrary/src/main/res/drawable-mdpi/ic_rotate_90_degrees_ccw_white_24dp.png b/ScanDemoExample/scanlibrary/src/main/res/drawable-mdpi/ic_rotate_90_degrees_ccw_white_24dp.png
new file mode 100644
index 00000000..78ba6a2d
Binary files /dev/null and b/ScanDemoExample/scanlibrary/src/main/res/drawable-mdpi/ic_rotate_90_degrees_ccw_white_24dp.png differ
diff --git a/ScanDemoExample/scanlibrary/src/main/res/drawable-xhdpi/ic_rotate_90_degrees_ccw_white_24dp.png b/ScanDemoExample/scanlibrary/src/main/res/drawable-xhdpi/ic_rotate_90_degrees_ccw_white_24dp.png
new file mode 100644
index 00000000..1f03dc60
Binary files /dev/null and b/ScanDemoExample/scanlibrary/src/main/res/drawable-xhdpi/ic_rotate_90_degrees_ccw_white_24dp.png differ
diff --git a/ScanDemoExample/scanlibrary/src/main/res/drawable-xxhdpi/ic_rotate_90_degrees_ccw_white_24dp.png b/ScanDemoExample/scanlibrary/src/main/res/drawable-xxhdpi/ic_rotate_90_degrees_ccw_white_24dp.png
new file mode 100644
index 00000000..ef39c171
Binary files /dev/null and b/ScanDemoExample/scanlibrary/src/main/res/drawable-xxhdpi/ic_rotate_90_degrees_ccw_white_24dp.png differ
diff --git a/ScanDemoExample/scanlibrary/src/main/res/drawable-xxxhdpi/ic_rotate_90_degrees_ccw_white_24dp.png b/ScanDemoExample/scanlibrary/src/main/res/drawable-xxxhdpi/ic_rotate_90_degrees_ccw_white_24dp.png
new file mode 100644
index 00000000..adfd6457
Binary files /dev/null and b/ScanDemoExample/scanlibrary/src/main/res/drawable-xxxhdpi/ic_rotate_90_degrees_ccw_white_24dp.png differ
diff --git a/ScanDemoExample/scanlibrary/src/main/res/layout/fragment_scan.xml b/ScanDemoExample/scanlibrary/src/main/res/layout/fragment_scan.xml
index 5eedbeac..75dab687 100644
--- a/ScanDemoExample/scanlibrary/src/main/res/layout/fragment_scan.xml
+++ b/ScanDemoExample/scanlibrary/src/main/res/layout/fragment_scan.xml
@@ -1,9 +1,9 @@
-
+
+
+
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/ScanDemoExample/scanlibrary/src/main/res/menu/scan_menu.xml b/ScanDemoExample/scanlibrary/src/main/res/menu/scan_menu.xml
index 1ea9943a..75cb5c91 100644
--- a/ScanDemoExample/scanlibrary/src/main/res/menu/scan_menu.xml
+++ b/ScanDemoExample/scanlibrary/src/main/res/menu/scan_menu.xml
@@ -1,6 +1,12 @@