From 2b57ae2ece54d3c65aad81d37528a32034cd0c97 Mon Sep 17 00:00:00 2001 From: thrillfall Date: Mon, 4 May 2020 00:05:44 +0200 Subject: [PATCH 1/2] add option to set topic to scan filename --- .../OpenNoteScannerActivity.java | 52 ++++++++++++---- .../helpers/ScanTopicDialogFragment.java | 59 +++++++++++++++++++ app/src/main/res/layout/dialog_scan_topic.xml | 18 ++++++ app/src/main/res/values/strings.xml | 5 ++ app/src/main/res/xml/settings.xml | 6 ++ 5 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/todobom/opennotescanner/helpers/ScanTopicDialogFragment.java create mode 100644 app/src/main/res/layout/dialog_scan_topic.xml diff --git a/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java b/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java index 37135ec9..626add6a 100644 --- a/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java +++ b/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java @@ -53,6 +53,7 @@ import com.todobom.opennotescanner.helpers.CustomOpenCVLoader; import com.todobom.opennotescanner.helpers.OpenNoteMessage; import com.todobom.opennotescanner.helpers.PreviewFrame; +import com.todobom.opennotescanner.helpers.ScanTopicDialogFragment; import com.todobom.opennotescanner.helpers.ScannedDocument; import com.todobom.opennotescanner.views.HUDCanvasView; @@ -85,8 +86,8 @@ * status bar and navigation/system bar) with user interaction. */ public class OpenNoteScannerActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener , SurfaceHolder.Callback, - Camera.PictureCallback, Camera.PreviewCallback { + implements NavigationView.OnNavigationItemSelectedListener, SurfaceHolder.Callback, + Camera.PictureCallback, Camera.PreviewCallback, ScanTopicDialogFragment.SetTopicDialogListener { /** * Some older devices needs a small delay between UI widget updates @@ -159,6 +160,8 @@ public void run() { private boolean mBugRotate=false; private SharedPreferences mSharedPref; private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); + private String scanTopic = null; + private Mat mat; public HUDCanvasView getHUD() { return mHud; @@ -690,7 +693,7 @@ public void surfaceCreated(SurfaceHolder holder) { if ( displayRatio > previewRatio ) { ViewGroup.LayoutParams surfaceParams = mSurfaceView.getLayoutParams(); - previewHeight = (int) ( (float) size.y/displayRatio*previewRatio); + previewHeight = (int) ((float) size.y / displayRatio * previewRatio); surfaceParams.height = previewHeight; mSurfaceView.setLayoutParams(surfaceParams); @@ -881,16 +884,32 @@ public void onPictureTaken(byte[] data, Camera camera) { Log.d(TAG, "onPictureTaken - received image " + pictureSize.width + "x" + pictureSize.height); - Mat mat = new Mat(new Size(pictureSize.width, pictureSize.height), CvType.CV_8U); + mat = new Mat(new Size(pictureSize.width, pictureSize.height), CvType.CV_8U); mat.put(0, 0, data); setImageProcessorBusy(true); - sendImageProcessorMessage("pictureTaken", mat); - camera.cancelAutoFocus(); + if (mSharedPref.getBoolean("custom_scan_topic", false)) { + FragmentManager fm = getSupportFragmentManager(); + final ScanTopicDialogFragment scanTopicDialogFragment = new ScanTopicDialogFragment(); + scanTopicDialogFragment.show(fm, getString(R.string.scan_topic_dialog_title)); + + return; + } + + issueProcessingOfTakenPicture(); + } + + @Override + public void onFinishTopicDialog(String userInputScanTopic) { + scanTopic = userInputScanTopic; + issueProcessingOfTakenPicture(); + } + + private void issueProcessingOfTakenPicture() { + sendImageProcessorMessage("pictureTaken", mat); scanClicked = false; safeToTakePicture = true; - } public void sendImageProcessorMessage(String messageText , Object obj ) { @@ -932,10 +951,8 @@ public void saveDocument(ScannedDocument scannedDocument) { folder.mkdirs(); Log.d(TAG, "wrote: created folder "+folder.getPath()); } - fileName = Environment.getExternalStorageDirectory().toString() - + "/" + folderName + "/DOC-" - + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) - + imgSuffix; + + fileName = createFileName(imgSuffix, folderName); } Mat endDoc = new Mat(Double.valueOf(doc.size().width).intValue(), Double.valueOf(doc.size().height).intValue(), CvType.CV_8UC4); @@ -1004,6 +1021,19 @@ public void saveDocument(ScannedDocument scannedDocument) { } + private String createFileName(String imgSuffix, String folderName) { + String fileName; + fileName = Environment.getExternalStorageDirectory().toString() + + "/" + folderName + "/"; + if (scanTopic != null) { + fileName += scanTopic + "-"; + } + fileName += "DOC-" + + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + + imgSuffix; + return fileName; + } + class AnimationRunnable implements Runnable { private Size imageSize; diff --git a/app/src/main/java/com/todobom/opennotescanner/helpers/ScanTopicDialogFragment.java b/app/src/main/java/com/todobom/opennotescanner/helpers/ScanTopicDialogFragment.java new file mode 100644 index 00000000..a18a98fe --- /dev/null +++ b/app/src/main/java/com/todobom/opennotescanner/helpers/ScanTopicDialogFragment.java @@ -0,0 +1,59 @@ +package com.todobom.opennotescanner.helpers; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; + +import com.todobom.opennotescanner.R; + +public class ScanTopicDialogFragment extends DialogFragment { + + private EditText scanTopic; + + public ScanTopicDialogFragment() { + } + + public interface SetTopicDialogListener { + void onFinishTopicDialog(String inputText); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); + alertDialogBuilder.setTitle(R.string.set_scan_topic); + + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_scan_topic, null); + alertDialogBuilder.setView(view); + scanTopic = view.findViewById(R.id.editTextScanTopic); + alertDialogBuilder.setPositiveButton(R.string.set_scan_topic, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + SetTopicDialogListener listener = (SetTopicDialogListener) getActivity(); + listener.onFinishTopicDialog(scanTopic.getText().toString()); + dismiss(); + + } + + }); + + alertDialogBuilder.setNegativeButton(R.string.skip_scan_topic, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (dialog != null ) { + SetTopicDialogListener listener = (SetTopicDialogListener) getActivity(); + listener.onFinishTopicDialog(null); + dialog.dismiss(); + } + } + }); + + return alertDialogBuilder.create(); + } +} diff --git a/app/src/main/res/layout/dialog_scan_topic.xml b/app/src/main/res/layout/dialog_scan_topic.xml new file mode 100644 index 00000000..43e92612 --- /dev/null +++ b/app/src/main/res/layout/dialog_scan_topic.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e051644..84478518 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,4 +67,9 @@ Save final images to PNG format. Notice that metadata isn\'t supported yet on PNG, so some features will not be available. Format not supported Image format doesn\'t support tagging + Set scan topic + Cancel + Custom scan topic + Please provide a topic + Skip Topic diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index bcb4ce54..72e7e8a9 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -68,6 +68,12 @@ android:key="storage_folder" android:summary="@string/storage_folder_summary" /> + Date: Mon, 4 May 2020 00:07:12 +0200 Subject: [PATCH 2/2] run android studio reformat --- .../OpenNoteScannerActivity.java | 181 +++++++++--------- 1 file changed, 86 insertions(+), 95 deletions(-) diff --git a/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java b/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java index 626add6a..237996da 100644 --- a/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java +++ b/app/src/main/java/com/todobom/opennotescanner/OpenNoteScannerActivity.java @@ -157,7 +157,7 @@ public void run() { private HUDCanvasView mHud; private View mWaitSpinner; private FABToolbarLayout mFabToolbar; - private boolean mBugRotate=false; + private boolean mBugRotate = false; private SharedPreferences mSharedPref; private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); private String scanTopic = null; @@ -175,7 +175,7 @@ public void setAttemptToFocus(boolean attemptToFocus) { this.attemptToFocus = attemptToFocus; } - private boolean imageProcessorBusy=true; + private boolean imageProcessorBusy = true; private boolean attemptToFocus = false; @Override @@ -186,7 +186,7 @@ protected void onCreate(Bundle savedInstanceState) { mSharedPref = PreferenceManager.getDefaultSharedPreferences(this); - if (mSharedPref.getBoolean("isFirstRun",true) && !mSharedPref.getBoolean("usage_stats",false)) { + if (mSharedPref.getBoolean("isFirstRun", true) && !mSharedPref.getBoolean("usage_stats", false)) { statsOptInDialog(); } @@ -258,11 +258,11 @@ public void run() { @Override public void onClick(View v) { colorMode = !colorMode; - ((ImageView)v).setColorFilter(colorMode ? 0xFFFFFFFF : 0xFFA0F0A0); + ((ImageView) v).setColorFilter(colorMode ? 0xFFFFFFFF : 0xFFA0F0A0); - sendImageProcessorMessage("colorMode" , colorMode ); + sendImageProcessorMessage("colorMode", colorMode); - Toast.makeText(getApplicationContext(), colorMode?R.string.colorMode:R.string.bwMode, Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), colorMode ? R.string.colorMode : R.string.bwMode, Toast.LENGTH_SHORT).show(); } }); @@ -274,11 +274,11 @@ public void onClick(View v) { @Override public void onClick(View v) { filterMode = !filterMode; - ((ImageView)v).setColorFilter(filterMode ? 0xFFFFFFFF : 0xFFA0F0A0); + ((ImageView) v).setColorFilter(filterMode ? 0xFFFFFFFF : 0xFFA0F0A0); - sendImageProcessorMessage("filterMode" , filterMode ); + sendImageProcessorMessage("filterMode", filterMode); - Toast.makeText(getApplicationContext(), filterMode?R.string.filterModeOn:R.string.filterModeOff, Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), filterMode ? R.string.filterModeOn : R.string.filterModeOff, Toast.LENGTH_SHORT).show(); } }); @@ -290,7 +290,7 @@ public void onClick(View v) { @Override public void onClick(View v) { mFlashMode = setFlash(!mFlashMode); - ((ImageView)v).setColorFilter(mFlashMode ? 0xFFFFFFFF : 0xFFA0F0A0); + ((ImageView) v).setColorFilter(mFlashMode ? 0xFFFFFFFF : 0xFFA0F0A0); } }); @@ -303,8 +303,8 @@ public void onClick(View v) { @Override public void onClick(View v) { autoMode = !autoMode; - ((ImageView)v).setColorFilter(autoMode ? 0xFFFFFFFF : 0xFFA0F0A0); - Toast.makeText(getApplicationContext(), autoMode?R.string.autoMode:R.string.manualMode, Toast.LENGTH_SHORT).show(); + ((ImageView) v).setColorFilter(autoMode ? 0xFFFFFFFF : 0xFFA0F0A0); + Toast.makeText(getApplicationContext(), autoMode ? R.string.autoMode : R.string.manualMode, Toast.LENGTH_SHORT).show(); } }); @@ -313,7 +313,7 @@ public void onClick(View v) { settingsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(v.getContext() , SettingsActivity.class); + Intent intent = new Intent(v.getContext(), SettingsActivity.class); startActivity(intent); } }); @@ -324,7 +324,7 @@ public void onClick(View v) { @Override public void onClick(View v) { - Intent intent = new Intent(v.getContext() , GalleryGridActivity.class); + Intent intent = new Intent(v.getContext(), GalleryGridActivity.class); startActivity(intent); } }); @@ -361,7 +361,7 @@ public boolean setFlash(boolean stateFlash) { } private void checkResumePermissions() { - if (ContextCompat.checkSelfPermission( this, + if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { @@ -376,7 +376,7 @@ private void checkResumePermissions() { private void checkCreatePermissions() { - if (ContextCompat.checkSelfPermission( this, + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { @@ -496,7 +496,7 @@ public void onManagerConnected(int status) { } break; default: { - Log.d(TAG, "opencvstatus: "+status); + Log.d(TAG, "opencvstatus: " + status); super.onManagerConnected(status); } break; @@ -505,8 +505,6 @@ public void onManagerConnected(int status) { }; - - @Override public void onResume() { super.onResume(); @@ -522,15 +520,15 @@ public void onResume() { Log.d(TAG, "resuming"); - for ( String build: Build.SUPPORTED_ABIS) { - Log.d(TAG,"myBuild "+ build); + for (String build : Build.SUPPORTED_ABIS) { + Log.d(TAG, "myBuild " + build); } checkCreatePermissions(); CustomOpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback); - if (mImageThread == null ) { + if (mImageThread == null) { mImageThread = new HandlerThread("Worker Thread"); mImageThread.start(); } @@ -586,16 +584,16 @@ public List getResolutionList() { } public Camera.Size getMaxPreviewResolution() { - int maxWidth=0; - Camera.Size curRes=null; + int maxWidth = 0; + Camera.Size curRes = null; mCamera.lock(); - for ( Camera.Size r: getResolutionList() ) { - if (r.width>maxWidth) { - Log.d(TAG,"supported preview resolution: "+r.width+"x"+r.height); - maxWidth=r.width; - curRes=r; + for (Camera.Size r : getResolutionList()) { + if (r.width > maxWidth) { + Log.d(TAG, "supported preview resolution: " + r.width + "x" + r.height); + maxWidth = r.width; + curRes = r; } } @@ -608,32 +606,32 @@ public List getPictureResolutionList() { } public Camera.Size getMaxPictureResolution(float previewRatio) { - int maxPixels=0; - int ratioMaxPixels=0; - Camera.Size currentMaxRes=null; - Camera.Size ratioCurrentMaxRes=null; - for ( Camera.Size r: getPictureResolutionList() ) { + int maxPixels = 0; + int ratioMaxPixels = 0; + Camera.Size currentMaxRes = null; + Camera.Size ratioCurrentMaxRes = null; + for (Camera.Size r : getPictureResolutionList()) { float pictureRatio = (float) r.width / r.height; - Log.d(TAG,"supported picture resolution: "+r.width+"x"+r.height+" ratio: "+pictureRatio); + Log.d(TAG, "supported picture resolution: " + r.width + "x" + r.height + " ratio: " + pictureRatio); int resolutionPixels = r.width * r.height; - if (resolutionPixels>ratioMaxPixels && pictureRatio == previewRatio) { - ratioMaxPixels=resolutionPixels; - ratioCurrentMaxRes=r; + if (resolutionPixels > ratioMaxPixels && pictureRatio == previewRatio) { + ratioMaxPixels = resolutionPixels; + ratioCurrentMaxRes = r; } - if (resolutionPixels>maxPixels) { - maxPixels=resolutionPixels; - currentMaxRes=r; + if (resolutionPixels > maxPixels) { + maxPixels = resolutionPixels; + currentMaxRes = r; } } boolean matchAspect = mSharedPref.getBoolean("match_aspect", true); - if (ratioCurrentMaxRes!=null && matchAspect) { + if (ratioCurrentMaxRes != null && matchAspect) { - Log.d(TAG,"Max supported picture resolution with preview aspect ratio: " - + ratioCurrentMaxRes.width+"x"+ratioCurrentMaxRes.height); + Log.d(TAG, "Max supported picture resolution with preview aspect ratio: " + + ratioCurrentMaxRes.width + "x" + ratioCurrentMaxRes.height); return ratioCurrentMaxRes; } @@ -665,9 +663,7 @@ public void surfaceCreated(SurfaceHolder holder) { try { int cameraId = findBestCamera(); mCamera = Camera.open(cameraId); - } - - catch (RuntimeException e) { + } catch (RuntimeException e) { System.err.println(e); return; } @@ -687,11 +683,11 @@ public void surfaceCreated(SurfaceHolder holder) { int displayWidth = Math.min(size.y, size.x); int displayHeight = Math.max(size.y, size.x); - float displayRatio = (float) displayHeight / displayWidth; + float displayRatio = (float) displayHeight / displayWidth; int previewHeight = displayHeight; - if ( displayRatio > previewRatio ) { + if (displayRatio > previewRatio) { ViewGroup.LayoutParams surfaceParams = mSurfaceView.getLayoutParams(); previewHeight = (int) ((float) size.y / displayRatio * previewRatio); surfaceParams.height = previewHeight; @@ -729,9 +725,9 @@ public void surfaceCreated(SurfaceHolder holder) { Camera.Size maxRes = getMaxPictureResolution(previewRatio); - if ( maxRes != null) { + if (maxRes != null) { param.setPictureSize(maxRes.width, maxRes.height); - Log.d(TAG,"max supported picture resolution: " + maxRes.width + "x" + maxRes.height); + Log.d(TAG, "max supported picture resolution: " + maxRes.width + "x" + maxRes.height); } PackageManager pm = getPackageManager(); @@ -788,9 +784,7 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig private void refreshCamera() { try { mCamera.stopPreview(); - } - - catch (Exception e) { + } catch (Exception e) { } try { @@ -798,8 +792,7 @@ private void refreshCamera() { mCamera.startPreview(); mCamera.setPreviewCallback(this); - } - catch (Exception e) { + } catch (Exception e) { } } @@ -819,9 +812,9 @@ public void onPreviewFrame(byte[] data, Camera camera) { android.hardware.Camera.Size pictureSize = camera.getParameters().getPreviewSize(); Log.d(TAG, "onPreviewFrame - received image " + pictureSize.width + "x" + pictureSize.height - + " focused: "+ mFocused +" imageprocessor: "+(imageProcessorBusy?"busy":"available")); + + " focused: " + mFocused + " imageprocessor: " + (imageProcessorBusy ? "busy" : "available")); - if ( mFocused && ! imageProcessorBusy ) { + if (mFocused && !imageProcessorBusy) { setImageProcessorBusy(true); Mat yuv = new Mat(new Size(pictureSize.width, pictureSize.height * 1.5), CvType.CV_8UC1); yuv.put(0, 0, data); @@ -831,7 +824,7 @@ public void onPreviewFrame(byte[] data, Camera camera) { yuv.release(); - sendImageProcessorMessage("previewFrame", new PreviewFrame( mat, autoMode, !(autoMode || scanClicked) )); + sendImageProcessorMessage("previewFrame", new PreviewFrame(mat, autoMode, !(autoMode || scanClicked))); } } @@ -867,7 +860,7 @@ public void onAutoFocus(boolean success, Camera camera) { attemptToFocus = true; } - camera.takePicture(null,null,mThis); + camera.takePicture(null, null, mThis); } }); return true; @@ -912,10 +905,10 @@ private void issueProcessingOfTakenPicture() { safeToTakePicture = true; } - public void sendImageProcessorMessage(String messageText , Object obj ) { - Log.d(TAG,"sending message to ImageProcessor: "+messageText+" - "+obj.toString()); + public void sendImageProcessorMessage(String messageText, Object obj) { + Log.d(TAG, "sending message to ImageProcessor: " + messageText + " - " + obj.toString()); Message msg = mImageProcessor.obtainMessage(); - msg.obj = new OpenNoteMessage(messageText, obj ); + msg.obj = new OpenNoteMessage(messageText, obj); mImageProcessor.sendMessage(msg); } @@ -929,27 +922,27 @@ public void saveDocument(ScannedDocument scannedDocument) { Uri fileUri = null; String imgSuffix = ".jpg"; - if (mSharedPref.getBoolean("save_png",false)) { + if (mSharedPref.getBoolean("save_png", false)) { imgSuffix = ".png"; } if (intent.getAction().equals("android.media.action.IMAGE_CAPTURE")) { fileUri = ((Uri) intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT)); - Log.d(TAG,"intent uri: " + fileUri.toString()); + Log.d(TAG, "intent uri: " + fileUri.toString()); try { - fileName = File.createTempFile("onsFile",imgSuffix, this.getCacheDir()).getPath(); + fileName = File.createTempFile("onsFile", imgSuffix, this.getCacheDir()).getPath(); } catch (IOException e) { e.printStackTrace(); return; } isIntent = true; } else { - String folderName=mSharedPref.getString("storage_folder","OpenNoteScanner"); + String folderName = mSharedPref.getString("storage_folder", "OpenNoteScanner"); File folder = new File(Environment.getExternalStorageDirectory().toString() - + "/" + folderName ); + + "/" + folderName); if (!folder.exists()) { folder.mkdirs(); - Log.d(TAG, "wrote: created folder "+folder.getPath()); + Log.d(TAG, "wrote: created folder " + folder.getPath()); } fileName = createFileName(imgSuffix, folderName); @@ -966,9 +959,9 @@ public void saveDocument(ScannedDocument scannedDocument) { ExifInterface exif = new ExifInterface(fileName); exif.setAttribute("UserComment", "Generated using Open Note Scanner"); String nowFormatted = mDateFormat.format(new Date().getTime()); - exif.setAttribute(ExifInterface.TAG_DATETIME,nowFormatted); - exif.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED , nowFormatted); - exif.setAttribute("Software" , "OpenNoteScanner " + BuildConfig.VERSION_NAME + " https://goo.gl/2JwEPq"); + exif.setAttribute(ExifInterface.TAG_DATETIME, nowFormatted); + exif.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, nowFormatted); + exif.setAttribute("Software", "OpenNoteScanner " + BuildConfig.VERSION_NAME + " https://goo.gl/2JwEPq"); exif.saveAttributes(); } catch (IOException e) { e.printStackTrace(); @@ -981,9 +974,9 @@ public void saveDocument(ScannedDocument scannedDocument) { inputStream = new FileInputStream(fileName); realOutputStream = this.getContentResolver().openOutputStream(fileUri); // Transfer bytes from in to out - byte [] buffer = new byte[1024]; + byte[] buffer = new byte[1024]; int len; - while( (len = inputStream.read(buffer)) > 0 ) { + while ((len = inputStream.read(buffer)) > 0) { realOutputStream.write(buffer, 0, len); } } catch (FileNotFoundException e) { @@ -1010,8 +1003,8 @@ public void saveDocument(ScannedDocument scannedDocument) { setResult(RESULT_OK, intent); finish(); } else { - animateDocument(fileName,scannedDocument); - addImageToGallery(fileName , this); + animateDocument(fileName, scannedDocument); + addImageToGallery(fileName, this); } // Record goal "PictureTaken" @@ -1037,7 +1030,7 @@ private String createFileName(String imgSuffix, String folderName) { class AnimationRunnable implements Runnable { private Size imageSize; - private Point[] previewPoints =null; + private Point[] previewPoints = null; public Size previewSize = null; public String fileName = null; public int width; @@ -1054,8 +1047,8 @@ public AnimationRunnable(String filename, ScannedDocument document) { } } - public double hipotenuse( Point a , Point b) { - return Math.sqrt( Math.pow(a.x - b.x , 2 ) + Math.pow(a.y - b.y , 2 )); + public double hipotenuse(Point a, Point b) { + return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)); } @Override @@ -1097,14 +1090,14 @@ public void run() { double yRatio = height / previewSize.width; params.topMargin = (int) (previewPoints[3].x * yRatio); - params.leftMargin = (int) ( (previewSize.height - previewPoints[3].y ) * xRatio); + params.leftMargin = (int) ((previewSize.height - previewPoints[3].y) * xRatio); params.width = (int) (documentWidth * xRatio); params.height = (int) (documentHeight * yRatio); } else { - params.topMargin = height/4; - params.leftMargin = width/4; - params.width = width/2; - params.height = height/2; + params.topMargin = height / 4; + params.leftMargin = width / 4; + params.width = width / 2; + params.height = height / 2; } bitmap = decodeSampledBitmapFromUri(fileName, params.width, params.height); @@ -1114,8 +1107,8 @@ public void run() { imageView.setVisibility(View.VISIBLE); TranslateAnimation translateAnimation = new TranslateAnimation( - Animation.ABSOLUTE , 0 , Animation.ABSOLUTE , -params.leftMargin , - Animation.ABSOLUTE , 0 , Animation.ABSOLUTE , height-params.topMargin + Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -params.leftMargin, + Animation.ABSOLUTE, 0, Animation.ABSOLUTE, height - params.topMargin ); ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0, 1, 0); @@ -1155,18 +1148,16 @@ public void onAnimationRepeat(Animation animation) { private void animateDocument(String filename, ScannedDocument quadrilateral) { - AnimationRunnable runnable = new AnimationRunnable(filename,quadrilateral); + AnimationRunnable runnable = new AnimationRunnable(filename, quadrilateral); runOnUiThread(runnable); } - private void shootSound() - { + private void shootSound() { AudioManager meng = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int volume = meng.getStreamVolume(AudioManager.STREAM_NOTIFICATION); - if (volume != 0) - { + if (volume != 0) { if (_shootMP == null) { _shootMP = MediaPlayer.create(this, Uri.parse("file:///system/media/audio/ui/camera_click.ogg")); } @@ -1191,8 +1182,8 @@ private void statsOptInDialog() { statsOptInDialog.setPositiveButton(R.string.answer_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mSharedPref.edit().putBoolean("usage_stats",true).commit(); - mSharedPref.edit().putBoolean("isFirstRun",false).commit(); + mSharedPref.edit().putBoolean("usage_stats", true).commit(); + mSharedPref.edit().putBoolean("isFirstRun", false).commit(); dialog.dismiss(); } }); @@ -1200,8 +1191,8 @@ public void onClick(DialogInterface dialog, int which) { statsOptInDialog.setNegativeButton(R.string.answer_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mSharedPref.edit().putBoolean("usage_stats",false).commit(); - mSharedPref.edit().putBoolean("isFirstRun",false).commit(); + mSharedPref.edit().putBoolean("usage_stats", false).commit(); + mSharedPref.edit().putBoolean("isFirstRun", false).commit(); dialog.dismiss(); } });