Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
309c2f00
A
AndroidUtilCode
项目概览
mmm-rain
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
309c2f00
编写于
11月 23, 2016
作者:
C
cmj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 11/23 log
上级
bed457ee
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
41 addition
and
45 deletion
+41
-45
README-CN.md
README-CN.md
+1
-1
README.md
README.md
+1
-1
app/src/main/java/com/blankj/androidutilcode/Services/LocationService.java
.../com/blankj/androidutilcode/Services/LocationService.java
+21
-34
app/src/main/java/com/blankj/androidutilcode/activities/LocationActivity.java
...m/blankj/androidutilcode/activities/LocationActivity.java
+10
-1
update_log.md
update_log.md
+2
-0
utilcode/build.gradle
utilcode/build.gradle
+3
-3
utilcode/src/main/java/com/blankj/utilcode/utils/LocationUtils.java
...rc/main/java/com/blankj/utilcode/utils/LocationUtils.java
+3
-5
未找到文件。
README-CN.md
浏览文件 @
309c2f00
...
@@ -502,7 +502,7 @@ getEntries : 获取压缩文件中的文件对象
...
@@ -502,7 +502,7 @@ getEntries : 获取压缩文件中的文件对象
***
***
Gradle:
Gradle:
```
groovy
```
groovy
compile
'com.blankj:utilcode:1.3.
3
'
compile
'com.blankj:utilcode:1.3.
4
'
```
```
### Proguard
### Proguard
...
...
README.md
浏览文件 @
309c2f00
...
@@ -502,7 +502,7 @@ getEntries
...
@@ -502,7 +502,7 @@ getEntries
***
***
Gradle:
Gradle:
```
groovy
```
groovy
compile
'com.blankj:utilcode:1.3.
3
'
compile
'com.blankj:utilcode:1.3.
4
'
```
```
### Proguard
### Proguard
...
...
app/src/main/java/com/blankj/androidutilcode/Services/LocationService.java
浏览文件 @
309c2f00
...
@@ -11,6 +11,7 @@ import android.support.annotation.Nullable;
...
@@ -11,6 +11,7 @@ import android.support.annotation.Nullable;
import
com.blankj.androidutilcode.App
;
import
com.blankj.androidutilcode.App
;
import
com.blankj.utilcode.utils.LocationUtils
;
import
com.blankj.utilcode.utils.LocationUtils
;
import
com.blankj.utilcode.utils.ThreadPoolUtils
;
import
com.blankj.utilcode.utils.ToastUtils
;
import
com.blankj.utilcode.utils.ToastUtils
;
/**
/**
...
@@ -23,8 +24,8 @@ import com.blankj.utilcode.utils.ToastUtils;
...
@@ -23,8 +24,8 @@ import com.blankj.utilcode.utils.ToastUtils;
*/
*/
public
class
LocationService
extends
Service
{
public
class
LocationService
extends
Service
{
private
boolean
isSuccess
;
private
boolean
isSuccess
;
private
LocationUtils
locationUtils
;
private
LocationUtils
locationUtils
;
private
String
lastLatitude
=
"loading..."
;
private
String
lastLatitude
=
"loading..."
;
private
String
lastLongitude
=
"loading..."
;
private
String
lastLongitude
=
"loading..."
;
private
String
latitude
=
"loading..."
;
private
String
latitude
=
"loading..."
;
...
@@ -33,36 +34,11 @@ public class LocationService extends Service {
...
@@ -33,36 +34,11 @@ public class LocationService extends Service {
private
String
locality
=
"loading..."
;
private
String
locality
=
"loading..."
;
private
String
street
=
"loading..."
;
private
String
street
=
"loading..."
;
private
OnGetLocationListener
mOnGetLocationListener
;
private
OnGetLocationListener
mOnGetLocationListener
;
private
Thread
mThread
;
public
void
setOnGetLocationListener
(
OnGetLocationListener
onGetLocationListener
)
{
public
void
setOnGetLocationListener
(
OnGetLocationListener
onGetLocationListener
)
{
mOnGetLocationListener
=
onGetLocationListener
;
mOnGetLocationListener
=
onGetLocationListener
;
}
}
@Override
public
void
onCreate
()
{
super
.
onCreate
();
mThread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Looper
.
prepare
();
locationUtils
=
new
LocationUtils
(
App
.
getInstance
());
isSuccess
=
locationUtils
.
init
(
1000
,
0
,
mOnLocationChangeListener
);
if
(
isSuccess
)
{
ToastUtils
.
showShortToastSafe
(
App
.
getInstance
(),
"init success"
);
}
else
{
ToastUtils
.
showShortToastSafe
(
App
.
getInstance
(),
"init fail"
);
if
(
mOnGetLocationListener
!=
null
)
{
mOnGetLocationListener
.
getLocation
(
"unknown"
,
"unknown"
,
"unknown"
,
"unknown"
,
"unknown"
,
"unknown"
,
"unknown"
);
}
}
Looper
.
loop
();
}
});
mThread
.
start
();
}
private
LocationUtils
.
OnLocationChangeListener
mOnLocationChangeListener
=
new
LocationUtils
.
OnLocationChangeListener
()
{
private
LocationUtils
.
OnLocationChangeListener
mOnLocationChangeListener
=
new
LocationUtils
.
OnLocationChangeListener
()
{
@Override
@Override
public
void
getLastKnownLocation
(
Location
location
)
{
public
void
getLastKnownLocation
(
Location
location
)
{
...
@@ -80,18 +56,12 @@ public class LocationService extends Service {
...
@@ -80,18 +56,12 @@ public class LocationService extends Service {
if
(
mOnGetLocationListener
!=
null
)
{
if
(
mOnGetLocationListener
!=
null
)
{
mOnGetLocationListener
.
getLocation
(
lastLatitude
,
lastLongitude
,
latitude
,
longitude
,
country
,
locality
,
street
);
mOnGetLocationListener
.
getLocation
(
lastLatitude
,
lastLongitude
,
latitude
,
longitude
,
country
,
locality
,
street
);
}
}
// 开启新线程来获取地理位置
// new Thread(new Runnable() {
// @Override
// public void run() {
country
=
locationUtils
.
getCountryName
(
Double
.
parseDouble
(
latitude
),
Double
.
parseDouble
(
longitude
));
country
=
locationUtils
.
getCountryName
(
Double
.
parseDouble
(
latitude
),
Double
.
parseDouble
(
longitude
));
locality
=
locationUtils
.
getLocality
(
Double
.
parseDouble
(
latitude
),
Double
.
parseDouble
(
longitude
));
locality
=
locationUtils
.
getLocality
(
Double
.
parseDouble
(
latitude
),
Double
.
parseDouble
(
longitude
));
street
=
locationUtils
.
getStreet
(
Double
.
parseDouble
(
latitude
),
Double
.
parseDouble
(
longitude
));
street
=
locationUtils
.
getStreet
(
Double
.
parseDouble
(
latitude
),
Double
.
parseDouble
(
longitude
));
if
(
mOnGetLocationListener
!=
null
)
{
if
(
mOnGetLocationListener
!=
null
)
{
mOnGetLocationListener
.
getLocation
(
lastLatitude
,
lastLongitude
,
latitude
,
longitude
,
country
,
locality
,
street
);
mOnGetLocationListener
.
getLocation
(
lastLatitude
,
lastLongitude
,
latitude
,
longitude
,
country
,
locality
,
street
);
}
}
// }
// }).start();
}
}
@Override
@Override
...
@@ -100,6 +70,21 @@ public class LocationService extends Service {
...
@@ -100,6 +70,21 @@ public class LocationService extends Service {
}
}
};
};
@Override
public
void
onCreate
()
{
super
.
onCreate
();
locationUtils
=
new
LocationUtils
(
App
.
getInstance
());
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Looper
.
prepare
();
isSuccess
=
locationUtils
.
init
(
1000
,
0
,
mOnLocationChangeListener
);
if
(
isSuccess
)
ToastUtils
.
showShortToastSafe
(
App
.
getInstance
(),
"init success"
);
Looper
.
loop
();
}
}).
start
();
}
@Nullable
@Nullable
@Override
@Override
public
IBinder
onBind
(
Intent
intent
)
{
public
IBinder
onBind
(
Intent
intent
)
{
...
@@ -114,8 +99,10 @@ public class LocationService extends Service {
...
@@ -114,8 +99,10 @@ public class LocationService extends Service {
@Override
@Override
public
void
onDestroy
()
{
public
void
onDestroy
()
{
super
.
onDestroy
();
locationUtils
.
removeListener
();
locationUtils
.
removeListener
();
// 一定要制空,否则内存泄漏
mOnGetLocationListener
=
null
;
super
.
onDestroy
();
}
}
/**
/**
...
...
app/src/main/java/com/blankj/androidutilcode/activities/LocationActivity.java
浏览文件 @
309c2f00
...
@@ -32,13 +32,22 @@ public class LocationActivity extends Activity {
...
@@ -32,13 +32,22 @@ public class LocationActivity extends Activity {
tvAboutLocation
=
(
TextView
)
findViewById
(
R
.
id
.
tv_about_location
);
tvAboutLocation
=
(
TextView
)
findViewById
(
R
.
id
.
tv_about_location
);
tvAboutLocation
.
setText
(
"lastLatitude: unknown"
+
"\nlastLongitude: unknown"
+
"\nlatitude: unknown"
+
"\nlongitude: unknown"
+
"\ngetCountryName: unknown"
+
"\ngetLocality: unknown"
+
"\ngetStreet: unknown"
);
bindService
(
new
Intent
(
this
,
LocationService
.
class
),
conn
,
Context
.
BIND_AUTO_CREATE
);
bindService
(
new
Intent
(
this
,
LocationService
.
class
),
conn
,
Context
.
BIND_AUTO_CREATE
);
}
}
@Override
@Override
protected
void
onDestroy
()
{
protected
void
onDestroy
()
{
super
.
onDestroy
();
unbindService
(
conn
);
unbindService
(
conn
);
super
.
onDestroy
();
}
}
ServiceConnection
conn
=
new
ServiceConnection
()
{
ServiceConnection
conn
=
new
ServiceConnection
()
{
...
...
update_log.md
浏览文件 @
309c2f00
###
###
#### 16/11/23 LocationUtils测试完毕,发布1.3.4
#### 16/11/22 查看LocationActivity内存泄漏
#### 16/11/21 优化README
#### 16/11/21 优化README
#### 16/11/20 完善LocationUtils
#### 16/11/20 完善LocationUtils
#### 16/11/19 完善SizeUtils
#### 16/11/19 完善SizeUtils
...
...
utilcode/build.gradle
浏览文件 @
309c2f00
...
@@ -7,8 +7,8 @@ android {
...
@@ -7,8 +7,8 @@ android {
defaultConfig
{
defaultConfig
{
minSdkVersion
11
minSdkVersion
11
targetSdkVersion
24
targetSdkVersion
24
versionCode
1
2
versionCode
1
3
versionName
"1.3.
3
"
versionName
"1.3.
4
"
}
}
buildTypes
{
buildTypes
{
release
{
release
{
...
@@ -25,5 +25,5 @@ dependencies {
...
@@ -25,5 +25,5 @@ dependencies {
provided
'com.android.support:support-v4:24.0.0'
provided
'com.android.support:support-v4:24.0.0'
provided
'com.android.support:design:24.0.0'
provided
'com.android.support:design:24.0.0'
}
}
//
apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
apply
from:
"https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//gradlew bintrayUpload
//gradlew bintrayUpload
\ No newline at end of file
utilcode/src/main/java/com/blankj/utilcode/utils/LocationUtils.java
浏览文件 @
309c2f00
...
@@ -54,7 +54,9 @@ public class LocationUtils {
...
@@ -54,7 +54,9 @@ public class LocationUtils {
* 打开Gps设置界面
* 打开Gps设置界面
*/
*/
public
void
openGpsSettings
()
{
public
void
openGpsSettings
()
{
mContext
.
startActivity
(
new
Intent
(
Settings
.
ACTION_LOCATION_SOURCE_SETTINGS
));
Intent
intent
=
new
Intent
(
Settings
.
ACTION_LOCATION_SOURCE_SETTINGS
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
mContext
.
startActivity
(
intent
);
}
}
/**
/**
...
@@ -76,10 +78,6 @@ public class LocationUtils {
...
@@ -76,10 +78,6 @@ public class LocationUtils {
if
(!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
NETWORK_PROVIDER
)
if
(!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
NETWORK_PROVIDER
)
&&
!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
))
{
&&
!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
))
{
ToastUtils
.
showShortToastSafe
(
mContext
,
"无法定位,请打开定位服务"
);
ToastUtils
.
showShortToastSafe
(
mContext
,
"无法定位,请打开定位服务"
);
openGpsSettings
();
}
if
(!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
NETWORK_PROVIDER
)
&&
!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
))
{
return
false
;
return
false
;
}
}
String
provider
=
mLocationManager
.
getBestProvider
(
getCriteria
(),
true
);
String
provider
=
mLocationManager
.
getBestProvider
(
getCriteria
(),
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录