提交 2a2887c8 编写于 作者: B Blankj

see 03/29 log

上级 897ba1b5
......@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.5-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.6-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -41,7 +41,7 @@ If this ptoject helps you a lot, and you would like to support this ptoject's fu
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.5-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.6-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -48,7 +48,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':utilcode')
// implementation project(':utilcode')
implementation project(':subutil')
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
......@@ -56,7 +56,7 @@ dependencies {
// LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
// implementation 'com.blankj:utilcode:1.13.5'
implementation 'com.blankj:utilcode:1.13.6'
}
......@@ -65,7 +65,7 @@ public class BarStatusFragmentActivity extends BaseActivity {
mFragmentList.add(BarStatusAlphaFragment.newInstance());
mFragmentList.add(BarStatusImageViewFragment.newInstance());
mVpStatusBar.setOffscreenPageLimit(2);
mVpStatusBar.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
......@@ -96,7 +96,6 @@ public class BarStatusFragmentActivity extends BaseActivity {
});
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
@Override
......
......@@ -33,8 +33,8 @@ ext {
min_sdk_version = 14
target_sdk_version = 27
version_code = 1_013_005
version_name = '1.13.5'// E.g 1.9.72 => 1,009,072
version_code = 1_013_006
version_name = '1.13.6'// E.g 1.9.72 => 1,009,072
// App dependencies
support_version = '27.0.2'
......
package com.blankj.subutil.util;
import android.util.Log;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/03/21
* desc :
* </pre>
*/
public class BitUtils {
private BitUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 获取运算数指定位置的值<br>
* 例如: 0000 1011 获取其第 0 位的值为 1, 第 2 位 的值为 0<br>
*
* @param source 需要运算的数
* @param pos 指定位置 (0...7)
* @return 指定位置的值(0 or 1)
*/
public static byte getBitValue(byte source, int pos) {
return (byte) ((source >> pos) & 1);
}
/**
* 将运算数指定位置的值置为指定值<br>
* 例: 0000 1011 需要更新为 0000 1111, 即第 2 位的值需要置为 1<br>
*
* @param source 需要运算的数
* @param pos 指定位置 (0<=pos<=7)
* @param value 只能取值为 0, 或 1, 所有大于0的值作为1处理, 所有小于0的值作为0处理
* @return 运算后的结果数
*/
public static byte setBitValue(byte source, int pos, byte value) {
byte mask = (byte) (1 << pos);
if (value > 0) {
source |= mask;
} else {
source &= (~mask);
}
return source;
}
/**
* 将运算数指定位置取反值<br>
* 例: 0000 1011 指定第 3 位取反, 结果为 0000 0011; 指定第2位取反, 结果为 0000 1111<br>
*
* @param source
* @param pos 指定位置 (0<=pos<=7)
* @return 运算后的结果数
*/
public static byte reverseBitValue(byte source, int pos) {
byte mask = (byte) (1 << pos);
return (byte) (source ^ mask);
}
/**
* 检查运算数的指定位置是否为1<br>
*
* @param source 需要运算的数
* @param pos 指定位置 (0<=pos<=7)
* @return true 表示指定位置值为1, false 表示指定位置值为 0
*/
public static boolean checkBitValue(byte source, int pos) {
source = (byte) (source >>> pos);
return (source & 1) == 1;
}
/**
* 入口函数做测试<br>
*
* @param args
*/
public static void main(String[] args) {
// 取十进制 11 (二级制 0000 1011) 为例子
byte source = 11;
// 取第2位值并输出, 结果应为 0000 1011
for (byte i = 7; i >= 0; i--) {
Log.d("BitUtils", getBitValue(source, i) + "");
}
// 将第6位置为1并输出 , 结果为 75 (0100 1011)
Log.d("BitUtils", setBitValue(source, 6, (byte) 1) + "");
// 将第6位取反并输出, 结果应为75(0100 1011)
Log.d("BitUtils", reverseBitValue(source, 6) + "");
// 检查第6位是否为1,结果应为false
Log.d("BitUtils", checkBitValue(source, 6) + "");
// 输出为1的位, 结果应为 0 1 3
for (byte i = 0; i < 8; i++) {
if (checkBitValue(source, i)) {
Log.d("BitUtils", i + "");
}
}
}
}
package com.blankj.subutil.util;
import static java.lang.Math.PI;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/03/21
* desc :
* </pre>
*/
public class CoordinateConvertUtils {
private final static double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
private final static double A = 6378245.0;
private final static double EE = 0.00669342162296594323;
/**
* BD09 坐标转 GCJ02 坐标
*
* @param lng BD09 坐标纬度
* @param lat BD09 坐标经度
* @return GCJ02 坐标:[经度,纬度]
*/
public static double[] bd09ToGcj02(double lng, double lat) {
double x = lng - 0.0065;
double y = lat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
double gg_lng = z * Math.cos(theta);
double gg_lat = z * Math.sin(theta);
return new double[]{gg_lng, gg_lat};
}
/**
* GCJ02 坐标转 BD09 坐标
*
* @param lng GCJ02 坐标经度
* @param lat GCJ02 坐标纬度
* @return BD09 坐标:[经度,纬度]
*/
public static double[] gcj02ToBd09(double lng, double lat) {
double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * X_PI);
double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * X_PI);
double bd_lng = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
return new double[]{bd_lng, bd_lat};
}
/**
* GCJ02 坐标转 WGS84 坐标
*
* @param lng GCJ02 坐标经度
* @param lat GCJ02 坐标纬度
* @return WGS84 坐标:[经度,纬度]
*/
public static double[] gcj02ToWGS84(double lng, double lat) {
if (outOfChina(lng, lat)) {
return new double[]{lng, lat};
}
double dlat = transformLat(lng - 105.0, lat - 35.0);
double dlng = transformLng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * PI;
double magic = Math.sin(radlat);
magic = 1 - EE * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((A * (1 - EE)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (A / sqrtmagic * Math.cos(radlat) * PI);
double mglat = lat + dlat;
double mglng = lng + dlng;
return new double[]{lng * 2 - mglng, lat * 2 - mglat};
}
/**
* WGS84 坐标 转 GCJ02 坐标
*
* @param lng WGS84 坐标经度
* @param lat WGS84 坐标纬度
* @return GCJ02 坐标:[经度,纬度]
*/
public static double[] wgs84ToGcj02(double lng, double lat) {
if (outOfChina(lng, lat)) {
return new double[]{lng, lat};
}
double dlat = transformLat(lng - 105.0, lat - 35.0);
double dlng = transformLng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * PI;
double magic = Math.sin(radlat);
magic = 1 - EE * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((A * (1 - EE)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (A / sqrtmagic * Math.cos(radlat) * PI);
double mglat = lat + dlat;
double mglng = lng + dlng;
return new double[]{mglng, mglat};
}
/**
* BD09 坐标 转 WGS84 坐标
*
* @param lng BD09 坐标经度
* @param lat BD09 坐标纬度
* @return WGS84 坐标:[经度,纬度]
*/
public static double[] bd09ToWGS84(double lng, double lat) {
double[] gcj = bd09ToGcj02(lng, lat);
return gcj02ToWGS84(gcj[0], gcj[1]);
}
/**
* WGS84 坐标转 BD09 坐标
*
* @param lng WGS84 坐标经度
* @param lat WGS84 坐标纬度
* @return BD09 坐标:[经度,纬度]
*/
public static double[] wgs84ToBd09(double lng, double lat) {
double[] gcj = wgs84ToGcj02(lng, lat);
return gcj02ToBd09(gcj[0], gcj[1]);
}
private static double transformLat(double lng, double lat) {
double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
return ret;
}
private static double transformLng(double lng, double lat) {
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
return ret;
}
/**
* 判断坐标是否不在国内
*
* @param lng 经度
* @param lat 纬度
* @return 坐标是否在国内
*/
public static boolean outOfChina(double lng, double lat) {
return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271;
}
}
package com.blankj.subutil.util;
import org.junit.Assert;
import org.junit.Test;
import static java.lang.Math.PI;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/03/22
* desc :
* </pre>
*/
public class CoordinateConvertUtilsTest {
// 以下为各个坐标系的 天安门坐标
private static final double[] locationWGS84 = new double[]{116.3912022800, 39.9075017400};
private static final double[] locationGCJ02 = new double[]{116.3973900000, 39.9088600000};
private static final double[] locationBD09 = new double[]{116.4038206839, 39.9152478931};
// 以下为美国纽约坐标
private static final double[] newyorkWGS84 = new double[]{-74.0059413000, 40.7127837000};
@Test
public void gcj2BD09() throws Exception {
double[] BD09 = CoordinateConvertUtils.gcj02ToBd09(locationGCJ02[0], locationGCJ02[1]);
double distance = distance(locationBD09[0], locationBD09[1], BD09[0], BD09[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void bd092GCJ() {
double[] GCJ02 = CoordinateConvertUtils.bd09ToGcj02(locationBD09[0], locationBD09[1]);
double distance = distance(locationGCJ02[0], locationGCJ02[1], GCJ02[0], GCJ02[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void bd092WGS() {
double[] WGS84 = CoordinateConvertUtils.bd09ToWGS84(locationBD09[0], locationBD09[1]);
double distance = distance(locationWGS84[0], locationWGS84[1], WGS84[0], WGS84[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void wgs2BD09() {
double[] BD09 = CoordinateConvertUtils.wgs84ToBd09(locationWGS84[0], locationWGS84[1]);
double distance = distance(locationBD09[0], locationBD09[1], BD09[0], BD09[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void wgs2GCJ() {
double[] GCJ02 = CoordinateConvertUtils.wgs84ToGcj02(locationWGS84[0], locationWGS84[1]);
double distance = distance(locationGCJ02[0], locationGCJ02[1], GCJ02[0], GCJ02[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void gcj2WGS() {
double[] WGS84 = CoordinateConvertUtils.gcj02ToWGS84(locationGCJ02[0], locationGCJ02[1]);
double distance = distance(locationWGS84[0], locationWGS84[1], WGS84[0], WGS84[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void gcj2WGSExactly() {
double[] WGS84 = CoordinateConvertUtils.gcj02ToWGS84(locationGCJ02[0], locationGCJ02[1]);
double distance = distance(locationWGS84[0], locationWGS84[1], WGS84[0], WGS84[1]);
System.out.println("distance: " + distance);
Assert.assertTrue(distance < 10);
}
@Test
public void outOfChina() {
Assert.assertFalse(CoordinateConvertUtils.outOfChina(locationWGS84[0], locationWGS84[1]));
Assert.assertTrue(CoordinateConvertUtils.outOfChina(newyorkWGS84[0], newyorkWGS84[1]));
}
public static double distance(double lngA, double latA, double lngB, double latB) {
int earthR = 6371000;
double x = Math.cos(latA * PI / 180) * Math.cos(latB * PI / 180) * Math.cos((lngA - lngB) * PI / 180);
double y = Math.sin(latA * PI / 180) * Math.sin(latB * PI / 180);
double s = x + y;
if (s > 1)
s = 1;
if (s < -1)
s = -1;
double alpha = Math.acos(s);
return alpha * earthR;
}
}
\ No newline at end of file
* 18/03/29 兼容 Utils 的初始化传入 application,发布 1.13.6 版本
* 18/03/20 修复 PermissionUtils 子进程的问题,发布 1.13.5 版本
* 18/03/16 新增 gradle 插件来格式化 README
* 18/03/14 修复 KeyboardUtils#getContentViewInvisibleHeight,发布 1.13.4 版本
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
compile 'com.blankj:utilcode:1.13.5'
compile 'com.blankj:utilcode:1.13.6'
```
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
compile 'com.blankj:utilcode:1.13.5'
compile 'com.blankj:utilcode:1.13.6'
```
......
......@@ -88,6 +88,17 @@ public final class Utils {
Utils.sApplication.registerActivityLifecycleCallbacks(mCallbacks);
}
/**
* Init utils.
* <p>Init it in the class of Application.</p>
*
* @param application application
*/
public static void init(@NonNull final Application application) {
Utils.sApplication = application;
Utils.sApplication.registerActivityLifecycleCallbacks(mCallbacks);
}
/**
* Return the context of Application object.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册