an>
- long gatherTime = Preferences.getInstance(this).getGatherTime();
- if(gatherTime<System.currentTimeMillis()){
- mHandler.sendEmptyMessageDelayed(MSG_FETCH_TOUR_INFO,60000);
- }
- }
private void fetchTourInfo(){
+ mHandler.removeMessages(MSG_FETCH_TOUR_INFO);
mHandler.sendEmptyMessageDelayed(MSG_FETCH_TOUR_INFO,FETCH_GATHER_INFO_PERIOD);
- if(!Preferences.getInstance(this).isTourMode()&&Preferences.getInstance(this).getTourEndTime()<System.currentTimeMillis()){
+ if(!Preferences.getInstance(this).isTourMode()){
+ LogHelper.d(TAG,"已经知道不是旅行模式,跳过此次集合信息请求");
return;
}
long gatherTime = Preferences.getInstance(this).getGatherTime();
- if(gatherTime>System.currentTimeMillis()){
+ if(Preferences.getInstance(this).isTourMode() && gatherTime>System.currentTimeMillis()){
+ LogHelper.d(TAG,"已经知道是旅行模式,且集合时间已得到,跳过此次集合信息请求");
return;
}
if(fetchTourInfoTask!=null && fetchTourInfoTask.getStatus()== AsyncTask.Status.RUNNING){
return;
}
- HashMap<String,String> params = new HashMap<String,String>();
+ LogHelper.d(TAG,"发起获取集合信息的网络请求");
+ HashMap<String,String> params = new HashMap<>();
String userId = Preferences.getInstance(this).getUserId();
if(userId.length()==0){
return;
@@ -131,7 +129,6 @@ public class MyLocationService extends Service implements Handler.Callback{
fetchTourInfoTask = new HttpPostTask(this,params) {
-
@Override
protected boolean parseResponse(Context context, String response) {
try{
@@ -146,7 +143,7 @@ public class MyLocationService extends Service implements Handler.Callback{
String phone = group.getString("phone");
Preferences.getInstance(context).setTourGuidePhone(phone);
String gatherTimeStr = group.getString("gather_at");
- Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr));
+ Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr)+30*60*1000);
String endTimeStr = group.getString("ended_at");
Preferences.getInstance(context).setTourEndTime(TimeUtils.getStandardTimeInMiliSec(endTimeStr));
if(group.has("gather_location")){
@@ -202,7 +199,7 @@ public class MyLocationService extends Service implements Handler.Callback{
}
double lat = loc.getLatitude();
double lon = loc.getLongitude();
- LogHelper.dfile("czy","经纬度 lat = "+lat+"lon="+lon+" 位置 ="+loc.getAddress());
+ LogHelper.d(TAG,"上报经纬度 lat = "+lat+"lon="+lon+" 位置 ="+loc.getAddress());
reportLocationWhenTourMode(lat,lon);
}
};
@@ -211,9 +208,11 @@ public class MyLocationService extends Service implements Handler.Callback{
private void startLocation(){
initLocation();
if(Preferences.getInstance(this).isTourMode()){
+ LogHelper.d(TAG,"当前是旅行模式,开始定位");
locationClient.setLocationOption(locationOption);
locationClient.startLocation();
if(Preferences.getInstance(this).getGatherTime()> System.currentTimeMillis()){
+ LogHelper.d(TAG,"当前是旅行模式,且存在集合时间,预约下一次定位");
mHandler.sendEmptyMessageDelayed(MSG_START_LOCATION,Preferences.getInstance(this)
.getGatherTime()-System.currentTimeMillis()>LOCATION_PERIOD_CHANGE_DEADLINE ? LOCATION_MAX_PERIOD:LOCATION_MIN_PERIOD);
}
@@ -235,7 +234,7 @@ private void reportLocationWhenTourMode(double lat, double lon){
if(locationClient!=null){
locationClient.stopLocation();
}
- if(lat == lastLat && lon ==lastLon && repeatTime<5){
+ if(lat == lastLat && lon ==lastLon && repeatTime<2){
repeatTime++;
return;
}
@@ -4,7 +4,7 @@ buildscript {
|
||
| 4 | 4 |
jcenter() |
| 5 | 5 |
} |
| 6 | 6 |
dependencies {
|
| 7 |
- classpath 'com.android.tools.build:gradle:2.3.0' |
|
| 7 |
+ classpath 'com.android.tools.build:gradle:2.3.1' |
|
| 8 | 8 |
|
| 9 | 9 |
// NOTE: Do not place your application dependencies here; they belong |
| 10 | 10 |
// in the individual module build.gradle files |