Skip to content

Commit 66a4c04

Browse files
committed
see 02/22 log
1 parent e36f7d1 commit 66a4c04

File tree

3 files changed

+50
-28
lines changed

3 files changed

+50
-28
lines changed

lib/subutil/src/main/java/com/blankj/subutil/util/CoordinateUtils.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,34 @@ public static double[] wgs84ToBd09(double lng, double lat) {
121121
return gcj02ToBd09(gcj[0], gcj[1]);
122122
}
123123

124+
/**
125+
* Mercator 坐标转 WGS84 坐标
126+
*
127+
* @param lng Mercator 坐标经度
128+
* @param lat Mercator 坐标纬度
129+
* @return WGS84 坐标:[经度,纬度]
130+
*/
131+
public static double[] mercatorToWGS84(double lng, double lat) {
132+
double x = lng / 20037508.34d * 180.;
133+
double y = lat / 20037508.34d * 180.;
134+
y = 180 / PI * (2 * Math.atan(Math.exp(y * PI / 180.0)) - PI / 2);
135+
return new double[]{x, y};
136+
}
137+
138+
/**
139+
* WGS84 坐标转 Mercator 坐标
140+
*
141+
* @param lng WGS84 坐标经度
142+
* @param lat WGS84 坐标纬度
143+
* @return Mercator 坐标:[经度,纬度]
144+
*/
145+
public static double[] wgs84ToMercator(double lng, double lat) {
146+
double x = lng * 20037508.34D / 180.0;
147+
double y = Math.log(Math.tan((90.0 + lat) * PI / 360.0)) / (PI / 180.);
148+
y = y * 20037508.34D / 180.0;
149+
return new double[]{x, y};
150+
}
151+
124152
private static double transformLat(double lng, double lat) {
125153
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));
126154
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;

lib/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ public static Intent getComponentIntent(final String pkgName,
389389
public static Intent getShutdownIntent() {
390390
Intent intent;
391391
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
392-
intent = new Intent(Intent.ACTION_SHUTDOWN);
393-
} else {
394392
intent = new Intent("com.android.internal.intent.action.REQUEST_SHUTDOWN");
393+
} else {
394+
intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
395395
}
396396
intent.putExtra("android.intent.extra.KEY_CONFIRM", false);
397397
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

lib/utilcode/src/main/java/com/blankj/utilcode/util/ScreenUtils.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,74 +112,68 @@ public static float getScreenDensity() {
112112
public static int getScreenDensityDpi() {
113113
return Resources.getSystem().getDisplayMetrics().densityDpi;
114114
}
115-
116-
117-
118-
115+
119116
/**
120-
* Return X (width) of the screen expressed as dots-per-inch.
117+
* Return the exact physical pixels per inch of the screen in the Y dimension.
121118
*
122-
* @return the width of screen density expressed as dots-per-inch
119+
* @return the exact physical pixels per inch of the screen in the Y dimension
123120
*/
124-
public static int getScreenXDpi() {
121+
public static float getScreenXDpi() {
125122
return Resources.getSystem().getDisplayMetrics().xdpi;
126123
}
127-
124+
128125
/**
129-
* Return Y (height) of the screen expressed as dots-per-inch.
126+
* Return the exact physical pixels per inch of the screen in the Y dimension.
130127
*
131-
* @return the height of screen density expressed as dots-per-inch
128+
* @return the exact physical pixels per inch of the screen in the Y dimension
132129
*/
133-
public static int getScreenYDpi() {
130+
public static float getScreenYDpi() {
134131
return Resources.getSystem().getDisplayMetrics().ydpi;
135132
}
136-
137-
138-
133+
139134
/**
140135
* Return the distance between the given View's X (start point of View's width) and the screen width.
141136
*
142137
* @return the distance between the given View's X (start point of View's width) and the screen width.
143138
*/
144-
public float calculateDistanceByX(View view) {
145-
int[] point = new int[0];
139+
public int calculateDistanceByX(View view) {
140+
int[] point = new int[2];
146141
view.getLocationOnScreen(point);
147-
return (getScreenWidth() - point[0]).toFloat();
142+
return getScreenWidth() - point[0];
148143
}
149144

150145
/**
151146
* Return the distance between the given View's Y (start point of View's height) and the screen height.
152147
*
153148
* @return the distance between the given View's Y (start point of View's height) and the screen height.
154149
*/
155-
public float calculateDistanceByY(View view) {
156-
int[] point = new int[0];
150+
public int calculateDistanceByY(View view) {
151+
int[] point = new int[2];
157152
view.getLocationOnScreen(point);
158-
return (getScreenHeight() - point[1]).toFloat();
153+
return getScreenHeight() - point[1];
159154
}
160155

161156
/**
162157
* Return the X coordinate of the given View on the screen.
163158
*
164159
* @return X coordinate of the given View on the screen.
165160
*/
166-
public int getViewX(View view){
167-
int[] point = new int[0];
161+
public int getViewX(View view) {
162+
int[] point = new int[2];
168163
view.getLocationOnScreen(point);
169164
return point[0];
170165
}
171-
166+
172167
/**
173168
* Return the Y coordinate of the given View on the screen.
174169
*
175170
* @return Y coordinate of the given View on the screen.
176171
*/
177-
public int getViewY(View view){
178-
int[] point = new int[0];
172+
public int getViewY(View view) {
173+
int[] point = new int[2];
179174
view.getLocationOnScreen(point);
180175
return point[1];
181176
}
182-
183177

184178
/**
185179
* Set full screen.

0 commit comments

Comments
 (0)