mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
added JavaDoc comments
This commit is contained in:
parent
4bb3e58c4e
commit
7e6374f11a
3 changed files with 77 additions and 5 deletions
|
|
@ -37,12 +37,23 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an URL for thumbnail
|
||||
*
|
||||
* @param filename Thumbnail file name
|
||||
* @return URL of thumbnail
|
||||
*/
|
||||
public static String makeThumbBaseUrl(@NonNull String filename) {
|
||||
String name = new PageTitle(filename).getPrefixedText();
|
||||
String sha = new String(Hex.encodeHex(DigestUtils.md5(name)));
|
||||
return String.format("%s/%s/%s/%s", BuildConfig.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes given URL in UTF-8 format
|
||||
* @param url Unformatted URL
|
||||
* @return Formatted URL
|
||||
*/
|
||||
public static String urlEncode(String url) {
|
||||
try {
|
||||
return URLEncoder.encode(url, "utf-8");
|
||||
|
|
@ -61,6 +72,11 @@ public class Utils {
|
|||
return string.substring(0, 1).toUpperCase(Locale.getDefault()) + string.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates licence name with given ID
|
||||
* @param license License ID
|
||||
* @return Name of license
|
||||
*/
|
||||
public static int licenseNameFor(String license) {
|
||||
switch (license) {
|
||||
case Prefs.Licenses.CC_BY_3:
|
||||
|
|
@ -81,6 +97,12 @@ public class Utils {
|
|||
throw new RuntimeException("Unrecognized license value: " + license);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixing incorrect extension
|
||||
* @param title File name
|
||||
* @param extension Correct extension
|
||||
* @return File with correct extension
|
||||
*/
|
||||
public static String fixExtension(String title, String extension) {
|
||||
Pattern jpegPattern = Pattern.compile("\\.jpeg$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
|
|
@ -96,6 +118,11 @@ public class Utils {
|
|||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether dark theme is active or not
|
||||
* @param context Activity context
|
||||
* @return The state of dark theme
|
||||
*/
|
||||
public static boolean isDarkTheme(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("theme", false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,21 @@ public class WelcomeActivity extends BaseActivity {
|
|||
|
||||
private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
|
||||
|
||||
/**
|
||||
* Creates a way to change current activity to WelcomeActivity
|
||||
*
|
||||
* @param context Activity context
|
||||
*/
|
||||
public static void startYourself(Context context) {
|
||||
Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
|
||||
context.startActivity(welcomeIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises exiting fields and dependencies
|
||||
*
|
||||
* @param savedInstanceState WelcomeActivity bundled data
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -30,14 +45,12 @@ public class WelcomeActivity extends BaseActivity {
|
|||
adapter.setCallback(this::finish);
|
||||
}
|
||||
|
||||
/**
|
||||
* References WelcomePageAdapter to null before the activity is destroyed
|
||||
*/
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
adapter.setCallback(null);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public static void startYourself(Context context) {
|
||||
Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
|
||||
context.startActivity(welcomeIntent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,13 @@ public class LengthUtils {
|
|||
return computeAngleBetween(from, to) * 6371009.0D; // Earth's radius in meter
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes angle between two points
|
||||
*
|
||||
* @param from Point A
|
||||
* @param to Point B
|
||||
* @return Angle in radius
|
||||
*/
|
||||
private static double computeAngleBetween(LatLng from, LatLng to) {
|
||||
return distanceRadians(Math.toRadians(from.getLatitude()),
|
||||
Math.toRadians(from.getLongitude()),
|
||||
|
|
@ -44,18 +51,43 @@ public class LengthUtils {
|
|||
Math.toRadians(to.getLongitude()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes arc length between 2 points
|
||||
* @param lat1 Latitude of point A
|
||||
* @param lng1 Longitude of point A
|
||||
* @param lat2 Latitude of point B
|
||||
* @param lng2 Longitude of point B
|
||||
* @return Arc length between the points
|
||||
*/
|
||||
private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) {
|
||||
return arcHav(havDistance(lat1, lat2, lng1 - lng2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets twice the amount of arc sine of (x)^(1/2)
|
||||
* @param x Angle in radian
|
||||
* @return Twice the angle
|
||||
*/
|
||||
private static double arcHav(double x) {
|
||||
return 2.0D * Math.asin(Math.sqrt(x));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes distance between two points that are on same Longitude
|
||||
* @param lat1 Latitude of point A
|
||||
* @param lat2 Latitude of point B
|
||||
* @param longitude Longitude on which they lie
|
||||
* @return Arc length between points
|
||||
*/
|
||||
private static double havDistance(double lat1, double lat2, double longitude) {
|
||||
return hav(lat1 - lat2) + hav(longitude) * Math.cos(lat1) * Math.cos(lat2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes square sine function for half of the value entered
|
||||
* @param x Angle in radians
|
||||
* @return One-forth of square of sine function
|
||||
*/
|
||||
private static double hav(double x) {
|
||||
double sinHalf = Math.sin(x * 0.5D);
|
||||
return sinHalf * sinHalf;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue