Skip to content

Commit

Permalink
see 11/23 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Nov 23, 2016
1 parent bed457e commit 309c2f0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ getEntries : 获取压缩文件中的文件对象
***
Gradle:
``` groovy
compile 'com.blankj:utilcode:1.3.3'
compile 'com.blankj:utilcode:1.3.4'
```

### Proguard
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ getEntries
***
Gradle:
``` groovy
compile 'com.blankj:utilcode:1.3.3'
compile 'com.blankj:utilcode:1.3.4'
```

### Proguard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.blankj.androidutilcode.App;
import com.blankj.utilcode.utils.LocationUtils;
import com.blankj.utilcode.utils.ThreadPoolUtils;
import com.blankj.utilcode.utils.ToastUtils;

/**
Expand All @@ -23,8 +24,8 @@
*/
public class LocationService extends Service {

private boolean isSuccess;
private LocationUtils locationUtils;
private boolean isSuccess;
private LocationUtils locationUtils;
private String lastLatitude = "loading...";
private String lastLongitude = "loading...";
private String latitude = "loading...";
Expand All @@ -33,36 +34,11 @@ public class LocationService extends Service {
private String locality = "loading...";
private String street = "loading...";
private OnGetLocationListener mOnGetLocationListener;
private Thread mThread;

public void setOnGetLocationListener(OnGetLocationListener 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() {
@Override
public void getLastKnownLocation(Location location) {
Expand All @@ -80,18 +56,12 @@ public void onLocationChanged(final Location location) {
if (mOnGetLocationListener != null) {
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));
locality = locationUtils.getLocality(Double.parseDouble(latitude), Double.parseDouble(longitude));
street = locationUtils.getStreet(Double.parseDouble(latitude), Double.parseDouble(longitude));
if (mOnGetLocationListener != null) {
mOnGetLocationListener.getLocation(lastLatitude, lastLongitude, latitude, longitude, country, locality, street);
}
// }
// }).start();
}

@Override
Expand All @@ -100,6 +70,21 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
}
};

@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
@Override
public IBinder onBind(Intent intent) {
Expand All @@ -114,8 +99,10 @@ public LocationService getService() {

@Override
public void onDestroy() {
super.onDestroy();
locationUtils.removeListener();
// 一定要制空,否则内存泄漏
mOnGetLocationListener = null;
super.onDestroy();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ protected void onCreate(Bundle savedInstanceState) {

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);
}

@Override
protected void onDestroy() {
super.onDestroy();
unbindService(conn);
super.onDestroy();
}

ServiceConnection conn = new ServiceConnection() {
Expand Down
2 changes: 2 additions & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
###
#### 16/11/23 LocationUtils测试完毕,发布1.3.4
#### 16/11/22 查看LocationActivity内存泄漏
#### 16/11/21 优化README
#### 16/11/20 完善LocationUtils
#### 16/11/19 完善SizeUtils
Expand Down
6 changes: 3 additions & 3 deletions utilcode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
versionCode 12
versionName "1.3.3"
versionCode 13
versionName "1.3.4"
}
buildTypes {
release {
Expand All @@ -25,5 +25,5 @@ dependencies {
provided 'com.android.support:support-v4: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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public boolean isGpsEnabled() {
* 打开Gps设置界面
*/
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);
}

/**
Expand All @@ -76,10 +78,6 @@ public boolean init(long minTime, long minDistance, OnLocationChangeListener lis
if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
&& !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
ToastUtils.showShortToastSafe(mContext, "无法定位,请打开定位服务");
openGpsSettings();
}
if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
&& !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
return false;
}
String provider = mLocationManager.getBestProvider(getCriteria(), true);
Expand Down

0 comments on commit 309c2f0

Please sign in to comment.