Commit b8ae70386a3428c337a95c4b994a196ea98dc9fe

Authored by 杨帅
1 parent a90484e2

1 修复BUG

app/src/main/java/com/example/modulepedometer/MainActivity.java
... ... @@ -31,8 +31,8 @@ public class MainActivity extends AppCompatActivity {
31 31 super.onCreate(savedInstanceState);
32 32 setContentView(R.layout.activity_main);
33 33  
34   -// String uid = "10535072";
35   - String uid = "358916";
  34 + String uid = "10535072";
  35 +// String uid = "358916";
36 36 // String uid = "358689";
37 37  
38 38 findViewById(R.id.recordd).setOnClickListener(new View.OnClickListener() {
... ...
config.gradle
... ... @@ -21,7 +21,7 @@ ext {
21 21 //编译方式
22 22 debug : false,
23 23 //版本号
24   - version: "0.6.21",
  24 + version: "0.7.0",
25 25 //Lib库前缀
26 26 packeg : "com.cnlive.module",
27 27 //Lib库名称
... ...
moudle_pedometer/src/main/AndroidManifest.xml
... ... @@ -52,36 +52,46 @@
52 52 android:required="true" />
53 53  
54 54 <application android:persistent="true">
55   - <activity android:name="com.cnlive.moudle.collectionTrace.ui.activity.RaceNameListActivity"
  55 + <activity
  56 + android:name="com.cnlive.moudle.collectionTrace.ui.activity.RaceNameListActivity"
56 57 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
57   - android:screenOrientation="portrait"/>
58   - <activity android:name="com.cnlive.moudle.collectionTrace.ui.activity.RaceListActivity"
  58 + android:screenOrientation="portrait" />
  59 + <activity
  60 + android:name="com.cnlive.moudle.collectionTrace.ui.activity.RaceListActivity"
59 61 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
60   - android:screenOrientation="portrait"/>
61   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.LineUpAgainActivity"
  62 + android:screenOrientation="portrait" />
  63 + <activity
  64 + android:name="com.cnlive.moudle.pedometer.ui.activity.LineUpAgainActivity"
62 65 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
63   - android:screenOrientation="portrait"/>
64   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.SelfRecordActivity"
  66 + android:screenOrientation="portrait" />
  67 + <activity
  68 + android:name="com.cnlive.moudle.pedometer.ui.activity.SelfRecordActivity"
65 69 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
66   - android:screenOrientation="portrait"/>
67   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.TakePartActivity"
  70 + android:screenOrientation="portrait" />
  71 + <activity
  72 + android:name="com.cnlive.moudle.pedometer.ui.activity.TakePartActivity"
68 73 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
69   - android:screenOrientation="portrait"/>
70   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.RunLineActivity"
  74 + android:screenOrientation="portrait" />
  75 + <activity
  76 + android:name="com.cnlive.moudle.pedometer.ui.activity.RunLineActivity"
71 77 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
72   - android:screenOrientation="portrait"/>
73   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.MyRecordActivity"
  78 + android:screenOrientation="portrait" />
  79 + <activity
  80 + android:name="com.cnlive.moudle.pedometer.ui.activity.MyRecordActivity"
74 81 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
75   - android:screenOrientation="portrait"/>
76   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.ShareRecordActivity"
  82 + android:screenOrientation="portrait" />
  83 + <activity
  84 + android:name="com.cnlive.moudle.pedometer.ui.activity.ShareRecordActivity"
77 85 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
78   - android:screenOrientation="portrait"/>
79   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.RaceRecordActivity"
  86 + android:screenOrientation="portrait" />
  87 + <activity
  88 + android:name="com.cnlive.moudle.pedometer.ui.activity.RaceRecordActivity"
80 89 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
81   - android:screenOrientation="portrait"/>
82   - <activity android:name="com.cnlive.moudle.pedometer.ui.activity.RegistrationInfoActivity"
  90 + android:screenOrientation="portrait" />
  91 + <activity
  92 + android:name="com.cnlive.moudle.pedometer.ui.activity.RegistrationInfoActivity"
83 93 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
84   - android:screenOrientation="portrait"/>
  94 + android:screenOrientation="portrait" />
85 95  
86 96 <service
87 97 android:name="com.cnlive.moudle.pedometer.service.StepService"
... ... @@ -183,7 +193,7 @@
183 193 android:enabled="true"
184 194 android:exported="true"
185 195 android:priority="1000"
186   - android:process=":re" />
  196 + android:process=":alive" />
187 197 <service
188 198 android:name="com.cnlive.moudle.collectionTrace.service.CollStepService"
189 199 android:enabled="true"
... ... @@ -221,22 +231,27 @@
221 231 <activity
222 232 android:name="com.cnlive.moudle.collectionTrace.ui.activity.CollPedometerMainActivity"
223 233 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  234 + android:launchMode="singleTask"
224 235 android:screenOrientation="portrait" />
225 236 <activity
226 237 android:name="com.cnlive.moudle.collectionTrace.ui.activity.CollRunningFinishActivity"
227 238 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  239 + android:launchMode="singleTask"
228 240 android:screenOrientation="portrait" /> <!-- android:theme="@style/Theme.AppCompat.Light.NoActionBar" -->
229 241 <activity
230 242 android:name="com.cnlive.moudle.collectionTrace.ui.activity.CollRunningMapActivity"
231 243 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  244 + android:launchMode="singleTask"
232 245 android:screenOrientation="portrait" />
233 246 <activity
234 247 android:name="com.cnlive.moudle.collectionTrace.ui.activity.CollRunRaceDetailActivity"
235 248 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  249 + android:launchMode="singleTask"
236 250 android:screenOrientation="portrait" />
237 251 <activity
238 252 android:name="com.cnlive.moudle.collectionTrace.ui.activity.StartCollectTraceActivity"
239 253 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  254 + android:launchMode="singleTask"
240 255 android:screenOrientation="portrait" />
241 256 </application>
242 257  
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningMapFragmentView.java
... ... @@ -534,7 +534,6 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener
534 534 mLocClient = new LocationClient(getContext());
535 535 mLocClient.registerLocationListener(myListener);
536 536 LocationClientOption option = new LocationClientOption();
537   - option.setOpenGps(true); // 打开gps
538 537 //可选,设置返回经纬度坐标类型,默认GCJ02
539 538 //GCJ02:国测局坐标;
540 539 //BD09ll:百度经纬度坐标;
... ... @@ -551,11 +550,11 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener
551 550 //LocationMode. Device_Sensors:仅使用设备;
552 551 option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
553 552 //可选,设置是否需要地址信息,默认不需要
554   - option.setIsNeedAddress(true);
  553 + option.setIsNeedAddress(false);
555 554 //可选,设置是否需要地址描述
556   - option.setIsNeedLocationDescribe(true);
  555 + option.setIsNeedLocationDescribe(false);
557 556 //需要POI信息
558   - option.setIsNeedLocationPoiList(true);
  557 + option.setIsNeedLocationPoiList(false);
559 558 //可选,设置是否需要设备方向结果
560 559 option.setNeedDeviceDirect(false);
561 560 //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者
... ... @@ -604,6 +603,7 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener
604 603 if (location == null || mMapView == null || getContext() == null) {
605 604 return;
606 605 }
  606 +
607 607 //正在搜索GPS信号
608 608 if (location.getGpsAccuracyStatus() == BDLocation.GPS_ACCURACY_UNKNOWN) {
609 609 if (fragment.binding.tvGpsPopBg.getVisibility() != View.VISIBLE) {
... ... @@ -653,9 +653,9 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener
653 653 fragment.binding.ivGpsState.setBackground(getContext().getResources().getDrawable(R.drawable.rt_training_gps_3));
654 654 }
655 655 }
656   -// if (followMyLocation == null || followMyLocation.latitude == 0 || followMyLocation.longitude == 0) {
657   -// return;
658   -// }
  656 + if (followMyLocation == null || followMyLocation.latitude == 0 || followMyLocation.longitude == 0) {
  657 + return;
  658 + }
659 659 MapStatus.Builder builder = new MapStatus.Builder();
660 660 mCurrentAccracy = location.getRadius();
661 661 followMyLocation = new MyLocationData.Builder()
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/StartTraceFragmentView.java
... ... @@ -8,6 +8,7 @@ import android.hardware.Sensor;
8 8 import android.hardware.SensorEvent;
9 9 import android.hardware.SensorEventListener;
10 10 import android.hardware.SensorManager;
  11 +import android.os.Build;
11 12 import android.support.v4.content.ContextCompat;
12 13 import android.text.TextUtils;
13 14 import android.util.Log;
... ... @@ -156,7 +157,7 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener {
156 157 */
157 158 public void checkIsHasRunningRace() {
158 159 //先判断有没有数据
159   - CollUserStepEntity userStepEntity = CollStepUtil.getCollUserStepData(getContext(), CommonInfo.getUserId(getContext()));
  160 + CollUserStepEntity userStepEntity = CollStepUtil.getCollUserStepData(getContext(), CollCommonInfo.getUserId(getContext()));
160 161 if (null != userStepEntity) {
161 162 //判断用户是否点击wanc
162 163 if (0 == userStepEntity.getFinishTimeStamp()) {
... ... @@ -259,7 +260,11 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener {
259 260 CollCommonInfo.setTsRunBaiduTraceService(context, true);
260 261 CollCommonInfo.setIsWriteUserStep(context, true);
261 262 Intent intent = new Intent(fragment.getActivity(), CollKeepLiveService.class);
262   - ContextCompat.startForegroundService(fragment.getActivity(), intent);
  263 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  264 + fragment.getActivity().startForegroundService(intent);
  265 + } else {
  266 + fragment.getActivity().startService(intent);
  267 + }
263 268  
264 269 }
265 270  
... ... @@ -448,7 +453,7 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener {
448 453 MapStatus.Builder builder = new MapStatus.Builder();
449 454 builder.target(new LatLng(followMyLocation.latitude, followMyLocation.longitude)).zoom(DEFULT_ZOOM);
450 455 baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
451   - isFollowUserShow=false;
  456 + isFollowUserShow = false;
452 457 }
453 458 }
454 459 // if (location.hasAddr()) {
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/receivers/CollServiceReceiver.java
... ... @@ -23,7 +23,7 @@ public class CollServiceReceiver extends BroadcastReceiver {
23 23 private final String TAG = "CollServiceReceiver";
24 24  
25 25 public CollServiceReceiver() {
26   -
  26 + super();
27 27 }
28 28  
29 29 public CollServiceReceiver(PowerManager.WakeLock wakeLock) {
... ... @@ -72,7 +72,7 @@ public class CollServiceReceiver extends BroadcastReceiver {
72 72 }
73 73 Log.e(TAG, "启动KeepLiveService");
74 74 } else {
75   - Log.e(TAG, "KeepLiveService已经在运行");
  75 + Log.e(TAG, "collKeepLiveService已经在运行");
76 76  
77 77 }
78 78 String action = intent.getAction();
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/service/CollKeepLiveService.java
... ... @@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
4 4 import android.app.Notification;
5 5 import android.app.NotificationChannel;
6 6 import android.app.NotificationManager;
  7 +import android.app.PendingIntent;
7 8 import android.app.Service;
8 9 import android.content.ComponentName;
9 10 import android.content.Context;
... ... @@ -19,6 +20,8 @@ import android.util.Log;
19 20  
20 21 import com.cnlive.moudle.collectionTrace.receivers.CollServiceReceiver;
21 22 import com.cnlive.moudle.collectionTrace.commonInfo.CollCommonInfo;
  23 +import com.cnlive.moudle.collectionTrace.ui.activity.CollRunningMapActivity;
  24 +import com.cnlive.moudle.pedometer.ui.activity.PedometerMainActivity;
22 25 import com.cnlive.moudle.pedometer.utils.ServiceUtils;
23 26 import com.example.moudle_pedometer.R;
24 27  
... ... @@ -36,19 +39,19 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple
36 39 public static MediaPlayer mMediaPlayer;
37 40 //广播
38 41 private static CollServiceReceiver myReceiver;
39   - private String CHANNEL_ONE_ID = "com.cnlive.keep";
40   - private String CHANNEL_ONE_NAME = "KeepLive";
  42 + private String CHANNEL_ONE_ID = "com.cnlive.collkeep";
  43 + private String CHANNEL_ONE_NAME = "collKeepLive";
41 44 private NotificationManager mNM;
42 45 private Notification notification = null;
43 46 //是否在后台运行
44 47 public static boolean isKeepService = true;
45 48 public static CollKeepLiveService instance;
46   - private int startId;
47 49 private final String TAG = "CollKeepLiveService";
48 50 private Handler handler;
49 51 private Runnable runnable;
50 52 private boolean isRegisterReceiver = false;
51 53 private boolean isStartForegroundService = false;
  54 + private final int NOTIFICATION_ID = 1;
52 55  
53 56 public CollKeepLiveService() {
54 57 }
... ... @@ -70,7 +73,7 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple
70 73 handler.postDelayed(this, 5000);
71 74 } else {
72 75 try {
73   - if (myReceiver != null&&isRegisterReceiver) {
  76 + if (myReceiver != null && isRegisterReceiver) {
74 77 unregisterReceiver(myReceiver);
75 78 }
76 79 } catch (Exception e) {
... ... @@ -143,16 +146,15 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple
143 146 }
144 147 }
145 148 }
146   - this.startId = startId;
147 149 //跨进程读取配置文件
148 150 boolean isRun = CollCommonInfo.getIsRunKeepAliveService(getApplicationContext());
149 151  
150 152 if (isRun) {
  153 + showHideForegroundNotification();
  154 + startPlaySong();
151 155 if (runnable != null) {
152 156 handler.postDelayed(runnable, 5000);
153 157 }
154   - showHideForegroundNotification();
155   - startPlaySong();
156 158 }
157 159 return START_STICKY;
158 160 }
... ... @@ -205,21 +207,26 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple
205 207 channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PRIVATE);
206 208 mNM.createNotificationChannel(channel);
207 209 }
  210 + Intent notificationIntent = new Intent(this, CollRunningMapActivity.class);
208 211 notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID)
  212 + .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0))
  213 + .setSmallIcon(R.mipmap.ic_launcher)
  214 +// .setCustomContentView(remoteViews)
