Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/utils.java
package it.reyboz.bustorino.backend; | package it.reyboz.bustorino.backend; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.Intent; | import android.content.Intent; | ||||
import android.net.ConnectivityManager; | import android.net.ConnectivityManager; | ||||
import android.net.NetworkInfo; | import android.net.NetworkInfo; | ||||
import android.net.Uri; | import android.net.Uri; | ||||
import android.util.Log; | import android.util.Log; | ||||
import android.util.TypedValue; | import android.util.TypedValue; | ||||
import android.view.View; | import android.view.View; | ||||
import java.io.PrintWriter; | |||||
import java.io.StringWriter; | |||||
public abstract class utils { | public abstract class utils { | ||||
private static final double EarthRadius = 6371e3; | private static final double EarthRadius = 6371e3; | ||||
public static Double measuredistanceBetween(double lat1,double long1,double lat2,double long2){ | public static Double measuredistanceBetween(double lat1,double long1,double lat2,double long2){ | ||||
final double phi1 = Math.toRadians(lat1); | final double phi1 = Math.toRadians(lat1); | ||||
final double phi2 = Math.toRadians(lat2); | final double phi2 = Math.toRadians(lat2); | ||||
final double deltaPhi = Math.toRadians(lat2-lat1); | final double deltaPhi = Math.toRadians(lat2-lat1); | ||||
final double deltaTheta = Math.toRadians(long2-long1); | final double deltaTheta = Math.toRadians(long2-long1); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | public abstract class utils { | ||||
* Open an URL in the default browser. | * Open an URL in the default browser. | ||||
* | * | ||||
* @param url URL | * @param url URL | ||||
*/ | */ | ||||
public static void openIceweasel(String url, Context context) { | public static void openIceweasel(String url, Context context) { | ||||
Intent browserIntent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | Intent browserIntent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | ||||
context.startActivity(browserIntent1); | context.startActivity(browserIntent1); | ||||
} | } | ||||
/** | |||||
* Print the first i lines of the the trace of an exception | |||||
* https://stackoverflow.com/questions/21706722/fetch-only-first-n-lines-of-a-stack-trace | |||||
*/ | |||||
public static String traceCaller(Exception ex, int i) { | |||||
StringWriter sw = new StringWriter(); | |||||
PrintWriter pw = new PrintWriter(sw); | |||||
StringBuilder sb = new StringBuilder(); | |||||
ex.printStackTrace(pw); | |||||
String ss = sw.toString(); | |||||
String[] splitted = ss.split("\n"); | |||||
sb.append("\n"); | |||||
if(splitted.length > 2 + i) { | |||||
for(int x = 2; x < i+2; x++) { | |||||
sb.append(splitted[x].trim()); | |||||
sb.append("\n"); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
return "Trace too Short."; | |||||
} | |||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register