Adding overlay to camera module.

Adding retake and next icons.
parent 255a7d7d
...@@ -151,6 +151,8 @@ public abstract class BasePhotoActivity extends BaseActivity { ...@@ -151,6 +151,8 @@ public abstract class BasePhotoActivity extends BaseActivity {
public static final int RESULT_DELETED = 3583; public static final int RESULT_DELETED = 3583;
public static final int RESULT_RETURNED = 9583;
} }
@Override @Override
......
...@@ -165,7 +165,7 @@ public class CameraActivity extends BaseActivity implements PhotoTakenCallback, ...@@ -165,7 +165,7 @@ public class CameraActivity extends BaseActivity implements PhotoTakenCallback,
String path = data.getStringExtra(BasePhotoActivity.EXTRAS.PATH); String path = data.getStringExtra(BasePhotoActivity.EXTRAS.PATH);
PhotoUtil.deletePhoto(path); PhotoUtil.deletePhoto(path);
break; break;
case 14: case BasePhotoActivity.EXTRAS.RESULT_RETURNED:
setResult(resultCode, data); setResult(resultCode, data);
finish(); finish();
break; break;
......
...@@ -70,7 +70,7 @@ public class PhotoPreviewActivity extends BasePhotoActivity { ...@@ -70,7 +70,7 @@ public class PhotoPreviewActivity extends BasePhotoActivity {
} }
public void usePhoto(MenuItem item) { public void usePhoto(MenuItem item) {
setResult(14, setIntentData()); setResult(EXTRAS.RESULT_RETURNED, setIntentData());
finish(); finish();
} }
......
...@@ -119,7 +119,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback ...@@ -119,7 +119,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
paint2 = new Paint(); paint2 = new Paint();
paint2.setAntiAlias(true); paint2.setAntiAlias(true);
paint2.setColor(Color.BLUE); paint2.setColor(Color.BLUE);
paint2.setStrokeWidth(1f); paint2.setStrokeWidth(10f);
canvasFrame.setImageBitmap(bitmap); canvasFrame.setImageBitmap(bitmap);
} }
...@@ -235,19 +235,26 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback ...@@ -235,19 +235,26 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
private void drawEarFrame(Rect rect) { private void drawEarFrame(Rect rect) {
canvas2.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); canvas2.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
paint2.setStyle(Paint.Style.STROKE); paint2.setStyle(Paint.Style.STROKE);
float cx = canvas2.getWidth() * 0.5f; paint2.setStrokeCap(Paint.Cap.ROUND);
float cy = canvas2.getHeight() * 0.5f; paint2.setStrokeWidth(10.0f);
float width = canvas2.getWidth();
float height = canvas2.getHeight();
float cx = width * 0.6375f;
float cy = height * 0.5f;
float delta = canvas2.getWidth()*0.25f; float delta = canvas2.getWidth()*0.25f;
RectF rectf = new RectF(cx-delta, cy -delta, cx+delta, cy+delta); RectF rectf = new RectF(0.0f, height * 0.15f, width*0.85f, height*0.85f);
canvas2.drawArc(rectf, 90, -180, true, paint2); canvas2.drawArc(rectf, 90, -180, true, paint2);
//canvas2.drawCircle(canvas2.getWidth() / 2, canvas2.getHeight() / 2, canvas2.getWidth() / 4, paint2); //canvas2.drawPoint(cx, cy, paint2);
//canvas2.drawCircle(canvas2.getWidth()/2, canvas2.getHeight()/2, 10, paint2);
paint2.setStrokeWidth(3.0f);
canvas2.drawLine(cx, cy - 30.0f, cx, cy + 30.0f, paint2);
canvas2.drawLine(cx+30.f, cy, cx-30.0f, cy, paint2);
paint2.setStrokeWidth(4.0f);
canvas2.drawCircle(cx, cy, 4, paint2);
//canvas2.drawLine(rect.left, rect.top, rect.right, rect.top, paint2);
//canvas2.drawLine(rect.right, rect.top, rect.right, rect.bottom, paint2);
//canvas2.drawLine(rect.right, rect.bottom, rect.left, rect.bottom, paint2);
//canvas2.drawLine(rect.left, rect.bottom, rect.left, rect.top, paint2);
canvasFrame.draw(canvas2); canvasFrame.draw(canvas2);
canvasFrame.invalidate(); canvasFrame.invalidate();
} }
......
...@@ -16,6 +16,7 @@ import android.os.Environment; ...@@ -16,6 +16,7 @@ import android.os.Environment;
import com.aluxoft.earrecognition.EarIdentifier; import com.aluxoft.earrecognition.EarIdentifier;
import com.aluxoft.earrecognition.utils.ImageUtils; import com.aluxoft.earrecognition.utils.ImageUtils;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import com.yalantis.cameramodule.activity.BasePhotoActivity;
import com.yalantis.cameramodule.activity.CameraActivity; import com.yalantis.cameramodule.activity.CameraActivity;
import java.io.File; import java.io.File;
...@@ -30,7 +31,7 @@ import io.fabric.sdk.android.Fabric; ...@@ -30,7 +31,7 @@ import io.fabric.sdk.android.Fabric;
*/ */
public class IntentSearchFeatures extends Activity{ public class IntentSearchFeatures extends Activity{
private File location; //private File location;
public static final int KEY_REQUEST_IMAGE = 1; public static final int KEY_REQUEST_IMAGE = 1;
public static final int KEY_SIFT_ACTIVITY_LOADER = 2; public static final int KEY_SIFT_ACTIVITY_LOADER = 2;
...@@ -40,13 +41,12 @@ public class IntentSearchFeatures extends Activity{ ...@@ -40,13 +41,12 @@ public class IntentSearchFeatures extends Activity{
protected void onCreate(Bundle saveInstanceState) { protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState); super.onCreate(saveInstanceState);
Fabric.with(this, new Crashlytics()); Fabric.with(this, new Crashlytics());
this.takePhoto(); this.takePhoto();
} }
public boolean takePhoto() { public boolean takePhoto() {
/*
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try { try {
location = ImageUtils.createTempImageFile(); location = ImageUtils.createTempImageFile();
...@@ -62,21 +62,14 @@ public class IntentSearchFeatures extends Activity{ ...@@ -62,21 +62,14 @@ public class IntentSearchFeatures extends Activity{
startActivityForResult(i, KEY_REQUEST_IMAGE); startActivityForResult(i, KEY_REQUEST_IMAGE);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
return false; return false;
} }*/
return true;
/*
Intent intent = new Intent(this, CameraActivity.class); Intent intent = new Intent(this, CameraActivity.class);
File storage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); intent.putExtra(CameraActivity.PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
intent.putExtra(CameraActivity.PATH, storage);
intent.putExtra(CameraActivity.OPEN_PHOTO_PREVIEW, true); intent.putExtra(CameraActivity.OPEN_PHOTO_PREVIEW, true);
//intent.putExtra(CameraActivity.LAYOUT_ID, R.layout.fragment_camera_custom);
intent.putExtra(CameraActivity.USE_FRONT_CAMERA, false); intent.putExtra(CameraActivity.USE_FRONT_CAMERA, false);
startActivity(intent); startActivityForResult(intent, KEY_REQUEST_IMAGE);
return true; return true;
*/
} }
...@@ -85,14 +78,15 @@ public class IntentSearchFeatures extends Activity{ ...@@ -85,14 +78,15 @@ public class IntentSearchFeatures extends Activity{
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if(requestCode == KEY_REQUEST_IMAGE) { if(requestCode == KEY_REQUEST_IMAGE) {
//Go grab the image and set it's location //Go grab the image and set it's location
if(location == null || !location.exists()) { String filePath = data.getStringExtra(BasePhotoActivity.EXTRAS.PATH);
location = null; if (filePath != null) {
} else { File location = new File(filePath);
String path = location.getAbsolutePath(); if (location != null && location.exists()) {
EarIdentifier identifier = new EarIdentifier(null); String path = location.getAbsolutePath();
Intent intent = new Intent("com.auriclon.activity_sift"); Intent intent = new Intent("com.auriclon.activity_sift");
intent.putExtra("image_path", path); intent.putExtra("image_path", path);
startActivityForResult(intent, KEY_SIFT_ACTIVITY_LOADER); startActivityForResult(intent, KEY_SIFT_ACTIVITY_LOADER);
}
} }
} else if (requestCode == KEY_SIFT_ACTIVITY_LOADER) { } else if (requestCode == KEY_SIFT_ACTIVITY_LOADER) {
startActivityForResult(data, KEY_TOP_X); startActivityForResult(data, KEY_TOP_X);
...@@ -109,7 +103,7 @@ public class IntentSearchFeatures extends Activity{ ...@@ -109,7 +103,7 @@ public class IntentSearchFeatures extends Activity{
finish(); finish();
} }
} }
/*
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
...@@ -117,5 +111,5 @@ public class IntentSearchFeatures extends Activity{ ...@@ -117,5 +111,5 @@ public class IntentSearchFeatures extends Activity{
outState.putString("location", location.toString()); outState.putString("location", location.toString());
} }
} }
*/
} }
...@@ -12,6 +12,7 @@ import android.content.Intent; ...@@ -12,6 +12,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -24,6 +25,8 @@ import com.aluxoft.earrecognition.loader.PatientLoaderCommcare; ...@@ -24,6 +25,8 @@ import com.aluxoft.earrecognition.loader.PatientLoaderCommcare;
import com.aluxoft.earrecognition.utils.FileCache; import com.aluxoft.earrecognition.utils.FileCache;
import com.aluxoft.earrecognition.utils.ImageUtils; import com.aluxoft.earrecognition.utils.ImageUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yalantis.cameramodule.activity.BasePhotoActivity;
import com.yalantis.cameramodule.activity.CameraActivity;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
...@@ -44,8 +47,6 @@ public class IntentTransferFeatures extends Activity { ...@@ -44,8 +47,6 @@ public class IntentTransferFeatures extends Activity {
private ProgressDialog loading; private ProgressDialog loading;
File location;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -75,17 +76,13 @@ public class IntentTransferFeatures extends Activity { ...@@ -75,17 +76,13 @@ public class IntentTransferFeatures extends Activity {
} }
return; return;
} }
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Intent intent = new Intent(IntentTransferFeatures.this, CameraActivity.class);
try { intent.putExtra(CameraActivity.PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
location = ImageUtils.createTempImageFile(); intent.putExtra(CameraActivity.OPEN_PHOTO_PREVIEW, true);
} catch (IOException e1) { intent.putExtra(CameraActivity.USE_FRONT_CAMERA, false);
e1.printStackTrace();
return;
}
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(location));
try { try {
startActivityForResult(i, KEY_REQUEST_IMAGE); startActivityForResult(intent, KEY_REQUEST_IMAGE);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(IntentTransferFeatures.this, "No Camera", Toast.LENGTH_SHORT).show(); Toast.makeText(IntentTransferFeatures.this, "No Camera", Toast.LENGTH_SHORT).show();
} }
...@@ -95,7 +92,6 @@ public class IntentTransferFeatures extends Activity { ...@@ -95,7 +92,6 @@ public class IntentTransferFeatures extends Activity {
// If there is a valid picture in cache, we display the photo and // If there is a valid picture in cache, we display the photo and
// create a cachePictureButton to pass back to CommCare // create a cachePictureButton to pass back to CommCare
if (this.findViewById(R.id.current_picture) != null) { if (this.findViewById(R.id.current_picture) != null) {
final Button cachePictureButton = (Button) this.findViewById(R.id.current_picture); final Button cachePictureButton = (Button) this.findViewById(R.id.current_picture);
ImageView image = (ImageView) this.findViewById(R.id.image); ImageView image = (ImageView) this.findViewById(R.id.image);
image.setImageDrawable(Drawable.createFromPath(imageCache.getAbsolutePath())); image.setImageDrawable(Drawable.createFromPath(imageCache.getAbsolutePath()));
...@@ -122,20 +118,12 @@ public class IntentTransferFeatures extends Activity { ...@@ -122,20 +118,12 @@ public class IntentTransferFeatures extends Activity {
finish(); finish();
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(IntentTransferFeatures.this, Toast.makeText(IntentTransferFeatures.this,
"An error occurred when loading the features.", Toast.LENGTH_LONG); "An error occurred when loading the features.", Toast.LENGTH_LONG).show();
cachePictureButton.setEnabled(false); cachePictureButton.setEnabled(false);
} }
} }
}); });
} }
if(this.getLastNonConfigurationInstance() != null) {
location = ((IntentTransferFeatures)this.getLastNonConfigurationInstance()).location;
}
if(savedInstanceState != null) {
location = new File(savedInstanceState.getString("location"));
}
} }
@Override @Override
...@@ -143,14 +131,16 @@ public class IntentTransferFeatures extends Activity { ...@@ -143,14 +131,16 @@ public class IntentTransferFeatures extends Activity {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if(requestCode == KEY_REQUEST_IMAGE) { if(requestCode == KEY_REQUEST_IMAGE) {
// Pass image location to SIFT activity // Pass image location to SIFT activity
if(location == null || !location.exists()) { // Go grab the image and set it's location
location = null; String filePath = data.getStringExtra(BasePhotoActivity.EXTRAS.PATH);
} else { if (filePath != null) {
File location = new File(filePath);
if (location != null && location.exists()) {
String path = location.getAbsolutePath(); String path = location.getAbsolutePath();
EarIdentifier identifier = new EarIdentifier(null);
Intent intent = new Intent("com.auriclon.activity_sift"); Intent intent = new Intent("com.auriclon.activity_sift");
intent.putExtra("image_path", path); intent.putExtra("image_path", path);
startActivityForResult(intent, KEY_SIFT_ACTIVITY_LOADER); startActivityForResult(intent, KEY_SIFT_ACTIVITY_LOADER);
}
} }
} else if (requestCode == KEY_SIFT_ACTIVITY_LOADER) { } else if (requestCode == KEY_SIFT_ACTIVITY_LOADER) {
// Fetches features from SIFT activity to return to CommCare // Fetches features from SIFT activity to return to CommCare
......
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@android:color/transparent"/>
<size android:width="3dp" android:height="50dp"/>
</shape>
</item>
<item android:bottom="20dp">
<rotate
android:fromDegrees="-45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners
android:radius="2dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
</shape>
</rotate>
</item>
<item android:top="20dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:topLeftRadius="0dp"/>
</shape>
</rotate>
</item>
</layer-list>
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
<Button <Button
android:id="@+id/take_picture" android:id="@+id/take_picture"
android:drawableTop="@mipmap/ic_ear" android:drawableTop="@drawable/retake_picture"
android:text="Take ear picture" android:text="Retake ear picture"
android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_width="0.0dip" android:layout_height="fill_parent"
android:layout_weight="1.0" android:layout_weight="1.0"
/> />
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<Button <Button
android:id="@+id/current_picture" android:id="@+id/current_picture"
android:text="Use current picture" android:text="Use current picture"
android:drawableTop="@drawable/right_arrow"
android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_width="0.0dip" android:layout_height="fill_parent"
android:layout_weight="1.0" /> android:layout_weight="1.0" />
</LinearLayout> </LinearLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/camera_preview"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/capture"
android:src="@drawable/camera_capture"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="@dimen/small_margin"/>
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
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