Android Distance Calculate getMessageForDistance(long distance)

Here you can find the source of getMessageForDistance(long distance)

Description

get Message For Distance

Declaration

public static final String getMessageForDistance(long distance) 

Method Source Code

//package com.java2s;
import java.text.MessageFormat;

public class Main {
    private static final String pattern = "{0} {1} {2}";
    private static final String DAYS = "days";
    private static final String AWAY = "to go";
    private static final String PAST = "past";
    private static final String TODAY = "Today";
    private static final String TOMORROW = "Tomorrow";
    private static final String YESTERDAY = "Yesterday";

    public static final String getMessageForDistance(long distance) {
        if (distance == 0)
            return TODAY;
        if (distance == 1)
            return TOMORROW;
        if (distance == -1)
            return YESTERDAY;

        String pastOrFuture = distance > 0 ? AWAY : PAST;
        distance = distance < 0 ? distance * -1 : distance;
        String message = MessageFormat.format(pattern, new Object[] {
                distance, DAYS, pastOrFuture });
        return message;
    }//from   w w  w .  ja  v a 2  s . co m
}

Related

  1. distanceBetweenTwoPoints(double lat1, double lng1, double lat2, double lng2)
  2. KmToMiles(int distance)
  3. getTempsTrajetBus(int distance)
  4. getTempsTrajetPied(int distance)
  5. hammingDistance(String sourceHashCode, String hashCode)
  6. calculateEte(boolean useBearing, double distance, double speed, double bearing, double heading)
  7. fetchRawEte(boolean useBearing, double distance, double speed, double bearing, double heading)
  8. distance(double lat1, double lon1, double lat2, double lon2, char unit)
  9. computeSpeed(int distance, long duration)