Code cleanup.

parent ed55b12a
...@@ -12,25 +12,7 @@ ...@@ -12,25 +12,7 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/Widget.AppCompat.Light.ActionBar" > android:theme="@style/Widget.AppCompat.Light.ActionBar" >
<!-- <activity <!-- Install test screen.
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> -->
<activity <activity
android:name=".activities.EarCaptureActivity" android:name=".activities.EarCaptureActivity"
android:label="@string/app_name" android:label="@string/app_name"
...@@ -40,7 +22,9 @@ ...@@ -40,7 +22,9 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
-->
<!-- Search case_id intent (Follow-up) -->
<activity android:name=".intents.IntentSearchFeatures" <activity android:name=".intents.IntentSearchFeatures"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
...@@ -49,6 +33,7 @@ ...@@ -49,6 +33,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Take photo intent (Register) -->
<activity android:name=".intents.IntentTransferingFeatures" <activity android:name=".intents.IntentTransferingFeatures"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
...@@ -57,6 +42,8 @@ ...@@ -57,6 +42,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Private API -->
<!-- Call by IntentTransferingFeatures (Follow-up) -->
<activity android:name=".activities.SelectFollowupActivity" <activity android:name=".activities.SelectFollowupActivity"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
...@@ -64,7 +51,7 @@ ...@@ -64,7 +51,7 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Call by IntentTransferingFeatures, IntentSearchFeatures (Follow-up/Register) -->
<activity android:name=".activities.SIFTActivity" <activity android:name=".activities.SIFTActivity"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
...@@ -77,6 +64,6 @@ ...@@ -77,6 +64,6 @@
android:name="io.fabric.ApiKey" android:name="io.fabric.ApiKey"
android:value="8f546553db41cde72b997b22a2d5d9639236a29b" /> android:value="8f546553db41cde72b997b22a2d5d9639236a29b" />
</application> </application>
<!-- Todo: Remove permission if not used -->
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
</manifest> </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; package com.aluxoft.earrecognition.intents;
import android.app.Activity; import android.app.Activity;
...@@ -5,10 +10,8 @@ import android.content.ActivityNotFoundException; ...@@ -5,10 +10,8 @@ import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;
import com.aluxoft.earrecognition.EarIdentifier; import com.aluxoft.earrecognition.EarIdentifier;
import com.aluxoft.earrecognition.activities.SelectFollowupActivity;
import com.aluxoft.earrecognition.utils.ImageUtils; import com.aluxoft.earrecognition.utils.ImageUtils;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
...@@ -18,7 +21,9 @@ import java.io.IOException; ...@@ -18,7 +21,9 @@ import java.io.IOException;
import io.fabric.sdk.android.Fabric; 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{ public class IntentSearchFeatures extends Activity{
...@@ -34,16 +39,6 @@ public class IntentSearchFeatures extends Activity{ ...@@ -34,16 +39,6 @@ public class IntentSearchFeatures extends Activity{
Fabric.with(this, new Crashlytics()); Fabric.with(this, new Crashlytics());
this.takePhoto(); 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; package com.aluxoft.earrecognition.intents;
import android.app.Activity; import android.app.Activity;
...@@ -28,7 +33,9 @@ import java.io.IOException; ...@@ -28,7 +33,9 @@ import java.io.IOException;
import java.util.UUID; 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 { public class IntentTransferingFeatures extends Activity {
...@@ -43,6 +50,7 @@ public class IntentTransferingFeatures extends Activity { ...@@ -43,6 +50,7 @@ public class IntentTransferingFeatures extends Activity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Getting picture from cache and checking if is valid
FileCache imageCache = FileCache.getFile(this.getApplicationContext(), FileCache.FileCacheType.Image); FileCache imageCache = FileCache.getFile(this.getApplicationContext(), FileCache.FileCacheType.Image);
FileCache featuresCache = FileCache.getFile(this.getApplicationContext(), FileCache.FileCacheType.Features); FileCache featuresCache = FileCache.getFile(this.getApplicationContext(), FileCache.FileCacheType.Features);
if (imageCache.isValid() && featuresCache.isValid()) { if (imageCache.isValid() && featuresCache.isValid()) {
...@@ -51,12 +59,47 @@ public class IntentTransferingFeatures extends Activity { ...@@ -51,12 +59,47 @@ public class IntentTransferingFeatures extends Activity {
setContentView(R.layout.activity_callout); setContentView(R.layout.activity_callout);
} }
// 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.",
Toast.LENGTH_LONG);
loginInCommCareToast.show();
}
return;
}
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
location = ImageUtils.createTempImageFile();
} catch (IOException e1) {
e1.printStackTrace();
return;
}
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(location));
try {
startActivityForResult(i, KEY_REQUEST_IMAGE);
} catch (ActivityNotFoundException e) {
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) { if (this.findViewById(R.id.current_picture) != null) {
final Button button = (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()));
button.setOnClickListener(new View.OnClickListener() { cachePictureButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
try { try {
...@@ -74,54 +117,18 @@ public class IntentTransferingFeatures extends Activity { ...@@ -74,54 +117,18 @@ public class IntentTransferingFeatures extends Activity {
.getFile(IntentTransferingFeatures.this.getApplicationContext(), .getFile(IntentTransferingFeatures.this.getApplicationContext(),
FileCache.FileCacheType.Features) FileCache.FileCacheType.Features)
) )
); );
IntentTransferingFeatures.this.setResult(Activity.RESULT_OK, returningIntent); IntentTransferingFeatures.this.setResult(Activity.RESULT_OK, returningIntent);
finish(); finish();
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(IntentTransferingFeatures.this, "An error occurred when loading the features.", Toast.LENGTH_LONG); Toast.makeText(IntentTransferingFeatures.this,
button.setEnabled(false); "An error occurred when loading the features.", Toast.LENGTH_LONG);
cachePictureButton.setEnabled(false);
} }
} }
}); });
} }
this.findViewById(R.id.take_picture).setOnClickListener(new View.OnClickListener() {
private Toast loginInCommCareToast = null;
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.",
Toast.LENGTH_LONG);
loginInCommCareToast.show();
}
return;
}
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
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);
} catch (ActivityNotFoundException e) {
Toast.makeText(IntentTransferingFeatures.this, "No Camera", Toast.LENGTH_SHORT).show();
}
}
});
if(this.getLastNonConfigurationInstance() != null) { if(this.getLastNonConfigurationInstance() != null) {
location = ((IntentTransferingFeatures)this.getLastNonConfigurationInstance()).location; location = ((IntentTransferingFeatures)this.getLastNonConfigurationInstance()).location;
} }
...@@ -131,24 +138,22 @@ public class IntentTransferingFeatures extends Activity { ...@@ -131,24 +138,22 @@ public class IntentTransferingFeatures extends Activity {
} }
} }
/* (non-Javadoc)
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
*/
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
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 // Pass image location to SIFT activity
if(location == null || !location.exists()) { if(location == null || !location.exists()) {
location = null; location = null;
} else { } else {
String path = location.getAbsolutePath(); String path = location.getAbsolutePath();
EarIdentifier identifier = new EarIdentifier(null); 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
_showTransferringMessage(); _showTransferringMessage();
String list = data.getStringExtra("list"); String list = data.getStringExtra("list");
EarIdList earIdList = new Gson().fromJson(list, EarIdList.class); 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