Skip to content

Commit 52beabd

Browse files
committed
Added rotation feature
1 parent d632a1f commit 52beabd

10 files changed

Lines changed: 72 additions & 11 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

ScanDemoExample/.DS_Store

0 Bytes
Binary file not shown.
6 KB
Binary file not shown.
6 KB
Binary file not shown.
6 KB
Binary file not shown.

ScanDemoExample/scanlibrary/src/main/java/com/scanlibrary/ResultFragment.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import android.app.FragmentManager;
66
import android.content.Intent;
77
import android.graphics.Bitmap;
8+
import android.graphics.Matrix;
89
import android.net.Uri;
910
import android.os.AsyncTask;
1011
import android.os.Bundle;
1112
import android.view.LayoutInflater;
1213
import android.view.View;
1314
import android.view.ViewGroup;
1415
import android.widget.Button;
16+
import android.widget.ImageButton;
1517
import android.widget.ImageView;
1618
import android.widget.Toast;
1719

@@ -30,8 +32,11 @@ public class ResultFragment extends Fragment {
3032
private Button MagicColorButton;
3133
private Button grayModeButton;
3234
private Button bwButton;
35+
private ImageButton rotateLeftButton;
36+
private ImageButton rotateRightButton;
3337
private Bitmap transformed;
3438
private static ProgressDialogFragment progressDialogFragment;
39+
float currentRotation = 0;
3540

3641
public ResultFragment() {
3742
}
@@ -43,6 +48,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
4348
return view;
4449
}
4550

51+
public Bitmap RotateBitmap(Bitmap source, float angle)
52+
{
53+
Matrix matrix = new Matrix();
54+
matrix.postRotate(angle);
55+
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
56+
}
57+
4658
private void init() {
4759
scannedImageView = (ImageView) view.findViewById(R.id.scannedImage);
4860
originalButton = (Button) view.findViewById(R.id.original);
@@ -56,7 +68,27 @@ private void init() {
5668
Bitmap bitmap = getBitmap();
5769
setScannedImage(bitmap);
5870
doneButton = (Button) view.findViewById(R.id.doneButton);
71+
rotateLeftButton = (ImageButton) view.findViewById(R.id.btnRLeft);
72+
rotateRightButton = (ImageButton) view.findViewById(R.id.btnRRight);
5973
doneButton.setOnClickListener(new DoneButtonClickListener());
74+
rotateLeftButton.setOnClickListener(new View.OnClickListener() {
75+
@Override
76+
public void onClick(View v) {
77+
if(currentRotation == 360){
78+
currentRotation = -90;
79+
}
80+
setScannedImage(RotateBitmap(original,currentRotation+=90));
81+
}
82+
});
83+
rotateRightButton.setOnClickListener(new View.OnClickListener() {
84+
@Override
85+
public void onClick(View v) {
86+
if(currentRotation == 360){
87+
currentRotation = -90;
88+
}
89+
setScannedImage(RotateBitmap(original,currentRotation-=90));
90+
}
91+
});
6092
}
6193

6294
private Bitmap getBitmap() {
6 KB
Binary file not shown.
7.77 KB
Loading
7.77 KB
Loading

ScanDemoExample/scanlibrary/src/main/res/layout/result_layout.xml

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
android:background="@android:color/transparent"
3030
android:drawableTop="@drawable/ic_enhamce_image"
3131
android:singleLine="true"
32-
android:text="Magic color"
32+
android:text="Color"
3333
android:textColor="@android:color/white" />
3434

3535
<Button
@@ -40,7 +40,7 @@
4040
android:background="@android:color/transparent"
4141
android:drawableTop="@drawable/ic_gray"
4242
android:singleLine="true"
43-
android:text="Gray Mode"
43+
android:text="Gray"
4444
android:textColor="@android:color/white" />
4545

4646
<Button
@@ -51,19 +51,48 @@
5151
android:background="@android:color/transparent"
5252
android:drawableTop="@drawable/ic_black_and_white"
5353
android:singleLine="true"
54-
android:text="B and W"
54+
android:text="B/W"
5555
android:textColor="@android:color/white" />
5656
</LinearLayout>
5757

58-
<Button
59-
android:id="@+id/doneButton"
60-
android:layout_width="fill_parent"
61-
android:layout_height="wrap_content"
62-
android:layout_alignParentBottom="true"
63-
android:background="@color/bottom_background_color"
58+
<LinearLayout
6459
android:orientation="horizontal"
65-
android:padding="@dimen/bottom_bar_padding"
66-
android:text="@string/done" />
60+
android:layout_alignParentBottom="true"
61+
android:layout_width="match_parent"
62+
android:layout_height="wrap_content">
63+
64+
<ImageButton
65+
android:scaleType="centerInside"
66+
android:id="@+id/btnRLeft"
67+
android:src="@drawable/rotating_left"
68+
android:layout_width="70dp"
69+
android:background="@color/bottom_background_color"
70+
android:padding="@dimen/bottom_bar_padding"
71+
android:layout_marginRight="10dp"
72+
android:layout_height="match_parent" />
73+
74+
<Button
75+
android:id="@+id/doneButton"
76+
android:layout_width="0dp"
77+
android:layout_weight="1"
78+
android:layout_height="wrap_content"
79+
android:background="@color/bottom_background_color"
80+
android:orientation="horizontal"
81+
android:padding="@dimen/bottom_bar_padding"
82+
android:text="@string/done" />
83+
84+
<ImageButton
85+
android:scaleType="centerInside"
86+
android:id="@+id/btnRRight"
87+
android:src="@drawable/rotating_right"
88+
android:layout_width="70dp"
89+
android:background="@color/bottom_background_color"
90+
android:padding="@dimen/bottom_bar_padding"
91+
android:layout_marginLeft="10dp"
92+
android:layout_height="match_parent" />
93+
94+
</LinearLayout>
95+
6796

6897

6998
<FrameLayout

0 commit comments

Comments
 (0)