@@ -1,5 +1,6 @@ |
||
| 1 | 1 |
package ai.pai.client.activity; |
| 2 | 2 |
|
| 3 |
+import android.content.Intent; |
|
| 3 | 4 |
import android.os.Bundle; |
| 4 | 5 |
import android.support.v4.app.FragmentActivity; |
| 5 | 6 |
import android.support.v7.app.AppCompatActivity; |
@@ -10,6 +11,7 @@ import com.android.common.utils.NetworkUtil; |
||
| 10 | 11 |
import com.umeng.analytics.MobclickAgent; |
| 11 | 12 |
|
| 12 | 13 |
import ai.pai.client.R; |
| 14 |
+import ai.pai.client.services.MyLocationService; |
|
| 13 | 15 |
import ai.pai.client.swipelayout.SwipeBackActivityBase; |
| 14 | 16 |
import ai.pai.client.swipelayout.SwipeBackActivityHelper; |
| 15 | 17 |
import ai.pai.client.swipelayout.SwipeBackLayout; |
@@ -45,6 +47,9 @@ public class BaseActivity extends FragmentActivity implements SwipeBackActivityB |
||
| 45 | 47 |
protected void onResume() {
|
| 46 | 48 |
super.onResume(); |
| 47 | 49 |
MobclickAgent.onResume(this); |
| 50 |
+ Intent intent = new Intent(this, MyLocationService.class); |
|
| 51 |
+ intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
|
|
| 52 |
+ startService(intent); |
|
| 48 | 53 |
} |
| 49 | 54 |
|
| 50 | 55 |
@Override |
@@ -117,7 +117,7 @@ public class MainActivity extends AppCompatActivity |
||
| 117 | 117 |
protected void onResume() {
|
| 118 | 118 |
super.onResume(); |
| 119 | 119 |
callGuideBtn.setVisibility(TextUtils.isEmpty(Preferences.getInstance(this).getTourGuidePhone()) ? View.INVISIBLE : View.VISIBLE); |
| 120 |
- gatherBtn.setVisibility(Preferences.getInstance(this).getGatherTime()+30*60*1000<System.currentTimeMillis() ? View.INVISIBLE : View.VISIBLE); |
|
| 120 |
+ gatherBtn.setVisibility(Preferences.getInstance(this).getGatherTime()<System.currentTimeMillis() ? View.INVISIBLE : View.VISIBLE); |
|
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 | 123 |
|
@@ -126,7 +126,8 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh |
||
| 126 | 126 |
if(fetchTourInfoTask!=null && fetchTourInfoTask.getStatus()== AsyncTask.Status.RUNNING){
|
| 127 | 127 |
return; |
| 128 | 128 |
} |
| 129 |
- HashMap<String,String> params = new HashMap<String,String>(); |
|
| 129 |
+ LogHelper.d(TAG,"导游定位 每次进入首页均去请求旅行及集合信息"); |
|
| 130 |
+ HashMap<String,String> params = new HashMap<>(); |
|
| 130 | 131 |
String userId = Preferences.getInstance(getActivity()).getUserId(); |
| 131 | 132 |
if(userId.length()==0){
|
| 132 | 133 |
return; |
@@ -153,7 +154,7 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh |
||
| 153 | 154 |
String phone = group.getString("phone");
|
| 154 | 155 |
Preferences.getInstance(context).setTourGuidePhone(phone); |
| 155 | 156 |
String gatherTimeStr = group.getString("gather_at");
|
| 156 |
- Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr)); |
|
| 157 |
+ Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr)+30*60*1000); |
|
| 157 | 158 |
if(group.has("gather_location")){
|
| 158 | 159 |
String location = group.getString("gather_location");
|
| 159 | 160 |
Preferences.getInstance(context).setTourGatherLocation(location); |
@@ -192,11 +193,13 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh |
||
| 192 | 193 |
super.onPostSuccess(context); |
| 193 | 194 |
initBanner(); |
| 194 | 195 |
if(Preferences.getInstance(context).isTourMode()){
|
| 196 |
+ LogHelper.d(TAG,"导游定位 当前是旅行模式"); |
|
| 195 | 197 |
Intent intent = new Intent(context, MyLocationService.class); |
| 196 | 198 |
intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
|
| 197 | 199 |
context.startService(intent); |
| 198 | 200 |
checkLocationPermission(); |
| 199 | 201 |
}else{
|
| 202 |
+ LogHelper.d(TAG,"导游定位 当前不是旅行模式"); |
|
| 200 | 203 |
Intent intent = new Intent(context, MyLocationService.class); |
| 201 | 204 |
intent.putExtra("command",MyLocationService.COMMAND_DESTROY_LOCATION);
|
| 202 | 205 |
context.startService(intent); |
@@ -283,7 +286,7 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh |
||
| 283 | 286 |
JSONObject info = json.getJSONObject("data");
|
| 284 | 287 |
JSONArray photoArray = info.getJSONArray("photos");
|
| 285 | 288 |
if(photoArray!=null && photoArray.length()>0){
|
| 286 |
- photoItems = new ArrayList<GroupPhotoItem>(); |
|
| 289 |
+ photoItems = new ArrayList<>(); |
|
| 287 | 290 |
int len = photoArray.length(); |
| 288 | 291 |
for(int k = 0; k<len;k++){
|
| 289 | 292 |
JSONObject photoObj = photoArray.getJSONObject(k); |
@@ -39,20 +39,23 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 39 | 39 |
private double lastLon; |
| 40 | 40 |
private double repeatTime; |
| 41 | 41 |
|
| 42 |
- private static final int FETCH_GATHER_INFO_PERIOD = 20*60*1000; |
|
| 43 |
- private static final int LOCATION_MAX_PERIOD = 10*60*1000; |
|
| 44 |
- private static final int LOCATION_MIN_PERIOD = 60*1000; |
|
| 45 |
- private static final int LOCATION_PERIOD_CHANGE_DEADLINE = 15*60*1000; |
|
| 42 |
+ private static final int FETCH_GATHER_INFO_PERIOD = 5*60*1000; |
|
| 43 |
+ private static final int LOCATION_MAX_PERIOD = 60*1000; |
|
| 44 |
+ private static final int LOCATION_MIN_PERIOD = 30*1000; |
|
| 45 |
+ private static final int LOCATION_PERIOD_CHANGE_DEADLINE = 90*60*1000; |
|
| 46 | 46 |
private static final int MSG_FETCH_TOUR_INFO = 4567; |
| 47 | 47 |
private static final int MSG_START_LOCATION = 4568; |
| 48 | 48 |
|
| 49 | 49 |
private Handler mHandler; |
| 50 | 50 |
|
| 51 | 51 |
private HttpPostTask fetchTourInfoTask; |
| 52 |
+ |
|
| 53 |
+ private static final String TAG = "导游定位"; |
|
| 52 | 54 |
|
| 53 | 55 |
@Override |
| 54 | 56 |
public void onCreate() {
|
| 55 | 57 |
super.onCreate(); |
| 58 |
+ LogHelper.d(TAG,"服务启动"); |
|
| 56 | 59 |
mHandler = new Handler(this); |
| 57 | 60 |
} |
| 58 | 61 |
|
@@ -63,7 +66,7 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 63 | 66 |
|
| 64 | 67 |
@Override |
| 65 | 68 |
public int onStartCommand(Intent intent, int flags, int startId) {
|
| 66 |
- if(intent==null){
|
|
| 69 |
+ if(intent == null){
|
|
| 67 | 70 |
return super.onStartCommand(intent,flags,startId); |
| 68 | 71 |
} |
| 69 | 72 |
Bundle bundle= intent.getExtras(); |
@@ -72,7 +75,7 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 72 | 75 |
} |
| 73 | 76 |
int command = bundle.getInt("command",0);
|
| 74 | 77 |
initLocation(); |
| 75 |
- initGatherInfo(); |
|
| 78 |
+ mHandler.sendEmptyMessageDelayed(MSG_FETCH_TOUR_INFO,5000); |
|
| 76 | 79 |
switch (command) {
|
| 77 | 80 |
case COMMAND_START_LOCATION: |
| 78 | 81 |
startLocation(); |
@@ -100,29 +103,24 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 100 | 103 |
locationClient.setLocationListener(locationListener); |
| 101 | 104 |
} |
| 102 | 105 |
|
| 103 |
- private void initGatherInfo(){
|
|
| 104 |
- if(!Preferences.getInstance(this).isTourMode()&&Preferences.getInstance(this).getTourEndTime()<System.currentTimeMillis()){
|
|
| 105 |
- return; |
|
| 106 |
- } |
|
| 107 |
- long gatherTime = Preferences.getInstance(this).getGatherTime(); |
|
| 108 |
- if(gatherTime<System.currentTimeMillis()){
|
|
| 109 |
- mHandler.sendEmptyMessageDelayed(MSG_FETCH_TOUR_INFO,60000); |
|
| 110 |
- } |
|
| 111 |
- } |
|
| 112 | 106 |
|
| 113 | 107 |
private void fetchTourInfo(){
|
| 108 |
+ mHandler.removeMessages(MSG_FETCH_TOUR_INFO); |
|
| 114 | 109 |
mHandler.sendEmptyMessageDelayed(MSG_FETCH_TOUR_INFO,FETCH_GATHER_INFO_PERIOD); |
| 115 |
- if(!Preferences.getInstance(this).isTourMode()&&Preferences.getInstance(this).getTourEndTime()<System.currentTimeMillis()){
|
|
| 110 |
+ if(!Preferences.getInstance(this).isTourMode()){
|
|
| 111 |
+ LogHelper.d(TAG,"已经知道不是旅行模式,跳过此次集合信息请求"); |
|
| 116 | 112 |
return; |
| 117 | 113 |
} |
| 118 | 114 |
long gatherTime = Preferences.getInstance(this).getGatherTime(); |
| 119 |
- if(gatherTime>System.currentTimeMillis()){
|
|
| 115 |
+ if(Preferences.getInstance(this).isTourMode() && gatherTime>System.currentTimeMillis()){
|
|
| 116 |
+ LogHelper.d(TAG,"已经知道是旅行模式,且集合时间已得到,跳过此次集合信息请求"); |
|
| 120 | 117 |
return; |
| 121 | 118 |
} |
| 122 | 119 |
if(fetchTourInfoTask!=null && fetchTourInfoTask.getStatus()== AsyncTask.Status.RUNNING){
|
| 123 | 120 |
return; |
| 124 | 121 |
} |
| 125 |
- HashMap<String,String> params = new HashMap<String,String>(); |
|
| 122 |
+ LogHelper.d(TAG,"发起获取集合信息的网络请求"); |
|
| 123 |
+ HashMap<String,String> params = new HashMap<>(); |
|
| 126 | 124 |
String userId = Preferences.getInstance(this).getUserId(); |
| 127 | 125 |
if(userId.length()==0){
|
| 128 | 126 |
return; |
@@ -131,7 +129,6 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 131 | 129 |
|
| 132 | 130 |
fetchTourInfoTask = new HttpPostTask(this,params) {
|
| 133 | 131 |
|
| 134 |
- |
|
| 135 | 132 |
@Override |
| 136 | 133 |
protected boolean parseResponse(Context context, String response) {
|
| 137 | 134 |
try{
|
@@ -146,7 +143,7 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 146 | 143 |
String phone = group.getString("phone");
|
| 147 | 144 |
Preferences.getInstance(context).setTourGuidePhone(phone); |
| 148 | 145 |
String gatherTimeStr = group.getString("gather_at");
|
| 149 |
- Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr)); |
|
| 146 |
+ Preferences.getInstance(context).setGatherTime(TimeUtils.getStandardTimeInMiliSec(gatherTimeStr)+30*60*1000); |
|
| 150 | 147 |
String endTimeStr = group.getString("ended_at");
|
| 151 | 148 |
Preferences.getInstance(context).setTourEndTime(TimeUtils.getStandardTimeInMiliSec(endTimeStr)); |
| 152 | 149 |
if(group.has("gather_location")){
|
@@ -202,7 +199,7 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 202 | 199 |
} |
| 203 | 200 |
double lat = loc.getLatitude(); |
| 204 | 201 |
double lon = loc.getLongitude(); |
| 205 |
- LogHelper.dfile("czy","经纬度 lat = "+lat+"lon="+lon+" 位置 ="+loc.getAddress());
|
|
| 202 |
+ LogHelper.d(TAG,"上报经纬度 lat = "+lat+"lon="+lon+" 位置 ="+loc.getAddress()); |
|
| 206 | 203 |
reportLocationWhenTourMode(lat,lon); |
| 207 | 204 |
} |
| 208 | 205 |
}; |
@@ -211,9 +208,11 @@ public class MyLocationService extends Service implements Handler.Callback{
|
||
| 211 | 208 |
private void startLocation(){
|
| 212 | 209 |
initLocation(); |
| 213 | 210 |
if(Preferences.getInstance(this).isTourMode()){
|
| 211 |
+ LogHelper.d(TAG,"当前是旅行模式,开始定位"); |
|
| 214 | 212 |
locationClient.setLocationOption(locationOption); |
| 215 | 213 |
locationClient.startLocation(); |
| 216 | 214 |
if(Preferences.getInstance(this).getGatherTime()> System.currentTimeMillis()){
|
| 215 |
+ LogHelper.d(TAG,"当前是旅行模式,且存在集合时间,预约下一次定位"); |
|
| 217 | 216 |
mHandler.sendEmptyMessageDelayed(MSG_START_LOCATION,Preferences.getInstance(this) |
| 218 | 217 |
.getGatherTime()-System.currentTimeMillis()>LOCATION_PERIOD_CHANGE_DEADLINE ? LOCATION_MAX_PERIOD:LOCATION_MIN_PERIOD); |
| 219 | 218 |
} |
@@ -235,7 +234,7 @@ private void reportLocationWhenTourMode(double lat, double lon){
|
||
| 235 | 234 |
if(locationClient!=null){
|
| 236 | 235 |
locationClient.stopLocation(); |
| 237 | 236 |
} |
| 238 |
- if(lat == lastLat && lon ==lastLon && repeatTime<5){
|
|
| 237 |
+ if(lat == lastLat && lon ==lastLon && repeatTime<2){
|
|
| 239 | 238 |
repeatTime++; |
| 240 | 239 |
return; |
| 241 | 240 |
} |
@@ -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 |