Android Open Source - getback_gps Ariadne Location






From Project

Back to project page getback_gps.

License

The source code is released under:

GNU General Public License

If you think the Android project getback_gps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Custom Ariadne Location object/*ww w.  ja  v  a  2  s.c  o m*/
 *
 * Copyright (C) 2012-2015 Dieter Adriaenssens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package com.github.ruleant.getback_gps.lib
 * @author  Dieter Adriaenssens <ruleant@users.sourceforge.net>
 */
package com.github.ruleant.getback_gps.lib;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.location.Location;
import android.os.Build;

import com.github.ruleant.getback_gps.R;

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

/**
 * Custom Ariadne Location object, it inherits from Location class,
 * but overrides the getString() method.
 *
 * @author  Dieter Adriaenssens <ruleant@users.sourceforge.net>
 */
public class AriadneLocation extends Location {
    /**
     * Location timestamp expiration,
     * 5 minutes in milliseconds (5 * 60 * 1000).
     */
    private static final long LOC_EXPIRE = 300000;

    /**
     * Location name.
     */
    private String mName = null;

    /**
     * Constructor.
     *
     * @param provider Provider name
     */
    public AriadneLocation(final String provider) {
        super(provider);
    }

    /**
     * Constructor.
     *
     * @param location Location object
     */
    public AriadneLocation(final Location location) {
        super(location);
    }

    /**
     * Checks if the timestamp of the provided location
     * is more recent than this location.
     *
     * @param location Location object
     * @return true if location is more recent than this location
     */
    public final boolean isNewer(final Location location) {
        return location.getTime() > super.getTime();
    }

    /**
     * Sets location Name.
     *
     * @param name Location name
     */
    public final void setName(final String name) {
        mName = name;
    }

    /**
     * Gets location Name.
     *
     * @return Location name
     */
    public final String getName() {
        return mName;
    }

    /**
     * Checks if location timestamp is recent.
     *
     * @return true if location is recent.
     */
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public boolean isRecent() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return Tools.isTimestampRecent(getTime(), LOC_EXPIRE);
        } else {
            // use getElapsedRealtimeNanos when using API 17 or higher
            return Tools.isTimestampNanoRecent(getElapsedRealtimeNanos(),
                    LOC_EXPIRE * Tools.MILLI_IN_NANO);
        }
    }

    /**
     * Returns a formatted String representing the object.
     *
     * @param context Context of the App
     * @return formatted string
     */
    public final String toFormattedString(final Context context) {
        Resources res = context.getResources();
        DebugLevel debug = new DebugLevel(context);

        String locationText = "";

        // Location name
        String locationName = getName();
        if (locationName != null && locationName.length() > 0) {
            locationText += " " + res.getString(R.string.name)
                    + ": " + locationName + "\n";
        }

        // Format location
        Latitude latitude = new Latitude(context, getLatitude());
        locationText += " "
                + res.getString(R.string.latitude) + ": " + latitude.format();

        Longitude longitude = new Longitude(context, getLongitude());
        locationText += "\n "
                + res.getString(R.string.longitude) + ": " + longitude.format();

        if (hasAltitude()) {
            locationText += "\n "
                    + res.getString(R.string.altitude) + ": "
                    + FormatUtils.formatDist(getAltitude());
        }
        if (hasBearing()) {
            CardinalDirection cd = new CardinalDirection(context, getBearing());

            locationText += "\n "
                    + res.getString(R.string.bearing) + ": "
                    + cd.format();
        }
        if (hasSpeed()) {
            locationText += "\n "
                    + res.getString(R.string.speed) + ": "
                    + FormatUtils.formatSpeed(getSpeed(), context);
        }
        if (hasAccuracy()) {
            locationText += "\n "
                    + res.getString(R.string.accuracy) + ": "
                    + FormatUtils.formatDist(getAccuracy());
        }

        // Location provider
        String providerName = getProvider();
        if (providerName != null && providerName.length() > 0) {
            locationText += "\n "
                    + res.getString(R.string.provider) + ": "
                    + FormatUtils.localizeProviderName(context, providerName);
        }

        // Format Timestamp
        if (getTime() > 0) {
            Date date = new Date(getTime());
            DateFormat formatter
                    = SimpleDateFormat.getDateTimeInstance();
            locationText += "\n "
                    + res.getString(R.string.timestamp) + ": "
                    + formatter.format(date);

            // display "recent" message
            if (debug.checkDebugLevel(DebugLevel.DEBUG_LEVEL_MEDIUM)) {
                if (isRecent()) {
                    locationText += "\n "
                            + res.getString(R.string.loc_updated_recent);
                } else {
                    locationText += "\n "
                            + res.getString(R.string.loc_updated_not_recent);
                }
            }
        }

        // Display raw when in debug mode
        if (debug.checkDebugLevel(DebugLevel.DEBUG_LEVEL_HIGH)) {
            locationText += "\n\n "
                    + res.getString(R.string.raw) + ": "
                    + toString();
        }

        return locationText;
    }
}




Java Source Code List

com.github.ruleant.getback_gps.AboutActivity.java
com.github.ruleant.getback_gps.AbstractGetBackGpsActivity.java
com.github.ruleant.getback_gps.DetailsActivity.java
com.github.ruleant.getback_gps.LocationService.java
com.github.ruleant.getback_gps.MainActivity.java
com.github.ruleant.getback_gps.NavigationView.java
com.github.ruleant.getback_gps.SettingsActivity.java
com.github.ruleant.getback_gps.lib.AbstractGeoCoordinate.java
com.github.ruleant.getback_gps.lib.AriadneLocation.java
com.github.ruleant.getback_gps.lib.CardinalDirection.java
com.github.ruleant.getback_gps.lib.CircularAverage.java
com.github.ruleant.getback_gps.lib.CoordinateConverterInterface.java
com.github.ruleant.getback_gps.lib.CoordinateRotation.java
com.github.ruleant.getback_gps.lib.Coordinate.java
com.github.ruleant.getback_gps.lib.Coordinates.java
com.github.ruleant.getback_gps.lib.DebugLevel.java
com.github.ruleant.getback_gps.lib.FormatUtils.java
com.github.ruleant.getback_gps.lib.Latitude.java
com.github.ruleant.getback_gps.lib.Longitude.java
com.github.ruleant.getback_gps.lib.LowPassFilter.java
com.github.ruleant.getback_gps.lib.Navigator.java
com.github.ruleant.getback_gps.lib.SensorOrientation.java
com.github.ruleant.getback_gps.lib.StoredDestination.java
com.github.ruleant.getback_gps.lib.StoredLocation.java
com.github.ruleant.getback_gps.lib.Tools.java
com.github.ruleant.getback_gps.lib.package-info.java
com.github.ruleant.getback_gps.package-info.java
com.github.ruleant.unitconversion.UnitConversionInterface.java
com.github.ruleant.unitconversion.package-info.java