Commit d515d49a authored by Buwaneka 's avatar Buwaneka

add TakeImage.java

parent c886385b
package com.example.count;
import android.app.Activity;
import android.app.Dialog;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;
public class TakeImage extends Activity {
Bitmap selectedImageB;
ImageView image;
Button btnconfirm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.take_image_activity);
GlobleVariable.done=false;
Button btntake = findViewById(R.id.takeimage);
btnconfirm = findViewById(R.id.confirm);
image = findViewById(R.id.image);
btnconfirm.setEnabled(false);
btntake.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.start(TakeImage.this);
}
});
btnconfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog settingsDialog = new Dialog(TakeImage.this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.confirm_layout, null));
settingsDialog.show();
settingsDialog.setCanceledOnTouchOutside(true);
Button confirmed = settingsDialog.findViewById(R.id.confirmgo);
confirmed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TakeImage.this, ImageClassification.class));
}
});
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Uri resultUri = result.getUri();
image.setImageURI(resultUri);
try {
selectedImageB = MediaStore.Images.Media.getBitmap(this.getContentResolver(), resultUri);
} catch (IOException e) {
e.printStackTrace();
}
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
backgrounNumberSeperate newbackGP = new backgrounNumberSeperate();
newbackGP.start();
}
class backgrounNumberSeperate extends Thread{
public void run(){
SeperateNumbers OseperateNumber = new SeperateNumbers();
final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.pb);
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
simpleProgressBar.setVisibility(View.VISIBLE);
}
});
} catch (final Exception ex) {
Log.i("---","Exception in thread");
}
Bitmap NumberSeperateImage= OseperateNumber.getResizedBitmap(selectedImageB,600);
final Bitmap MarkedNumbers=OseperateNumber.BlackAndWite(NumberSeperateImage);
if (GlobleVariable.done){
GlobleVariable.bitmapNo.add(NumberSeperateImage);
try {
// code runs in a thread
runOnUiThread(new Runnable() {
@Override
public void run() {
simpleProgressBar.setVisibility(View.INVISIBLE);
image.setImageBitmap(MarkedNumbers);
btnconfirm.setEnabled(true);
}
});
} catch (final Exception ex) {
Log.i("---","Exception in thread");
}
}
else{
try {
// code runs in a thread
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"TRY AGAIN\n Follow Instructions Above",Toast.LENGTH_SHORT).show();
image.setImageResource(R.drawable.take);
simpleProgressBar.setVisibility(View.INVISIBLE);
btnconfirm.setEnabled(false);
}
});
} catch (final Exception ex) {
Log.i("---","Exception in thread");
}
}
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment