Skip to content

Instantly share code, notes, and snippets.

View zurche's full-sized avatar
👋

Alejandro Zurcher zurche

👋
View GitHub Profile
package com.example.zurcher.mycoollib;
/**
* Representation of a Latitude/Longitude pair Point in the map.
*/
public class Point {
float mLatitude;
float mLongitude;
public Point(float latitude, float longitude) {
/**
* This helper is used to calculate the distance between two Latitude/Longitude points in kilometers.
*/
public class LatLonDistanceCalculator {
private static final int EARTH_RADIUS_IN_KILOMETERS = 6371;
public static float calculateDistance(Point pointA,
Point pointB) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Point buenosAiresObeliscoPoint =
new Point((float) -34.6037389, (float) -58.3815704);
Point nycStatueOfLibertyPoint =
new Point((float) 40.6892494, (float) -74.0445004);
@zurche
zurche / AppInstallerMainActivity.java
Created November 25, 2016 13:45
An app to install a list of apps.
package com.example.zurcher.appinstaller;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
/**
* Counts chars in each sentence of a given paragraph.
* Sentence end counts as '.', '!' or '?'.
*
* @return ArrayList of integers that correspond to the count of chars of each sentence in the
* paragraph.
*/
private String countCharsInSentences(String paragraph) {
ArrayList<Integer> charsBySentence = new ArrayList<>();
int currentCharCount = 0;
/**
* This helper is used to calculate the distance between two Latitude/Longitude points in kilometers.
*/
public class LatLonDistanceCalculator {
private static final int EARTH_RADIUS_IN_KILOMETERS = 6371;
public static float calculateDistance(Point pointA,
Point pointB) {
@zurche
zurche / takepicture.java
Created February 13, 2017 18:06
This is how you take a picture in android
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
@zurche
zurche / checkCameraResult.java
Created February 13, 2017 18:08
This is how you check the image taken by the camera
@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 / encodeImageInBase64.java
Created February 13, 2017 18:10
This encodes a bitmap in base64
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);
}
public interface VisionApiService {
@POST("?key=<THIS_IS_WERE_YOU_PUT_YOUR_VISION_API_KEY>")
Call<LogoResponse> checkImageLogo(@Body LogoBodyModel logoBodyModel);
}