209 215 .setContentTitle(getResources().getString(R.string.app_name))
210   - .setContentText("正在记录您的运动")
211   - .setWhen(System.currentTimeMillis())
  216 + .setContentText(getResources().getString(R.string.keep_service_tip))
  217 + .setCategory(Notification.CATEGORY_SERVICE)
212 218 .setSound(null)
  219 + .setWhen(System.currentTimeMillis())
213 220 .build();
214 221 // 0 隐藏前台服务通知
215   - startForeground(100, notification);
  222 + startForeground(NOTIFICATION_ID, notification);
216 223 isStartForegroundService = true;
217   -// stopForeground(true);
218 224 }
219 225  
220 226 @Override
221 227 public void onDestroy() {
222 228 super.onDestroy();
  229 + Log.e(TAG, "onDestroy: ");
223 230 try {
224 231 if (myReceiver != null && isRegisterReceiver) {
225 232 unregisterReceiver(myReceiver);
... ... @@ -268,7 +275,7 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple
268 275 @Override
269 276 public void onCompletion(MediaPlayer mediaPlayer) {
270 277 boolean isRun = CollCommonInfo.getIsRunKeepAliveService(getApplicationContext());
271   -
  278 + Log.e(TAG, "onCompletion: 是否循环播放" + isRun);
272 279 if (isRun) {
273 280 Log.e(TAG, "重新播放");
274 281 mediaPlayer.start();
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/service/CollStepService.java
... ... @@ -36,6 +36,7 @@ import com.baidu.trace.model.OnTraceListener;
36 36 import com.baidu.trace.model.PushMessage;
37 37 import com.baidu.trace.model.StatusCodes;
38 38 import com.cnlive.moudle.collectionTrace.commonInfo.CollCommonInfo;
  39 +import com.cnlive.moudle.collectionTrace.ui.activity.CollRunningMapActivity;
39 40 import com.cnlive.moudle.pedometer.model.Constant;
40 41 import com.cnlive.moudle.pedometer.model.MessageEvent;
41 42 import com.cnlive.moudle.pedometer.model.step.StepCount;
... ... @@ -116,7 +117,7 @@ public class CollStepService extends Service implements SensorEventListener {
116 117 private String userId;
117 118 private Handler handler;
118 119 private Runnable speedRunnable;
119   - private final int NOTIFICATION_ID = 100;
  120 + private final int NOTIFICATION_ID = 101;
120 121 // private static int tempStep;//计步器临时保存步数
121 122 private static boolean pauseFlag;//是否暂停
122 123 private static int speedCurrentStep;//用于检测速度步数
... ... @@ -372,6 +373,7 @@ public class CollStepService extends Service implements SensorEventListener {
372 373 @SuppressLint("WrongConstant")
373 374 @Override
374 375 public int onStartCommand(Intent intent, int flags, int startId) {
  376 +
375 377 if (!EventBus.getDefault().isRegistered(this)) {
376 378 EventBus.getDefault().register(this);
377 379 }
... ... @@ -437,13 +439,13 @@ public class CollStepService extends Service implements SensorEventListener {
437 439 }
438 440  
439 441  
440   - Intent notificationIntent = new Intent(this, PedometerMainActivity.class);
  442 + Intent notificationIntent = new Intent(this, CollRunningMapActivity.class);
441 443 notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID)
442 444 .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0))
443 445 .setSmallIcon(R.mipmap.ic_launcher)
444 446 // .setCustomContentView(remoteViews)
445 447 .setContentTitle(getResources().getString(R.string.app_name))
446   - .setContentText("正在记录您的运动")
  448 + .setContentText(getResources().getString(R.string.step_service_tip))
447 449 .setCategory(Notification.CATEGORY_SERVICE)
448 450 .setSound(null)
449 451 .setWhen(System.currentTimeMillis())
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/KeepLiveService.java
... ... @@ -51,7 +51,7 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion
51 51 private Runnable runnable;
52 52 private boolean isRegisterReceiver = false;
53 53 private boolean isStartForeground = false;
54   -
  54 + private final int NOTIFICATION_ID = 1;
55 55 public KeepLiveService() {
56 56 }
57 57  
... ... @@ -230,13 +230,13 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion
230 230 .setSmallIcon(R.mipmap.ic_launcher)
231 231 // .setCustomContentView(remoteViews)
232 232 .setContentTitle(getResources().getString(R.string.app_name))
233   - .setContentText("正在记录您的运动")
  233 + .setContentText(getResources().getString(R.string.keep_service_tip))
234 234 .setCategory(Notification.CATEGORY_SERVICE)
235 235 .setSound(null)
236 236 .setWhen(System.currentTimeMillis())
237 237 .build();
238 238 // 0 隐藏前台服务通知
239   - startForeground(100, notification);
  239 + startForeground(NOTIFICATION_ID, notification);
240 240 isStartForeground=true;
241 241 }
242 242  
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
... ... @@ -136,7 +136,7 @@ public class StepService extends Service implements SensorEventListener {
136 136 private String userId;
137 137 private Handler handler;
138 138 private Runnable speedRunnable;
139   - private final int NOTIFICATION_ID = 100;
  139 + private final int NOTIFICATION_ID = 102;
140 140 // private static int tempStep;//计步器临时保存步数
141 141 private static boolean pauseFlag;//是否暂停
142 142 private static int speedCurrentStep;//用于检测速度步数
... ... @@ -619,7 +619,7 @@ public class StepService extends Service implements SensorEventListener {
619 619 .setSmallIcon(R.mipmap.ic_launcher)
620 620 // .setCustomContentView(remoteViews)
621 621 .setContentTitle(getResources().getString(R.string.app_name))
622   - .setContentText("正在记录您的运动")
  622 + .setContentText(getResources().getString(R.string.step_service_tip))
623 623 .setCategory(Notification.CATEGORY_SERVICE)
624 624 .setSound(null)
625 625 .setWhen(System.currentTimeMillis())
... ...
moudle_pedometer/src/main/res/values/strings.xml
... ... @@ -94,4 +94,6 @@
94 94 <string name="layout_coll_take_point_text">(打点)</string>
95 95 <!--默认头像url-->
96 96 <string name="default_face_url">http://wjj.ys1.cnliveimg.com/769/img/2018/0416/head_c.png</string>
  97 + <string name="step_service_tip">正在记录您的运动</string>
  98 + <string name="keep_service_tip">正在运行,请不要停止,否则无法记录您的轨迹</string>
97 99 </resources>
... ...