forked from upstream-mirrors/OpenTracks
Fix TCX export
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracks;
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
|
||||
import com.google.android.maps.GeoPoint;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -38,7 +38,7 @@ import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Utility class for decimating tracks at a given level of precision.
|
||||
*
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class MyTracksUtils {
|
||||
@@ -47,7 +47,7 @@ public class MyTracksUtils {
|
||||
/**
|
||||
* Computes the distance on the two sphere between the point c0 and the line
|
||||
* segment c1 to c2.
|
||||
*
|
||||
*
|
||||
* @param c0 the first coordinate
|
||||
* @param c1 the beginning of the line segment
|
||||
* @param c2 the end of the lone segment
|
||||
@@ -89,7 +89,7 @@ public class MyTracksUtils {
|
||||
/**
|
||||
* Decimates the given locations for a given zoom level. This uses a
|
||||
* Douglas-Peucker decimation algorithm.
|
||||
*
|
||||
*
|
||||
* @param tolerance in meters
|
||||
* @param locations input
|
||||
* @param decimated output
|
||||
@@ -152,7 +152,7 @@ public class MyTracksUtils {
|
||||
|
||||
/**
|
||||
* Decimates the given track for the given precision.
|
||||
*
|
||||
*
|
||||
* @param track a track
|
||||
* @param precision desired precision in meters
|
||||
*/
|
||||
@@ -165,7 +165,7 @@ public class MyTracksUtils {
|
||||
/**
|
||||
* Limits number of points by dropping any points beyond the given number of
|
||||
* points. Note: That'll actually discard points.
|
||||
*
|
||||
*
|
||||
* @param track a track
|
||||
* @param numberOfPoints maximum number of points
|
||||
*/
|
||||
@@ -179,7 +179,7 @@ public class MyTracksUtils {
|
||||
/**
|
||||
* Splits a track in multiple tracks where each piece has less or equal than
|
||||
* maxPoints.
|
||||
*
|
||||
*
|
||||
* @param track the track to split
|
||||
* @param maxPoints maximum number of points for each piece
|
||||
* @return a list of one or more track pieces
|
||||
@@ -214,7 +214,7 @@ public class MyTracksUtils {
|
||||
|
||||
/**
|
||||
* Test if a given GeoPoint is valid, i.e. within physical bounds.
|
||||
*
|
||||
*
|
||||
* @param geoPoint the point to be tested
|
||||
* @return true, if it is a physical location on earth.
|
||||
*/
|
||||
@@ -228,7 +228,7 @@ public class MyTracksUtils {
|
||||
* on Earth. Note: The special separator locations (which have latitude =
|
||||
* 100) will not qualify as valid. Neither will locations with lat=0 and lng=0
|
||||
* as these are most likely "bad" measurements which often cause trouble.
|
||||
*
|
||||
*
|
||||
* @param location the location to test
|
||||
* @return true if the location is a valid location.
|
||||
*/
|
||||
@@ -239,7 +239,7 @@ public class MyTracksUtils {
|
||||
|
||||
/**
|
||||
* Gets a location from a GeoPoint.
|
||||
*
|
||||
*
|
||||
* @param p a GeoPoint
|
||||
* @return the corresponding location
|
||||
*/
|
||||
@@ -259,37 +259,69 @@ public class MyTracksUtils {
|
||||
* Returns whether or not this is a release build.
|
||||
*/
|
||||
public static boolean isRelease(Context context) {
|
||||
try {
|
||||
Signature [] sigs = context.getPackageManager().getPackageInfo(
|
||||
context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
|
||||
for (Signature sig : sigs) {
|
||||
if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to get signatures", e);
|
||||
PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_SIGNATURES);
|
||||
if (packageInfo == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Signature sig: packageInfo.signatures) {
|
||||
if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see isRelease(Context)
|
||||
*/
|
||||
public static boolean isRelease() {
|
||||
return isRelease(MyTracks.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the My Tracks version from the manifest.
|
||||
*
|
||||
* @return the version, or an empty string in case of failure.
|
||||
*/
|
||||
public static String getMyTracksVersion(Context context) {
|
||||
PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_META_DATA);
|
||||
return packageInfo == null ? "" : packageInfo.versionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see getMyTracksVersion(Context)
|
||||
*/
|
||||
public static String getMyTracksVersion() {
|
||||
return getMyTracksVersion(MyTracks.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the My Tracks version code from the manifest.
|
||||
*
|
||||
* @return the version code, or an empty string in case of failure.
|
||||
*/
|
||||
public static int getMyTracksVersionCode() {
|
||||
PackageInfo packageInfo = getPackageInfo(MyTracks.getInstance(),
|
||||
PackageManager.GET_META_DATA);
|
||||
return packageInfo == null ? -1 : packageInfo.versionCode;
|
||||
}
|
||||
|
||||
private static PackageInfo getPackageInfo(Context context, int flags) {
|
||||
if (context == null) {
|
||||
Log.w(MyTracksConstants.TAG, "No context found when attempting to get version");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
PackageInfo pi = context.getPackageManager().getPackageInfo(
|
||||
"com.google.android.maps.mytracks",
|
||||
PackageManager.GET_META_DATA);
|
||||
return pi.versionName;
|
||||
return context.getPackageManager().getPackageInfo(
|
||||
"com.google.android.maps.mytracks", flags);
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.w(MyTracksConstants.TAG, "Failed to get version info.", e);
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries to acquire a partial wake lock if not already acquired. Logs errors
|
||||
* and gives up trying in case the wake lock cannot be acquired.
|
||||
|
||||
Reference in New Issue
Block a user