Skip to content

Commit

Permalink
Merge branch 'FasterScanningResult' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrejLukasevic committed Jan 25, 2016
2 parents 7d17812 + fdd2076 commit 59340a3
Show file tree
Hide file tree
Showing 37 changed files with 715 additions and 850 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.iml
ScanDemoExample/local.properties
ScanDemoExample/build/intermediates/dex-cache/cache.xml

ScanDemoExample/build/intermediates/dex-cache/cache.xml
163 changes: 95 additions & 68 deletions ScanDemoExample/app/src/main/java/com/scanner/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,109 +4,136 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.scanlibrary.ScanActivity;
import com.scanlibrary.ScanConstants;

import java.io.IOException;

public class MainActivity extends ActionBarActivity implements OnClickListener {

public class MainActivity extends ActionBarActivity {
// ===========================================================
// Constants
// ===========================================================

private static final int REQUEST_CODE = 99;
private Button scanButton;
private Button cameraButton;
private Button mediaButton;
private ImageView scannedImageView;
private static final int REQUEST_CODE_SCAN = 47;

private static final String SAVED_SCANNED_HHOTO = "scanned_photo";

// ===========================================================
// Fields
// ===========================================================

private final ViewHolder viewHolder = new ViewHolder();

private String scannedPhoto;

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getters & Setters
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
viewHolder.prepare(findViewById(android.R.id.content));

private void init() {
scanButton = (Button) findViewById(R.id.scanButton);
scanButton.setOnClickListener(new ScanButtonClickListener());
cameraButton = (Button) findViewById(R.id.cameraButton);
cameraButton.setOnClickListener(new ScanButtonClickListener(ScanConstants.OPEN_CAMERA));
mediaButton = (Button) findViewById(R.id.mediaButton);
mediaButton.setOnClickListener(new ScanButtonClickListener(ScanConstants.OPEN_MEDIA));
scannedImageView = (ImageView) findViewById(R.id.scannedImage);
}

private class ScanButtonClickListener implements View.OnClickListener {

private int preference;

public ScanButtonClickListener(int preference) {
this.preference = preference;
if (savedInstanceState != null) {
scannedPhoto = savedInstanceState.getString(SAVED_SCANNED_HHOTO);
}

public ScanButtonClickListener() {
if (scannedPhoto != null) {
viewHolder.image.setImageBitmap(getBitmapFromLocation(scannedPhoto));
}
}

@Override
public void onClick(View v) {
startScan(preference);
@Override
public void onClick(View v) {
if (v.equals(viewHolder.scabBtn)) {
onScanButtonClicked();
}
}

protected void startScan(int preference) {
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference);
startActivityForResult(intent, REQUEST_CODE);
@Override
protected void onResume() {
super.onResume();
viewHolder.scabBtn.setOnClickListener(this);
}

@Override
protected void onPause() {
super.onPause();
viewHolder.scabBtn.setOnClickListener(null);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
getContentResolver().delete(uri, null, null);
scannedImageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
if (requestCode == REQUEST_CODE_SCAN && resultCode == Activity.RESULT_OK) {
String imgPath = data.getStringExtra(ScanActivity.RESULT_IMAGE_PATH);
Bitmap bitmap = getBitmapFromLocation(imgPath);
viewHolder.image.setImageBitmap(bitmap);
// Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT);
// Bitmap bitmap = null;
// try {
// bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
// getContentResolver().delete(uri, null, null);
// viewHolder.image.setImageBitmap(bitmap);
// } catch (IOException e) {
// e.printStackTrace();
// }
}
}

private Bitmap convertByteArrayToBitmap(byte[] data) {
return BitmapFactory.decodeByteArray(data, 0, data.length);
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_SCANNED_HHOTO, scannedPhoto);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
// ===========================================================
// Methods
// ===========================================================

private void onScanButtonClicked() {
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanActivity.EXTRA_BRAND_IMG_RES, R.drawable.ic_crop_white_24dp);
intent.putExtra(ScanActivity.EXTRA_TITLE, "Crop Document");
intent.putExtra(ScanActivity.EXTRA_ACTION_BAR_COLOR, R.color.green);
intent.putExtra(ScanActivity.EXTRA_LANGUAGE, "ru");
startActivityForResult(intent, REQUEST_CODE_SCAN);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
private Bitmap getBitmapFromLocation(String absLocation) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
return BitmapFactory.decodeFile(absLocation, options);
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================

private static class ViewHolder {

return super.onOptionsItemSelected(item);
ImageView image;
View scabBtn;

void prepare(View parent) {
image = (ImageView) parent.findViewById(R.id.image);
scabBtn = parent.findViewById(R.id.scan);
}
}

}
35 changes: 10 additions & 25 deletions ScanDemoExample/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -9,42 +10,26 @@
tools:context=".MainActivity">

<ImageView
android:id="@+id/scannedImage"
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
android:layout_above="@+id/linearLayout"
android:layout_centerHorizontal="true"/>

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">

<Button
android:id="@+id/cameraButton"
android:id="@+id/scan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Camera" />


<Button
android:id="@+id/mediaButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Media" />

<Button
android:id="@+id/scanButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Scan" />
android:text="Scan"/>

</LinearLayout>


</RelativeLayout>
4 changes: 4 additions & 0 deletions ScanDemoExample/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="green">#006600</color>
</resources>
18 changes: 9 additions & 9 deletions ScanDemoExample/build/intermediates/dex-cache/cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<items version="2" >

<item
jar="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\exploded-aar\ScanDemoExample\scanlibrary\unspecified\jars\classes.jar"
jar="D:\AndroidSDK\extras\android\m2repository\com\android\support\support-annotations\21.0.3\support-annotations-21.0.3.jar"
jumboMode="false"
revision="23.0.2"
sha1="a322f4999d38a84285d59ce17f89189998f7a0e5">
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\classes-64d90915416580e77d24bb965361fe9e8c7cb330.jar" />
sha1="4b74cefe1f0c1b819e7260c8627a14674e37fd35">
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\support-annotations-21.0.3-34a57f82165fcc191123ae4d70b3d0379c72c265.jar" />
</item>
<item
jar="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\jars\classes.jar"
Expand All @@ -16,18 +16,18 @@
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\classes-17c37e4d74c16a2b8d488cc0c2d716655daf0c83.jar" />
</item>
<item
jar="D:\AndroidSDK\extras\android\m2repository\com\android\support\support-annotations\21.0.3\support-annotations-21.0.3.jar"
jar="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\jars\classes.jar"
jumboMode="false"
revision="23.0.2"
sha1="4b74cefe1f0c1b819e7260c8627a14674e37fd35">
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\support-annotations-21.0.3-34a57f82165fcc191123ae4d70b3d0379c72c265.jar" />
sha1="2c91c949a45a21cdecf26e03951e46c7beec9ad8">
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\classes-66995c60b970d702830aa0605612c69aa1b9a355.jar" />
</item>
<item
jar="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\jars\classes.jar"
jar="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\exploded-aar\ScanDemoExample\scanlibrary\unspecified\jars\classes.jar"
jumboMode="false"
revision="23.0.2"
sha1="2c91c949a45a21cdecf26e03951e46c7beec9ad8">
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\classes-66995c60b970d702830aa0605612c69aa1b9a355.jar" />
sha1="74310a3d25228a74911f4d4376df2dfd8449a3ca">
<dex dex="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\pre-dexed\debug\classes-64d90915416580e77d24bb965361fe9e8c7cb330.jar" />
</item>
<item
jar="D:\Android Workspace\AndroidDocumentScanner\ScanDemoExample\app\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\jars\libs\internal_impl-21.0.3.jar"
Expand Down
20 changes: 11 additions & 9 deletions ScanDemoExample/scanlibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scanlibrary" >
<manifest package="com.scanlibrary"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-feature
android:name="android.hardware.camera"
android:required="true" />
android:required="true"/>

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application android:allowBackup="true">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true">
<activity
android:name=".ScanActivity"
android:label="@string/document_scann_lib_name" >
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
</activity>
</application>

Expand Down

This file was deleted.

Loading

0 comments on commit 59340a3

Please sign in to comment.