This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculate distance between two gps points based in Haversine formula: http://en.wikipedia.org/wiki/Haversine_formula | |
* | |
* @param latitude1 GPS point 1 Latitude | |
* @param longitude1 GPS point 1 Longitude | |
* @param latitude2 GPS point 2 Latitude | |
* @param longitude2 GPS point 1 Longitude | |
* @return Distance in kilometers (km) | |
*/ | |
static double haversineDistance(float latitude1, float longitude1, float latitude2, float longitude2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert an unsigned integer to signed (keeping binary value) | |
* | |
* @param binary Integer whose binary value need to convert | |
* @return A byte with same binary than income integer | |
*/ | |
private static byte fromBinaryToByte(int binary) | |
{ | |
byte result = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a latitude/longitude in NMEA format to grades (4322.0399N to 43.36715) | |
* @param lat_or_long latitude/longitude in NMEA format | |
* @return GPS latitude/longitude in grades | |
*/ | |
public static float convertLatLon(String lat_or_long) | |
{ | |
int number_of_decimals = 4; // Número de decimales de los grados | |
String minute = lat_or_long.substring(lat_or_long.length() - (4 + number_of_decimals), lat_or_long.length() - 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final static DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()); | |
DATE_FORMAT.format(new Date()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts an object to a byte array | |
* | |
* @param object Object to convert (must implement Serializable) | |
* @return The object in byte[] | |
*/ | |
public static byte[] objectToByte(Object object) | |
{ | |
byte[] result = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts an object in byte[] to Object | |
* | |
* @param object Object in byte[] | |
* @return The original Object | |
*/ | |
public static Object byteToObject(byte[] object) | |
{ | |
Object result = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String convertTime(long start_time, long end_time) | |
{ | |
String result = "00:00:00"; | |
if (end_time > start_time) | |
{ | |
long time = end_time - start_time; | |
long time_hour = TimeUnit.MILLISECONDS.toHours(time); | |
time -= TimeUnit.HOURS.toMillis(time_hour); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScheduledExecutorService mScheduledExecutorService = Executors.newScheduledThreadPool(1);; | |
Future<?> mFuture = mScheduledExecutorService.scheduleAtFixedRate(new Runnable() | |
{ | |
public void run() | |
{ | |
// Task to do periodically | |
} | |
}, 0L, updateTime, TimeUnit.SECONDS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class MyTask extends AsyncTask<Void, String, Boolean> | |
{ | |
private ProgessDialog mProgressDialog; | |
public MyTask() | |
{ | |
mProgressDialog = new ProgressDialog(mActivity); | |
mProgressDialog.setTitle("ProgressDialog title"); | |
mProgressDialog.setMessage("ProgressDialog message..."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save to storage/folder/ | |
File fileDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folder/"); | |
fileDir.mkdirs(); | |
String name = "file.txt"; | |
File mFile = new File(fileDir, name); | |
BufferedWriter writer = null; | |
try | |
{ |
OlderNewer