Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Alejandro Zurcher zurche

👋
View GitHub Profile
View QueueActions.java
public interface QueueActions {
boolean isEmpty();
void reset();
void enqueue(Object o);
Object first() throws EmptyQueueException;
View StackActions.java
public interface StackActions {
int size();
boolean isEmpty();
void push(Object objectToPush);
Object pop() throws LinkedListEmptyException;
View LogoPostBuilder.java
public class LogoPostBuilder {
public static LogoBodyModel buildLogoDetectionBody(String image) {
LogoBodyModel logoBodyModel = new LogoBodyModel();
ArrayList<Feature> features = new ArrayList<>();
features.add(new Feature("LOGO_DETECTION", 1));
Request requests = new Request();
requests.setFeatures(features);
View checkImage.java
LogoBodyModel logoBodyModel = LogoPostBuilder.buildLogoDetectionBody(encodedImage);
Call<LogoResponse> checkImageCall = mService.checkImageLogo(logoBodyModel);
checkImageCall.enqueue(new Callback<LogoResponse>() {
@Override
public void onResponse(Call<LogoResponse> call, Response<LogoResponse> response) {
Log.d(TAG, "Got Response");
if(response.body().getResponses() != null &&
response.body().getResponses().get(0).getLogoAnnotations() != null) {
Log.d(TAG, "It's a: " + response.body().getResponses().get(0).getLogoAnnotations().get(0).getDescription());
View LogoBodyModel.java
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class LogoBodyModel {
@SerializedName("requests")
@Expose
private List<Request> requests = null;
View LogoResponse.java
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class LogoResponse {
@SerializedName("responses")
@Expose
private List<Response> responses = null;
View VisionAPIService.java
public interface VisionApiService {
@POST("?key=<THIS_IS_WERE_YOU_PUT_YOUR_VISION_API_KEY>")
Call<LogoResponse> checkImageLogo(@Body LogoBodyModel logoBodyModel);
}
@zurche
zurche / encodeImageInBase64.java
Created Feb 13, 2017
This encodes a bitmap in base64
View encodeImageInBase64.java
private String encodeImage(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArray = baos.toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}
@zurche
zurche / checkCameraResult.java
Created Feb 13, 2017
This is how you check the image taken by the camera
View checkCameraResult.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
checkImageLogo(encodeImage(imageBitmap));
}
}
@zurche
zurche / takepicture.java
Created Feb 13, 2017
This is how you take a picture in android
View takepicture.java
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
You can’t perform that action at this time.