diff --git a/.idea/misc.xml b/.idea/misc.xml index d10ede8..7158618 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/cs371m/chromavision/MainMenuActivity.java b/app/src/main/java/cs371m/chromavision/MainMenuActivity.java index b7c6b92..780677f 100644 --- a/app/src/main/java/cs371m/chromavision/MainMenuActivity.java +++ b/app/src/main/java/cs371m/chromavision/MainMenuActivity.java @@ -46,6 +46,8 @@ public class MainMenuActivity extends AppCompatActivity { private static final int REQUEST_CODE_PERMISSION = 3; private File storageDir; + private Uri mCameraImageUri; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -211,10 +213,14 @@ public void takeAPicture(View view) { Log.d(TAG, "takeAPicture: " + photoUri.toString()); - CropImage.activity(photoUri).setGuidelines(CropImageView.Guidelines.ON).start(this); + mCameraImageUri = photoUri; + + //CropImage.activity(photoUri).setGuidelines(CropImageView.Guidelines.ON).start(this); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(intent, CAMERA_REQUEST_CODE); + + } } @@ -235,7 +241,11 @@ public void pickFromGallery(View view) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); + + System.out.println("choosing"); + startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST_CODE); + } // public void pickFromGallery(View view) { @@ -269,6 +279,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } Bitmap scale = BitmapFactory.decodeStream(cameraInput); + System.out.println(croppedImage); + + File delete = new File(croppedImage.toString()); + if (delete.exists()) + System.out.println("it exists!!!"); + delete.delete(); + scale = resizeImageToScreen(scale); OutputStream fOut = null; @@ -321,8 +338,14 @@ else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { // Check which request we're responding to if (requestCode == CAMERA_REQUEST_CODE) { //galleryAddPic(); + System.out.println("Inside CAMERA_REQUEST_CODE"); - } else if (requestCode == GALLERY_REQUEST_CODE) { + System.out.println(mCameraImageUri); + + CropImage.activity(mCameraImageUri).setGuidelines(CropImageView.Guidelines.ON).start(this); + + } + else if (requestCode == GALLERY_REQUEST_CODE) { System.out.println("Inside GALLERY_REQUEST_CODE"); // Get the image from data @@ -332,14 +355,16 @@ else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { } System.out.println("selectedImage URI: " + selectedImage); - if (selectedImage != null) { - System.out.println("selectedImage toString: " + selectedImage.toString()); - } + + CropImage.activity(selectedImage).setGuidelines(CropImageView.Guidelines.ON).start(this); + + InputStream galleryInput = null; if (selectedImage != null) { galleryInput = getContentResolver().openInputStream(selectedImage); } + Bitmap scale = BitmapFactory.decodeStream(galleryInput); scale = resizeImageToScreen(scale); @@ -364,7 +389,7 @@ else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { resultIntent.putExtra("pictureUri", fileUri); resultIntent.putExtra("width", scale.getWidth()); resultIntent.putExtra("height", scale.getHeight()); - startActivityForResult(resultIntent, GALLERY_REQUEST_CODE); + //startActivityForResult(resultIntent, GALLERY_REQUEST_CODE); } else if (resultCode == RESULT_CANCELED) { // User cancelled the image capture diff --git a/app/src/main/java/cs371m/chromavision/ResultActivity.java b/app/src/main/java/cs371m/chromavision/ResultActivity.java index 3b8a9a3..81da1eb 100644 --- a/app/src/main/java/cs371m/chromavision/ResultActivity.java +++ b/app/src/main/java/cs371m/chromavision/ResultActivity.java @@ -13,6 +13,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -90,30 +91,32 @@ public boolean onTouch(View view, MotionEvent motionEvent){ if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE){ + int x = (int)motionEvent.getX(); + int y = (int)motionEvent.getY(); + bitmap = mImageView.getDrawingCache(); - if((int)motionEvent.getY()<0||(int)motionEvent.getX()<0){ + if(y < 0 || x < 0 || y > bitmap.getHeight() || x > bitmap.getWidth()) { } else { - if(motionEvent.getY()>bitmap.getHeight()){ - - - } - else { - int pixel = bitmap.getPixel((int) motionEvent.getX(), (int) motionEvent.getY()); - int redValue = Color.red(pixel); - int blueValue = Color.blue(pixel); - int greenValue = Color.green(pixel); - //System.out.println(); - - TextView textstuff = (TextView) findViewById(R.id.clickPixel); - textstuff.setBackgroundColor(Color.rgb(redValue, greenValue, blueValue)); - System.out.println((int) motionEvent.getX() + " , " + (int) motionEvent.getY()); - System.out.println("red =" + redValue + "blue = " + blueValue + "green = " + greenValue); - } + int pixel = bitmap.getPixel(x, y); + int redValue = Color.red(pixel); + int blueValue = Color.blue(pixel); + int greenValue = Color.green(pixel); + //System.out.println(); + + TextView clickPixelBackground = (TextView) findViewById(R.id.clickPixel); + TextView clickPixelLocation = (TextView) findViewById(R.id.clickPixelText); + LinearLayout border = (LinearLayout) findViewById(R.id.clickPixelBorder); + border.setBackgroundColor(Color.BLACK); + clickPixelBackground.setBackgroundColor(Color.rgb(redValue, greenValue, blueValue)); + System.out.println(x + " , " + y); + System.out.println("red =" + redValue + "blue = " + blueValue + "green = " + greenValue); + String loc = "(" + x + ", " + y + "): "; + clickPixelLocation.setText(loc); } } return true; @@ -363,7 +366,7 @@ private void determineColors(Bitmap image, String[][] colors) { image.getPixels(pixels, 0, width, 0, 0, width, height); - int[][] result = new int[height][width]; + //int[][] result = new int[height][width]; for (int pixel=0, row=0, col=0; pixel= 0.80) || (deg >= 0.3 && deg < 0.6 && hsb[1] colorCount[COLORS.valueOf("WHITE").ordinal()]++; return COLORS.valueOf("WHITE"); } - else if ((hsb[1] < 0.15 && hsb[2] >= 0.1 && hsb[2] < 0.66) || ((deg < 64 || deg >= 180) && hsb[1] < 0.15)) { + else if ((hsb[1] < 0.15 && hsb[2] >= 0.1 && hsb[2] < 0.75) || (hsb[1] < 0.4 && hsb[2] < 0.2) || ((deg < 64 || deg >= 180) && hsb[1] < 0.15)) { // Grey colorCount[COLORS.valueOf("GREY").ordinal()]++; return COLORS.valueOf("GREY"); @@ -448,29 +451,34 @@ else if ((hsb[1] < 0.15 && hsb[2] >= 0.1 && hsb[2] < 0.66) || ((deg < 64 || deg colorCount[COLORS.valueOf("PINK").ordinal()]++; return COLORS.valueOf("PINK"); } - else if (hsb[1] >= 0.8 || (deg >= 0 && hsb[1] >= 0.5)) { + else /*if (hsb[1] >= 0.8 || (deg >= 0 && hsb[1] >= 0.5))*/ { // Red colorCount[COLORS.valueOf("RED").ordinal()]++; return COLORS.valueOf("RED"); } - else { - // Dark Red - colorCount[COLORS.valueOf("DARK_RED").ordinal()]++; - return COLORS.valueOf("DARK_RED"); - } +// else { +// // Dark Red +// colorCount[COLORS.valueOf("DARK_RED").ordinal()]++; +// return COLORS.valueOf("DARK_RED"); +// } } else if (deg >= 11 && deg < 45) { - if ((hsb[1] >= 0.8 && hsb[2] >= 0.60)) { + if ((hsb[1] >= 0.8 || hsb[1] > 0.5 && hsb[2] > 0.7 || hsb[2] > 0.85 /*&& hsb[2] >= 0.60*/)) { // Orange colorCount[COLORS.valueOf("ORANGE").ordinal()]++; return COLORS.valueOf("ORANGE"); } - else if ((hsb[2] >= 0.75)) { - // Light Orange - colorCount[COLORS.valueOf("LIGHT_ORANGE").ordinal()]++; - return COLORS.valueOf("LIGHT_ORANGE"); - } +// else if ((hsb[2] >= 0.75)) { +// // Light Orange +// colorCount[COLORS.valueOf("LIGHT_ORANGE").ordinal()]++; +// return COLORS.valueOf("LIGHT_ORANGE"); +// } else { + if (hsb[1] < 0.4 && hsb[2] < 0.9) { + // Grey + colorCount[COLORS.valueOf("GREY").ordinal()]++; + return COLORS.valueOf("GREY"); + } // Brown colorCount[COLORS.valueOf("BROWN").ordinal()]++; return COLORS.valueOf("BROWN"); @@ -485,6 +493,10 @@ else if (deg >= 45 && deg < 70) { colorCount[COLORS.valueOf("BLUE").ordinal()]++; return COLORS.valueOf("BLUE"); } + else if (hsb[1] < 0.3 && hsb[2] < 0.85) { + colorCount[COLORS.valueOf("GREY").ordinal()]++; + return COLORS.valueOf("GREY"); + } else { // Yellow colorCount[COLORS.valueOf("YELLOW").ordinal()]++; diff --git a/app/src/main/res/layout/activity_result.xml b/app/src/main/res/layout/activity_result.xml index f549fda..b61dc03 100644 --- a/app/src/main/res/layout/activity_result.xml +++ b/app/src/main/res/layout/activity_result.xml @@ -17,22 +17,30 @@ + android:orientation="horizontal" > - + android:gravity="right" + android:layout_weight="0.5" + android:id="@+id/clickPixelText" + android:textIsSelectable="false" /> + + + + @@ -41,7 +49,7 @@ + android:layout_weight="0.5"> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 7c8ebfb..9a46c41 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -9,7 +9,7 @@