Code cleanup.

parent ed55b12a
......@@ -12,25 +12,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Widget.AppCompat.Light.ActionBar" >
<!-- <activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> -->
<!-- <activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> -->
<!-- Install test screen.
<activity
android:name=".activities.EarCaptureActivity"
android:label="@string/app_name"
......@@ -40,7 +22,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-->
<!-- Search case_id intent (Follow-up) -->
<activity android:name=".intents.IntentSearchFeatures"
android:screenOrientation="portrait">
<intent-filter>
......@@ -49,6 +33,7 @@
</intent-filter>
</activity>
<!-- Take photo intent (Register) -->
<activity android:name=".intents.IntentTransferingFeatures"
android:screenOrientation="portrait">
<intent-filter>
......@@ -57,6 +42,8 @@
</intent-filter>
</activity>
<!-- Private API -->
<!-- Call by IntentTransferingFeatures (Follow-up) -->
<activity android:name=".activities.SelectFollowupActivity"
android:screenOrientation="portrait">
<intent-filter>
......@@ -64,7 +51,7 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Call by IntentTransferingFeatures, IntentSearchFeatures (Follow-up/Register) -->
<activity android:name=".activities.SIFTActivity"
android:screenOrientation="portrait">
<intent-filter>
......@@ -77,6 +64,6 @@
android:name="io.fabric.ApiKey"
android:value="8f546553db41cde72b997b22a2d5d9639236a29b" />
</application>
<!-- Todo: Remove permission if not used -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
/*
Copyright by Boston University, 2016
Authors: Josejulio Martínez, Daniel Kornhauser
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
package com.aluxoft.earrecognition.intents;
import android.app.Activity;
......@@ -5,10 +10,8 @@ import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
import com.aluxoft.earrecognition.EarIdentifier;
import com.aluxoft.earrecognition.activities.SelectFollowupActivity;
import com.aluxoft.earrecognition.utils.ImageUtils;
import com.crashlytics.android.Crashlytics;
......@@ -18,7 +21,9 @@ import java.io.IOException;
import io.fabric.sdk.android.Fabric;
/**
* Created by dkor on 11/13/15.
* Entry point for the search by feature.
*
* Takes the photo, sends to the SIFT activity and displays the Top match list.
*/
public class IntentSearchFeatures extends Activity{
......@@ -34,16 +39,6 @@ public class IntentSearchFeatures extends Activity{
Fabric.with(this, new Crashlytics());
this.takePhoto();
// Mostrar la camara
/*
Intent returningIntent = new Intent(getIntent());
returningIntent.putExtra(
"ear_search_result",
"Juan");
this.setResult(Activity.RESULT_OK, returningIntent);
finish();
*/
}
......
/*
Copyright by Boston University, 2016
Authors: Josejulio Martínez, Daniel Kornhauser
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
package com.aluxoft.earrecognition.intents;
import android.app.Activity;
......@@ -28,7 +33,9 @@ import java.io.IOException;
import java.util.UUID;
/**
* Callout to transfer features to CommCare
* Entry point for fetching the features of a photo.
*
* Takes the photo, sends to SIFT activity and returns.
*/
public class IntentTransferingFeatures extends Activity {
......@@ -43,6 +50,7 @@ public class IntentTransferingFeatures extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Getting picture from cache and checking if is valid
FileCache imageCache = FileCache.getFile(this.getApplicationContext(), FileCache.FileCacheType.Image);
FileCache featuresCache = FileCache.getFile(this.getApplicationContext(), FileCache.FileCacheType.Features);
if (imageCache.isValid() && featuresCache.isValid()) {
......@@ -51,48 +59,14 @@ public class IntentTransferingFeatures extends Activity {
setContentView(R.layout.activity_callout);
}
if (this.findViewById(R.id.current_picture) != null) {
final Button button = (Button) this.findViewById(R.id.current_picture);
ImageView image = (ImageView) this.findViewById(R.id.image);
image.setImageDrawable(Drawable.createFromPath(imageCache.getAbsolutePath()));
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
_showTransferringMessage();
Intent returningIntent = new Intent(getIntent());
Bundle responses = new Bundle();
responses.putString("ear_id", UUID.randomUUID().toString());
returningIntent.putExtra("odk_intent_bundle", responses);
returningIntent.putExtra(
"odk_intent_data",
FileUtils.readFileToString(
FileCache
.getFile(IntentTransferingFeatures.this.getApplicationContext(),
FileCache.FileCacheType.Features)
)
);
IntentTransferingFeatures.this.setResult(Activity.RESULT_OK, returningIntent);
finish();
} catch (Exception e) {
Toast.makeText(IntentTransferingFeatures.this, "An error occurred when loading the features.", Toast.LENGTH_LONG);
button.setEnabled(false);
}
}
});
}
this.findViewById(R.id.take_picture).setOnClickListener(new View.OnClickListener() {
// Creating the takePictureButton
Button takePictureButton = (Button) this.findViewById(R.id.take_picture);
takePictureButton.setOnClickListener(new View.OnClickListener() {
private Toast loginInCommCareToast = null;
@Override
public void onClick(View v) {
if (!EarDataLoaderCommcare.checkConnection(IntentTransferingFeatures.this)) {
if (loginInCommCareToast == null || loginInCommCareToast.getView().getWindowVisibility() != View.VISIBLE) {
loginInCommCareToast = Toast.makeText(IntentTransferingFeatures.this,
"Please login in CommCare application to proceed.",
......@@ -105,13 +79,10 @@ public class IntentTransferingFeatures extends Activity {
try {
location = ImageUtils.createTempImageFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return;
}
// if this gets modified, the onActivityResult in
// FormEntyActivity will also need to be updated.
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(location));
try {
startActivityForResult(i, KEY_REQUEST_IMAGE);
......@@ -119,8 +90,44 @@ public class IntentTransferingFeatures extends Activity {
Toast.makeText(IntentTransferingFeatures.this, "No Camera", Toast.LENGTH_SHORT).show();
}
}
});
// If there is a valid picture in cache, we display the photo and
// create a cachePictureButton to pass back to CommCare
if (this.findViewById(R.id.current_picture) != null) {
final Button cachePictureButton = (Button) this.findViewById(R.id.current_picture);
ImageView image = (ImageView) this.findViewById(R.id.image);
image.setImageDrawable(Drawable.createFromPath(imageCache.getAbsolutePath()));
cachePictureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
_showTransferringMessage();
Intent returningIntent = new Intent(getIntent());
Bundle responses = new Bundle();
responses.putString("ear_id", UUID.randomUUID().toString());
returningIntent.putExtra("odk_intent_bundle", responses);
returningIntent.putExtra(
"odk_intent_data",
FileUtils.readFileToString(
FileCache
.getFile(IntentTransferingFeatures.this.getApplicationContext(),
FileCache.FileCacheType.Features)
)
);
IntentTransferingFeatures.this.setResult(Activity.RESULT_OK, returningIntent);
finish();
} catch (Exception e) {
Toast.makeText(IntentTransferingFeatures.this,
"An error occurred when loading the features.", Toast.LENGTH_LONG);
cachePictureButton.setEnabled(false);
}
}
});
}
if(this.getLastNonConfigurationInstance() != null) {
location = ((IntentTransferingFeatures)this.getLastNonConfigurationInstance()).location;
......@@ -131,14 +138,11 @@ public class IntentTransferingFeatures extends Activity {
}
}
/* (non-Javadoc)
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == KEY_REQUEST_IMAGE) {
//Go grab the image and set it's location
// Pass image location to SIFT activity
if(location == null || !location.exists()) {
location = null;
} else {
......@@ -149,6 +153,7 @@ public class IntentTransferingFeatures extends Activity {
startActivityForResult(intent, KEY_SIFT_ACTIVITY_LOADER);
}
} else if (requestCode == KEY_SIFT_ACTIVITY_LOADER) {
// Fetches features from SIFT activity to return to CommCare
_showTransferringMessage();
String list = data.getStringExtra("list");
EarIdList earIdList = new Gson().fromJson(list, EarIdList.class);
......
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