package pt.passarola.utils;

import android.content.Context;
import android.support.annotation.Nullable;

import com.google.android.gms.common.GoogleApiAvailability;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import static com.google.android.gms.common.ConnectionResult.SUCCESS;

/**
 * Created by ruigoncalo on 22/10/15.
 */
public class Utils {

    /**
     * Validate if device has GooglePlayServices app installed
     */
    public static boolean isGooglePlayServicesAvailable(Context context) {
        return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == SUCCESS;
    }

    /**
     * Normalize the value of a distance expressed in meters.
     * 989 meters = 989 meters
     * 1000 meters = 1.0 km
     * 1500 meters = 1.5 km
     *
     * @param distanceInMeters distance number in meters
     * @return distance normalized with distance units
     */
    public static String getNormalizedDistance(int distanceInMeters){
        float distance = (float) distanceInMeters;
        if(distance < 1000){
            return distanceInMeters + " meters";
        } else {
            return String.format("%.02f", distance/1000) + " km";
        }
    }

    /**
     * Generate a date object from a string
     *
     * @param date string date
     * @return date object that follows the format "yyyy-mm-dd"
     */
    @Nullable
    public static Date getDateFromString(String date){
        Date result;
        DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd", Locale.UK);

        try {
            result = dateFormat.parse(date);
        } catch (ParseException e){
            result = null;
        }

        return result;
    }

}
@@ -54,16 +54,71 @@
 ontext;%0A
+import android.content.Intent;%0Aimport android.net.Uri;%0A
 import a
@@ -1841,9 +1841,751 @@
 %0A    %7D%0A%0A
+    /**%0A     * Open intent with data%0A     *%0A     * @param context used to start activity%0A     * @param link intent's data%0A     */%0A    public static void openLink(Context context, String link) %7B%0A        Intent intent = new Intent(Intent.ACTION_VIEW);%0A        intent.setData(Uri.parse(link));%0A        context.startActivity(intent);%0A    %7D%0A%0A    /**%0A     * Open contact screen by providing a phone number%0A     * @param context used to start activity%0A     * @param phoneNumber data to show on contact screen%0A     */%0A    public static void openContact(Context context, String phoneNumber)%7B%0A        Intent intent = new Intent(Intent.ACTION_VIEW);%0A        intent.setData(Uri.parse(%22tel:%22 + phoneNumber));%0A        context.startActivity(intent);%0A    %7D%0A%0A
 %7D

Add static methods to start activities with data