diff options
Diffstat (limited to 'main/src/cgeo/geocaching/cgBase.java')
-rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 152 |
1 files changed, 0 insertions, 152 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index b26b8c8..38b404e 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -2595,158 +2595,6 @@ public class cgBase { } } - public static boolean isInViewPort(int centerLat1, int centerLon1, int centerLat2, int centerLon2, int spanLat1, int spanLon1, int spanLat2, int spanLon2) { - try { - // expects coordinates in E6 format - final int left1 = centerLat1 - (spanLat1 / 2); - final int right1 = centerLat1 + (spanLat1 / 2); - final int top1 = centerLon1 + (spanLon1 / 2); - final int bottom1 = centerLon1 - (spanLon1 / 2); - - final int left2 = centerLat2 - (spanLat2 / 2); - final int right2 = centerLat2 + (spanLat2 / 2); - final int top2 = centerLon2 + (spanLon2 / 2); - final int bottom2 = centerLon2 - (spanLon2 / 2); - - if (left2 <= left1) { - return false; - } - if (right2 >= right1) { - return false; - } - if (top2 >= top1) { - return false; - } - if (bottom2 <= bottom1) { - return false; - } - - return true; - } catch (Exception e) { - Log.e(Settings.tag, "cgBase.isInViewPort: " + e.toString()); - return false; - } - } - - // viewport is defined by center, span and some (10%) reserve on every side - /** - * Check if coordinates are located in a viewport (defined by its center and span - * in each direction). The viewport also includes a 10% extension on each side. - * - * @param centerLat - * the viewport center latitude - * @param centerLon - * the viewport center longitude - * @param spanLat - * the latitude span - * @param spanLon - * the longitude span - * @param coords - * the coordinates to check - * @return true if the coordinates are in the viewport - */ - public static boolean isCacheInViewPort(int centerLat, int centerLon, int spanLat, int spanLon, final Geopoint coords) { - return Math.abs(coords.getLatitudeE6() - centerLat) <= Math.abs(spanLat) * 0.6 && - Math.abs(coords.getLongitudeE6() - centerLon) <= Math.abs(spanLon) * 0.6; - } - - private static char[] base64map1 = new char[64]; - - static { - int i = 0; - for (char c = 'A'; c <= 'Z'; c++) { - base64map1[i++] = c; - } - for (char c = 'a'; c <= 'z'; c++) { - base64map1[i++] = c; - } - for (char c = '0'; c <= '9'; c++) { - base64map1[i++] = c; - } - base64map1[i++] = '+'; - base64map1[i++] = '/'; - } - private static byte[] base64map2 = new byte[128]; - - static { - for (int i = 0; i < base64map2.length; i++) { - base64map2[i] = -1; - } - for (int i = 0; i < 64; i++) { - base64map2[base64map1[i]] = (byte) i; - } - } - - public static String base64Encode(byte[] in) { - int iLen = in.length; - int oDataLen = (iLen * 4 + 2) / 3; // output length without padding - int oLen = ((iLen + 2) / 3) * 4; // output length including padding - char[] out = new char[oLen]; - int ip = 0; - int op = 0; - - while (ip < iLen) { - int i0 = in[ip++] & 0xff; - int i1 = ip < iLen ? in[ip++] & 0xff : 0; - int i2 = ip < iLen ? in[ip++] & 0xff : 0; - int o0 = i0 >>> 2; - int o1 = ((i0 & 3) << 4) | (i1 >>> 4); - int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6); - int o3 = i2 & 0x3F; - out[op++] = base64map1[o0]; - out[op++] = base64map1[o1]; - out[op] = op < oDataLen ? base64map1[o2] : '='; - op++; - out[op] = op < oDataLen ? base64map1[o3] : '='; - op++; - } - - return new String(out); - } - - public static byte[] base64Decode(String text) { - char[] in = text.toCharArray(); - - int iLen = in.length; - if (iLen % 4 != 0) { - throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4."); - } - while (iLen > 0 && in[iLen - 1] == '=') { - iLen--; - } - int oLen = (iLen * 3) / 4; - byte[] out = new byte[oLen]; - int ip = 0; - int op = 0; - while (ip < iLen) { - int i0 = in[ip++]; - int i1 = in[ip++]; - int i2 = ip < iLen ? in[ip++] : 'A'; - int i3 = ip < iLen ? in[ip++] : 'A'; - if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127) { - throw new IllegalArgumentException("Illegal character in Base64 encoded data."); - } - int b0 = base64map2[i0]; - int b1 = base64map2[i1]; - int b2 = base64map2[i2]; - int b3 = base64map2[i3]; - if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0) { - throw new IllegalArgumentException("Illegal character in Base64 encoded data."); - } - int o0 = (b0 << 2) | (b1 >>> 4); - int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2); - int o2 = ((b2 & 3) << 6) | b3; - out[op++] = (byte) o0; - if (op < oLen) { - out[op++] = (byte) o1; - } - if (op < oLen) { - out[op++] = (byte) o2; - } - } - return out; - } - public static boolean runNavigation(Activity activity, Resources res, Settings settings, final Geopoint coords) { return runNavigation(activity, res, settings, coords, null); } |