Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jborak/charityspotter
Browse files Browse the repository at this point in the history
  • Loading branch information
igweckay committed Nov 8, 2015
2 parents 26f8362 + 5672b29 commit cb726f6
Show file tree
Hide file tree
Showing 20 changed files with 489 additions and 9 deletions.
2 changes: 2 additions & 0 deletions android/CharitySpot/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ dependencies {
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.firebase:firebase-client-android:2.4.0+'
compile 'com.clarifai:clarifai-api-java:1.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.kbeanie:image-chooser-library:1.5.2@aar'
}
5 changes: 5 additions & 0 deletions android/CharitySpot/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- USE_CREDENTIALS is necessary for Google+ login -->
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
Expand Down Expand Up @@ -41,6 +43,9 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.charityspotter.charityspot.ItemListActivity" />
</activity>
<activity
android:name=".ImageChooserActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
package com.charityspotter.charityspot;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.kbeanie.imagechooser.api.ChooserType;
import com.kbeanie.imagechooser.api.ChosenImage;
import com.kbeanie.imagechooser.api.ImageChooserListener;
import com.kbeanie.imagechooser.api.ImageChooserManager;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import java.io.File;

/**
* Created by morrisonchang on 11/8/15.
*/
public class ImageChooserActivity extends Activity implements ImageChooserListener {

private final static String TAG = "ICA";

private ImageView imageViewThumbnail;

private ImageView imageViewThumbSmall;

private TextView textViewFile;
private TextView taglisttext;

private ImageChooserManager imageChooserManager;

private ProgressBar pbar;

private String filePath;

private int chooserType;

private boolean isActivityResultOver = false;

private String originalFilePath;
private String thumbnailFilePath;
private String thumbnailSmallFilePath;
ImageTagger itag;
String[] tagResults;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Activity Created");
setContentView(R.layout.activity_image_chooser);

itag = new ImageTagger();

Button buttonTakePicture = (Button) findViewById(R.id.buttonTakePicture);
buttonTakePicture.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
takePicture();
}
});
Button buttonChooseImage = (Button) findViewById(R.id.buttonChooseImage);
buttonChooseImage.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
chooseImage();
}
});



imageViewThumbnail = (ImageView) findViewById(R.id.imageViewThumb);
imageViewThumbSmall = (ImageView) findViewById(R.id.imageViewThumbSmall);
textViewFile = (TextView) findViewById(R.id.textViewFile);

taglisttext = (TextView) findViewById(R.id.taglisttext);

pbar = (ProgressBar) findViewById(R.id.progressBar);
pbar.setVisibility(View.GONE);

}

private void chooseImage() {
chooserType = ChooserType.REQUEST_PICK_PICTURE;
imageChooserManager = new ImageChooserManager(this,
ChooserType.REQUEST_PICK_PICTURE, true);
imageChooserManager.setImageChooserListener(this);
imageChooserManager.clearOldFiles();
try {
pbar.setVisibility(View.VISIBLE);
filePath = imageChooserManager.choose();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

private void takePicture() {
chooserType = ChooserType.REQUEST_CAPTURE_PICTURE;
imageChooserManager = new ImageChooserManager(this,
ChooserType.REQUEST_CAPTURE_PICTURE, true);
imageChooserManager.setImageChooserListener(this);
try {
pbar.setVisibility(View.VISIBLE);
filePath = imageChooserManager.choose();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG, "OnActivityResult");
Log.i(TAG, "File Path : " + filePath);
Log.i(TAG, "Chooser Type: " + chooserType);
if (resultCode == RESULT_OK
&& (requestCode == ChooserType.REQUEST_PICK_PICTURE || requestCode == ChooserType.REQUEST_CAPTURE_PICTURE)) {
if (imageChooserManager == null) {
reinitializeImageChooser();
}
imageChooserManager.submit(requestCode, data);
} else {
pbar.setVisibility(View.GONE);
}
}

@Override
public void onImageChosen(final ChosenImage image) {
runOnUiThread(new Runnable() {

@Override
public void run() {
Log.i(TAG, "Chosen Image: O - " + image.getFilePathOriginal());
Log.i(TAG, "Chosen Image: T - " + image.getFileThumbnail());
Log.i(TAG, "Chosen Image: Ts - " + image.getFileThumbnailSmall());
isActivityResultOver = true;
originalFilePath = image.getFilePathOriginal();
thumbnailFilePath = image.getFileThumbnail();
thumbnailSmallFilePath = image.getFileThumbnailSmall();
pbar.setVisibility(View.GONE);
if (image != null) {
Log.i(TAG, "Chosen Image: Is not null");
textViewFile.setText(image.getFilePathOriginal());
loadImage(imageViewThumbnail, image.getFileThumbnail());
loadImage(imageViewThumbSmall, image.getFileThumbnailSmall());
new Thread() {
public void run() {
tagResults = itag.getTag(new File(image.getFilePathOriginal()));
}
}.start();

StringBuffer outSb = new StringBuffer("Tags: ");
if(tagResults != null) {
for (String e : tagResults) {
outSb.append("'" + e + "' ");
Log.i(TAG, "Tag entry:" + e);
}
} else {
outSb = new StringBuffer("NO TAGS");
Log.i(TAG,"NO TAGS");
}
taglisttext.setText(outSb.toString());

} else {
Log.i(TAG, "Chosen Image: Is null");
}
}
});
}

private void loadImage(ImageView iv, final String path) {
Picasso.with(ImageChooserActivity.this)
.load(Uri.fromFile(new File(path)))
.fit()
.centerInside()
.into(iv, new Callback() {
@Override
public void onSuccess() {
Log.i(TAG, "Picasso Success Loading Thumbnail - " + path);
}

@Override
public void onError() {
Log.i(TAG, "Picasso Error Loading Thumbnail Small - " + path);
}
});
}

@Override
public void onError(final String reason) {
runOnUiThread(new Runnable() {

@Override
public void run() {
Log.i(TAG, "OnError: " + reason);
pbar.setVisibility(View.GONE);
Toast.makeText(ImageChooserActivity.this, reason,
Toast.LENGTH_LONG).show();
}
});
}

// Should be called if for some reason the ImageChooserManager is null (Due
// to destroying of activity for low memory situations)
private void reinitializeImageChooser() {
imageChooserManager = new ImageChooserManager(this, chooserType, true);
imageChooserManager.setImageChooserListener(this);
imageChooserManager.reinitialize(filePath);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
Log.i(TAG, "Saving Stuff");
Log.i(TAG, "File Path: " + filePath);
Log.i(TAG, "Chooser Type: " + chooserType);
outState.putBoolean("activity_result_over", isActivityResultOver);
outState.putInt("chooser_type", chooserType);
outState.putString("media_path", filePath);
outState.putString("orig", originalFilePath);
outState.putString("thumb", thumbnailFilePath);
outState.putString("thumbs", thumbnailSmallFilePath);
super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
if (savedInstanceState != null) {
if (savedInstanceState.containsKey("chooser_type")) {
chooserType = savedInstanceState.getInt("chooser_type");
}
if (savedInstanceState.containsKey("media_path")) {
filePath = savedInstanceState.getString("media_path");
}
if (savedInstanceState.containsKey("activity_result_over")) {
isActivityResultOver = savedInstanceState.getBoolean("activity_result_over");
originalFilePath = savedInstanceState.getString("orig");
thumbnailFilePath = savedInstanceState.getString("thumb");
thumbnailSmallFilePath = savedInstanceState.getString("thumbs");
}
}
Log.i(TAG, "Restoring Stuff");
Log.i(TAG, "File Path: " + filePath);
Log.i(TAG, "Chooser Type: " + chooserType);
Log.i(TAG, "Activity Result Over: " + isActivityResultOver);
if (isActivityResultOver) {
populateData();
}
super.onRestoreInstanceState(savedInstanceState);
}

private void populateData() {
Log.i(TAG, "Populating Data");
loadImage(imageViewThumbnail, thumbnailFilePath);
loadImage(imageViewThumbSmall, thumbnailSmallFilePath);
}

@Override
public void onDestroy() {
super.onDestroy();
Log.i(TAG, "Activity Destroyed");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.charityspotter.charityspot;

import android.util.Log;

import com.clarifai.api.ClarifaiClient;
import com.clarifai.api.RecognitionRequest;
import com.clarifai.api.RecognitionResult;
Expand All @@ -13,6 +15,7 @@
*/
public class ImageTagger {

String TAG = "ImageTagger";
private static final String APP_ID = "HPEW2NyFNo8vKK2zf3BRowpxs6HyCMJTcapAOEQq";
private static final String APP_SECRET = "2WNH9BioxGSHWA_IkhjLwZyMO-Bi5po1qpLXSRPW";

Expand All @@ -23,6 +26,8 @@ public ImageTagger() {
}

public String[] getTag(File imgFile) {

Log.i(TAG, "Using file" + imgFile.getAbsolutePath());
List<RecognitionResult> results = client.recognize(new RecognitionRequest(imgFile));

int numTags = results.get(0).getTags().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
private View mProgressView;
private View mLoginFormView;
private Intent goActivity;
private Intent takePictureActivity;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -102,6 +103,15 @@ public void onClick(View v) {
}
});

takePictureActivity = new Intent(this,ImageChooserActivity.class);
Button mTakePictureButton = (Button) findViewById(R.id.take_picture_button);
mTakePictureButton.setOnClickListener((new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(takePictureActivity);
}
}));

mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cb726f6

Please sign in to comment.