diff --git a/.gitignore b/.gitignore index 148ffae5..f02eb964 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.iml ScanDemoExample/local.properties ScanDemoExample/build/intermediates/dex-cache/cache.xml + +ScanDemoExample/build/intermediates/dex-cache/cache.xml diff --git a/ScanDemoExample/app/src/main/java/com/scanner/demo/MainActivity.java b/ScanDemoExample/app/src/main/java/com/scanner/demo/MainActivity.java index a45db24c..98e627af 100644 --- a/ScanDemoExample/app/src/main/java/com/scanner/demo/MainActivity.java +++ b/ScanDemoExample/app/src/main/java/com/scanner/demo/MainActivity.java @@ -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); + } } + } diff --git a/ScanDemoExample/app/src/main/res/layout/activity_main.xml b/ScanDemoExample/app/src/main/res/layout/activity_main.xml index 3710726c..7806993b 100644 --- a/ScanDemoExample/app/src/main/res/layout/activity_main.xml +++ b/ScanDemoExample/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,5 @@ - + android:layout_above="@+id/linearLayout" + android:layout_centerHorizontal="true"/> + android:layout_height="wrap_content" + android:layout_alignParentBottom="true"> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/black" + android:orientation="vertical"> @@ -34,7 +23,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:adjustViewBounds="true" /> + android:adjustViewBounds="true"/> + android:visibility="gone"/> diff --git a/ScanDemoExample/scanlibrary/src/main/res/layout/pick_image_fragment.xml b/ScanDemoExample/scanlibrary/src/main/res/layout/pick_image_fragment.xml deleted file mode 100644 index edb0e907..00000000 --- a/ScanDemoExample/scanlibrary/src/main/res/layout/pick_image_fragment.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/ScanDemoExample/scanlibrary/src/main/res/layout/result_layout.xml b/ScanDemoExample/scanlibrary/src/main/res/layout/result_layout.xml deleted file mode 100644 index 569f0d44..00000000 --- a/ScanDemoExample/scanlibrary/src/main/res/layout/result_layout.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ScanDemoExample/scanlibrary/src/main/res/layout/scan_layout.xml b/ScanDemoExample/scanlibrary/src/main/res/layout/scan_layout.xml deleted file mode 100644 index dce546f5..00000000 --- a/ScanDemoExample/scanlibrary/src/main/res/layout/scan_layout.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - \ 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 new file mode 100644 index 00000000..1ea9943a --- /dev/null +++ b/ScanDemoExample/scanlibrary/src/main/res/menu/scan_menu.xml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/ScanDemoExample/scanlibrary/src/main/res/values-lt/strings.xml b/ScanDemoExample/scanlibrary/src/main/res/values-lt/strings.xml new file mode 100644 index 00000000..cc564237 --- /dev/null +++ b/ScanDemoExample/scanlibrary/src/main/res/values-lt/strings.xml @@ -0,0 +1,7 @@ + + + Baigti + Transformuoti + Negalima iškirpti dokumento, pakeiskite taškus + Transformuojama... + \ No newline at end of file diff --git a/ScanDemoExample/scanlibrary/src/main/res/values-ru/strings.xml b/ScanDemoExample/scanlibrary/src/main/res/values-ru/strings.xml new file mode 100644 index 00000000..a61f59cd --- /dev/null +++ b/ScanDemoExample/scanlibrary/src/main/res/values-ru/strings.xml @@ -0,0 +1,7 @@ + + + Завершить + Обрезать + Не можем обрезать изображение, меняйте пункты + Трансформируется... + \ No newline at end of file diff --git a/ScanDemoExample/scanlibrary/src/main/res/values/strings.xml b/ScanDemoExample/scanlibrary/src/main/res/values/strings.xml index 9e11f732..ded5ef8c 100644 --- a/ScanDemoExample/scanlibrary/src/main/res/values/strings.xml +++ b/ScanDemoExample/scanlibrary/src/main/res/values/strings.xml @@ -1,12 +1,9 @@ - ScanLibrary - Hello world! - Settings - Scanning - Done - Scan - Cant crop the image, change the points - Ok + ScanLibrary + Finish + Crop + Can\'t crop the image, change the points + Transforming...