Commit 23a48968059993874c2f7586b31a85fcc236fd47
1 parent
7ea646bd
1.修改数据库结构
2.实现跑步完成提交数据功能
Showing
45 changed files
with
3554 additions
and
306 deletions
Too many changes to show.
To preserve performance only 45 of 54 files are displayed.
build.gradle
moudle_pedometer/build.gradle
| ... | ... | @@ -6,7 +6,7 @@ android { |
| 6 | 6 | compileSdkVersion 28 |
| 7 | 7 | buildToolsVersion "28.0.3" |
| 8 | 8 | |
| 9 | - | |
| 9 | + useLibrary 'org.apache.http.legacy' | |
| 10 | 10 | defaultConfig { |
| 11 | 11 | minSdkVersion rootProject.ext.minSdkVersion |
| 12 | 12 | targetSdkVersion rootProject.ext.targetSdkVersion |
| ... | ... | @@ -112,5 +112,13 @@ dependencies { |
| 112 | 112 | implementation project(':library_baidumap') |
| 113 | 113 | //加载动画 |
| 114 | 114 | implementation 'com.wang.avi:library:2.1.3' |
| 115 | - | |
| 115 | + implementation "com.cnlive.libs:video_qiniu:$rootProject.libVideoQiniu" | |
| 116 | + //七牛上传 | |
| 117 | + implementation "com.qiniu:qiniu-android-sdk:$rootProject.qiniuAndroidSdk" | |
| 118 | + implementation("com.cnlive:lib_upload:$rootProject.libUpload") { | |
| 119 | + exclude group: 'com.android.support' | |
| 120 | + exclude group: 'com.cnlive' | |
| 121 | + } | |
| 122 | + implementation "com.cnlive.libs:mediapicker:$rootProject.libMediaPicker" | |
| 123 | + implementation 'org.apache.httpcomponents:httpcore:4.4.2' | |
| 116 | 124 | } | ... | ... |
moudle_pedometer/src/main/AndroidManifest.xml
| ... | ... | @@ -122,9 +122,11 @@ |
| 122 | 122 | android:process=":step" /> |
| 123 | 123 | <activity |
| 124 | 124 | android:name="com.cnlive.moudle.pedometer.ui.activity.RunningMapActivity" |
| 125 | + android:launchMode="singleTask" | |
| 125 | 126 | android:process=":step" /> <!-- android:theme="@style/Theme.AppCompat.Light.NoActionBar" --> |
| 126 | 127 | <activity |
| 127 | 128 | android:name="com.cnlive.moudle.pedometer.ui.activity.RunRaceDetailActivity" |
| 129 | + android:launchMode="singleTask" | |
| 128 | 130 | android:process=":step" /> |
| 129 | 131 | <activity |
| 130 | 132 | android:name="com.cnlive.moudle.pedometer.ui.activity.RunningFinishActivity" | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunMainFragmentView.java
| ... | ... | @@ -269,9 +269,9 @@ public class CollRunMainFragmentView implements MvpView { |
| 269 | 269 | //隐藏两个按钮 |
| 270 | 270 | fragment.binding.flStopTip.setVisibility(View.INVISIBLE); |
| 271 | 271 | fragment.binding.llTwoBottomButton.setVisibility(View.GONE); |
| 272 | - ButtonAnimUtil.setViewShowZoomIn(fragment.binding.llPause); | |
| 272 | +// ButtonAnimUtil.setViewShowZoomIn(fragment.binding.llPause); | |
| 273 | 273 | //显示暂停按钮 |
| 274 | - fragment.binding.llPause.setVisibility(View.VISIBLE); | |
| 274 | + fragment.binding.flPause.setVisibility(View.VISIBLE); | |
| 275 | 275 | // |
| 276 | 276 | } |
| 277 | 277 | }, ButtonAnimUtil.DEFAULT_ZOOM_DURATION * 2); |
| ... | ... | @@ -401,12 +401,12 @@ public class CollRunMainFragmentView implements MvpView { |
| 401 | 401 | //将当前计时器时间戳写入数据库 |
| 402 | 402 | setSQLPauseTime(uid); |
| 403 | 403 | needWriteDataFlag = false; |
| 404 | - ButtonAnimUtil.setViewHideZoomOut(fragment.binding.llPause); | |
| 404 | +// ButtonAnimUtil.setViewHideZoomOut(fragment.binding.llPause); | |
| 405 | 405 | handler.postDelayed(new Runnable() { |
| 406 | 406 | @Override |
| 407 | 407 | public void run() { |
| 408 | 408 | //隐藏本身 |
| 409 | - fragment.binding.llPause.setVisibility(View.GONE); | |
| 409 | + fragment.binding.flPause.setVisibility(View.GONE); | |
| 410 | 410 | } |
| 411 | 411 | }, ButtonAnimUtil.HIDE_VIEW_ZOOM_DURATION); |
| 412 | 412 | //显示继续按钮 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunRaceDetailFragmentView.java
| ... | ... | @@ -119,9 +119,9 @@ public class CollRunRaceDetailFragmentView implements MvpView, SensorEventListen |
| 119 | 119 | this.runRaceDetailInfo = runRaceDetailInfo; |
| 120 | 120 | //初始化地图点位 |
| 121 | 121 | if (runRaceDetailInfo.getLatLongitude() != null) { |
| 122 | - Log.e(TAG, "initView: 长度:" + runRaceDetailInfo.getLatLongitude().length()); | |
| 122 | +// Log.e(TAG, "initView: 长度:" + runRaceDetailInfo.getLatLongitude().length()); | |
| 123 | 123 | trackPoints = GsonUtil.jsonToList(runRaceDetailInfo.getLatLongitude(), LatLng.class); |
| 124 | - Log.e(TAG, "initView: trackPoints" + trackPoints.size()); | |
| 124 | +// Log.e(TAG, "initView: trackPoints" + trackPoints.size()); | |
| 125 | 125 | // MyMapUtil.drawServerLineTrack(getContext(), baiduMap, trackPoints, SortType.asc, R.color.green_round, R.drawable.icon_start, R.drawable.icon_end); |
| 126 | 126 | // //自动计算地图缩放 |
| 127 | 127 | MapStatus.Builder builder = new MapStatus.Builder(); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/commonInfo/CommonInfo.java
| ... | ... | @@ -295,6 +295,69 @@ public class CommonInfo { |
| 295 | 295 | return MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).getBoolean("runIsPauseState", false); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | + /** | |
| 299 | + * 设置轨迹查询开始时间 | |
| 300 | + * | |
| 301 | + * @param context | |
| 302 | + * @param startTime | |
| 303 | + */ | |
| 304 | + public static void setQueryTraceStartTime(Context context, long startTime) { | |
| 305 | + MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).putLong("runQueryTraceStartTime", startTime); | |
| 306 | + | |
| 307 | + } | |
| 308 | + | |
| 309 | + /** | |
| 310 | + * 互殴轨迹查询开始时间 | |
| 311 | + * | |
| 312 | + * @param context | |
| 313 | + */ | |
| 314 | + public static long getQueryTraceStartTime(Context context) { | |
| 315 | + return MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).getLong("runQueryTraceStartTime", 0); | |
| 316 | + | |
| 317 | + } | |
| 318 | + | |
| 319 | + /** | |
| 320 | + * 设置轨迹查询结束时间 | |
| 321 | + * | |
| 322 | + * @param context | |
| 323 | + * @param startTime | |
| 324 | + */ | |
| 325 | + public static void setQueryTraceEndTime(Context context, long startTime) { | |
| 326 | + MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).putLong("runQueryTraceEndTime", startTime); | |
| 327 | + | |
| 328 | + } | |
| 329 | + | |
| 330 | + /** | |
| 331 | + * 互殴轨迹查询开始时间 | |
| 332 | + * | |
| 333 | + * @param context | |
| 334 | + */ | |
| 335 | + public static long getQueryTraceEndTime(Context context) { | |
| 336 | + return MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).getLong("runQueryTraceEndTime", 0); | |
| 337 | + | |
| 338 | + } | |
| 339 | + | |
| 340 | + /** | |
| 341 | + * 设置轨迹查询实体名称 | |
| 342 | + * | |
| 343 | + * @param context | |
| 344 | + */ | |
| 345 | + public static void setQueryEntityName(Context context, String entityName) { | |
| 346 | + MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).putString("runQueryEntityName", entityName); | |
| 347 | + | |
| 348 | + } | |
| 349 | + | |
| 350 | + /** | |
| 351 | + * 互殴轨迹查询\的实体名称 | |
| 352 | + * | |
| 353 | + * @param context | |
| 354 | + */ | |
| 355 | + public static String getQueryQueryEntityName(Context context) { | |
| 356 | + return MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).getString("runQueryEntityName", ""); | |
| 357 | + | |
| 358 | + } | |
| 359 | + | |
| 360 | + | |
| 298 | 361 | /*重置 |
| 299 | 362 | * @param context |
| 300 | 363 | */ |
| ... | ... | @@ -309,6 +372,12 @@ public class CommonInfo { |
| 309 | 372 | MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("FirstStepSendTraceTip"); |
| 310 | 373 | MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("FenceId"); |
| 311 | 374 | MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("IsFirstShowTimeTip"); |
| 375 | + MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("runIsPauseState"); | |
| 376 | +// MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("runQueryTraceStartTime"); | |
| 377 | +// MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("runQueryTraceEndTime"); | |
| 378 | +// MySpHelper.getInstance(context, Context.MODE_MULTI_PROCESS).removeKey("runQueryEntityName"); | |
| 379 | + | |
| 380 | + | |
| 312 | 381 | } |
| 313 | 382 | |
| 314 | 383 | /*重置赛事 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunRaceDetailFragmentPresenter.java
| ... | ... | @@ -33,41 +33,6 @@ public class RunRaceDetailFragmentPresenter extends MvpBasePresenter<RunRaceDeta |
| 33 | 33 | paramsMap.put("sid", userId); |
| 34 | 34 | // 0-用户使用 1-运营使用 |
| 35 | 35 | paramsMap.put("state", state); |
| 36 | -// Logic.create(paramsMap) | |
| 37 | -// .action(new Logic.Action<Map<String, String>, BaseInfo<RunRaceDetailInfo>>() { | |
| 38 | -// @Override | |
| 39 | -// public Disposable action(Map<String, String> paramsMap, DataCallback<BaseInfo<RunRaceDetailInfo>> dataCallback) { | |
| 40 | -// return ApiRequest.service(ApiServiceRunLin.class, api -> api.getRunRaceDetail(paramsMap)).subscribe(context, dataCallback); | |
| 41 | -// } | |
| 42 | -// }).<BaseInfo<RunRaceDetailInfo>>event() | |
| 43 | -// .setStateCallback(new StateCallback() { | |
| 44 | -// @Override | |
| 45 | -// public void onState(int i) { | |
| 46 | -// if (getView() == null) { | |
| 47 | -// return; | |
| 48 | -// } | |
| 49 | -// if (i == STATE_LOAD) { | |
| 50 | -// QMUITipDialogUtil.loadingDialog(context, "正在获取赛事详情", false); | |
| 51 | -// } else if (i == STATE_IDLE) { | |
| 52 | -// } | |
| 53 | -// | |
| 54 | -// } | |
| 55 | -// }) | |
| 56 | -// .setSuccessCallback(new SuccessCallback<BaseInfo<RunRaceDetailInfo>>() { | |
| 57 | -// @Override | |
| 58 | -// public void onSuccess(BaseInfo<RunRaceDetailInfo> runRaceDetailInfoBaseInfo) { | |
| 59 | -// if (getView() == null) { | |
| 60 | -// return; | |
| 61 | -// } | |
| 62 | -// } | |
| 63 | -// }).setFailureCallback(new FailureCallback() { | |
| 64 | -// @Override | |
| 65 | -// public void onFailure(int i, String s) { | |
| 66 | -// if (getView() == null) { | |
| 67 | -// return; | |
| 68 | -// } | |
| 69 | -// } | |
| 70 | -// }).start(); | |
| 71 | 36 | Logic.create(paramsMap).action(new Logic.Action<Map<String, String>, BaseInfo<RunRaceDetailInfo>>() { |
| 72 | 37 | @Override |
| 73 | 38 | public Disposable action(Map<String, String> stringStringMap, DataCallback<BaseInfo<RunRaceDetailInfo>> dataCallback) { | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningFinishFragmetPresenter.java
| 1 | 1 | package com.cnlive.moudle.pedometer.frame.presenter; |
| 2 | 2 | |
| 3 | +import android.content.Context; | |
| 4 | +import android.graphics.Bitmap; | |
| 5 | +import android.os.Handler; | |
| 6 | +import android.text.TextUtils; | |
| 7 | +import android.util.Log; | |
| 8 | +import android.view.View; | |
| 9 | +import android.widget.Toast; | |
| 10 | + | |
| 11 | +import com.baidu.mapapi.map.BaiduMap; | |
| 12 | +import com.baidu.mapapi.model.LatLng; | |
| 13 | +import com.baidu.trace.LBSTraceClient; | |
| 14 | +import com.baidu.trace.model.SortType; | |
| 15 | +import com.cnlive.libs.base.logic.Event; | |
| 16 | +import com.cnlive.libs.base.logic.Logic; | |
| 17 | +import com.cnlive.libs.base.logic.callback.DataCallback; | |
| 18 | +import com.cnlive.libs.base.logic.callback.FailureCallback; | |
| 19 | +import com.cnlive.libs.base.logic.callback.StateCallback; | |
| 20 | +import com.cnlive.libs.base.logic.callback.SuccessCallback; | |
| 21 | +import com.cnlive.libs.base.util.ToastUtil; | |
| 22 | +import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; | |
| 3 | 23 | import com.cnlive.moudle.pedometer.frame.view.RunningFinishFragmentView; |
| 24 | +import com.cnlive.moudle.pedometer.model.RunningFinishBean; | |
| 25 | +import com.cnlive.moudle.pedometer.net.ApiServiceRunLin; | |
| 26 | +import com.cnlive.moudle.pedometer.net.SubscriptionRequest; | |
| 27 | +import com.cnlive.moudle.pedometer.net.bean.BaseInfo; | |
| 28 | +import com.cnlive.moudle.pedometer.net.bean.RunRaceDetailInfo; | |
| 29 | +import com.cnlive.moudle.pedometer.service.StepService; | |
| 30 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 31 | +import com.cnlive.moudle.pedometer.ui.widget.SelectDialog; | |
| 32 | +import com.cnlive.moudle.pedometer.ui.widget.TipDialog; | |
| 33 | +import com.cnlive.moudle.pedometer.upload.UploadLogic; | |
| 34 | +import com.cnlive.moudle.pedometer.utils.GsonUtil; | |
| 35 | +import com.cnlive.moudle.pedometer.utils.MyMapUtil; | |
| 36 | +import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; | |
| 37 | +import com.cnlive.moudle.pedometer.utils.StepUtil; | |
| 38 | +import com.cnlive.moudle.pedometer.utils.TimeUtil; | |
| 39 | +import com.example.moudle_pedometer.R; | |
| 4 | 40 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 5 | 41 | |
| 42 | +import java.io.File; | |
| 43 | +import java.io.FileOutputStream; | |
| 44 | +import java.text.SimpleDateFormat; | |
| 45 | +import java.util.ArrayList; | |
| 46 | +import java.util.Date; | |
| 47 | +import java.util.HashMap; | |
| 48 | +import java.util.List; | |
| 49 | +import java.util.Map; | |
| 50 | + | |
| 51 | +import io.reactivex.disposables.Disposable; | |
| 52 | + | |
| 53 | +import static com.cnlive.libs.base.logic.Config.STATE_IDLE; | |
| 54 | +import static com.cnlive.libs.base.logic.Config.STATE_LOAD; | |
| 55 | + | |
| 6 | 56 | public class RunningFinishFragmetPresenter extends MvpBasePresenter<RunningFinishFragmentView> { |
| 57 | + private LBSTraceClient mClient = null; | |
| 58 | + private String imports = "[{\"latitude\":39.93395837223,\"latitudeE6\":3.993395837223E7,\"longitude\":116.30855458458,\"longitudeE6\":1.1630855458457999E8},{\"latitude\":39.93396326228,\"latitudeE6\":3.993396326228E7,\"longitude\":116.30861833018,\"longitudeE6\":1.1630861833017999E8},{\"latitude\":39.934156956749995,\"latitudeE6\":3.993415695675E7,\"longitude\":116.30869672329999,\"longitudeE6\":1.163086967233E8},{\"latitude\":39.934220163784,\"latitudeE6\":3.9934220163784E7,\"longitude\":116.3087100148,\"longitudeE6\":1.163087100148E8},{\"latitude\":39.934285263072,\"latitudeE6\":3.9934285263072E7,\"longitude\":116.30866498582,\"longitudeE6\":1.1630866498582E8},{\"latitude\":39.934351994321,\"latitudeE6\":3.9934351994320996E7,\"longitude\":116.30865820422,\"longitudeE6\":1.1630865820422E8},{\"latitude\":39.934393506188,\"latitudeE6\":3.9934393506188005E7,\"longitude\":116.3087268324,\"longitudeE6\":1.163087268324E8},{\"latitude\":39.934515310648,\"latitudeE6\":3.9934515310648E7,\"longitude\":116.30877023341,\"longitudeE6\":1.1630877023341E8},{\"latitude\":39.934576888398,\"latitudeE6\":3.9934576888398E7,\"longitude\":116.30876860572,\"longitudeE6\":1.1630876860572E8},{\"latitude\":39.934641987882,\"latitudeE6\":3.9934641987882E7,\"longitude\":116.30872520428,\"longitudeE6\":1.1630872520427999E8},{\"latitude\":39.934720386354,\"latitudeE6\":3.9934720386354E7,\"longitude\":116.30874175083,\"longitudeE6\":1.1630874175083E8},{\"latitude\":39.934703845843,\"latitudeE6\":3.9934703845843E7,\"longitude\":116.30880197017,\"longitudeE6\":1.1630880197016999E8},{\"latitude\":39.934719055573,\"latitudeE6\":3.9934719055573E7,\"longitude\":116.30896553874,\"longitudeE6\":1.1630896553874E8},{\"latitude\":39.93482461107,\"latitudeE6\":3.993482461107E7,\"longitude\":116.30924466304002,\"longitudeE6\":1.1630924466304001E8},{\"latitude\":39.934804821527,\"latitudeE6\":3.9934804821527004E7,\"longitude\":116.30935804892,\"longitudeE6\":1.1630935804892E8},{\"latitude\":39.934856643274,\"latitudeE6\":3.9934856643274E7,\"longitude\":116.30943996874,\"longitudeE6\":1.1630943996874E8},{\"latitude\":39.934844987999,\"latitudeE6\":3.9934844987999E7,\"longitude\":116.30952026112,\"longitudeE6\":1.1630952026112E8},{\"latitude\":39.934722121282,\"latitudeE6\":3.9934722121282004E7,\"longitude\":116.30967542086,\"longitudeE6\":1.1630967542086E8},{\"latitude\":39.934828721701,\"latitudeE6\":3.9934828721701E7,\"longitude\":116.30960516489,\"longitudeE6\":1.1630960516489E8},{\"latitude\":39.934408798988,\"latitudeE6\":3.9934408798988E7,\"longitude\":116.30961357453,\"longitudeE6\":1.1630961357453E8},{\"latitude\":39.934345321571,\"latitudeE6\":3.9934345321571E7,\"longitude\":116.30960842073,\"longitudeE6\":1.1630960842073E8},{\"latitude\":39.93436159016,\"latitudeE6\":3.9934361590160005E7,\"longitude\":116.30954331882,\"longitudeE6\":1.1630954331882E8},{\"latitude\":39.934295133241,\"latitudeE6\":3.9934295133241E7,\"longitude\":116.30957668364,\"longitudeE6\":1.1630957668364E8},{\"latitude\":39.934188525341,\"latitudeE6\":3.9934188525341E7,\"longitude\":116.30958183769,\"longitudeE6\":1.1630958183769001E8},{\"latitude\":39.933976660469,\"latitudeE6\":3.9933976660469E7,\"longitude\":116.30954494693,\"longitudeE6\":1.1630954494693E8},{\"latitude\":39.933993190121,\"latitudeE6\":3.9933993190121E7,\"longitude\":116.30939114375,\"longitudeE6\":1.1630939114375001E8},{\"latitude\":39.933938115564,\"latitudeE6\":3.9933938115563996E7,\"longitude\":116.30932956832,\"longitudeE6\":1.1630932956831999E8},{\"latitude\":39.933916130555,\"latitudeE6\":3.9933916130555E7,\"longitude\":116.30922269279,\"longitudeE6\":1.1630922269279E8},{\"latitude\":39.933836097011,\"latitudeE6\":3.9933836097011E7,\"longitude\":116.30914077307,\"longitudeE6\":1.1630914077307E8}]\n"; | |
| 59 | + | |
| 60 | + public void saveRouteData(Context context, UserStepEntity userStepEntity, RunningFinishBean runningFinishBean) { | |
| 61 | + // 赛事id | |
| 62 | + String eventId = userStepEntity.getStreetId(); | |
| 63 | + //用户ID | |
| 64 | + String sid = CommonInfo.getUserId(context); | |
| 65 | + //用时 | |
| 66 | + String employTime = runningFinishBean.getEmployTime(); | |
| 67 | + //路线全程里数 | |
| 68 | + String mileage = ""; | |
| 69 | + if ("--".equals(runningFinishBean.getRunDistance())) { | |
| 70 | + mileage = "0"; | |
| 71 | + } else { | |
| 72 | + mileage = runningFinishBean.getRunDistance(); | |
| 73 | + } | |
| 74 | + //配速 | |
| 75 | + String pace = ""; | |
| 76 | + if ("--".equals(runningFinishBean.getSpeed())) { | |
| 77 | + pace = "0"; | |
| 78 | + } else { | |
| 79 | + pace = runningFinishBean.getSpeed(); | |
| 80 | + } | |
| 81 | + // 路线图 | |
| 82 | + String roadmap = runningFinishBean.getRoadmap(); | |
| 83 | + //经纬度 | |
| 84 | + String latLongitude = ""; | |
| 85 | + // 开始时间 | |
| 86 | + String startTime = userStepEntity.getStartTimeStamp() + ""; | |
| 87 | + //结束时间 | |
| 88 | + String endTime = userStepEntity.getFinishTimeStamp() + ""; | |
| 89 | + //暂停时间 | |
| 90 | + String pauseTime = ""; | |
| 91 | + String isPause = "0";//1暂停 | |
| 92 | + if (userStepEntity.getPauseCount() > 0) { | |
| 93 | + pauseTime = userStepEntity.getUserPauseTimeStamp() + ""; | |
| 94 | + isPause = "1"; | |
| 95 | + } | |
| 96 | + //继续时间 | |
| 97 | + String continueTime = ""; | |
| 98 | + //是否完成 | |
| 99 | + String completeStatus = runningFinishBean.getIsFinish(); | |
| 100 | + | |
| 101 | + //设置请求参数 | |
| 102 | + Map<String, String> paramsMap = new HashMap<>(); | |
| 103 | + paramsMap.put("eventId", eventId); | |
| 104 | + paramsMap.put("sid", sid); | |
| 105 | + paramsMap.put("employTime", employTime); | |
| 106 | + paramsMap.put("mileage", mileage); | |
| 107 | + paramsMap.put("pace", pace); | |
| 108 | + paramsMap.put("latLongitude", latLongitude); | |
| 109 | + paramsMap.put("roadmap", roadmap); | |
| 110 | + paramsMap.put("startTime", startTime); | |
| 111 | + paramsMap.put("endTime", endTime); | |
| 112 | + paramsMap.put("pauseTime", pauseTime); | |
| 113 | + paramsMap.put("continueTime", continueTime); | |
| 114 | + paramsMap.put("isPause", isPause); | |
| 115 | + paramsMap.put("completeStatus", completeStatus); | |
| 116 | + | |
| 117 | + | |
| 118 | + Logic.create(paramsMap).action(new Logic.Action<Map<String, String>, BaseInfo>() { | |
| 119 | + @Override | |
| 120 | + public Disposable action(Map<String, String> stringStringMap, DataCallback<BaseInfo> dataCallback) { | |
| 121 | + return SubscriptionRequest.service(ApiServiceRunLin.class, api -> api.saveRouteData(stringStringMap)).subscribe(context, dataCallback); | |
| 122 | + } | |
| 123 | + }).<BaseInfo>event() | |
| 124 | + .setFailureCallback(new FailureCallback() { | |
| 125 | + @Override | |
| 126 | + public void onFailure(int code, String message) { | |
| 127 | + QMUITipDialogUtil.dismessDialog(); | |
| 128 | + if (getView() == null) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + Log.e("saveRouteData", "onFailure: " + message); | |
| 132 | +// getView().hideLoadingView(); | |
| 133 | +// getView().showRetryView(code, new View.OnClickListener() { | |
| 134 | +// @Override | |
| 135 | +// public void onClick(View view) { | |
| 136 | +// getRunRaceDetailInfo(context, id, userId,state); | |
| 137 | +// } | |
| 138 | +// }); | |
| 139 | + } | |
| 140 | + }).setSuccessCallback(new SuccessCallback<BaseInfo>() { | |
| 141 | + @Override | |
| 142 | + public void onSuccess(BaseInfo baseInfo) { | |
| 143 | + if (getView() == null) { | |
| 144 | + return; | |
| 145 | + } | |
| 146 | + Log.e("saveRouteData", "onSuccess: "); | |
| 147 | + | |
| 148 | + QMUITipDialogUtil.dismessDialog(); | |
| 149 | + getView().updataIsFinish(runningFinishBean); | |
| 150 | + StepUtil.clearRunData(context, CommonInfo.getUserId(context)); | |
| 151 | + CommonInfo.reset(context); | |
| 152 | + | |
| 153 | + } | |
| 154 | + }).start(); | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * 查询当前用户历史轨迹 | |
| 159 | + */ | |
| 160 | + public void queryHistoryTrace(Context context, UserStepEntity userStepEntity, RunningFinishBean runningFinishBean) { | |
| 161 | + //查询当前用户的历史轨迹 | |
| 162 | + long startTime = userStepEntity.getStartTimeStamp(); | |
| 163 | + //获取当前的时间戳(秒) | |
| 164 | + long endTime = userStepEntity.getFinishTimeStamp(); | |
| 165 | + //获取当前的实体名称 | |
| 166 | + String entityName = CommonInfo.getUserId(context); | |
| 167 | + //路线全程里数 | |
| 168 | + | |
| 169 | + //打的重要点 | |
| 170 | + List<LatLng> importPoints = GsonUtil.jsonToList(imports, LatLng.class); | |
| 171 | + if (mClient == null) { | |
| 172 | + mClient = new LBSTraceClient(context); | |
| 173 | + } | |
| 174 | + MyMapUtil.queryHistoryTrace(context, mClient, entityName, startTime, endTime, new MyMapUtil.CallBack() { | |
| 175 | + @Override | |
| 176 | + public void success(List<LatLng> resultPoints) { | |
| 177 | + if (resultPoints != null) { | |
| 178 | + if (getView() != null && resultPoints != null) { | |
| 179 | + if (importPoints != null && resultPoints != null) { | |
| 180 | + //判断是否完成 | |
| 181 | + boolean isFinish = MyMapUtil.checkIsFinishTrace(importPoints, resultPoints, 0.6); | |
| 182 | + if (isFinish) { | |
| 183 | + Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 184 | + runningFinishBean.setIsFinish("1"); | |
| 185 | + } else { | |
| 186 | + Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 187 | + runningFinishBean.setIsFinish("0"); | |
| 188 | + } | |
| 189 | + MyMapUtil.drawHistoryTrack(context, getView().baiduMap, resultPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end); | |
| 190 | + new Handler().postDelayed(new Runnable() { | |
| 191 | + @Override | |
| 192 | + public void run() { | |
| 193 | + //开始截图 | |
| 194 | + getView().baiduMap.snapshot(new BaiduMap.SnapshotReadyCallback() { | |
| 195 | + @Override | |
| 196 | + public void onSnapshotReady(Bitmap bitmap) { | |
| 197 | + if (context == null) { | |
| 198 | + return; | |
| 199 | + } | |
| 200 | + if (null == bitmap) { | |
| 201 | + return; | |
| 202 | + } | |
| 203 | + //开始保存截屏 | |
| 204 | + try { | |
| 205 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); | |
| 206 | + File image = new File(context.getExternalCacheDir() + "/location_screenshot_" + sdf.format(new Date()) + ".jpeg"); | |
| 207 | + FileOutputStream fos = new FileOutputStream(image); | |
| 208 | + boolean b = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); | |
| 209 | + fos.flush(); | |
| 210 | + fos.close(); | |
| 211 | + String mapImagePath = image.getAbsolutePath(); | |
| 212 | + if (!TextUtils.isEmpty(mapImagePath)) { | |
| 213 | + QMUITipDialogUtil.loadingDialog(context, "正在上传数据", false); | |
| 214 | + //开始上传7牛 | |
| 215 | + List<String> imagePaths = new ArrayList<>(); | |
| 216 | + imagePaths.add(mapImagePath); | |
| 217 | + UploadLogic.uploadAddressPicInfo(getView().getContext(), imagePaths, new Event<String>() | |
| 218 | + .setFailureCallback(new FailureCallback() { | |
| 219 | + @Override | |
| 220 | + public void onFailure(int i, String s) { | |
| 221 | + QMUITipDialogUtil.dismessDialog(); | |
| 222 | + } | |
| 223 | + }) | |
| 224 | + .setSuccessCallback(new SuccessCallback<String>() { | |
| 225 | + @Override | |
| 226 | + public void onSuccess(String data) { | |
| 227 | + //设置截图 | |
| 228 | + runningFinishBean.setRoadmap(data); | |
| 229 | + //开始向服务器传数据 | |
| 230 | + saveRouteData(context, userStepEntity, runningFinishBean); | |
| 231 | + } | |
| 232 | + }) | |
| 233 | + ); | |
| 234 | + } | |
| 235 | + } catch (Exception e) { | |
| 236 | + e.printStackTrace(); | |
| 237 | + } | |
| 238 | + } | |
| 239 | + }); | |
| 240 | +// | |
| 241 | + } | |
| 242 | + }, 2000); | |
| 243 | + // | |
| 244 | + } | |
| 245 | + } | |
| 246 | + } | |
| 247 | + //查询失败 | |
| 248 | + else { | |
| 249 | + QMUITipDialogUtil.dismessDialog(); | |
| 250 | + SelectDialog selectDialog = new SelectDialog(context, "获取轨迹失败,是否重试?", "重试", new SelectDialog.DialogInterface() { | |
| 251 | + @Override | |
| 252 | + public void onClick(SelectDialog dialog) { | |
| 253 | + dialog.dismiss(); | |
| 254 | + queryHistoryTrace(context, userStepEntity, runningFinishBean); | |
| 255 | + } | |
| 256 | + }, "暂存", new SelectDialog.DialogInterface() { | |
| 257 | + @Override | |
| 258 | + public void onClick(SelectDialog dialog) { | |
| 259 | + dialog.dismiss(); | |
| 260 | + } | |
| 261 | + }); | |
| 262 | + selectDialog.setCanceledOnTouchOutside(false); | |
| 263 | + selectDialog.setCancelable(false); | |
| 264 | + selectDialog.show(); | |
| 265 | + } | |
| 266 | + } | |
| 267 | + }); | |
| 268 | + | |
| 269 | + } | |
| 270 | + | |
| 271 | + /** | |
| 272 | + * 查询运营人员踩得轨迹 | |
| 273 | + * | |
| 274 | + * @param userStepEntity | |
| 275 | + */ | |
| 276 | + public void getServerStreetTrace(Context context, UserStepEntity userStepEntity) { | |
| 277 | + if (mClient == null) { | |
| 278 | + mClient = new LBSTraceClient(context); | |
| 279 | + } | |
| 280 | + long serverStartTime = userStepEntity.getQueryTraceStartTime(); | |
| 281 | + long serverEndTime = userStepEntity.getQueryTraceEndTime(); | |
| 282 | + String serverEntityName = userStepEntity.getQueryEntityName(); | |
| 283 | + if (serverStartTime != 0 && serverEndTime != 0 && !TextUtils.isEmpty(serverEntityName) && mClient != null) { | |
| 284 | + //查询服务赛道历史轨迹 | |
| 285 | + MyMapUtil.queryHistoryTrace(context, mClient, serverEntityName, serverStartTime, serverEndTime, new MyMapUtil.CallBack() { | |
| 286 | + @Override | |
| 287 | + public void success(List<LatLng> resultPoints) { | |
| 288 | + if (resultPoints != null && resultPoints.size() > 1) { | |
| 289 | + if (getView() == null) { | |
| 290 | + return; | |
| 291 | + } | |
| 292 | + getView().drawServerStreetTrace(resultPoints); | |
| 293 | + } | |
| 294 | + | |
| 295 | + | |
| 296 | + } | |
| 297 | + }); | |
| 298 | + } | |
| 299 | + | |
| 300 | + } | |
| 7 | 301 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningMapFragmentPresenter.java
| ... | ... | @@ -4,6 +4,7 @@ import android.content.Context; |
| 4 | 4 | import android.graphics.Bitmap; |
| 5 | 5 | import android.graphics.BitmapFactory; |
| 6 | 6 | import android.os.Handler; |
| 7 | +import android.text.TextUtils; | |
| 7 | 8 | import android.util.Log; |
| 8 | 9 | import android.widget.Toast; |
| 9 | 10 | |
| ... | ... | @@ -60,16 +61,19 @@ import com.baidu.trace.model.SortType; |
| 60 | 61 | import com.baidu.trace.model.StatusCodes; |
| 61 | 62 | import com.baidu.trace.model.TraceLocation; |
| 62 | 63 | import com.baidu.trace.model.TransportMode; |
| 64 | +import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; | |
| 63 | 65 | import com.cnlive.moudle.pedometer.frame.view.RunningMapFragmentView; |
| 64 | 66 | import com.cnlive.moudle.pedometer.model.Constant; |
| 65 | 67 | import com.cnlive.moudle.pedometer.model.RoutePoint; |
| 66 | 68 | import com.cnlive.moudle.pedometer.service.StepService; |
| 69 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 67 | 70 | import com.cnlive.moudle.pedometer.utils.BitmapUtil; |
| 68 | 71 | import com.cnlive.moudle.pedometer.utils.CommonUtil; |
| 69 | 72 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 70 | 73 | import com.cnlive.moudle.pedometer.utils.MapUtil; |
| 71 | 74 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| 72 | 75 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 76 | +import com.cnlive.moudle.pedometer.utils.TimeUtil; | |
| 73 | 77 | import com.example.moudle_pedometer.R; |
| 74 | 78 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 75 | 79 | |
| ... | ... | @@ -106,11 +110,34 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 106 | 110 | /** |
| 107 | 111 | * 轨迹点集合 |
| 108 | 112 | */ |
| 109 | - private List<LatLng> realTimePoints; | |
| 110 | 113 | private String imports = "[{\"latitude\":39.93395837223,\"latitudeE6\":3.993395837223E7,\"longitude\":116.30855458458,\"longitudeE6\":1.1630855458457999E8},{\"latitude\":39.93396326228,\"latitudeE6\":3.993396326228E7,\"longitude\":116.30861833018,\"longitudeE6\":1.1630861833017999E8},{\"latitude\":39.934156956749995,\"latitudeE6\":3.993415695675E7,\"longitude\":116.30869672329999,\"longitudeE6\":1.163086967233E8},{\"latitude\":39.934220163784,\"latitudeE6\":3.9934220163784E7,\"longitude\":116.3087100148,\"longitudeE6\":1.163087100148E8},{\"latitude\":39.934285263072,\"latitudeE6\":3.9934285263072E7,\"longitude\":116.30866498582,\"longitudeE6\":1.1630866498582E8},{\"latitude\":39.934351994321,\"latitudeE6\":3.9934351994320996E7,\"longitude\":116.30865820422,\"longitudeE6\":1.1630865820422E8},{\"latitude\":39.934393506188,\"latitudeE6\":3.9934393506188005E7,\"longitude\":116.3087268324,\"longitudeE6\":1.163087268324E8},{\"latitude\":39.934515310648,\"latitudeE6\":3.9934515310648E7,\"longitude\":116.30877023341,\"longitudeE6\":1.1630877023341E8},{\"latitude\":39.934576888398,\"latitudeE6\":3.9934576888398E7,\"longitude\":116.30876860572,\"longitudeE6\":1.1630876860572E8},{\"latitude\":39.934641987882,\"latitudeE6\":3.9934641987882E7,\"longitude\":116.30872520428,\"longitudeE6\":1.1630872520427999E8},{\"latitude\":39.934720386354,\"latitudeE6\":3.9934720386354E7,\"longitude\":116.30874175083,\"longitudeE6\":1.1630874175083E8},{\"latitude\":39.934703845843,\"latitudeE6\":3.9934703845843E7,\"longitude\":116.30880197017,\"longitudeE6\":1.1630880197016999E8},{\"latitude\":39.934719055573,\"latitudeE6\":3.9934719055573E7,\"longitude\":116.30896553874,\"longitudeE6\":1.1630896553874E8},{\"latitude\":39.93482461107,\"latitudeE6\":3.993482461107E7,\"longitude\":116.30924466304002,\"longitudeE6\":1.1630924466304001E8},{\"latitude\":39.934804821527,\"latitudeE6\":3.9934804821527004E7,\"longitude\":116.30935804892,\"longitudeE6\":1.1630935804892E8},{\"latitude\":39.934856643274,\"latitudeE6\":3.9934856643274E7,\"longitude\":116.30943996874,\"longitudeE6\":1.1630943996874E8},{\"latitude\":39.934844987999,\"latitudeE6\":3.9934844987999E7,\"longitude\":116.30952026112,\"longitudeE6\":1.1630952026112E8},{\"latitude\":39.934722121282,\"latitudeE6\":3.9934722121282004E7,\"longitude\":116.30967542086,\"longitudeE6\":1.1630967542086E8},{\"latitude\":39.934828721701,\"latitudeE6\":3.9934828721701E7,\"longitude\":116.30960516489,\"longitudeE6\":1.1630960516489E8},{\"latitude\":39.934408798988,\"latitudeE6\":3.9934408798988E7,\"longitude\":116.30961357453,\"longitudeE6\":1.1630961357453E8},{\"latitude\":39.934345321571,\"latitudeE6\":3.9934345321571E7,\"longitude\":116.30960842073,\"longitudeE6\":1.1630960842073E8},{\"latitude\":39.93436159016,\"latitudeE6\":3.9934361590160005E7,\"longitude\":116.30954331882,\"longitudeE6\":1.1630954331882E8},{\"latitude\":39.934295133241,\"latitudeE6\":3.9934295133241E7,\"longitude\":116.30957668364,\"longitudeE6\":1.1630957668364E8},{\"latitude\":39.934188525341,\"latitudeE6\":3.9934188525341E7,\"longitude\":116.30958183769,\"longitudeE6\":1.1630958183769001E8},{\"latitude\":39.933976660469,\"latitudeE6\":3.9933976660469E7,\"longitude\":116.30954494693,\"longitudeE6\":1.1630954494693E8},{\"latitude\":39.933993190121,\"latitudeE6\":3.9933993190121E7,\"longitude\":116.30939114375,\"longitudeE6\":1.1630939114375001E8},{\"latitude\":39.933938115564,\"latitudeE6\":3.9933938115563996E7,\"longitude\":116.30932956832,\"longitudeE6\":1.1630932956831999E8},{\"latitude\":39.933916130555,\"latitudeE6\":3.9933916130555E7,\"longitude\":116.30922269279,\"longitudeE6\":1.1630922269279E8},{\"latitude\":39.933836097011,\"latitudeE6\":3.9933836097011E7,\"longitude\":116.30914077307,\"longitudeE6\":1.1630914077307E8}]\n"; |
| 111 | 114 | private HashMap<Integer, Boolean> importHash; |
| 112 | - private static int matchIndex = 0; | |
| 113 | 115 | |
| 116 | + /** | |
| 117 | + * 查询运营人员踩得轨迹 | |
| 118 | + * | |
| 119 | + * @param userStepEntity | |
| 120 | + */ | |
| 121 | + public void getServerStreetTrace(Context context, UserStepEntity userStepEntity) { | |
| 122 | + long serverStartTime = userStepEntity.getQueryTraceStartTime(); | |
| 123 | + long serverEndTime = userStepEntity.getQueryTraceEndTime(); | |
| 124 | + String serverEntityName = userStepEntity.getQueryEntityName(); | |
| 125 | + if (serverStartTime != 0 && serverEndTime != 0 && !TextUtils.isEmpty(serverEntityName) && StepService.mClient != null) { | |
| 126 | + //查询服务赛道历史轨迹 | |
| 127 | + MyMapUtil.queryHistoryTrace(context, StepService.mClient, serverEntityName, serverStartTime, serverEndTime, new MyMapUtil.CallBack() { | |
| 128 | + @Override | |
| 129 | + public void success(List<LatLng> resultPoints) { | |
| 130 | + if (resultPoints != null && resultPoints.size() > 1) { | |
| 131 | + if (getView() == null) { | |
| 132 | + return; | |
| 133 | + } | |
| 134 | + getView().drawServerStreetTrace(resultPoints); | |
| 135 | + } | |
| 136 | + } | |
| 137 | + }); | |
| 138 | + } | |
| 139 | + | |
| 140 | + } | |
| 114 | 141 | // /** |
| 115 | 142 | // * 查询历史轨迹 |
| 116 | 143 | // * |
| ... | ... | @@ -313,19 +340,21 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 313 | 340 | |
| 314 | 341 | |
| 315 | 342 | /** |
| 316 | - * 查询历史轨迹 | |
| 317 | - * | |
| 318 | - * @param startTime | |
| 319 | - * @param endTime | |
| 343 | + * 查询当前用户历史轨迹 | |
| 320 | 344 | */ |
| 321 | - public void queryHistoryTrace(Context context, String entityName, long startTime, long endTime) { | |
| 322 | - Log.e(TAG, "queryHistoryTrace: 时间:" + startTime); | |
| 345 | + public void queryHistoryTrace(Context context, UserStepEntity userStepEntity) { | |
| 346 | + //查询当前用户的历史轨迹 | |
| 347 | + long startTime = userStepEntity.getStartTimeStamp(); | |
| 348 | + //获取当前的时间戳(秒) | |
| 349 | + long endTime = TimeUtil.getNowTimeStamp(); | |
| 350 | + //获取当前的实体名称 | |
| 351 | + String entityName = CommonInfo.getUserId(context); | |
| 323 | 352 | //打的重要点 |
| 324 | 353 | List<LatLng> importPoints = GsonUtil.jsonToList(imports, LatLng.class); |
| 325 | 354 | MyMapUtil.queryHistoryTrace(context, StepService.mClient, entityName, startTime, endTime, new MyMapUtil.CallBack() { |
| 326 | 355 | @Override |
| 327 | 356 | public void success(List<LatLng> resultPoints) { |
| 328 | - if (resultPoints != null&&resultPoints.size()>1) { | |
| 357 | + if (resultPoints != null && resultPoints.size() > 1) { | |
| 329 | 358 | if (getView() != null && resultPoints != null) { |
| 330 | 359 | if (resultPoints.size() == 1) { |
| 331 | 360 | getView().setHistoryLastPoint(resultPoints.get(0)); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -60,6 +60,7 @@ public class RunMainFragmentView implements MvpView { |
| 60 | 60 | private int timeCountDown;//时间倒计时 |
| 61 | 61 | private String uid; |
| 62 | 62 | private boolean needWriteDataFlag = true;//是否需要将计时器基值写入到数据库 |
| 63 | + private UserStepEntity userStepEntity; | |
| 63 | 64 | // 定位相关 |
| 64 | 65 | private LocationClient mLocClient; |
| 65 | 66 | public MyLocationListenner myListener = new MyLocationListenner(); |
| ... | ... | @@ -118,6 +119,7 @@ public class RunMainFragmentView implements MvpView { |
| 118 | 119 | public void initView() { |
| 119 | 120 | Log.e(TAG, "initView: +时间" + SystemClock.elapsedRealtime()); |
| 120 | 121 | uid = CommonInfo.getUserId(getContext()); |
| 122 | + userStepEntity = StepUtil.getUserStepData(getContext(), uid); | |
| 121 | 123 | initLocationClient(); |
| 122 | 124 | fragment.binding.llRunMainRoot.setVisibility(View.GONE); |
| 123 | 125 | ButtonAnimUtil.startAnimation(fragment.binding.llStartTimeTip, false); |
| ... | ... | @@ -186,7 +188,6 @@ public class RunMainFragmentView implements MvpView { |
| 186 | 188 | handler.postDelayed(runnable, 1000); |
| 187 | 189 | CommonInfo.setIsFirstShowTimeTip(getContext(), false); |
| 188 | 190 | } else { |
| 189 | - UserStepEntity userStepEntity = StepUtil.getUserStepData(getContext(), uid); | |
| 190 | 191 | //隐藏计时界面 |
| 191 | 192 | fragment.binding.llStartTimeTip.setVisibility(View.GONE); |
| 192 | 193 | fragment.binding.llRunMainRoot.setVisibility(View.VISIBLE); |
| ... | ... | @@ -208,6 +209,8 @@ public class RunMainFragmentView implements MvpView { |
| 208 | 209 | fragment.binding.chronometer.setFormat("00:00:01"); |
| 209 | 210 | fragment.binding.chronometer.setBase(SystemClock.elapsedRealtime()); |
| 210 | 211 | } |
| 212 | + //设置继续运动时间 | |
| 213 | + StepUtil.setContinueTime(getContext(),uid,TimeUtil.getNowTimeStamp()); | |
| 211 | 214 | //因为进来以后就运动了,所以需要改变状态 |
| 212 | 215 | CommonInfo.setIsPauseState(getContext(), false); |
| 213 | 216 | //重新设置开始时间 |
| ... | ... | @@ -259,6 +262,8 @@ public class RunMainFragmentView implements MvpView { |
| 259 | 262 | fragment.binding.flContinue.setOnClickListener(new View.OnClickListener() { |
| 260 | 263 | @Override |
| 261 | 264 | public void onClick(View view) { |
| 265 | + //设置继续运动时间 | |
| 266 | + StepUtil.setContinueTime(getContext(),uid,TimeUtil.getNowTimeStamp()); | |
| 262 | 267 | //设置继续标志 |
| 263 | 268 | CommonInfo.setIsPauseState(getContext(), false); |
| 264 | 269 | //继续记录轨迹 |
| ... | ... | @@ -276,10 +281,9 @@ public class RunMainFragmentView implements MvpView { |
| 276 | 281 | public void run() { |
| 277 | 282 | //隐藏两个按钮 |
| 278 | 283 | fragment.binding.flStopTip.setVisibility(View.INVISIBLE); |
| 279 | - fragment.binding.llTwoBottomButton.setVisibility(View.GONE); | |
| 280 | - ButtonAnimUtil.setViewShowZoomIn(fragment.binding.llPause); | |
| 284 | +// ButtonAnimUtil.setViewShowZoomIn(fragment.binding.llPause); | |
| 281 | 285 | //显示暂停按钮 |
| 282 | - fragment.binding.llPause.setVisibility(View.VISIBLE); | |
| 286 | + fragment.binding.flPause.setVisibility(View.VISIBLE); | |
| 283 | 287 | } |
| 284 | 288 | }, ButtonAnimUtil.DEFAULT_ZOOM_DURATION * 2); |
| 285 | 289 | //继续计步 |
| ... | ... | @@ -335,13 +339,15 @@ public class RunMainFragmentView implements MvpView { |
| 335 | 339 | ButtonAnimUtil.setViewDefault(fragment.binding.flStop); |
| 336 | 340 | dialog.dismiss(); |
| 337 | 341 | RunningFinishBean runningFinishBean = new RunningFinishBean(); |
| 338 | - runningFinishBean.setStartPoint("开始地点"); | |
| 339 | - runningFinishBean.setEndPoint("结束地点"); | |
| 342 | + runningFinishBean.setStartPoint(userStepEntity.getStartPoint()); | |
| 343 | + runningFinishBean.setEndPoint(userStepEntity.getEndPoint()); | |
| 340 | 344 | runningFinishBean.setRunDistance(fragment.binding.tvRunDistance.getText().toString()); |
| 341 | 345 | runningFinishBean.setSpeed(fragment.binding.tvSpeed.getText().toString()); |
| 342 | 346 | runningFinishBean.setStep(fragment.binding.tvStepCount.getText().toString()); |
| 343 | 347 | runningFinishBean.setTime(fragment.binding.chronometer.getText().toString()); |
| 344 | 348 | runningFinishBean.setDate(TimeUtil.getFormatNowTime()); |
| 349 | + //设置用时 | |
| 350 | + runningFinishBean.setEmployTime(TimeUtil.getChronometerSeconds(fragment.binding.chronometer)); | |
| 345 | 351 | RunningFinishActivity.startActivity(fragment.getActivity(), runningFinishBean); |
| 346 | 352 | fragment.getActivity().finish(); |
| 347 | 353 | } |
| ... | ... | @@ -395,61 +401,40 @@ public class RunMainFragmentView implements MvpView { |
| 395 | 401 | fragment.binding.flPause.setOnClickListener(new View.OnClickListener() { |
| 396 | 402 | @Override |
| 397 | 403 | public void onClick(View view) { |
| 398 | - //将当前计时器时间戳写入数据库 | |
| 399 | - setSQLPauseTime(uid); | |
| 400 | - //设置暂停标志 | |
| 401 | - CommonInfo.setIsPauseState(getContext(), true); | |
| 402 | - //暂停轨迹记录 | |
| 403 | - if (StepService.mClient != null && StepService.traceListener != null) { | |
| 404 | - CommonInfo.setTsRunBaiduTraceService(getContext(), false); | |
| 405 | - StepService.mClient.stopGather(StepService.traceListener); | |
| 406 | - } | |
| 407 | - needWriteDataFlag = false; | |
| 408 | - ButtonAnimUtil.setViewHideZoomOut(fragment.binding.llPause); | |
| 409 | - handler.postDelayed(new Runnable() { | |
| 404 | + //进行提示 | |
| 405 | + SelectDialog selectDialog = new SelectDialog(getContext(), getContext().getString(R.string.run_pause_tip), "否", new SelectDialog.DialogInterface() { | |
| 410 | 406 | @Override |
| 411 | - public void run() { | |
| 412 | - //隐藏本身 | |
| 413 | - fragment.binding.llPause.setVisibility(View.GONE); | |
| 407 | + public void onClick(SelectDialog dialog) { | |
| 408 | + dialog.dismiss(); | |
| 414 | 409 | } |
| 415 | - }, ButtonAnimUtil.HIDE_VIEW_ZOOM_DURATION); | |
| 416 | - | |
| 410 | + }, "是", new SelectDialog.DialogInterface() { | |
| 411 | + @Override | |
| 412 | + public void onClick(SelectDialog dialog) { | |
| 413 | + dialog.dismiss(); | |
| 414 | + //进行暂停 | |
| 415 | + onBtnPause(); | |
| 416 | + } | |
| 417 | + }); | |
| 418 | + selectDialog.setCancelable(false); | |
| 419 | + selectDialog.setCanceledOnTouchOutside(true); | |
| 420 | + //先获取暂停次数 | |
| 417 | 421 | //获取当前用户暂停次数 |
| 418 | 422 | int userPauseCount = StepUtil.getUserPauseCount(getContext(), uid); |
| 419 | - if (userPauseCount != -1) { | |
| 420 | - if (userPauseCount > 1) { | |
| 421 | - //设置停止标志位,关闭相关服务 | |
| 422 | - setStopStartFlag(); | |
| 423 | - //清除数据库 | |
| 424 | - StepUtil.clearRunData(getContext(), CommonInfo.getUserId(getContext())); | |
| 425 | - //进行提示 | |
| 426 | - TipDialog tipDialog = new TipDialog(getContext(), getContext().getString(R.string.more_than_pause_count_tip), "我知道了", R.color.green_round, new TipDialog.DialogInterface() { | |
| 427 | - @Override | |
| 428 | - public void onClick(TipDialog dialog) { | |
| 429 | - //关闭当前对话框 | |
| 430 | - dialog.dismiss(); | |
| 431 | - //关闭当前页面 | |
| 432 | - if (getContext() == null) { | |
| 433 | - return; | |
| 434 | - } | |
| 435 | - fragment.getActivity().finish(); | |
| 436 | - } | |
| 437 | - }); | |
| 438 | - tipDialog.setCanceledOnTouchOutside(false); | |
| 439 | - tipDialog.setCancelable(false); | |
| 440 | - tipDialog.show(); | |
| 441 | - | |
| 442 | - } | |
| 443 | - //显示继续按钮 | |
| 444 | - fragment.binding.llTwoBottomButton.setVisibility(View.VISIBLE); | |
| 445 | - ButtonAnimUtil.setViewShowZoomIn(fragment.binding.flContinue); | |
| 446 | - ButtonAnimUtil.setViewShowZoomIn(fragment.binding.flStop); | |
| 447 | - //停止计时 | |
| 448 | - fragment.binding.chronometer.stop(); | |
| 449 | - mRecordTime = SystemClock.elapsedRealtime(); | |
| 450 | - //暂停计步 | |
| 451 | - EventBus.getDefault().post(new MessageEvent(Constant.SERVICE_STEP_COUNT_PAUSE, "")); | |
| 423 | + if (userPauseCount < 1) { | |
| 424 | + selectDialog.show(); | |
| 425 | + } else { | |
| 426 | + //只提示,不进行任何操作 | |
| 427 | + TipDialog tipDialog = new TipDialog(getContext(), "当前无法暂停", "我知道了", R.color.green_round, new TipDialog.DialogInterface() { | |
| 428 | + @Override | |
| 429 | + public void onClick(TipDialog dialog) { | |
| 430 | + dialog.dismiss(); | |
| 431 | + } | |
| 432 | + }); | |
| 433 | + tipDialog.setCanceledOnTouchOutside(false); | |
| 434 | + tipDialog.setCancelable(false); | |
| 435 | + tipDialog.show(); | |
| 452 | 436 | } |
| 437 | + | |
| 453 | 438 | } |
| 454 | 439 | }); |
| 455 | 440 | //gps点击事件 |
| ... | ... | @@ -475,7 +460,7 @@ public class RunMainFragmentView implements MvpView { |
| 475 | 460 | } |
| 476 | 461 | }); |
| 477 | 462 | //返回按钮点击事件 |
| 478 | - fragment.binding.ivBack.setOnClickListener(new View.OnClickListener() { | |
| 463 | + fragment.binding.llBack.setOnClickListener(new View.OnClickListener() { | |
| 479 | 464 | @Override |
| 480 | 465 | public void onClick(View view) { |
| 481 | 466 | if (getContext() == null) { |
| ... | ... | @@ -493,24 +478,84 @@ public class RunMainFragmentView implements MvpView { |
| 493 | 478 | }); |
| 494 | 479 | } |
| 495 | 480 | |
| 481 | + /** | |
| 482 | + * 暂停按钮 | |
| 483 | + */ | |
| 484 | + public void onBtnPause() { | |
| 485 | + //将当前计时器时间戳写入数据库 | |
| 486 | + setSQLPauseTime(uid); | |
| 487 | + //设置暂停标志 | |
| 488 | + CommonInfo.setIsPauseState(getContext(), true); | |
| 489 | + //暂停轨迹记录 | |
| 490 | + if (StepService.mClient != null && StepService.traceListener != null) { | |
| 491 | + CommonInfo.setTsRunBaiduTraceService(getContext(), false); | |
| 492 | + StepService.mClient.stopGather(StepService.traceListener); | |
| 493 | + } | |
| 494 | + needWriteDataFlag = false; | |
| 495 | +// ButtonAnimUtil.setViewHideZoomOut(fragment.binding.llPause); | |
| 496 | + handler.postDelayed(new Runnable() { | |
| 497 | + @Override | |
| 498 | + public void run() { | |
| 499 | + //隐藏本身 | |
| 500 | + fragment.binding.flPause.setVisibility(View.GONE); | |
| 501 | + } | |
| 502 | + }, ButtonAnimUtil.HIDE_VIEW_ZOOM_DURATION); | |
| 503 | + | |
| 504 | + //获取当前用户暂停次数 | |
| 505 | + int userPauseCount = StepUtil.getUserPauseCount(getContext(), uid); | |
| 506 | + if (userPauseCount != -1) { | |
| 507 | + if (userPauseCount > 1) { | |
| 508 | + //设置停止标志位,关闭相关服务 | |
| 509 | + setStopStartFlag(); | |
| 510 | + //清除数据库 | |
| 511 | + StepUtil.clearRunData(getContext(), CommonInfo.getUserId(getContext())); | |
| 512 | + //进行提示 | |
| 513 | + TipDialog tipDialog = new TipDialog(getContext(), getContext().getString(R.string.more_than_pause_count_tip), "我知道了", R.color.green_round, new TipDialog.DialogInterface() { | |
| 514 | + @Override | |
| 515 | + public void onClick(TipDialog dialog) { | |
| 516 | + //关闭当前对话框 | |
| 517 | + dialog.dismiss(); | |
| 518 | + //关闭当前页面 | |
| 519 | + if (getContext() == null) { | |
| 520 | + return; | |
| 521 | + } | |
| 522 | + fragment.getActivity().finish(); | |
| 523 | + } | |
| 524 | + }); | |
| 525 | + tipDialog.setCanceledOnTouchOutside(false); | |
| 526 | + tipDialog.setCancelable(false); | |
| 527 | + tipDialog.show(); | |
| 528 | + | |
| 529 | + } | |
| 530 | + //显示继续按钮 | |
| 531 | + ButtonAnimUtil.setViewShowZoomIn(fragment.binding.flContinue); | |
| 532 | + ButtonAnimUtil.setViewShowZoomIn(fragment.binding.flStop); | |
| 533 | + //停止计时 | |
| 534 | + fragment.binding.chronometer.stop(); | |
| 535 | + mRecordTime = SystemClock.elapsedRealtime(); | |
| 536 | + //暂停计步 | |
| 537 | + EventBus.getDefault().post(new MessageEvent(Constant.SERVICE_STEP_COUNT_PAUSE, "")); | |
| 538 | + } | |
| 539 | + } | |
| 540 | + | |
| 496 | 541 | public void setSQLPauseTime(String id) { |
| 497 | - Log.e(TAG, "setSQLPauseTime: " ); | |
| 542 | + Log.e(TAG, "setSQLPauseTime: "); | |
| 498 | 543 | // if (needWriteDataFlag) { |
| 499 | - //将当前计时器时间戳写入数据库 | |
| 500 | - if (!TextUtils.isEmpty(id)) { | |
| 501 | - UserStepEntity userStepEntity = StepUtil.getUserStepData(fragment.getActivity(), uid); | |
| 502 | - if (userStepEntity != null) { | |
| 503 | - userStepEntity.setPauseTimeStamp(fragment.binding.chronometer.getBase()); | |
| 504 | - //设置当前暂停的时间戳 | |
| 505 | - userStepEntity.setRecordTime(SystemClock.elapsedRealtime()); | |
| 506 | - //设置当前用户暂停的时间戳 | |
| 507 | - userStepEntity.setUserPauseTimeStamp(TimeUtil.getNowTimeStamp()); | |
| 508 | - //设置暂停次数 | |
| 509 | - userStepEntity.setPauseCount(userStepEntity.getPauseCount() + 1); | |
| 510 | - //更新数据 | |
| 511 | - StepUtil.updateStepData(fragment.getActivity(), userStepEntity); | |
| 512 | - } | |
| 544 | + //将当前计时器时间戳写入数据库 | |
| 545 | + if (!TextUtils.isEmpty(id)) { | |
| 546 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(fragment.getActivity(), uid); | |
| 547 | + if (userStepEntity != null) { | |
| 548 | + userStepEntity.setPauseTimeStamp(fragment.binding.chronometer.getBase()); | |
| 549 | + //设置当前暂停的时间戳 | |
| 550 | + userStepEntity.setRecordTime(SystemClock.elapsedRealtime()); | |
| 551 | + //设置当前用户暂停的时间戳 | |
| 552 | + userStepEntity.setUserPauseTimeStamp(TimeUtil.getNowTimeStamp()); | |
| 553 | + //设置暂停次数 | |
| 554 | + userStepEntity.setPauseCount(userStepEntity.getPauseCount() + 1); | |
| 555 | + //更新数据 | |
| 556 | + StepUtil.updateStepData(fragment.getActivity(), userStepEntity); | |
| 513 | 557 | } |
| 558 | + } | |
| 514 | 559 | // } |
| 515 | 560 | } |
| 516 | 561 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunRaceDetailFragmentView.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.Handler; | |
| 11 | 12 | import android.os.SystemClock; |
| 12 | 13 | import android.support.v4.content.ContextCompat; |
| 13 | 14 | import android.text.TextUtils; |
| ... | ... | @@ -53,6 +54,9 @@ import com.baidu.trace.LBSTraceClient; |
| 53 | 54 | import com.baidu.trace.Trace; |
| 54 | 55 | import com.baidu.trace.model.LocationMode; |
| 55 | 56 | import com.baidu.trace.model.SortType; |
| 57 | +import com.cnlive.libs.base.logic.Event; | |
| 58 | +import com.cnlive.libs.base.logic.callback.FailureCallback; | |
| 59 | +import com.cnlive.libs.base.logic.callback.SuccessCallback; | |
| 56 | 60 | import com.cnlive.moudle.pedometer.commonInfo.CollCommonInfo; |
| 57 | 61 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 58 | 62 | import com.cnlive.moudle.pedometer.model.Constant; |
| ... | ... | @@ -67,6 +71,7 @@ import com.cnlive.moudle.pedometer.ui.activity.TakePartActivity; |
| 67 | 71 | import com.cnlive.moudle.pedometer.ui.fragment.RunRaceDetailFragment; |
| 68 | 72 | import com.cnlive.moudle.pedometer.ui.widget.SelectDialog; |
| 69 | 73 | import com.cnlive.moudle.pedometer.ui.widget.TipDialog; |
| 74 | +import com.cnlive.moudle.pedometer.upload.UploadLogic; | |
| 70 | 75 | import com.cnlive.moudle.pedometer.utils.BitmapUtil; |
| 71 | 76 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 72 | 77 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| ... | ... | @@ -80,8 +85,12 @@ import com.example.moudle_pedometer.R; |
| 80 | 85 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 81 | 86 | import com.sothree.slidinguppanel.SlidingUpPanelLayout; |
| 82 | 87 | |
| 88 | +import java.io.File; | |
| 89 | +import java.io.FileOutputStream; | |
| 83 | 90 | import java.io.LineNumberReader; |
| 91 | +import java.text.SimpleDateFormat; | |
| 84 | 92 | import java.util.ArrayList; |
| 93 | +import java.util.Date; | |
| 85 | 94 | import java.util.LinkedList; |
| 86 | 95 | import java.util.List; |
| 87 | 96 | |
| ... | ... | @@ -126,6 +135,8 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 126 | 135 | private UserStepEntity userStepEntity; |
| 127 | 136 | private boolean isDifferentStreet = false; |
| 128 | 137 | private LBSTraceClient mClient = null; |
| 138 | + private List<LatLng> resultStreetPoints; | |
| 139 | + public List<LatLng> importStreetPoints;//运营打的重要的点 | |
| 129 | 140 | |
| 130 | 141 | public RunRaceDetailFragmentView(RunRaceDetailFragment fragment) { |
| 131 | 142 | this.fragment = fragment; |
| ... | ... | @@ -137,29 +148,78 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 137 | 148 | |
| 138 | 149 | |
| 139 | 150 | public void initView(RunRaceDetailInfo runRaceDetailInfo) { |
| 151 | + | |
| 152 | +// new Handler().postDelayed(new Runnable() { | |
| 153 | +// @Override | |
| 154 | +// public void run() { | |
| 155 | +// baiduMap.snapshot(new BaiduMap.SnapshotReadyCallback() { | |
| 156 | +// @Override | |
| 157 | +// public void onSnapshotReady(Bitmap bitmap) { | |
| 158 | +// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); | |
| 159 | +// if (null == bitmap) { | |
| 160 | +// return; | |
| 161 | +// } | |
| 162 | +// QMUITipDialogUtil.loadingDialog(getContext(), "上传", false); | |
| 163 | +// //开始保存截屏 | |
| 164 | +// try { | |
| 165 | +// File image = new File(getContext().getExternalCacheDir() + "/location_screenshot_" + sdf.format(new Date()) + ".jpeg"); | |
| 166 | +// FileOutputStream fos = new FileOutputStream(image); | |
| 167 | +// boolean b = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); | |
| 168 | +// fos.flush(); | |
| 169 | +// fos.close(); | |
| 170 | +// List<String> imagePaths = new ArrayList<>(); | |
| 171 | +// imagePaths.add(image.getAbsolutePath()); | |
| 172 | +// Log.e(TAG, "onSnapshotReady: "+image.getAbsolutePath() ); | |
| 173 | +// | |
| 174 | +// UploadLogic.uploadAddressPicInfo(getContext(), imagePaths, new Event<String>() | |
| 175 | +// .setFailureCallback(new FailureCallback() { | |
| 176 | +// @Override | |
| 177 | +// public void onFailure(int i, String s) { | |
| 178 | +// QMUITipDialogUtil.dismessDialog(); | |
| 179 | +// Log.e(TAG, "onFailure: " + s); | |
| 180 | +// } | |
| 181 | +// }) | |
| 182 | +// .setSuccessCallback(new SuccessCallback<String>() { | |
| 183 | +// @Override | |
| 184 | +// public void onSuccess(String data) { | |
| 185 | +// QMUITipDialogUtil.dismessDialog(); | |
| 186 | +// Log.e(TAG, "onSuccess: " + data); | |
| 187 | +// } | |
| 188 | +// }) | |
| 189 | +// ); | |
| 190 | +// } catch (Exception e) { | |
| 191 | +// e.printStackTrace(); | |
| 192 | +// } | |
| 193 | +// } | |
| 194 | +// }); | |
| 195 | +// // | |
| 196 | +// } | |
| 197 | +// },2000); | |
| 198 | + | |
| 140 | 199 | if (fragment.getActivity() == null) { |
| 141 | 200 | return; |
| 142 | 201 | } |
| 143 | 202 | this.runRaceDetailInfo = runRaceDetailInfo; |
| 144 | 203 | // //初始化地图点位 |
| 145 | -// if (runRaceDetailInfo.getLatLongitude() != null) { | |
| 146 | -// Log.e(TAG, "initView: 长度:" + runRaceDetailInfo.getLatLongitude().length()); | |
| 147 | -// trackPoints = GsonUtil.jsonToList(runRaceDetailInfo.getLatLongitude().trim(), LatLng.class); | |
| 148 | -// Log.e(TAG, "initView: trackPoints" + trackPoints.size()); | |
| 149 | -// MyMapUtil.drawServerLineTrack(getContext(), baiduMap, trackPoints, SortType.asc, R.color.green_round, R.drawable.icon_start, R.drawable.icon_end); | |
| 150 | -// //自动计算地图缩放 | |
| 151 | -// MapStatus.Builder builder = new MapStatus.Builder(); | |
| 152 | -// builder.target(MyMapUtil.getCenterZoomPosition(trackPoints)); | |
| 153 | -// builder.zoom(MyMapUtil.getZoom(trackPoints)); | |
| 154 | -// baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 155 | -// } | |
| 204 | + if (runRaceDetailInfo.getLatLongitude() != null) { | |
| 205 | + importStreetPoints = GsonUtil.jsonToList(runRaceDetailInfo.getLatLongitude().trim(), LatLng.class); | |
| 206 | + Log.e(TAG, "importStreetPoints点数量" + importStreetPoints.size()); | |
| 207 | + } | |
| 156 | 208 | //轨迹开始时间 |
| 157 | 209 | long startTime = 0; |
| 158 | 210 | //轨迹结束时间 |
| 159 | 211 | long endTime = 0; |
| 160 | - if (!TextUtils.isEmpty(runRaceDetailInfo.getStartTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEndTime())&&!TextUtils.isEmpty(runRaceDetailInfo.getEntityName())) { | |
| 212 | + if (!TextUtils.isEmpty(runRaceDetailInfo.getStartTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEndTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEntityName())) { | |
| 161 | 213 | startTime = Long.parseLong(runRaceDetailInfo.getStartTime()); |
| 162 | 214 | endTime = Long.parseLong(runRaceDetailInfo.getEndTime()); |
| 215 | + //todo 注意后续查询历史轨迹的时候,必须查数据库中的时间,因为涉及到历史运动恢复,所以不能用这个sp文件中的,这里设置,只是为了在服务启动成功后, | |
| 216 | + //设置轨迹查询实体名称 | |
| 217 | + CommonInfo.setQueryEntityName(getContext(), runRaceDetailInfo.getEntityName()); | |
| 218 | + //设置轨迹查询开始时间 | |
| 219 | + CommonInfo.setQueryTraceStartTime(getContext(), startTime); | |
| 220 | + //设置轨迹查询结束时间 | |
| 221 | + CommonInfo.setQueryTraceEndTime(getContext(), endTime); | |
| 222 | + | |
| 163 | 223 | mClient = new LBSTraceClient(getContext()); |
| 164 | 224 | //获取轨迹 |
| 165 | 225 | if (mClient != null) { |
| ... | ... | @@ -167,6 +227,7 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 167 | 227 | @Override |
| 168 | 228 | public void success(List<LatLng> resultPoints) { |
| 169 | 229 | if (resultPoints != null && resultPoints.size() > 1) { |
| 230 | + resultStreetPoints = resultPoints; | |
| 170 | 231 | Log.e(TAG, "resultPoints: " + resultPoints.size()); |
| 171 | 232 | MyMapUtil.drawServerLineTrack(getContext(), baiduMap, resultPoints, SortType.asc, R.color.green_round, R.drawable.icon_start, R.drawable.icon_end); |
| 172 | 233 | // //自动计算地图缩放 |
| ... | ... | @@ -175,14 +236,8 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 175 | 236 | // builder.zoom(MyMapUtil.getZoom(resultPoints)); |
| 176 | 237 | // baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); |
| 177 | 238 | |
| 178 | - LatLngBounds.Builder builder = new LatLngBounds.Builder(); | |
| 179 | - for (LatLng latLng : resultPoints) { | |
| 180 | - builder.include(latLng); | |
| 181 | - } | |
| 182 | - MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngBounds(builder.build()); | |
| 183 | - baiduMap.setMapStatus(mapStatusUpdate); | |
| 184 | - MapStatusUpdate msu = MapStatusUpdateFactory.zoomBy(-0.8f); | |
| 185 | - baiduMap.setMapStatus(msu); | |
| 239 | + //设置地图自动缩放 | |
| 240 | + MyMapUtil.setMapAutoZoom(baiduMap, resultPoints, -1.5f); | |
| 186 | 241 | |
| 187 | 242 | } |
| 188 | 243 | } |
| ... | ... | @@ -247,9 +302,8 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 247 | 302 | } |
| 248 | 303 | }); |
| 249 | 304 | /*************************设置相关页面数据***************************/ |
| 250 | - | |
| 251 | - //设置围栏ID | |
| 252 | - if (!TextUtils.isEmpty(runRaceDetailInfo.getFenceId())) { | |
| 305 | + if (runRaceDetailInfo.getFenceId() != null) { | |
| 306 | + //设置围栏ID | |
| 253 | 307 | CommonInfo.setFenceId(getContext(), Integer.parseInt(runRaceDetailInfo.getFenceId())); |
| 254 | 308 | } |
| 255 | 309 | //设置标题 |
| ... | ... | @@ -438,7 +492,12 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 438 | 492 | } |
| 439 | 493 | //现在开始 |
| 440 | 494 | else if ("1".equals(fragment.binding.rlScrollViewStartBtn.getTag())) { |
| 441 | - startStepService(getContext()); | |
| 495 | + //先判断是否从百度查询到赛事轨迹 | |
| 496 | + if (resultStreetPoints != null) { | |
| 497 | + startStepService(getContext()); | |
| 498 | + } else { | |
| 499 | + QMUITipDialogUtil.textDialog(getContext(), "正在获取轨迹请稍后...", 1); | |
| 500 | + } | |
| 442 | 501 | } |
| 443 | 502 | //继续运动 |
| 444 | 503 | else if ("2".equals(fragment.binding.rlScrollViewStartBtn.getTag())) { |
| ... | ... | @@ -515,10 +574,10 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 515 | 574 | stopStepService(); |
| 516 | 575 | startStepService(getContext()); |
| 517 | 576 | } else { |
| 518 | - PedometerMainActivity.startActivity(fragment.getActivity()); | |
| 577 | + PedometerMainActivity.startActivity(fragment.getActivity(), runRaceDetailInfo.getStartLocation(), runRaceDetailInfo.getEndLocation(),importStreetPoints); | |
| 519 | 578 | } |
| 520 | 579 | } else { |
| 521 | - PedometerMainActivity.startActivity(fragment.getActivity()); | |
| 580 | + PedometerMainActivity.startActivity(fragment.getActivity(), runRaceDetailInfo.getStartLocation(), runRaceDetailInfo.getEndLocation(),importStreetPoints); | |
| 522 | 581 | } |
| 523 | 582 | } |
| 524 | 583 | |
| ... | ... | @@ -540,6 +599,7 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 540 | 599 | if (baiduMap == null) { |
| 541 | 600 | baiduMap = mMapView.getMap(); |
| 542 | 601 | } |
| 602 | + | |
| 543 | 603 | if (routePlanSearch == null) { |
| 544 | 604 | routePlanSearch = RoutePlanSearch.newInstance(); |
| 545 | 605 | } |
| ... | ... | @@ -851,6 +911,20 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 851 | 911 | if (mMapView != null) { |
| 852 | 912 | mMapView.onResume(); |
| 853 | 913 | } |
| 914 | + //todo 防止停止后,再次开始,无法获取到赛道的轨迹 | |
| 915 | + if (runRaceDetailInfo != null) { | |
| 916 | + if (!TextUtils.isEmpty(runRaceDetailInfo.getStartTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEndTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEntityName())) { | |
| 917 | + long startTime = Long.parseLong(runRaceDetailInfo.getStartTime()); | |
| 918 | + long endTime = Long.parseLong(runRaceDetailInfo.getEndTime()); | |
| 919 | + //todo 注意后续查询历史轨迹的时候,必须查数据库中的时间,因为涉及到历史运动恢复,所以不能用这个sp文件中的,这里设置,只是为了在服务启动成功后, | |
| 920 | + //设置轨迹查询实体名称 | |
| 921 | + CommonInfo.setQueryEntityName(getContext(), runRaceDetailInfo.getEntityName()); | |
| 922 | + //设置轨迹查询开始时间 | |
| 923 | + CommonInfo.setQueryTraceStartTime(getContext(), startTime); | |
| 924 | + //设置轨迹查询结束时间 | |
| 925 | + CommonInfo.setQueryTraceEndTime(getContext(), endTime); | |
| 926 | + } | |
| 927 | + } | |
| 854 | 928 | |
| 855 | 929 | } |
| 856 | 930 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningFinishFragmentView.java
| ... | ... | @@ -5,17 +5,31 @@ import android.text.TextUtils; |
| 5 | 5 | import android.util.Log; |
| 6 | 6 | import android.view.View; |
| 7 | 7 | |
| 8 | +import com.baidu.mapapi.map.BaiduMap; | |
| 9 | +import com.baidu.mapapi.map.MapView; | |
| 10 | +import com.baidu.mapapi.map.UiSettings; | |
| 11 | +import com.baidu.mapapi.model.LatLng; | |
| 12 | +import com.baidu.trace.model.SortType; | |
| 8 | 13 | import com.bumptech.glide.Glide; |
| 9 | 14 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 10 | 15 | import com.cnlive.moudle.pedometer.model.RunningFinishBean; |
| 11 | 16 | import com.cnlive.moudle.pedometer.ui.fragment.RunningFinishFragment; |
| 12 | 17 | import com.cnlive.moudle.pedometer.ui.fragment.RunningMapFragment; |
| 18 | +import com.cnlive.moudle.pedometer.utils.MyMapUtil; | |
| 19 | +import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; | |
| 20 | +import com.example.moudle_pedometer.R; | |
| 13 | 21 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 22 | +import com.sothree.slidinguppanel.SlidingUpPanelLayout; | |
| 23 | + | |
| 24 | +import java.util.List; | |
| 14 | 25 | |
| 15 | 26 | |
| 16 | 27 | public class RunningFinishFragmentView implements MvpView { |
| 17 | 28 | private final String TAG = "RunningFinishView"; |
| 18 | 29 | private RunningFinishFragment fragment; |
| 30 | + public BaiduMap baiduMap; | |
| 31 | + private MapView mMapView; | |
| 32 | + private UiSettings mUiSettings; | |
| 19 | 33 | |
| 20 | 34 | public RunningFinishFragmentView(RunningFinishFragment fragment) { |
| 21 | 35 | this.fragment = fragment; |
| ... | ... | @@ -26,6 +40,8 @@ public class RunningFinishFragmentView implements MvpView { |
| 26 | 40 | } |
| 27 | 41 | |
| 28 | 42 | public void initView(RunningFinishBean runningFinishBean) { |
| 43 | + this.mMapView = fragment.binding.mapView; | |
| 44 | + initMap(); | |
| 29 | 45 | //设置用户头像 |
| 30 | 46 | String faceUrl = CommonInfo.getUserIcon(getContext()); |
| 31 | 47 | if (!TextUtils.isEmpty(faceUrl)) { |
| ... | ... | @@ -70,5 +86,65 @@ public class RunningFinishFragmentView implements MvpView { |
| 70 | 86 | fragment.getActivity().finish(); |
| 71 | 87 | } |
| 72 | 88 | }); |
| 89 | + //完成按钮 | |
| 90 | + fragment.binding.rlScrollViewStartBtn.setOnClickListener(new View.OnClickListener() { | |
| 91 | + @Override | |
| 92 | + public void onClick(View view) { | |
| 93 | + if ("1".equals(fragment.binding.rlScrollViewStartBtn.getTag())) { | |
| 94 | + if (fragment.getActivity() != null) { | |
| 95 | + fragment.getActivity().finish(); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + } | |
| 99 | + }); | |
| 100 | + } | |
| 101 | + | |
| 102 | + public void initMap() { | |
| 103 | + if (baiduMap == null) { | |
| 104 | + baiduMap = mMapView.getMap(); | |
| 105 | + } | |
| 106 | + if (mUiSettings == null) { | |
| 107 | + mUiSettings = baiduMap.getUiSettings(); | |
| 108 | + } | |
| 109 | + //启动所有手势 | |
| 110 | + mUiSettings.setAllGesturesEnabled(true); | |
| 111 | + //通过设置enable为true或false 选择是否显示缩放按钮 | |
| 112 | + mMapView.showZoomControls(false); | |
| 113 | + mUiSettings.setEnlargeCenterWithDoubleClickEnable(true); | |
| 114 | + //隐藏自带的指南针,改用自定义指南针 杨帅 | |
| 115 | + mUiSettings.setCompassEnabled(false); | |
| 116 | + //显示定位图层 | |
| 117 | + baiduMap.setMyLocationEnabled(false); | |
| 118 | + } | |
| 119 | + | |
| 120 | + public void drawServerStreetTrace(List<LatLng> trackPoints) { | |
| 121 | + if (getContext() == null) { | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + MyMapUtil.drawServerLineTrack(getContext(), baiduMap, trackPoints, SortType.asc, R.color.green_50, R.drawable.icon_start, R.drawable.icon_end); | |
| 125 | + //设置地图自动缩放 | |
| 126 | + MyMapUtil.setMapAutoZoom(baiduMap, trackPoints, -1.5f); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public void updataIsFinish(RunningFinishBean runningFinishBean) { | |
| 130 | + if (getContext() == null || runningFinishBean == null) { | |
| 131 | + return; | |
| 132 | + } | |
| 133 | + //显示提示框 | |
| 134 | + QMUITipDialogUtil.messageDialog(getContext(), "成绩已上传", 2); | |
| 135 | + //改变提示文字 | |
| 136 | + fragment.binding.tvRunNow.setText("完成"); | |
| 137 | + fragment.binding.rlScrollViewStartBtn.setTag("1"); | |
| 138 | + fragment.binding.loading.setVisibility(View.GONE); | |
| 139 | + //设置是否完成 | |
| 140 | + if ("1".equals(runningFinishBean.getIsFinish())) { | |
| 141 | + fragment.binding.includeFinishRunRoute.tvFinishState.setText("路线完成"); | |
| 142 | + fragment.binding.includeFinishRunRoute.tvFinishState.setTextColor(getContext().getResources().getColor(R.color.green_round)); | |
| 143 | + } else { | |
| 144 | + fragment.binding.includeFinishRunRoute.tvFinishState.setText("路线未完成"); | |
| 145 | + fragment.binding.includeFinishRunRoute.tvFinishState.setTextColor(getContext().getResources().getColor(R.color.red)); | |
| 146 | + } | |
| 147 | + fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED); | |
| 148 | + | |
| 73 | 149 | } |
| 74 | 150 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningMapFragmentView.java
| ... | ... | @@ -23,6 +23,7 @@ import com.baidu.mapapi.map.BaiduMap; |
| 23 | 23 | import com.baidu.mapapi.map.BitmapDescriptor; |
| 24 | 24 | import com.baidu.mapapi.map.BitmapDescriptorFactory; |
| 25 | 25 | import com.baidu.mapapi.map.MapStatus; |
| 26 | +import com.baidu.mapapi.map.MapStatusUpdate; | |
| 26 | 27 | import com.baidu.mapapi.map.MapStatusUpdateFactory; |
| 27 | 28 | import com.baidu.mapapi.map.MapView; |
| 28 | 29 | import com.baidu.mapapi.map.MarkerOptions; |
| ... | ... | @@ -31,6 +32,7 @@ import com.baidu.mapapi.map.MyLocationData; |
| 31 | 32 | import com.baidu.mapapi.map.Overlay; |
| 32 | 33 | import com.baidu.mapapi.map.UiSettings; |
| 33 | 34 | import com.baidu.mapapi.model.LatLng; |
| 35 | +import com.baidu.mapapi.model.LatLngBounds; | |
| 34 | 36 | import com.baidu.mapapi.utils.DistanceUtil; |
| 35 | 37 | import com.baidu.trace.model.SortType; |
| 36 | 38 | import com.cnlive.moudle.pedometer.model.RunningMapBean; |
| ... | ... | @@ -71,7 +73,6 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 71 | 73 | public MyLocationListenner myListener = new MyLocationListenner(); |
| 72 | 74 | private final int DEFULT_ZOOM = 17; |
| 73 | 75 | private boolean isFirstLoadMap = true; |
| 74 | - private List<LatLng> trackPoints; | |
| 75 | 76 | private Overlay currentLine; |
| 76 | 77 | private List<LatLng> currentPoints; |
| 77 | 78 | |
| ... | ... | @@ -83,9 +84,8 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 83 | 84 | return fragment == null ? null : fragment.getActivity(); |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | - public void initView(List<LatLng> trackPoints) { | |
| 87 | + public void initView() { | |
| 87 | 88 | currentPoints = new ArrayList<>(); |
| 88 | - this.trackPoints = trackPoints; | |
| 89 | 89 | this.mMapView = fragment.binding.mapView; |
| 90 | 90 | if (baiduMap == null) { |
| 91 | 91 | baiduMap = mMapView.getMap(); |
| ... | ... | @@ -156,24 +156,6 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 156 | 156 | baiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() { |
| 157 | 157 | @Override |
| 158 | 158 | public void onMapLoaded() { |
| 159 | - //自动计算地图缩放 | |
| 160 | - MapStatus.Builder builder = new MapStatus.Builder(); | |
| 161 | - builder.target(MyMapUtil.getCenterZoomPosition(trackPoints)); | |
| 162 | - builder.zoom(MyMapUtil.getZoom(trackPoints)); | |
| 163 | - baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 164 | - if (isFirstLoadMap) { | |
| 165 | - isFirstLoadMap = false; | |
| 166 | - new Handler().postDelayed(new Runnable() { | |
| 167 | - @Override | |
| 168 | - public void run() { | |
| 169 | - //绘制赛道轨迹 | |
| 170 | - if (getContext() == null) { | |
| 171 | - return; | |
| 172 | - } | |
| 173 | - MyMapUtil.drawServerLineTrack(getContext(), baiduMap, trackPoints, SortType.asc, R.color.green_50, R.drawable.icon_start, R.drawable.icon_end); | |
| 174 | - } | |
| 175 | - }, 1500); | |
| 176 | - } | |
| 177 | 159 | } |
| 178 | 160 | }); |
| 179 | 161 | //返回键 |
| ... | ... | @@ -218,6 +200,15 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 218 | 200 | |
| 219 | 201 | } |
| 220 | 202 | |
| 203 | + public void drawServerStreetTrace(List<LatLng> trackPoints) { | |
| 204 | + if (getContext() == null) { | |
| 205 | + return; | |
| 206 | + } | |
| 207 | + MyMapUtil.drawServerLineTrack(getContext(), baiduMap, trackPoints, SortType.asc, R.color.green_50, R.drawable.icon_start, R.drawable.icon_end); | |
| 208 | + //设置地图自动缩放 | |
| 209 | + MyMapUtil.setMapAutoZoom(baiduMap, trackPoints, -1.5f); | |
| 210 | + } | |
| 211 | + | |
| 221 | 212 | |
| 222 | 213 | /** |
| 223 | 214 | * //设置定位监听器,获取到用户当前位置 杨帅 |
| ... | ... | @@ -429,7 +420,9 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 429 | 420 | // 此处设置开发者获取到的方向信息,顺时针0-360 |
| 430 | 421 | .direction(mCurrentDirection).latitude(mylocation.latitude) |
| 431 | 422 | .longitude(mylocation.longitude).build(); |
| 432 | - baiduMap.setMyLocationData(mylocation); | |
| 423 | + if (baiduMap != null) { | |
| 424 | + baiduMap.setMyLocationData(mylocation); | |
| 425 | + } | |
| 433 | 426 | } |
| 434 | 427 | } |
| 435 | 428 | lastX = x; | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/model/Constant.java
| ... | ... | @@ -3,7 +3,7 @@ package com.cnlive.moudle.pedometer.model; |
| 3 | 3 | public class Constant { |
| 4 | 4 | public static final long SERVICE_ID = 213511; |
| 5 | 5 | public static final int TAG = 1; |
| 6 | - public static final int GATHER_INTERVAL = 3;//位置采集周期 | |
| 6 | + public static final int GATHER_INTERVAL =2;//位置采集周期 | |
| 7 | 7 | public static final int PACK_INTERVAL = 10;//位置采集周期 |
| 8 | 8 | |
| 9 | 9 | public static final int SERVICE_STEP_COUNT_UPDATE = 0;//步数更新 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/model/RunningFinishBean.java
| ... | ... | @@ -17,8 +17,25 @@ public class RunningFinishBean implements Serializable { |
| 17 | 17 | private String endPoint; |
| 18 | 18 | private String date; |
| 19 | 19 | private List<String> latList; |
| 20 | + private String employTime; | |
| 21 | + private String isFinish; | |
| 22 | + private String roadmap; | |
| 20 | 23 | |
| 24 | + public String getRoadmap() { | |
| 25 | + return roadmap; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void setRoadmap(String roadmap) { | |
| 29 | + this.roadmap = roadmap; | |
| 30 | + } | |
| 21 | 31 | |
| 32 | + public String getIsFinish() { | |
| 33 | + return isFinish; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public void setIsFinish(String isFinish) { | |
| 37 | + this.isFinish = isFinish; | |
| 38 | + } | |
| 22 | 39 | |
| 23 | 40 | public String getRunDistance() { |
| 24 | 41 | return runDistance; |
| ... | ... | @@ -75,4 +92,20 @@ public class RunningFinishBean implements Serializable { |
| 75 | 92 | public void setDate(String date) { |
| 76 | 93 | this.date = date; |
| 77 | 94 | } |
| 95 | + | |
| 96 | + public List<String> getLatList() { | |
| 97 | + return latList; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public void setLatList(List<String> latList) { | |
| 101 | + this.latList = latList; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public String getEmployTime() { | |
| 105 | + return employTime; | |
| 106 | + } | |
| 107 | + | |
| 108 | + public void setEmployTime(String employTime) { | |
| 109 | + this.employTime = employTime; | |
| 110 | + } | |
| 78 | 111 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/ApiServiceRunLin.java
| ... | ... | @@ -64,5 +64,12 @@ public interface ApiServiceRunLin { |
| 64 | 64 | */ |
| 65 | 65 | @POST("Daren/event/getRouteRecordList.action") |
| 66 | 66 | Observable<Result<BaseInfo<SelfRecordInfo>>> getSelfRecordInfo(@QueryMap() Map<String, String> maps); |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 保存个人约跑路线记录 | |
| 70 | + */ | |
| 71 | + @POST("Daren/event/routeRecord.action") | |
| 72 | + Observable<Result<BaseInfo>> saveRouteData(@QueryMap() Map<String, String> maps); | |
| 73 | + | |
| 67 | 74 | } |
| 68 | 75 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/SubscriptionRequest.java
| ... | ... | @@ -3,6 +3,7 @@ package com.cnlive.moudle.pedometer.net; |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | |
| 5 | 5 | import okhttp3.Interceptor; |
| 6 | + | |
| 6 | 7 | import com.cnlive.libs.base.application.AppConfig; |
| 7 | 8 | import com.cnlive.libs.base.logic.callback.DataCallback; |
| 8 | 9 | import com.cnlive.libs.data.network.ApiBuild; |
| ... | ... | @@ -11,6 +12,7 @@ import com.cnlive.libs.data.network.interceptor.NetPPEncryptInterceptor; |
| 11 | 12 | import com.cnlive.libs.data.network.interceptor.NetPPPayEncryptInterceptor; |
| 12 | 13 | import com.cnlive.libs.data.network.interceptor.SignEncryptInterceptor; |
| 13 | 14 | import com.cnlive.moudle.pedometer.net.bean.BaseInfo; |
| 15 | +import com.cnlive.moudle.pedometer.net.bean.upload.api.ApiServiceOpen; | |
| 14 | 16 | |
| 15 | 17 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 16 | 18 | import io.reactivex.disposables.Disposable; |
| ... | ... | @@ -21,17 +23,19 @@ import static com.cnlive.libs.base.logic.Config.SUCCESS; |
| 21 | 23 | |
| 22 | 24 | /** |
| 23 | 25 | * Created by Lynn on 2019/3/27. |
| 26 | + * modify by ShinnyYang | |
| 24 | 27 | */ |
| 25 | 28 | public class SubscriptionRequest<Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> { |
| 26 | 29 | private static final String SP_CMS_URL_DEBUT = "http://cmstest.cnlive.com:8768/"; |
| 27 | 30 | private static final String SP_CMS_URL = "http://cms.cnlive.com:8768/"; |
| 28 | - | |
| 31 | + private static final int OKHTTP_KEEP_ALIVE_DURATION_SECONDS = 10; | |
| 32 | + //OPEN API 接口域名 | |
| 33 | + private static final String OPEN_URL = "https://api.cnlive.com/"; | |
| 29 | 34 | //网++ 接口域名 |
| 30 | 35 | public static final String SP_BASE_URL = "https://apiwjj.cnlive.com/"; |
| 31 | 36 | //网++ 测试环境 接口域名 |
| 32 | 37 | public static final String SP_DEBUG_URL = "http://apiwjjtest.cnlive.com/"; |
| 33 | 38 | //OPEN API 接口域名 |
| 34 | - private static final String SP_OPEN_URL = "https://api.cnlive.com/"; | |
| 35 | 39 | private Observable observable; |
| 36 | 40 | |
| 37 | 41 | private static <T> String baseCMSEndpoint() { |
| ... | ... | @@ -43,7 +47,11 @@ public class SubscriptionRequest<Observable extends io.reactivex.Observable<Resu |
| 43 | 47 | } |
| 44 | 48 | |
| 45 | 49 | private static <T> String serviceEndpoint(Class<T> clazz) { |
| 46 | - return baseEndpoint(); | |
| 50 | + if (clazz == ApiServiceOpen.class) { | |
| 51 | + return OPEN_URL; | |
| 52 | + } else { | |
| 53 | + return baseEndpoint(); | |
| 54 | + } | |
| 47 | 55 | } |
| 48 | 56 | |
| 49 | 57 | public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> |
| ... | ... | @@ -51,6 +59,21 @@ public class SubscriptionRequest<Observable extends io.reactivex.Observable<Resu |
| 51 | 59 | return service(clazz, api, new SignEncryptInterceptor()); |
| 52 | 60 | } |
| 53 | 61 | |
| 62 | + public static <Service> Service service(Class<Service> clazz) { | |
| 63 | + return service(clazz, new SignEncryptInterceptor()); | |
| 64 | + } | |
| 65 | + | |
| 66 | + private static <Service> Service service(Class<Service> clazz, Interceptor... interceptor) { | |
| 67 | + return service(clazz, false, interceptor); | |
| 68 | + } | |
| 69 | + | |
| 70 | + private static <Service> Service service(Class<Service> clazz, boolean decode, Interceptor... interceptor) { | |
| 71 | + return ApiBuild.service(clazz, null) | |
| 72 | + .setEndpoint(serviceEndpoint(clazz)) | |
| 73 | + .addInterceptor(interceptor) | |
| 74 | + .service(decode, OKHTTP_KEEP_ALIVE_DURATION_SECONDS); | |
| 75 | + } | |
| 76 | + | |
| 54 | 77 | public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> |
| 55 | 78 | SubscriptionRequest<Observable, BaseData> serviceEncrypt(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api) { |
| 56 | 79 | return service(clazz, api, new NetPPEncryptInterceptor()); |
| ... | ... | @@ -78,13 +101,17 @@ public class SubscriptionRequest<Observable extends io.reactivex.Observable<Resu |
| 78 | 101 | Subscriber<BaseData> subscriber = new Subscriber<BaseData>(context) { |
| 79 | 102 | @Override |
| 80 | 103 | public void onCompleted(String s, String s1, BaseData data) { |
| 81 | - if (callback == null) return; | |
| 104 | + if (callback == null) { | |
| 105 | + return; | |
| 106 | + } | |
| 82 | 107 | callback.callback(SUCCESS, "", data); |
| 83 | 108 | } |
| 84 | 109 | |
| 85 | 110 | @Override |
| 86 | 111 | public void onError(String code, String message) { |
| 87 | - if (callback == null) return; | |
| 112 | + if (callback == null) { | |
| 113 | + return; | |
| 114 | + } | |
| 88 | 115 | int errorCode = -1; |
| 89 | 116 | try { |
| 90 | 117 | errorCode = Integer.valueOf(code); |
| ... | ... | @@ -101,5 +128,12 @@ public class SubscriptionRequest<Observable extends io.reactivex.Observable<Resu |
| 101 | 128 | .subscribe(subscriber.next, subscriber.error, subscriber.complete, subscriber.subscribe); |
| 102 | 129 | } |
| 103 | 130 | |
| 131 | + public static <Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 132 | + Disposable subscribe(Observable observable, Subscriber<BaseData> subscriber) { | |
| 133 | + return observable.take(1) | |
| 134 | + .subscribeOn(Schedulers.io()) | |
| 135 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 136 | + .subscribe(subscriber.next, subscriber.error, subscriber.complete, subscriber.subscribe); | |
| 137 | + } | |
| 104 | 138 | |
| 105 | 139 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/bean/upload/FeedBackInfo.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.net.bean.upload; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by Lynn on 2018/9/4. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +public class FeedBackInfo { | |
| 8 | + private String imageUrl; | |
| 9 | + private long imageWidth; | |
| 10 | + private long imageHeight; | |
| 11 | + | |
| 12 | + public String getImageUrl() { | |
| 13 | + return imageUrl; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public void setImageUrl(String imageUrl) { | |
| 17 | + this.imageUrl = imageUrl; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public long getImageWidth() { | |
| 21 | + return imageWidth; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public void setImageWidth(long imageWidth) { | |
| 25 | + this.imageWidth = imageWidth; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public long getImageHeight() { | |
| 29 | + return imageHeight; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public void setImageHeight(long imageHeight) { | |
| 33 | + this.imageHeight = imageHeight; | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public String toString() { | |
| 38 | + return "FeedBackInfo{" + | |
| 39 | + "imageUrl='" + imageUrl + '\'' + | |
| 40 | + ", imageWidth=" + imageWidth + | |
| 41 | + ", imageHeight=" + imageHeight + | |
| 42 | + '}'; | |
| 43 | + } | |
| 44 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/bean/upload/StorageInfoData.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.net.bean.upload; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by cnlive201803 on 2018/5/31. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +public class StorageInfoData { | |
| 8 | + private int storageId; | |
| 9 | + private String storageName; | |
| 10 | + private int storageType; | |
| 11 | + private int state; | |
| 12 | + private int contentType; | |
| 13 | + private int profile; | |
| 14 | + private String domain; | |
| 15 | + | |
| 16 | + | |
| 17 | + public int getStorageId() { | |
| 18 | + return storageId; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public void setStorageId(int storageId) { | |
| 22 | + this.storageId = storageId; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public String getStorageName() { | |
| 26 | + return storageName; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public void setStorageName(String storageName) { | |
| 30 | + this.storageName = storageName; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public int getStorageType() { | |
| 34 | + return storageType; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void setStorageType(int storageType) { | |
| 38 | + this.storageType = storageType; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public int getState() { | |
| 42 | + return state; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public void setState(int state) { | |
| 46 | + this.state = state; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public int getContentType() { | |
| 50 | + return contentType; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void setContentType(int contentType) { | |
| 54 | + this.contentType = contentType; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public int getProfile() { | |
| 58 | + return profile; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void setProfile(int profile) { | |
| 62 | + this.profile = profile; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public String getDomain() { | |
| 66 | + return domain; | |
| 67 | + } | |
| 68 | + | |
| 69 | + public void setDomain(String domain) { | |
| 70 | + this.domain = domain; | |
| 71 | + } | |
| 72 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/bean/upload/UploadAuthData.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.net.bean.upload; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by cnlive201803 on 2018/5/9. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +public class UploadAuthData { | |
| 8 | + private String Authorization; | |
| 9 | + private String Date; | |
| 10 | + private String token; | |
| 11 | + | |
| 12 | + public String getAuthorization() { | |
| 13 | + return Authorization; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public void setAuthorization(String authorization) { | |
| 17 | + Authorization = authorization; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public String getDate() { | |
| 21 | + return Date; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public void setDate(String date) { | |
| 25 | + Date = date; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public String getToken() { | |
| 29 | + return token; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public void setToken(String token) { | |
| 33 | + this.token = token; | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public String toString() { | |
| 38 | + return "UploadAuthData{" + | |
| 39 | + "Authorization='" + Authorization + '\'' + | |
| 40 | + ", Date='" + Date + '\'' + | |
| 41 | + ", token='" + token + '\'' + | |
| 42 | + '}'; | |
| 43 | + } | |
| 44 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/bean/upload/api/ApiServiceMoment.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.net.bean.upload.api; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.cnlive.moudle.pedometer.net.bean.BaseInfo; | |
| 5 | + | |
| 6 | +import java.util.List; | |
| 7 | +import java.util.Map; | |
| 8 | + | |
| 9 | +import io.reactivex.Observable; | |
| 10 | +import okhttp3.MultipartBody; | |
| 11 | +import okhttp3.RequestBody; | |
| 12 | +import retrofit2.adapter.rxjava2.Result; | |
| 13 | +import retrofit2.http.FieldMap; | |
| 14 | +import retrofit2.http.FormUrlEncoded; | |
| 15 | +import retrofit2.http.Headers; | |
| 16 | +import retrofit2.http.Multipart; | |
| 17 | +import retrofit2.http.POST; | |
| 18 | +import retrofit2.http.Part; | |
| 19 | +import retrofit2.http.PartMap; | |
| 20 | +import retrofit2.http.Path; | |
| 21 | +import retrofit2.http.QueryMap; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * 达人有关的接口 | |
| 25 | + */ | |
| 26 | +public interface ApiServiceMoment { | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 上传发布内容(图片传七牛) | |
| 30 | + */ | |
| 31 | + @POST("{user}") | |
| 32 | + Observable<Result<BaseInfo>> releaseMomentNe(@Path(value = "user", encoded = true) String path, @QueryMap Map<String, Object> maps); | |
| 33 | + | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 上传发布内容(不含图片) | |
| 37 | + */ | |
| 38 | + @POST("{user}") | |
| 39 | + Observable<Result<BaseInfo>> releaseMomentText(@Path(value = "user", encoded = true) String path, @QueryMap() Map<String, String> maps); | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | +} | |
| 44 | + | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/net/bean/upload/api/ApiServiceOpen.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.net.bean.upload.api; | |
| 2 | + | |
| 3 | +import com.cnlive.moudle.pedometer.net.bean.BaseInfo; | |
| 4 | +import com.cnlive.moudle.pedometer.net.bean.upload.StorageInfoData; | |
| 5 | +import com.cnlive.moudle.pedometer.net.bean.upload.UploadAuthData; | |
| 6 | +import java.util.List; | |
| 7 | +import java.util.Map; | |
| 8 | + | |
| 9 | +import io.reactivex.Observable; | |
| 10 | +import retrofit2.adapter.rxjava2.Result; | |
| 11 | +import retrofit2.http.POST; | |
| 12 | +import retrofit2.http.QueryMap; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Created by xiansong on 2018/3/22. | |
| 16 | + */ | |
| 17 | + | |
| 18 | +public interface ApiServiceOpen { | |
| 19 | + | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 上传鉴权 | |
| 23 | + * | |
| 24 | + * @param maps | |
| 25 | + * @return | |
| 26 | + */ | |
| 27 | + @POST("open/api2/vod_epg/getUploadAuthForApp") | |
| 28 | + Observable<Result<BaseInfo<UploadAuthData>>> getUploadAuthForApp(@QueryMap Map<String, String> maps); | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 获取存储信息 | |
| 32 | + * | |
| 33 | + * @param map | |
| 34 | + * @return | |
| 35 | + */ | |
| 36 | + @POST("open/api2/storage/getStorageInfo") | |
| 37 | + Observable<Result<BaseInfo<List<StorageInfoData>>>> getStorageInfo(@QueryMap Map<String, String> map); | |
| 38 | + | |
| 39 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/KeepLiveService.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,7 @@ import android.util.Log; |
| 19 | 20 | |
| 20 | 21 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 21 | 22 | import com.cnlive.moudle.pedometer.receivers.ServiceReceiver; |
| 23 | +import com.cnlive.moudle.pedometer.ui.activity.PedometerMainActivity; | |
| 22 | 24 | import com.cnlive.moudle.pedometer.utils.ServiceUtils; |
| 23 | 25 | import com.example.moudle_pedometer.R; |
| 24 | 26 | |
| ... | ... | @@ -209,9 +211,22 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 209 | 211 | channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PRIVATE); |
| 210 | 212 | mNM.createNotificationChannel(channel); |
| 211 | 213 | } |
| 214 | +// notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID) | |
| 215 | +// .setWhen(System.currentTimeMillis()) | |
| 216 | +// .setContentTitle(getApplicationContext().getString(R.string.app_name)) | |
| 217 | +// .setContentText("正在计步,请勿关闭") | |
| 218 | +// .setSound(null) | |
| 219 | +// .build(); | |
| 220 | + Intent notificationIntent = new Intent(this, PedometerMainActivity.class); | |
| 212 | 221 | notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID) |
| 213 | - .setWhen(System.currentTimeMillis()) | |
| 222 | + .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 223 | + .setSmallIcon(R.mipmap.ic_launcher) | |
| 224 | +// .setCustomContentView(remoteViews) | |
| 225 | + .setContentTitle(getResources().getString(R.string.app_name)) | |
| 226 | + .setContentText("正在记录您的运动") | |
| 227 | + .setCategory(Notification.CATEGORY_SERVICE) | |
| 214 | 228 | .setSound(null) |
| 229 | + .setWhen(System.currentTimeMillis()) | |
| 215 | 230 | .build(); |
| 216 | 231 | // 0 隐藏前台服务通知 |
| 217 | 232 | startForeground(100, notification); |
| ... | ... | @@ -221,11 +236,10 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 221 | 236 | @Override |
| 222 | 237 | public void onDestroy() { |
| 223 | 238 | super.onDestroy(); |
| 224 | - if (myReceiver != null) { | |
| 225 | - unregisterReceiver(myReceiver); | |
| 226 | - } | |
| 227 | 239 | try { |
| 228 | -// stopForeground(true); | |
| 240 | + if (myReceiver != null) { | |
| 241 | + unregisterReceiver(myReceiver); | |
| 242 | + } | |
| 229 | 243 | } catch (Exception e) { |
| 230 | 244 | } |
| 231 | 245 | stopPlaySong(); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
| ... | ... | @@ -28,8 +28,22 @@ import android.widget.Toast; |
| 28 | 28 | |
| 29 | 29 | import com.baidu.trace.LBSTraceClient; |
| 30 | 30 | import com.baidu.trace.Trace; |
| 31 | +import com.baidu.trace.api.fence.AddMonitoredPersonResponse; | |
| 32 | +import com.baidu.trace.api.fence.CreateFenceResponse; | |
| 33 | +import com.baidu.trace.api.fence.DeleteFenceResponse; | |
| 34 | +import com.baidu.trace.api.fence.DeleteMonitoredPersonResponse; | |
| 31 | 35 | import com.baidu.trace.api.fence.FenceAlarmPushInfo; |
| 36 | +import com.baidu.trace.api.fence.FenceListResponse; | |
| 37 | +import com.baidu.trace.api.fence.HistoryAlarmResponse; | |
| 38 | +import com.baidu.trace.api.fence.ListMonitoredPersonResponse; | |
| 32 | 39 | import com.baidu.trace.api.fence.MonitoredAction; |
| 40 | +import com.baidu.trace.api.fence.MonitoredStatus; | |
| 41 | +import com.baidu.trace.api.fence.MonitoredStatusByLocationResponse; | |
| 42 | +import com.baidu.trace.api.fence.MonitoredStatusInfo; | |
| 43 | +import com.baidu.trace.api.fence.MonitoredStatusRequest; | |
| 44 | +import com.baidu.trace.api.fence.MonitoredStatusResponse; | |
| 45 | +import com.baidu.trace.api.fence.OnFenceListener; | |
| 46 | +import com.baidu.trace.api.fence.UpdateFenceResponse; | |
| 33 | 47 | import com.baidu.trace.api.track.LatestPoint; |
| 34 | 48 | import com.baidu.trace.api.track.LatestPointResponse; |
| 35 | 49 | import com.baidu.trace.api.track.OnTrackListener; |
| ... | ... | @@ -55,7 +69,9 @@ import org.greenrobot.eventbus.Subscribe; |
| 55 | 69 | import org.greenrobot.eventbus.ThreadMode; |
| 56 | 70 | |
| 57 | 71 | import java.text.SimpleDateFormat; |
| 72 | +import java.util.ArrayList; | |
| 58 | 73 | import java.util.Date; |
| 74 | +import java.util.List; | |
| 59 | 75 | |
| 60 | 76 | |
| 61 | 77 | public class StepService extends Service implements SensorEventListener { |
| ... | ... | @@ -234,6 +250,25 @@ public class StepService extends Service implements SensorEventListener { |
| 234 | 250 | CommonInfo.setIsFirstStepSendTraceTip(getApplicationContext(), false); |
| 235 | 251 | EventBus.getDefault().post(new MessageEvent(Constant.START_TRACE_GATHER_SUCCESS, "")); |
| 236 | 252 | } |
| 253 | + //设置用户开始时间以及赛事ID | |
| 254 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getApplicationContext(), CommonInfo.getUserId(getApplicationContext())); | |
| 255 | + if (userStepEntity == null) { | |
| 256 | + StepUtil.setStepStartData(getApplicationContext(), userId, TimeUtil.getNowTimeStamp(), CommonInfo.getStreetId(getApplicationContext())); | |
| 257 | + //设置从服务器获取的时间(后续查询历史轨迹的时间,要从数据库中获取,因为涉及到现有运动恢复问题) | |
| 258 | + StepUtil.setQueryTraceTime(getApplicationContext(), userId, CommonInfo.getQueryTraceStartTime(getApplicationContext()), CommonInfo.getQueryTraceEndTime(getApplicationContext()), CommonInfo.getQueryQueryEntityName(getApplicationContext())); | |
| 259 | + int fenceId = CommonInfo.getFenceId(getApplicationContext()); | |
| 260 | + //设置围栏id | |
| 261 | + StepUtil.setFenceId(getApplicationContext(), CommonInfo.getUserId(getApplicationContext()), fenceId); | |
| 262 | + //清空临时保存的时间 | |
| 263 | + CommonInfo.setQueryTraceEndTime(getApplicationContext(), 0); | |
| 264 | + CommonInfo.setQueryTraceStartTime(getApplicationContext(), 0); | |
| 265 | + CommonInfo.setQueryEntityName(getApplicationContext(), ""); | |
| 266 | + CommonInfo.setFenceId(getApplicationContext(), -1); | |
| 267 | + } | |
| 268 | + //开始设置围栏报警 | |
| 269 | + startQueryFence(); | |
| 270 | + | |
| 271 | + | |
| 237 | 272 | } |
| 238 | 273 | } else { |
| 239 | 274 | boolean isFirstSendNotification = CommonInfo.getIsFirstStepSendTraceTip(getApplicationContext()); |
| ... | ... | @@ -327,16 +362,22 @@ public class StepService extends Service implements SensorEventListener { |
| 327 | 362 | if (null == alarmPushInfo) { |
| 328 | 363 | return; |
| 329 | 364 | } |
| 330 | - //超出范围 | |
| 331 | - if (alarmPushInfo.getMonitoredAction() == MonitoredAction.exit) { | |
| 332 | - EventBus.getDefault().post(new MessageEvent(Constant.EXIT_RANGE, "")); | |
| 333 | - } | |
| 334 | - //进入范围 | |
| 335 | - else if (alarmPushInfo.getMonitoredAction() == MonitoredAction.enter) { | |
| 336 | - EventBus.getDefault().post(new MessageEvent(Constant.ENTER_RANGE, "")); | |
| 365 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getApplicationContext(), CommonInfo.getUserId(getApplicationContext())); | |
| 366 | + if (userStepEntity == null) { | |
| 367 | + return; | |
| 337 | 368 | } |
| 338 | - Toast.makeText(getApplicationContext(), "onPushCallback:" + alarmPushInfo.getMonitoredAction(), Toast.LENGTH_SHORT).show(); | |
| 369 | + if (alarmPushInfo.getFenceId() == userStepEntity.getFenceId()) { | |
| 339 | 370 | |
| 371 | + //超出范围 | |
| 372 | + if (alarmPushInfo.getMonitoredAction() == MonitoredAction.exit) { | |
| 373 | + EventBus.getDefault().post(new MessageEvent(Constant.EXIT_RANGE, "")); | |
| 374 | + } | |
| 375 | + //进入范围 | |
| 376 | + else if (alarmPushInfo.getMonitoredAction() == MonitoredAction.enter) { | |
| 377 | + EventBus.getDefault().post(new MessageEvent(Constant.ENTER_RANGE, "")); | |
| 378 | + } | |
| 379 | + Toast.makeText(getApplicationContext(), "onPushCallback:" + alarmPushInfo.getMonitoredAction(), Toast.LENGTH_SHORT).show(); | |
| 380 | + } | |
| 340 | 381 | } |
| 341 | 382 | |
| 342 | 383 | @Override |
| ... | ... | @@ -347,15 +388,122 @@ public class StepService extends Service implements SensorEventListener { |
| 347 | 388 | //开启轨迹服务 |
| 348 | 389 | if (mClient != null) { |
| 349 | 390 | mClient.startTrace(mTrace, traceListener); |
| 350 | - //设置用户开始时间以及赛事ID | |
| 351 | - UserStepEntity userStepEntity = StepUtil.getUserStepData(getApplicationContext(), CommonInfo.getUserId(getApplicationContext())); | |
| 352 | - if (userStepEntity == null) { | |
| 353 | - StepUtil.setStepStartData(getApplicationContext(), userId, TimeUtil.getNowTimeStamp(), CommonInfo.getStreetId(getApplicationContext())); | |
| 354 | - } | |
| 355 | 391 | } |
| 356 | 392 | |
| 357 | 393 | } |
| 358 | 394 | |
| 395 | + public void startQueryFence() { | |
| 396 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getApplicationContext(), CommonInfo.getUserId(getApplicationContext())); | |
| 397 | + // 初始化围栏监听器 | |
| 398 | + OnFenceListener onFenceListener = new OnFenceListener() { | |
| 399 | + // 创建围栏回调 | |
| 400 | + @Override | |
| 401 | + public void onCreateFenceCallback(CreateFenceResponse createFenceResponse) { | |
| 402 | + if ("成功".equals(createFenceResponse.getMessage())) { | |
| 403 | +// Toast.makeText(context, "创建围栏回调成功", Toast.LENGTH_SHORT).show(); | |
| 404 | + Log.e(TAG, "onCreateFenceCallback: " + createFenceResponse.getFenceId()); | |
| 405 | + // 查询围栏监控者状态 | |
| 406 | + List<Long> list = new ArrayList<>(); | |
| 407 | + list.add(createFenceResponse.getFenceId()); | |
| 408 | + // 创建查询服务端围栏监控状态请求 | |
| 409 | + | |
| 410 | + } | |
| 411 | + } | |
| 412 | + | |
| 413 | + // 更新围栏回调 | |
| 414 | + @Override | |
| 415 | + public void onUpdateFenceCallback(UpdateFenceResponse updateFenceResponse) { | |
| 416 | + | |
| 417 | + } | |
| 418 | + | |
| 419 | + // 删除围栏回调 | |
| 420 | + @Override | |
| 421 | + public void onDeleteFenceCallback(DeleteFenceResponse deleteFenceResponse) { | |
| 422 | + | |
| 423 | + } | |
| 424 | + | |
| 425 | + // 围栏列表回调 | |
| 426 | + @Override | |
| 427 | + public void onFenceListCallback(FenceListResponse fenceListResponse) { | |
| 428 | + if ("成功".equals(fenceListResponse.getMessage())) { | |
| 429 | +// Toast.makeText(context, "围栏列表回调成功:" + fenceListResponse.getSize(), Toast.LENGTH_SHORT).show(); | |
| 430 | + } | |
| 431 | + } | |
| 432 | + | |
| 433 | + // 监控状态回调 | |
| 434 | + @Override | |
| 435 | + public void onMonitoredStatusCallback(MonitoredStatusResponse monitoredStatusResponse) { | |
| 436 | + if (monitoredStatusResponse.getMonitoredStatusInfos() != null) { | |
| 437 | + Toast.makeText(getApplicationContext(), "围栏列表回调成功:个数:" + monitoredStatusResponse.getMonitoredStatusInfos().size(), Toast.LENGTH_SHORT).show(); | |
| 438 | + } //查询监控对象状态响应结果 | |
| 439 | + List<MonitoredStatusInfo> monitoredStatusInfos = monitoredStatusResponse.getMonitoredStatusInfos(); | |
| 440 | + if (monitoredStatusInfos == null) { | |
| 441 | + return; | |
| 442 | + } | |
| 443 | + for (MonitoredStatusInfo monitoredStatusInfo : monitoredStatusInfos) { | |
| 444 | + if (monitoredStatusInfo.getFenceId() == userStepEntity.getFenceId()) { | |
| 445 | + MonitoredStatus status = monitoredStatusInfo.getMonitoredStatus();//获取状态 | |
| 446 | + switch (status) { | |
| 447 | + case in: | |
| 448 | + //监控的设备在围栏内 | |
| 449 | + Toast.makeText(getApplicationContext(), "监控的设备在围栏内", Toast.LENGTH_SHORT).show(); | |
| 450 | + Log.e(TAG, "监控的设备在围栏内: "); | |
| 451 | + break; | |
| 452 | + case out: | |
| 453 | + //监控的设备在围栏外 | |
| 454 | + Toast.makeText(getApplicationContext(), "监控的设备在围栏外", Toast.LENGTH_SHORT).show(); | |
| 455 | + Log.e(TAG, "监控的设备在围栏外: "); | |
| 456 | + | |
| 457 | + break; | |
| 458 | + case unknown: | |
| 459 | + //监控的设备状态未知 | |
| 460 | + Toast.makeText(getApplicationContext(), "监控的设备状态未知", Toast.LENGTH_SHORT).show(); | |
| 461 | + Log.e(TAG, "监控的设备状态未知: "); | |
| 462 | + | |
| 463 | + break; | |
| 464 | + } | |
| 465 | + } | |
| 466 | + } | |
| 467 | + } | |
| 468 | + | |
| 469 | + // 指定位置监控状态回调 | |
| 470 | + @Override | |
| 471 | + public void onMonitoredStatusByLocationCallback(MonitoredStatusByLocationResponse monitoredStatusByLocationResponse) { | |
| 472 | + Log.e(TAG, "onMonitoredStatusByLocationCallback: "); | |
| 473 | + } | |
| 474 | + | |
| 475 | + // 历史报警回调 | |
| 476 | + @Override | |
| 477 | + public void onHistoryAlarmCallback(HistoryAlarmResponse historyAlarmResponse) { | |
| 478 | + Log.e(TAG, "onHistoryAlarmCallback: "); | |
| 479 | + } | |
| 480 | + | |
| 481 | + @Override | |
| 482 | + public void onAddMonitoredPersonCallback(AddMonitoredPersonResponse addMonitoredPersonResponse) { | |
| 483 | + Log.e(TAG, "onAddMonitoredPersonCallback: "); | |
| 484 | + } | |
| 485 | + | |
| 486 | + @Override | |
| 487 | + public void onDeleteMonitoredPersonCallback(DeleteMonitoredPersonResponse deleteMonitoredPersonResponse) { | |
| 488 | + Log.e(TAG, "onDeleteMonitoredPersonCallback: "); | |
| 489 | + } | |
| 490 | + | |
| 491 | + @Override | |
| 492 | + public void onListMonitoredPersonCallback(ListMonitoredPersonResponse listMonitoredPersonResponse) { | |
| 493 | + Log.e(TAG, "onListMonitoredPersonCallback: "); | |
| 494 | + } | |
| 495 | + }; | |
| 496 | + if (userStepEntity != null) { | |
| 497 | + List<Long> fenids = new ArrayList<>(); | |
| 498 | + fenids.add(userStepEntity.getFenceId()); | |
| 499 | + MonitoredStatusRequest request1 = MonitoredStatusRequest.buildServerRequest(Constant.TAG, | |
| 500 | + Constant.SERVICE_ID, userId, fenids); | |
| 501 | + if (mClient != null) { | |
| 502 | + mClient.queryMonitoredStatus(request1, onFenceListener); | |
| 503 | + } | |
| 504 | + } | |
| 505 | + } | |
| 506 | + | |
| 359 | 507 | private long i = 0; |
| 360 | 508 | private long index = 0; |
| 361 | 509 | private int mJobId; |
| ... | ... | @@ -919,6 +1067,7 @@ public class StepService extends Service implements SensorEventListener { |
| 919 | 1067 | } |
| 920 | 1068 | } |
| 921 | 1069 | |
| 1070 | + | |
| 922 | 1071 | /** |
| 923 | 1072 | * 保存记步数据 |
| 924 | 1073 | */ | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/dao/DaoMaster.java
| ... | ... | @@ -21,14 +21,14 @@ public class DaoMaster extends AbstractDaoMaster { |
| 21 | 21 | |
| 22 | 22 | /** Creates underlying database table using DAOs. */ |
| 23 | 23 | public static void createAllTables(Database db, boolean ifNotExists) { |
| 24 | - UserStepEntityDao.createTable(db, ifNotExists); | |
| 25 | 24 | CollUserStepEntityDao.createTable(db, ifNotExists); |
| 25 | + UserStepEntityDao.createTable(db, ifNotExists); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** Drops underlying database table using DAOs. */ |
| 29 | 29 | public static void dropAllTables(Database db, boolean ifExists) { |
| 30 | - UserStepEntityDao.dropTable(db, ifExists); | |
| 31 | 30 | CollUserStepEntityDao.dropTable(db, ifExists); |
| 31 | + UserStepEntityDao.dropTable(db, ifExists); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| ... | ... | @@ -47,8 +47,8 @@ public class DaoMaster extends AbstractDaoMaster { |
| 47 | 47 | |
| 48 | 48 | public DaoMaster(Database db) { |
| 49 | 49 | super(db, SCHEMA_VERSION); |
| 50 | - registerDaoClass(UserStepEntityDao.class); | |
| 51 | 50 | registerDaoClass(CollUserStepEntityDao.class); |
| 51 | + registerDaoClass(UserStepEntityDao.class); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public DaoSession newSession() { | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/dao/DaoSession.java
| ... | ... | @@ -8,11 +8,11 @@ import org.greenrobot.greendao.database.Database; |
| 8 | 8 | import org.greenrobot.greendao.identityscope.IdentityScopeType; |
| 9 | 9 | import org.greenrobot.greendao.internal.DaoConfig; |
| 10 | 10 | |
| 11 | -import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 12 | 11 | import com.cnlive.moudle.pedometer.sql.entity.CollUserStepEntity; |
| 12 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 13 | 13 | |
| 14 | -import com.cnlive.moudle.pedometer.sql.dao.UserStepEntityDao; | |
| 15 | 14 | import com.cnlive.moudle.pedometer.sql.dao.CollUserStepEntityDao; |
| 15 | +import com.cnlive.moudle.pedometer.sql.dao.UserStepEntityDao; | |
| 16 | 16 | |
| 17 | 17 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. |
| 18 | 18 | |
| ... | ... | @@ -23,40 +23,40 @@ import com.cnlive.moudle.pedometer.sql.dao.CollUserStepEntityDao; |
| 23 | 23 | */ |
| 24 | 24 | public class DaoSession extends AbstractDaoSession { |
| 25 | 25 | |
| 26 | - private final DaoConfig userStepEntityDaoConfig; | |
| 27 | 26 | private final DaoConfig collUserStepEntityDaoConfig; |
| 27 | + private final DaoConfig userStepEntityDaoConfig; | |
| 28 | 28 | |
| 29 | - private final UserStepEntityDao userStepEntityDao; | |
| 30 | 29 | private final CollUserStepEntityDao collUserStepEntityDao; |
| 30 | + private final UserStepEntityDao userStepEntityDao; | |
| 31 | 31 | |
| 32 | 32 | public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig> |
| 33 | 33 | daoConfigMap) { |
| 34 | 34 | super(db); |
| 35 | 35 | |
| 36 | - userStepEntityDaoConfig = daoConfigMap.get(UserStepEntityDao.class).clone(); | |
| 37 | - userStepEntityDaoConfig.initIdentityScope(type); | |
| 38 | - | |
| 39 | 36 | collUserStepEntityDaoConfig = daoConfigMap.get(CollUserStepEntityDao.class).clone(); |
| 40 | 37 | collUserStepEntityDaoConfig.initIdentityScope(type); |
| 41 | 38 | |
| 42 | - userStepEntityDao = new UserStepEntityDao(userStepEntityDaoConfig, this); | |
| 39 | + userStepEntityDaoConfig = daoConfigMap.get(UserStepEntityDao.class).clone(); | |
| 40 | + userStepEntityDaoConfig.initIdentityScope(type); | |
| 41 | + | |
| 43 | 42 | collUserStepEntityDao = new CollUserStepEntityDao(collUserStepEntityDaoConfig, this); |
| 43 | + userStepEntityDao = new UserStepEntityDao(userStepEntityDaoConfig, this); | |
| 44 | 44 | |
| 45 | - registerDao(UserStepEntity.class, userStepEntityDao); | |
| 46 | 45 | registerDao(CollUserStepEntity.class, collUserStepEntityDao); |
| 46 | + registerDao(UserStepEntity.class, userStepEntityDao); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public void clear() { |
| 50 | - userStepEntityDaoConfig.clearIdentityScope(); | |
| 51 | 50 | collUserStepEntityDaoConfig.clearIdentityScope(); |
| 52 | - } | |
| 53 | - | |
| 54 | - public UserStepEntityDao getUserStepEntityDao() { | |
| 55 | - return userStepEntityDao; | |
| 51 | + userStepEntityDaoConfig.clearIdentityScope(); | |
| 56 | 52 | } |
| 57 | 53 | |
| 58 | 54 | public CollUserStepEntityDao getCollUserStepEntityDao() { |
| 59 | 55 | return collUserStepEntityDao; |
| 60 | 56 | } |
| 61 | 57 | |
| 58 | + public UserStepEntityDao getUserStepEntityDao() { | |
| 59 | + return userStepEntityDao; | |
| 60 | + } | |
| 61 | + | |
| 62 | 62 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/dao/UserStepEntityDao.java
| ... | ... | @@ -39,6 +39,12 @@ public class UserStepEntityDao extends AbstractDao<UserStepEntity, String> { |
| 39 | 39 | public final static Property PauseCount = new Property(12, int.class, "pauseCount", false, "PAUSE_COUNT"); |
| 40 | 40 | public final static Property UserPauseTimeStamp = new Property(13, long.class, "userPauseTimeStamp", false, "USER_PAUSE_TIME_STAMP"); |
| 41 | 41 | public final static Property ChronometerBase = new Property(14, long.class, "chronometerBase", false, "CHRONOMETER_BASE"); |
| 42 | + public final static Property QueryTraceStartTime = new Property(15, long.class, "queryTraceStartTime", false, "QUERY_TRACE_START_TIME"); | |
| 43 | + public final static Property QueryTraceEndTime = new Property(16, long.class, "queryTraceEndTime", false, "QUERY_TRACE_END_TIME"); | |
| 44 | + public final static Property QueryEntityName = new Property(17, String.class, "queryEntityName", false, "QUERY_ENTITY_NAME"); | |
| 45 | + public final static Property ContinueTime = new Property(18, long.class, "continueTime", false, "CONTINUE_TIME"); | |
| 46 | + public final static Property FenceId = new Property(19, long.class, "fenceId", false, "FENCE_ID"); | |
| 47 | + public final static Property ImportPoint = new Property(20, String.class, "importPoint", false, "IMPORT_POINT"); | |
| 42 | 48 | } |
| 43 | 49 | |
| 44 | 50 | |
| ... | ... | @@ -68,7 +74,13 @@ public class UserStepEntityDao extends AbstractDao<UserStepEntity, String> { |
| 68 | 74 | "\"STREET_ID\" TEXT," + // 11: streetId |
| 69 | 75 | "\"PAUSE_COUNT\" INTEGER NOT NULL ," + // 12: pauseCount |
| 70 | 76 | "\"USER_PAUSE_TIME_STAMP\" INTEGER NOT NULL ," + // 13: userPauseTimeStamp |
| 71 | - "\"CHRONOMETER_BASE\" INTEGER NOT NULL );"); // 14: chronometerBase | |
| 77 | + "\"CHRONOMETER_BASE\" INTEGER NOT NULL ," + // 14: chronometerBase | |
| 78 | + "\"QUERY_TRACE_START_TIME\" INTEGER NOT NULL ," + // 15: queryTraceStartTime | |
| 79 | + "\"QUERY_TRACE_END_TIME\" INTEGER NOT NULL ," + // 16: queryTraceEndTime | |
| 80 | + "\"QUERY_ENTITY_NAME\" TEXT," + // 17: queryEntityName | |
| 81 | + "\"CONTINUE_TIME\" INTEGER NOT NULL ," + // 18: continueTime | |
| 82 | + "\"FENCE_ID\" INTEGER NOT NULL ," + // 19: fenceId | |
| 83 | + "\"IMPORT_POINT\" TEXT);"); // 20: importPoint | |
| 72 | 84 | } |
| 73 | 85 | |
| 74 | 86 | /** Drops the underlying database table. */ |
| ... | ... | @@ -123,6 +135,20 @@ public class UserStepEntityDao extends AbstractDao<UserStepEntity, String> { |
| 123 | 135 | stmt.bindLong(13, entity.getPauseCount()); |
| 124 | 136 | stmt.bindLong(14, entity.getUserPauseTimeStamp()); |
| 125 | 137 | stmt.bindLong(15, entity.getChronometerBase()); |
| 138 | + stmt.bindLong(16, entity.getQueryTraceStartTime()); | |
| 139 | + stmt.bindLong(17, entity.getQueryTraceEndTime()); | |
| 140 | + | |
| 141 | + String queryEntityName = entity.getQueryEntityName(); | |
| 142 | + if (queryEntityName != null) { | |
| 143 | + stmt.bindString(18, queryEntityName); | |
| 144 | + } | |
| 145 | + stmt.bindLong(19, entity.getContinueTime()); | |
| 146 | + stmt.bindLong(20, entity.getFenceId()); | |
| 147 | + | |
| 148 | + String importPoint = entity.getImportPoint(); | |
| 149 | + if (importPoint != null) { | |
| 150 | + stmt.bindString(21, importPoint); | |
| 151 | + } | |
| 126 | 152 | } |
| 127 | 153 | |
| 128 | 154 | @Override |
| ... | ... | @@ -171,6 +197,20 @@ public class UserStepEntityDao extends AbstractDao<UserStepEntity, String> { |
| 171 | 197 | stmt.bindLong(13, entity.getPauseCount()); |
| 172 | 198 | stmt.bindLong(14, entity.getUserPauseTimeStamp()); |
| 173 | 199 | stmt.bindLong(15, entity.getChronometerBase()); |
| 200 | + stmt.bindLong(16, entity.getQueryTraceStartTime()); | |
| 201 | + stmt.bindLong(17, entity.getQueryTraceEndTime()); | |
| 202 | + | |
| 203 | + String queryEntityName = entity.getQueryEntityName(); | |
| 204 | + if (queryEntityName != null) { | |
| 205 | + stmt.bindString(18, queryEntityName); | |
| 206 | + } | |
| 207 | + stmt.bindLong(19, entity.getContinueTime()); | |
| 208 | + stmt.bindLong(20, entity.getFenceId()); | |
| 209 | + | |
| 210 | + String importPoint = entity.getImportPoint(); | |
| 211 | + if (importPoint != null) { | |
| 212 | + stmt.bindString(21, importPoint); | |
| 213 | + } | |
| 174 | 214 | } |
| 175 | 215 | |
| 176 | 216 | @Override |
| ... | ... | @@ -195,7 +235,13 @@ public class UserStepEntityDao extends AbstractDao<UserStepEntity, String> { |
| 195 | 235 | cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // streetId |
| 196 | 236 | cursor.getInt(offset + 12), // pauseCount |
| 197 | 237 | cursor.getLong(offset + 13), // userPauseTimeStamp |
| 198 | - cursor.getLong(offset + 14) // chronometerBase | |
| 238 | + cursor.getLong(offset + 14), // chronometerBase | |
| 239 | + cursor.getLong(offset + 15), // queryTraceStartTime | |
| 240 | + cursor.getLong(offset + 16), // queryTraceEndTime | |
| 241 | + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // queryEntityName | |
| 242 | + cursor.getLong(offset + 18), // continueTime | |
| 243 | + cursor.getLong(offset + 19), // fenceId | |
| 244 | + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // importPoint | |
| 199 | 245 | ); |
| 200 | 246 | return entity; |
| 201 | 247 | } |
| ... | ... | @@ -217,6 +263,12 @@ public class UserStepEntityDao extends AbstractDao<UserStepEntity, String> { |
| 217 | 263 | entity.setPauseCount(cursor.getInt(offset + 12)); |
| 218 | 264 | entity.setUserPauseTimeStamp(cursor.getLong(offset + 13)); |
| 219 | 265 | entity.setChronometerBase(cursor.getLong(offset + 14)); |
| 266 | + entity.setQueryTraceStartTime(cursor.getLong(offset + 15)); | |
| 267 | + entity.setQueryTraceEndTime(cursor.getLong(offset + 16)); | |
| 268 | + entity.setQueryEntityName(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17)); | |
| 269 | + entity.setContinueTime(cursor.getLong(offset + 18)); | |
| 270 | + entity.setFenceId(cursor.getLong(offset + 19)); | |
| 271 | + entity.setImportPoint(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); | |
| 220 | 272 | } |
| 221 | 273 | |
| 222 | 274 | @Override | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/entity/FailedEntity.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.sql.entity; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 上传失败列表 | |
| 5 | + * | |
| 6 | + * @author ShinnyYang | |
| 7 | + */ | |
| 8 | +public class FailedEntity { | |
| 9 | + private String uuid;//主键 | |
| 10 | + private String uid;//用户id | |
| 11 | + private String streetTitle;//赛道标题 | |
| 12 | + private boolean isPause;//是否暂停 | |
| 13 | + private String isFinish;//是否完成 | |
| 14 | + private String time;//用时 | |
| 15 | + private String speed;//配速 | |
| 16 | + private String step;//步数 | |
| 17 | + private String startPoint;//开始地点 | |
| 18 | + private String endPoint;//结束地点 | |
| 19 | + private long streetTraceStartTime;//赛道开始时间 | |
| 20 | + private long streetTraceEndTime;//赛道结束时间 | |
| 21 | + private String entityName;//实体名称 | |
| 22 | + private long userStartTime;//用户开始时间 | |
| 23 | + private long userEndTime;//用户结束时间 | |
| 24 | + private String importPoint;//关键点 | |
| 25 | + private String streetId;//赛事id | |
| 26 | + | |
| 27 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/entity/UserStepEntity.java
| ... | ... | @@ -22,11 +22,18 @@ public class UserStepEntity { |
| 22 | 22 | private int pauseCount;//暂停次数 |
| 23 | 23 | private long userPauseTimeStamp;//暂停时间戳 |
| 24 | 24 | private long chronometerBase;//计时器设置基础时间 |
| 25 | + private long queryTraceStartTime;//从服务器获取的开始时间呢 | |
| 26 | + private long queryTraceEndTime;//从服务器获取的结束时间呢 | |
| 27 | + private String queryEntityName;//从服务器获取的运营人员的实体名称 | |
| 28 | + private long continueTime;//继续运动时间 | |
| 29 | + private long fenceId;//围栏id | |
| 30 | + private String importPoint;//关键点 | |
| 25 | 31 | |
| 26 | - @Generated(hash = 562353866) | |
| 32 | + | |
| 33 | + @Generated(hash = 24427970) | |
| 27 | 34 | public UserStepEntity(String userId, String date, String stepCount, long pauseTimeStamp, long recordTime, double caloriesCount, String serverTraceData, |
| 28 | 35 | String startPoint, String endPoint, long startTimeStamp, long finishTimeStamp, String streetId, int pauseCount, long userPauseTimeStamp, |
| 29 | - long chronometerBase) { | |
| 36 | + long chronometerBase, long queryTraceStartTime, long queryTraceEndTime, String queryEntityName, long continueTime, long fenceId, String importPoint) { | |
| 30 | 37 | this.userId = userId; |
| 31 | 38 | this.date = date; |
| 32 | 39 | this.stepCount = stepCount; |
| ... | ... | @@ -42,6 +49,12 @@ public class UserStepEntity { |
| 42 | 49 | this.pauseCount = pauseCount; |
| 43 | 50 | this.userPauseTimeStamp = userPauseTimeStamp; |
| 44 | 51 | this.chronometerBase = chronometerBase; |
| 52 | + this.queryTraceStartTime = queryTraceStartTime; | |
| 53 | + this.queryTraceEndTime = queryTraceEndTime; | |
| 54 | + this.queryEntityName = queryEntityName; | |
| 55 | + this.continueTime = continueTime; | |
| 56 | + this.fenceId = fenceId; | |
| 57 | + this.importPoint = importPoint; | |
| 45 | 58 | } |
| 46 | 59 | |
| 47 | 60 | @Generated(hash = 273857141) |
| ... | ... | @@ -168,5 +181,53 @@ public class UserStepEntity { |
| 168 | 181 | this.chronometerBase = chronometerBase; |
| 169 | 182 | } |
| 170 | 183 | |
| 184 | + public long getQueryTraceStartTime() { | |
| 185 | + return this.queryTraceStartTime; | |
| 186 | + } | |
| 187 | + | |
| 188 | + public void setQueryTraceStartTime(long queryTraceStartTime) { | |
| 189 | + this.queryTraceStartTime = queryTraceStartTime; | |
| 190 | + } | |
| 191 | + | |
| 192 | + public long getQueryTraceEndTime() { | |
| 193 | + return this.queryTraceEndTime; | |
| 194 | + } | |
| 195 | + | |
| 196 | + public void setQueryTraceEndTime(long queryTraceEndTime) { | |
| 197 | + this.queryTraceEndTime = queryTraceEndTime; | |
| 198 | + } | |
| 199 | + | |
| 200 | + public String getQueryEntityName() { | |
| 201 | + return this.queryEntityName; | |
| 202 | + } | |
| 203 | + | |
| 204 | + public void setQueryEntityName(String queryEntityName) { | |
| 205 | + this.queryEntityName = queryEntityName; | |
| 206 | + } | |
| 207 | + | |
| 208 | + public long getContinueTime() { | |
| 209 | + return this.continueTime; | |
| 210 | + } | |
| 211 | + | |
| 212 | + public void setContinueTime(long continueTime) { | |
| 213 | + this.continueTime = continueTime; | |
| 214 | + } | |
| 215 | + | |
| 216 | + public long getFenceId() { | |
| 217 | + return this.fenceId; | |
| 218 | + } | |
| 219 | + | |
| 220 | + public void setFenceId(long fenceId) { | |
| 221 | + this.fenceId = fenceId; | |
| 222 | + } | |
| 223 | + | |
| 224 | + public String getImportPoint() { | |
| 225 | + return this.importPoint; | |
| 226 | + } | |
| 227 | + | |
| 228 | + public void setImportPoint(String importPoint) { | |
| 229 | + this.importPoint = importPoint; | |
| 230 | + } | |
| 231 | + | |
| 171 | 232 | |
| 172 | 233 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/activity/PedometerMainActivity.java
| ... | ... | @@ -13,6 +13,7 @@ import android.os.Bundle; |
| 13 | 13 | import android.support.annotation.NonNull; |
| 14 | 14 | import android.support.v4.app.NotificationManagerCompat; |
| 15 | 15 | import android.support.v4.content.ContextCompat; |
| 16 | +import android.text.TextUtils; | |
| 16 | 17 | import android.util.Log; |
| 17 | 18 | import android.view.KeyEvent; |
| 18 | 19 | import android.widget.Toast; |
| ... | ... | @@ -20,6 +21,7 @@ import android.widget.Toast; |
| 20 | 21 | import com.alibaba.android.arouter.facade.annotation.Route; |
| 21 | 22 | import com.baidu.mapapi.CoordType; |
| 22 | 23 | import com.baidu.mapapi.SDKInitializer; |
| 24 | +import com.baidu.mapapi.model.LatLng; | |
| 23 | 25 | import com.cnlive.libs.base.ui.QMUIFragment; |
| 24 | 26 | import com.cnlive.libs.base.ui.QMUIFragmentActivity; |
| 25 | 27 | import com.cnlive.libs.base.util.StatusBarUtil; |
| ... | ... | @@ -32,6 +34,9 @@ import com.cnlive.moudle.pedometer.utils.lib_permisshelper.PermissionsUtils; |
| 32 | 34 | import com.example.moudle_pedometer.R; |
| 33 | 35 | |
| 34 | 36 | |
| 37 | +import java.io.Serializable; | |
| 38 | +import java.util.List; | |
| 39 | + | |
| 35 | 40 | import static android.app.Notification.EXTRA_CHANNEL_ID; |
| 36 | 41 | import static android.provider.Settings.EXTRA_APP_PACKAGE; |
| 37 | 42 | |
| ... | ... | @@ -40,12 +45,15 @@ import static android.provider.Settings.EXTRA_APP_PACKAGE; |
| 40 | 45 | */ |
| 41 | 46 | @Route(path = "/moudle_pedometer/InterestActivity") |
| 42 | 47 | public class PedometerMainActivity extends QMUIFragmentActivity { |
| 43 | - private static final String TAG = "CollPedometerMainActivity"; | |
| 48 | + private static final String TAG = "PedometerMainActivity"; | |
| 44 | 49 | |
| 45 | 50 | private NotificationManagerCompat notificationManagerCompat; |
| 46 | 51 | private boolean isOpen; |
| 47 | 52 | private PermissionsUtils mPermissionsUtils = new PermissionsUtils();//权限申请 |
| 48 | 53 | private RunMainFragment fragment; |
| 54 | + private String startPointAdd; | |
| 55 | + private String endPointAdd; | |
| 56 | + private List<LatLng> importStreetPoints; | |
| 49 | 57 | |
| 50 | 58 | @Override |
| 51 | 59 | protected int getContextViewId() { |
| ... | ... | @@ -55,8 +63,9 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 55 | 63 | @Override |
| 56 | 64 | protected void onCreate(Bundle savedInstanceState) { |
| 57 | 65 | super.onCreate(savedInstanceState); |
| 58 | -// setContentView(R.layout.activity_pedometer_main); | |
| 59 | - | |
| 66 | + startPointAdd = getIntent().getExtras().getString("startPointAdd"); | |
| 67 | + endPointAdd = getIntent().getExtras().getString("endPointAdd"); | |
| 68 | + importStreetPoints = (List<LatLng>) getIntent().getExtras().getSerializable("importStreetPoints"); | |
| 60 | 69 | } |
| 61 | 70 | |
| 62 | 71 | |
| ... | ... | @@ -119,31 +128,13 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 119 | 128 | |
| 120 | 129 | @Override |
| 121 | 130 | protected void onResume() { |
| 122 | - | |
| 123 | - boolean result = false; | |
| 124 | - if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_BOOT_COMPLETED) == PackageManager.PERMISSION_GRANTED) { | |
| 125 | - result = true; | |
| 126 | - } | |
| 127 | - Log.e("i", "" + result + "," + getPackageName()); | |
| 128 | - PackageManager pm = getPackageManager(); | |
| 129 | - pm.checkPermission("android.permission.RECEIVE_BOOT_COMPLETED", getPackageName()); | |
| 130 | - try { | |
| 131 | - PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS); | |
| 132 | - for (int i = 0; i < packageInfo.requestedPermissions.length; i++) { | |
| 133 | - } | |
| 134 | -// Log.e("i", "" + packageInfo.requestedPermissions[i]); | |
| 135 | - } catch (PackageManager.NameNotFoundException e) { | |
| 136 | - e.printStackTrace(); | |
| 137 | - } | |
| 138 | - | |
| 139 | 131 | super.onResume(); |
| 140 | 132 | check(); |
| 141 | -// | |
| 142 | 133 | getPermissionsWithTip(); |
| 143 | 134 | } |
| 144 | 135 | |
| 145 | - private void addFragment() { | |
| 146 | - fragment = new RunMainFragment(); | |
| 136 | + private void addFragment(String startPointAdd, String endPointAdd, List<LatLng> importStreetPoints) { | |
| 137 | + fragment = RunMainFragment.newInstance(startPointAdd, endPointAdd, importStreetPoints); | |
| 147 | 138 | getSupportFragmentManager().beginTransaction() |
| 148 | 139 | .add(getContextViewId(), fragment, fragment.getClass().getSimpleName()) |
| 149 | 140 | .addToBackStack(fragment.getClass().getSimpleName()) |
| ... | ... | @@ -174,7 +165,9 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 174 | 165 | Toast.makeText(getApplicationContext(), getString(R.string.open_gps_tip), Toast.LENGTH_LONG).show(); |
| 175 | 166 | } else { |
| 176 | 167 | if (getCurrentFragment() == null) { |
| 177 | - addFragment(); | |
| 168 | + if (!TextUtils.isEmpty(startPointAdd) && !TextUtils.isEmpty(endPointAdd) && importStreetPoints != null) { | |
| 169 | + addFragment(startPointAdd, endPointAdd, importStreetPoints); | |
| 170 | + } | |
| 178 | 171 | } |
| 179 | 172 | } |
| 180 | 173 | } |
| ... | ... | @@ -220,8 +213,11 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 220 | 213 | return; |
| 221 | 214 | } |
| 222 | 215 | |
| 223 | - public static void startActivity(Activity activity) { | |
| 216 | + public static void startActivity(Activity activity, String startPointAdd, String endPointAdd, List<LatLng> importStreetPoints) { | |
| 224 | 217 | Intent intent = new Intent(activity, PedometerMainActivity.class); |
| 218 | + intent.putExtra("startPointAdd", startPointAdd); | |
| 219 | + intent.putExtra("endPointAdd", endPointAdd); | |
| 220 | + intent.putExtra("importStreetPoints", (Serializable) importStreetPoints); | |
| 225 | 221 | activity.startActivity(intent); |
| 226 | 222 | } |
| 227 | 223 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/activity/RunRaceDetailActivity.java
| 1 | 1 | package com.cnlive.moudle.pedometer.ui.activity; |
| 2 | 2 | |
| 3 | +import android.Manifest; | |
| 3 | 4 | import android.app.Activity; |
| 4 | 5 | import android.content.Context; |
| 5 | 6 | import android.content.Intent; |
| 6 | 7 | import android.os.Bundle; |
| 8 | +import android.provider.Settings; | |
| 9 | +import android.support.annotation.NonNull; | |
| 7 | 10 | import android.support.annotation.Nullable; |
| 8 | 11 | import android.support.design.widget.BottomSheetDialog; |
| 12 | +import android.text.TextUtils; | |
| 13 | +import android.util.Log; | |
| 9 | 14 | import android.view.View; |
| 10 | 15 | import android.widget.FrameLayout; |
| 16 | +import android.widget.Toast; | |
| 11 | 17 | |
| 12 | 18 | import com.alibaba.android.arouter.facade.annotation.Route; |
| 13 | 19 | import com.baidu.mapapi.CoordType; |
| ... | ... | @@ -23,7 +29,10 @@ import com.cnlive.moudle.pedometer.ui.fragment.RunMainFragment; |
| 23 | 29 | import com.cnlive.moudle.pedometer.ui.fragment.RunRaceDetailFragment; |
| 24 | 30 | import com.cnlive.moudle.pedometer.ui.fragment.RunningMapFragment; |
| 25 | 31 | import com.cnlive.moudle.pedometer.ui.widget.FivePersonIconView; |
| 32 | +import com.cnlive.moudle.pedometer.utils.MyMapUtil; | |
| 26 | 33 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 34 | +import com.cnlive.moudle.pedometer.utils.lib_permisshelper.PermissionsListener; | |
| 35 | +import com.cnlive.moudle.pedometer.utils.lib_permisshelper.PermissionsUtils; | |
| 27 | 36 | import com.example.moudle_pedometer.R; |
| 28 | 37 | |
| 29 | 38 | import java.util.ArrayList; |
| ... | ... | @@ -37,14 +46,15 @@ import java.util.List; |
| 37 | 46 | @Route(path = "/moudle_pedometer/CollRunRaceDetailActivity") |
| 38 | 47 | public class RunRaceDetailActivity extends QMUIFragmentActivity { |
| 39 | 48 | private QMUIFragment fragment; |
| 49 | + private PermissionsUtils mPermissionsUtils = new PermissionsUtils();//权限申请 | |
| 40 | 50 | |
| 41 | - public static void startActivity(Activity activity, String eventId,String userId,String userIcon,String userName,String userPhone) { | |
| 51 | + public static void startActivity(Activity activity, String eventId, String userId, String userIcon, String userName, String userPhone) { | |
| 42 | 52 | Intent intent = new Intent(activity, RunRaceDetailActivity.class); |
| 43 | 53 | intent.putExtra("eventId", eventId); |
| 44 | - intent.putExtra("userId",userId); | |
| 45 | - intent.putExtra("userIcon",userIcon); | |
| 46 | - intent.putExtra("userName",userName); | |
| 47 | - intent.putExtra("userPhone",userPhone); | |
| 54 | + intent.putExtra("userId", userId); | |
| 55 | + intent.putExtra("userIcon", userIcon); | |
| 56 | + intent.putExtra("userName", userName); | |
| 57 | + intent.putExtra("userPhone", userPhone); | |
| 48 | 58 | CommonInfo.setStreetId(activity, eventId); |
| 49 | 59 | activity.startActivity(intent); |
| 50 | 60 | } |
| ... | ... | @@ -58,25 +68,29 @@ public class RunRaceDetailActivity extends QMUIFragmentActivity { |
| 58 | 68 | protected void onCreate(Bundle savedInstanceState) { |
| 59 | 69 | super.onCreate(savedInstanceState); |
| 60 | 70 | |
| 61 | - if(getIntent().getStringExtra("userId") != null){ | |
| 62 | - CommonInfo.setUserId(this,getIntent().getStringExtra("userId")); | |
| 63 | - CommonInfo.setUserNickName(this,getIntent().getStringExtra("userName")); | |
| 64 | - CommonInfo.setUserIcon(this,getIntent().getStringExtra("userIcon")); | |
| 65 | - CommonInfo.setUserPhone(this,getIntent().getStringExtra("userPhone")); | |
| 71 | + if (getIntent().getStringExtra("userId") != null) { | |
| 72 | + CommonInfo.setUserId(this, getIntent().getStringExtra("userId")); | |
| 73 | + CommonInfo.setUserNickName(this, getIntent().getStringExtra("userName")); | |
| 74 | + CommonInfo.setUserIcon(this, getIntent().getStringExtra("userIcon")); | |
| 75 | + CommonInfo.setUserPhone(this, getIntent().getStringExtra("userPhone")); | |
| 66 | 76 | } |
| 67 | 77 | //判断用户是否结束运动 |
| 68 | 78 | // boolean isRunStep = CommonInfo.getIsRunStepService(this); |
| 69 | 79 | // //没有找到相关记录 |
| 70 | 80 | // if (!isRunStep) { |
| 71 | - fragment = new RunRaceDetailFragment(); | |
| 81 | + fragment = new RunRaceDetailFragment(); | |
| 72 | 82 | // } |
| 73 | 83 | // //找到记录 |
| 74 | 84 | // else { |
| 75 | 85 | // fragment = new RunMainFragment(); |
| 76 | 86 | // } |
| 77 | - if (fragment != null) { | |
| 78 | - addFragment(fragment); | |
| 79 | - } | |
| 87 | + | |
| 88 | + } | |
| 89 | + | |
| 90 | + @Override | |
| 91 | + protected void onResume() { | |
| 92 | + super.onResume(); | |
| 93 | + getPermissionsWithTip(); | |
| 80 | 94 | } |
| 81 | 95 | |
| 82 | 96 | private void addFragment(QMUIFragment fragment) { |
| ... | ... | @@ -89,10 +103,72 @@ public class RunRaceDetailActivity extends QMUIFragmentActivity { |
| 89 | 103 | @Override |
| 90 | 104 | public void onBackPressed() { |
| 91 | 105 | super.onBackPressed(); |
| 92 | - if (getCurrentFragment()!=null) { | |
| 106 | + if (getCurrentFragment() != null) { | |
| 93 | 107 | if (getCurrentFragment() instanceof RunMainFragment) { |
| 94 | 108 | return; |
| 95 | 109 | } |
| 96 | 110 | } |
| 97 | 111 | } |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 一次申请一组权限(使用拒绝弹框)点击事件 | |
| 115 | + */ | |
| 116 | + public void getPermissionsWithTip() { | |
| 117 | + mPermissionsUtils | |
| 118 | + .setPermissionsListener(new PermissionsListener() { | |
| 119 | + @Override | |
| 120 | + public void onDenied(String[] deniedPermissions) { | |
| 121 | + getPermissionsWithTip(); | |
| 122 | + } | |
| 123 | + | |
| 124 | + @Override | |
| 125 | + public void onGranted() { | |
| 126 | + //判断GPS是否开启 | |
| 127 | + if (!MyMapUtil.isOPenGps(getApplicationContext())) { | |
| 128 | + //开启GPS | |
| 129 | + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | |
| 130 | + startActivityForResult(intent, 10); | |
| 131 | + Toast.makeText(getApplicationContext(), getString(R.string.open_gps_tip), Toast.LENGTH_LONG).show(); | |
| 132 | + } else { | |
| 133 | + if (getCurrentFragment() == null) { | |
| 134 | + if (fragment != null) { | |
| 135 | + addFragment(fragment); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | + } | |
| 140 | + }) | |
| 141 | + .withActivity(RunRaceDetailActivity.this) | |
| 142 | + .getPermissions(RunRaceDetailActivity.this | |
| 143 | + , 100 | |
| 144 | + , Manifest.permission.INTERNET | |
| 145 | + , Manifest.permission.READ_EXTERNAL_STORAGE | |
| 146 | + , Manifest.permission.WRITE_EXTERNAL_STORAGE | |
| 147 | + , Manifest.permission.ACCESS_FINE_LOCATION | |
| 148 | + , Manifest.permission.ACCESS_COARSE_LOCATION | |
| 149 | + ); | |
| 150 | +// .getPermissionsWithTips(MainActivity.this | |
| 151 | +// ,100 | |
| 152 | +// , new String[]{"人家要录音","我们需要读取你的信息,磨磨唧唧的","我要上网","我要读内存卡","我要看日历","我要定位"} | |
| 153 | +// , Manifest.permission.RECORD_AUDIO | |
| 154 | +// , Manifest.permission.READ_SMS | |
| 155 | +// , Manifest.permission.INTERNET | |
| 156 | +// , Manifest.permission.READ_EXTERNAL_STORAGE | |
| 157 | +// , Manifest.permission.READ_CALENDAR | |
| 158 | +// , Manifest.permission.ACCESS_FINE_LOCATION); | |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * 权限回调 | |
| 163 | + * | |
| 164 | + * @param requestCode | |
| 165 | + * @param permissions | |
| 166 | + * @param grantResults | |
| 167 | + */ | |
| 168 | + @Override | |
| 169 | + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |
| 170 | + @NonNull int[] grantResults) { | |
| 171 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
| 172 | + mPermissionsUtils.dealResult(requestCode, permissions, grantResults); | |
| 173 | + } | |
| 98 | 174 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunMainFragment.java
| ... | ... | @@ -7,6 +7,7 @@ import android.text.TextUtils; |
| 7 | 7 | import android.util.Log; |
| 8 | 8 | import android.view.View; |
| 9 | 9 | |
| 10 | +import com.baidu.mapapi.model.LatLng; | |
| 10 | 11 | import com.cnlive.libs.base.ui.QMUIFragment; |
| 11 | 12 | import com.cnlive.libs.base.util.StatusBarUtil; |
| 12 | 13 | import com.cnlive.libs.base.util.StatusBarUtil2; |
| ... | ... | @@ -16,6 +17,7 @@ import com.cnlive.moudle.pedometer.frame.view.RunMainFragmentView; |
| 16 | 17 | import com.cnlive.moudle.pedometer.model.Constant; |
| 17 | 18 | import com.cnlive.moudle.pedometer.model.MessageEvent; |
| 18 | 19 | import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; |
| 20 | +import com.cnlive.moudle.pedometer.utils.GsonUtil; | |
| 19 | 21 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 20 | 22 | import com.example.moudle_pedometer.R; |
| 21 | 23 | import com.example.moudle_pedometer.databinding.FragmentRunMainBinding; |
| ... | ... | @@ -25,9 +27,25 @@ import org.greenrobot.eventbus.EventBus; |
| 25 | 27 | import org.greenrobot.eventbus.Subscribe; |
| 26 | 28 | import org.greenrobot.eventbus.ThreadMode; |
| 27 | 29 | |
| 30 | +import java.io.Serializable; | |
| 31 | +import java.util.List; | |
| 32 | + | |
| 28 | 33 | public class RunMainFragment extends QMUIFragment<RunMainFragmentView, RunMainFragmentPresenter, FragmentRunMainBinding> { |
| 29 | 34 | private final String TAG = "CollRunMainFragment"; |
| 30 | 35 | private String userId = "yangshuai"; |
| 36 | + private String startPointAdd; | |
| 37 | + private String endPointAdd; | |
| 38 | + private List<LatLng> importStreetPoints; | |
| 39 | + | |
| 40 | + public static RunMainFragment newInstance(String startPointAdd, String endPointAdd, List<LatLng> importStreetPoints) { | |
| 41 | + Bundle bundle = new Bundle(); | |
| 42 | + bundle.putString("startPointAdd", startPointAdd); | |
| 43 | + bundle.putString("endPointAdd", endPointAdd); | |
| 44 | + bundle.putSerializable("importStreetPoints", (Serializable) importStreetPoints); | |
| 45 | + RunMainFragment fragment = new RunMainFragment(); | |
| 46 | + fragment.setArguments(bundle); | |
| 47 | + return fragment; | |
| 48 | + } | |
| 31 | 49 | |
| 32 | 50 | @Override |
| 33 | 51 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| ... | ... | @@ -35,6 +53,26 @@ public class RunMainFragment extends QMUIFragment<RunMainFragmentView, RunMainFr |
| 35 | 53 | QMUIStatusBarHelper.setStatusBarDarkMode(getActivity()); |
| 36 | 54 | StatusBarUtil2.setColor(getActivity(), getResources().getColor(R.color.run_main_bg), 0); |
| 37 | 55 | EventBus.getDefault().register(this); |
| 56 | + if (getArguments() != null) { | |
| 57 | + startPointAdd = getArguments().getString("startPointAdd"); | |
| 58 | + endPointAdd = getArguments().getString("endPointAdd"); | |
| 59 | + importStreetPoints = (List<LatLng>) getArguments().getSerializable("importStreetPoints"); | |
| 60 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getActivity(), CommonInfo.getUserId(getActivity())); | |
| 61 | + if (userStepEntity != null) { | |
| 62 | + if (!TextUtils.isEmpty(startPointAdd) && !TextUtils.isEmpty(endPointAdd)) { | |
| 63 | + userStepEntity.setStartPoint(startPointAdd); | |
| 64 | + userStepEntity.setEndPoint(endPointAdd); | |
| 65 | + //更新数据 | |
| 66 | + StepUtil.updateStepData(getActivity(), userStepEntity); | |
| 67 | + } | |
| 68 | + //获取数据库中的重要点 | |
| 69 | + String importStr = userStepEntity.getImportPoint(); | |
| 70 | + if (TextUtils.isEmpty(importStr) && importStreetPoints != null) { | |
| 71 | + //设置重要点 | |
| 72 | + StepUtil.setImportPoints(getActivity(), CommonInfo.getUserId(getActivity()), GsonUtil.GsonString(importStreetPoints)); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + } | |
| 38 | 76 | if (getMvpView() != null) { |
| 39 | 77 | new Handler().postDelayed(new Runnable() { |
| 40 | 78 | @Override | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunRaceDetailFragment.java
| ... | ... | @@ -3,31 +3,20 @@ package com.cnlive.moudle.pedometer.ui.fragment; |
| 3 | 3 | import android.hardware.Sensor; |
| 4 | 4 | import android.hardware.SensorManager; |
| 5 | 5 | import android.os.Bundle; |
| 6 | -import android.support.annotation.NonNull; | |
| 7 | 6 | import android.support.annotation.Nullable; |
| 8 | -import android.support.design.widget.BottomSheetBehavior; | |
| 9 | -import android.support.design.widget.BottomSheetDialog; | |
| 10 | 7 | import android.text.TextUtils; |
| 11 | 8 | import android.util.Log; |
| 12 | 9 | import android.view.View; |
| 13 | -import android.widget.FrameLayout; | |
| 14 | -import android.widget.LinearLayout; | |
| 15 | 10 | |
| 16 | 11 | import com.cnlive.libs.base.ui.QMUIFragment; |
| 17 | 12 | import com.cnlive.libs.base.util.StatusBarUtil2; |
| 18 | -import com.cnlive.moudle.collectionTrace.ui.activity.CollPedometerMainActivity; | |
| 19 | 13 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 20 | 14 | import com.cnlive.moudle.pedometer.frame.presenter.RunRaceDetailFragmentPresenter; |
| 21 | 15 | import com.cnlive.moudle.pedometer.frame.view.RunRaceDetailFragmentView; |
| 22 | 16 | import com.cnlive.moudle.pedometer.model.Constant; |
| 23 | 17 | import com.cnlive.moudle.pedometer.model.MessageEvent; |
| 24 | -import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 25 | 18 | import com.cnlive.moudle.pedometer.ui.activity.PedometerMainActivity; |
| 26 | -import com.cnlive.moudle.pedometer.ui.widget.FivePersonIconView; | |
| 27 | -import com.cnlive.moudle.pedometer.utils.ChineseToSpeechUtil; | |
| 28 | 19 | import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; |
| 29 | -import com.cnlive.moudle.pedometer.utils.ScreenUtil; | |
| 30 | -import com.cnlive.moudle.pedometer.utils.StepUtil; | |
| 31 | 20 | import com.example.moudle_pedometer.R; |
| 32 | 21 | import com.example.moudle_pedometer.databinding.FragmentRunRaceDetailBinding; |
| 33 | 22 | import com.qmuiteam.qmui.util.QMUIStatusBarHelper; |
| ... | ... | @@ -37,8 +26,6 @@ import org.greenrobot.eventbus.EventBus; |
| 37 | 26 | import org.greenrobot.eventbus.Subscribe; |
| 38 | 27 | import org.greenrobot.eventbus.ThreadMode; |
| 39 | 28 | |
| 40 | -import java.util.ArrayList; | |
| 41 | -import java.util.List; | |
| 42 | 29 | |
| 43 | 30 | import static android.content.Context.SENSOR_SERVICE; |
| 44 | 31 | |
| ... | ... | @@ -48,7 +35,7 @@ import static android.content.Context.SENSOR_SERVICE; |
| 48 | 35 | * @author ShinnyYang |
| 49 | 36 | */ |
| 50 | 37 | public class RunRaceDetailFragment extends QMUIFragment<RunRaceDetailFragmentView, RunRaceDetailFragmentPresenter, FragmentRunRaceDetailBinding> { |
| 51 | - private static final String TAG = "CollRunRaceDetailFragment"; | |
| 38 | + private static final String TAG = "RunRaceFragment"; | |
| 52 | 39 | private SensorManager mSensorManager; |
| 53 | 40 | |
| 54 | 41 | @Override |
| ... | ... | @@ -78,8 +65,9 @@ public class RunRaceDetailFragment extends QMUIFragment<RunRaceDetailFragmentVie |
| 78 | 65 | getMvpView().initMap(); |
| 79 | 66 | } |
| 80 | 67 | if (getPresenter() != null) { |
| 81 | - if (!TextUtils.isEmpty(CommonInfo.getStreetId(getActivity()))) | |
| 68 | + if (!TextUtils.isEmpty(CommonInfo.getStreetId(getActivity()))) { | |
| 82 | 69 | getPresenter().getRunRaceDetailInfo(getActivity(), CommonInfo.getStreetId(getActivity()), CommonInfo.getUserId(getActivity()), "0"); |
| 70 | + } | |
| 83 | 71 | } |
| 84 | 72 | |
| 85 | 73 | } |
| ... | ... | @@ -189,8 +177,9 @@ public class RunRaceDetailFragment extends QMUIFragment<RunRaceDetailFragmentVie |
| 189 | 177 | //启动鹰眼成功 |
| 190 | 178 | if (messageEvent.getMessageType() == Constant.START_TRACE_GATHER_SUCCESS) { |
| 191 | 179 | if (getMvpView() != null) { |
| 180 | + Log.e(TAG, "跳转: " + getMvpView().importStreetPoints.size()); | |
| 192 | 181 | QMUITipDialogUtil.dismessDialog(); |
| 193 | - PedometerMainActivity.startActivity(getActivity()); | |
| 182 | + PedometerMainActivity.startActivity(getActivity(), binding.includeStreet.tvStartAddr.getText().toString(), binding.includeStreet.tvEndAddr.getText().toString(), getMvpView().importStreetPoints); | |
| 194 | 183 | } |
| 195 | 184 | } |
| 196 | 185 | //启动鹰眼失败 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunningFinishFragment.java
| 1 | 1 | package com.cnlive.moudle.pedometer.ui.fragment; |
| 2 | 2 | |
| 3 | 3 | import android.os.Bundle; |
| 4 | +import android.os.Handler; | |
| 4 | 5 | import android.support.annotation.Nullable; |
| 5 | 6 | import android.view.View; |
| 6 | 7 | |
| ... | ... | @@ -9,6 +10,8 @@ import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 9 | 10 | import com.cnlive.moudle.pedometer.frame.presenter.RunningFinishFragmetPresenter; |
| 10 | 11 | import com.cnlive.moudle.pedometer.frame.view.RunningFinishFragmentView; |
| 11 | 12 | import com.cnlive.moudle.pedometer.model.RunningFinishBean; |
| 13 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 14 | +import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; | |
| 12 | 15 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 13 | 16 | import com.example.moudle_pedometer.R; |
| 14 | 17 | import com.example.moudle_pedometer.databinding.FragmentFinishRunMapBinding; |
| ... | ... | @@ -45,9 +48,6 @@ public class RunningFinishFragment extends QMUIFragment<RunningFinishFragmentVie |
| 45 | 48 | @Override |
| 46 | 49 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 47 | 50 | super.onViewCreated(view, savedInstanceState); |
| 48 | - StepUtil.clearRunData(getActivity(), CommonInfo.getUserId(getActivity())); | |
| 49 | - //todo测试用 | |
| 50 | - CommonInfo.reset(getActivity()); | |
| 51 | 51 | if (getArguments() != null) { |
| 52 | 52 | runningFinishBean = (RunningFinishBean) getArguments().getSerializable("runningFinishBean"); |
| 53 | 53 | if (runningFinishBean != null) { |
| ... | ... | @@ -56,6 +56,20 @@ public class RunningFinishFragment extends QMUIFragment<RunningFinishFragmentVie |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getActivity(), CommonInfo.getUserId(getActivity())); | |
| 60 | + if (getMvpView() != null && userStepEntity != null) { | |
| 61 | + QMUITipDialogUtil.loadingDialog(getContext(), "正在获取轨迹信息,请稍后", false); | |
| 62 | + getPresenter().getServerStreetTrace(getActivity(), userStepEntity); | |
| 63 | + new Handler().postDelayed(new Runnable() { | |
| 64 | + @Override | |
| 65 | + public void run() { | |
| 66 | + getPresenter().queryHistoryTrace(getActivity(), userStepEntity, runningFinishBean); | |
| 67 | + } | |
| 68 | + },2000); | |
| 69 | +// StepUtil.clearRunData(context, CommonInfo.getUserId(context)); | |
| 70 | +// CommonInfo.reset(context); | |
| 71 | + } | |
| 72 | + | |
| 59 | 73 | } |
| 60 | 74 | |
| 61 | 75 | /** | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunningMapFragment.java
| ... | ... | @@ -23,11 +23,13 @@ import com.cnlive.moudle.pedometer.model.RunningMapBean; |
| 23 | 23 | import com.cnlive.moudle.pedometer.model.Constant; |
| 24 | 24 | import com.cnlive.moudle.pedometer.model.MessageEvent; |
| 25 | 25 | import com.cnlive.moudle.pedometer.service.StepService; |
| 26 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 26 | 27 | import com.cnlive.moudle.pedometer.ui.widget.TipDialog; |
| 27 | 28 | import com.cnlive.moudle.pedometer.utils.ChineseToSpeechUtil; |
| 28 | 29 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 29 | 30 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| 30 | 31 | import com.cnlive.moudle.pedometer.utils.MySpHelper; |
| 32 | +import com.cnlive.moudle.pedometer.utils.StepUtil; | |
| 31 | 33 | import com.cnlive.moudle.pedometer.utils.TimeUtil; |
| 32 | 34 | import com.example.moudle_pedometer.R; |
| 33 | 35 | import com.example.moudle_pedometer.databinding.FragmentRunningMapBinding; |
| ... | ... | @@ -47,7 +49,7 @@ import static android.content.Context.SENSOR_SERVICE; |
| 47 | 49 | * @author ShinnyYang |
| 48 | 50 | */ |
| 49 | 51 | public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, RunningMapFragmentPresenter, FragmentRunningMapBinding> { |
| 50 | - private static final String TAG = "CollRunningMapFragment"; | |
| 52 | + private static final String TAG = "RunningMapFragment"; | |
| 51 | 53 | private RunningMapBean runningMapBean; |
| 52 | 54 | private SensorManager mSensorManager; |
| 53 | 55 | private String test = "[{\"latitude\":39.933889208848,\"latitudeE6\":3.9933889208848E7,\"longitude\":116.30900265517,\"longitudeE6\":1.1630900265517001E8},{\"latitude\":39.933868507347,\"latitudeE6\":3.9933868507347E7,\"longitude\":116.30865416508,\"longitudeE6\":1.1630865416508E8},{\"latitude\":39.934756505077,\"latitudeE6\":3.9934756505077E7,\"longitude\":116.30860516469,\"longitudeE6\":1.1630860516468999E8},{\"latitude\":39.934781620502,\"latitudeE6\":3.9934781620502E7,\"longitude\":116.30961013007,\"longitudeE6\":1.1630961013007E8},{\"latitude\":39.934881620374,\"latitudeE6\":3.9934881620374E7,\"longitude\":116.30960513008,\"longitudeE6\":1.1630960513008E8},{\"latitude\":39.934077623132,\"latitudeE6\":3.9934077623132E7,\"longitude\":116.30965812942,\"longitudeE6\":1.1630965812942E8},{\"latitude\":39.933972618463,\"latitudeE6\":3.9933972618463E7,\"longitude\":116.30962113087,\"longitudeE6\":1.1630962113087E8},{\"latitude\":39.933932608856,\"latitudeE6\":3.9933932608856E7,\"longitude\":116.30953913383,\"longitudeE6\":1.1630953913383E8}]"; |
| ... | ... | @@ -96,45 +98,33 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 96 | 98 | mVibrator = (Vibrator) getActivity().getSystemService(Service.VIBRATOR_SERVICE); |
| 97 | 99 | //初始化提示框 |
| 98 | 100 | initTipDialog(); |
| 99 | - List<LatLng> trackPoints = GsonUtil.jsonToList(test, LatLng.class); | |
| 100 | - | |
| 101 | + getMvpView().initView(); | |
| 101 | 102 | if (getArguments() != null) { |
| 102 | 103 | runningMapBean = (RunningMapBean) getArguments().getSerializable("runningMapBean"); |
| 103 | 104 | } |
| 104 | - if (getMvpView() != null) { | |
| 105 | - getMvpView().initView(trackPoints); | |
| 106 | - if (runningMapBean != null) { | |
| 107 | - getMvpView().updateChronometer(runningMapBean); | |
| 108 | - } | |
| 105 | + if (runningMapBean != null) { | |
| 106 | + getMvpView().updateChronometer(runningMapBean); | |
| 109 | 107 | } |
| 110 | - //开始进行历史轨迹查询 | |
| 111 | - if (getPresenter() != null && !TextUtils.isEmpty(StepService.entityName)) { | |
| 112 | - long stepStartTime = 0; | |
| 113 | -// CommonInfo.getStepStartTime(getActivity()); | |
| 114 | - Log.e(TAG, "onViewCreated: 时间"+stepStartTime ); | |
| 115 | - long startTime = 0; | |
| 116 | -// if (stepStartTime != 0) { | |
| 117 | -// startTime = stepStartTime; | |
| 118 | -// } else { | |
| 119 | - startTime = (int) (System.currentTimeMillis() / 1000 -12); | |
| 120 | -// } | |
| 121 | - long current = TimeUtil.getNowTimeStamp(); | |
| 122 | -// long startTime = current - hour * 3600 * 1000 - minute * 60 * 1000 - second * 1000; | |
| 123 | - long endTime = current; | |
| 124 | -// Log.e(TAG, "onViewCreated: " + "hour:" + hour + ",minute" + minute + ",second:" + second); | |
| 125 | - getPresenter().queryHistoryTrace(getActivity(), StepService.entityName, startTime, endTime); | |
| 126 | 108 | |
| 109 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getActivity(), CommonInfo.getUserId(getActivity())); | |
| 110 | + if (getMvpView() != null && userStepEntity != null) { | |
| 111 | + //查询运营人员踩得轨迹 | |
| 112 | + getPresenter().getServerStreetTrace(getActivity(), userStepEntity); | |
| 113 | + | |
| 114 | + //开始查询 | |
| 115 | + getPresenter().queryHistoryTrace(getActivity(), userStepEntity); | |
| 127 | 116 | } |
| 128 | 117 | |
| 129 | 118 | |
| 130 | - List<com.baidu.trace.model.LatLng> fenceLatLngs = new ArrayList<>(); | |
| 131 | - for (LatLng latLng : trackPoints) { | |
| 132 | - com.baidu.trace.model.LatLng tempLatLng = new com.baidu.trace.model.LatLng(latLng.latitude, latLng.longitude); | |
| 133 | - fenceLatLngs.add(tempLatLng); | |
| 134 | - } | |
| 119 | +// List<com.baidu.trace.model.LatLng> fenceLatLngs = new ArrayList<>(); | |
| 120 | +// for (LatLng latLng : trackPoints) { | |
| 121 | +// com.baidu.trace.model.LatLng tempLatLng = new com.baidu.trace.model.LatLng(latLng.latitude, latLng.longitude); | |
| 122 | +// fenceLatLngs.add(tempLatLng); | |
| 123 | +// } | |
| 135 | 124 | // getPresenter().createFence(getActivity(), fenceLatLngs); |
| 136 | 125 | } |
| 137 | 126 | |
| 127 | + | |
| 138 | 128 | @Override |
| 139 | 129 | public void onResume() { |
| 140 | 130 | super.onResume(); |
| ... | ... | @@ -232,6 +222,7 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 232 | 222 | tipDialog.setCanceledOnTouchOutside(false); |
| 233 | 223 | } |
| 234 | 224 | } |
| 225 | + | |
| 235 | 226 | /** |
| 236 | 227 | * 屏蔽边缘返回 |
| 237 | 228 | * 杨帅 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/UploadLogic.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.upload; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.media.MediaMetadataRetriever; | |
| 5 | +import android.os.Environment; | |
| 6 | +import android.text.TextUtils; | |
| 7 | +import android.util.Log; | |
| 8 | + | |
| 9 | +import com.cnlive.libs.base.application.AppConfig; | |
| 10 | +import com.cnlive.libs.base.logic.Config; | |
| 11 | +import com.cnlive.libs.base.logic.Event; | |
| 12 | +import com.cnlive.libs.base.logic.Logic; | |
| 13 | +import com.cnlive.libs.base.logic.callback.DataCallback; | |
| 14 | +import com.cnlive.libs.base.util.ShareReleaseInfoUtil; | |
| 15 | +import com.cnlive.libs.base.util.StringUtils; | |
| 16 | +import com.cnlive.moudle.pedometer.net.SubscriptionRequest; | |
| 17 | +import com.cnlive.moudle.pedometer.net.bean.BaseInfo; | |
| 18 | +import com.cnlive.moudle.pedometer.net.bean.upload.FeedBackInfo; | |
| 19 | +import com.cnlive.moudle.pedometer.net.bean.upload.StorageInfoData; | |
| 20 | +import com.cnlive.moudle.pedometer.net.bean.upload.UploadAuthData; | |
| 21 | +import com.cnlive.moudle.pedometer.net.bean.upload.api.ApiServiceMoment; | |
| 22 | + | |
| 23 | +import org.json.JSONArray; | |
| 24 | +import org.json.JSONException; | |
| 25 | +import org.json.JSONObject; | |
| 26 | + | |
| 27 | +import java.io.File; | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.HashMap; | |
| 30 | +import java.util.List; | |
| 31 | +import java.util.Map; | |
| 32 | + | |
| 33 | +import static com.cnlive.libs.base.logic.Config.ERROR_DEF; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * Created by xiansong on 2018/2/6. | |
| 37 | + */ | |
| 38 | + | |
| 39 | +public class UploadLogic { | |
| 40 | + private static final String TEST_OBJECT_KEY = "802/wjj/video/%s/%s/%s.%s"; | |
| 41 | + private static final String RELEASE_OBJECT_KEY = "769/wjj/video/%s/%s/%s.%s"; | |
| 42 | + private static final String TEST_OBJECT_PIC__KEY = "802/img/%s/%s.%s"; | |
| 43 | + private static final String RELEASE_OBJECT_PIC__KEY = "769/img/%s/%s.%s"; | |
| 44 | + private static final String TEST_SEVEN = "http://wjjtest.ys2.cnliveimg.com/"; | |
| 45 | + private static final String RELEASE_SEVEN = "https://wjj.ys2.cnliveimg.com/"; | |
| 46 | + private static final String SEVEN = AppConfig.isDebug() ? TEST_SEVEN : RELEASE_SEVEN; | |
| 47 | + private static final String OBJECT_KEY = AppConfig.isDebug() ? TEST_OBJECT_KEY : RELEASE_OBJECT_KEY; | |
| 48 | + private static final String OBJECT_PIC_KEY = AppConfig.isDebug() ? TEST_OBJECT_PIC__KEY : RELEASE_OBJECT_PIC__KEY; | |
| 49 | + private static final String TEST_VIDEO_NAME = "802_%s_%s_%s_%s"; | |
| 50 | + private static final String RELEASE_VIDEO_NAME = "769_%s_%s_%s_%s"; | |
| 51 | + private static final String VIDEO_NAME = AppConfig.isDebug() ? TEST_VIDEO_NAME : RELEASE_VIDEO_NAME; | |
| 52 | + private static final String TAG = "UploadLogic"; | |
| 53 | + private static String src; | |
| 54 | + | |
| 55 | + | |
| 56 | + private static String isHorizontalScreen(String videoPath) { | |
| 57 | + if (TextUtils.isEmpty(videoPath)) { | |
| 58 | + return "0"; | |
| 59 | + } | |
| 60 | + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
| 61 | + MediaMetadataRetriever retr = new MediaMetadataRetriever(); | |
| 62 | + retr.setDataSource(videoPath); | |
| 63 | + String r = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); | |
| 64 | + if (TextUtils.isEmpty(r)) { | |
| 65 | + return "0"; | |
| 66 | + } | |
| 67 | + return (r.equals("90") || r.equals("270")) ? "0" : "1"; | |
| 68 | + } | |
| 69 | + return "0"; | |
| 70 | + } | |
| 71 | + | |
| 72 | + /*public static void uploadVideoInfo(Context context, String userId, String text, String address, String videoPath, Event<BaseInfo> event,int gotype) { | |
| 73 | + uploadVideoInfo(context, userId, text, address, videoPath, event,gotype); | |
| 74 | + }*/ | |
| 75 | + | |
| 76 | + | |
| 77 | + public static void uploadPicInfo(Context context, String userId, String text, String address, List<String> picPath, ArrayList width, ArrayList height, Event<BaseInfo> event, String gopath, String videotype) { | |
| 78 | + | |
| 79 | + uploadPicInfo(context, userId, "moment", text, address, picPath, width, height, event, gopath, videotype); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * 文件上传到七牛(webview 帮助反馈在用) | |
| 84 | + * | |
| 85 | + * @param context | |
| 86 | + * @param picPath | |
| 87 | + * @param width | |
| 88 | + * @param height | |
| 89 | + * @param event | |
| 90 | + */ | |
| 91 | + public static void uploadPic(Context context, boolean isZip, List<String> picPath, ArrayList width, ArrayList height, Event<List<FeedBackInfo>> event) { | |
| 92 | + Logic.create() | |
| 93 | + .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | |
| 94 | + UploadProvider.getStorageInfo(context, callback)) | |
| 95 | + .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | |
| 96 | + UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) | |
| 97 | + ) | |
| 98 | + .action((BaseInfo<UploadAuthData> data, DataCallback<Map<String, Object>> callback) -> | |
| 99 | + isZip ? UploadProvider.zipFiles(context, picPath, (code, message, imgs) -> { | |
| 100 | + Map map = new HashMap(); | |
| 101 | + map.put("image", imgs); | |
| 102 | + map.put("tocken", data.getData().getToken()); | |
| 103 | + if (event.active) callback.callback(code, "", map); | |
| 104 | + }) : Logic.process(() -> { | |
| 105 | + Map map = new HashMap(); | |
| 106 | + map.put("image", picPath); | |
| 107 | + map.put("tocken", data.getData().getToken()); | |
| 108 | + return map; | |
| 109 | + }, callback)) | |
| 110 | + .action((Map<String, Object> map, DataCallback<ArrayList<String>> callback) -> { | |
| 111 | + UploadProvider.doUploadPic(context, (List<String>) map.get("image"), (String) (map.get("tocken")), callback, | |
| 112 | + progress -> { | |
| 113 | + if (event.active) { | |
| 114 | + event.onProgress(progress); | |
| 115 | + } | |
| 116 | + }); | |
| 117 | + return null; | |
| 118 | + }) | |
| 119 | + .action((ArrayList<String> data, DataCallback<List<FeedBackInfo>> callback) -> | |
| 120 | + Logic.process(() -> { | |
| 121 | + List<FeedBackInfo> list = new ArrayList<>(); | |
| 122 | + for (int i = 0; i < ((ArrayList) data).size(); i++) { | |
| 123 | + FeedBackInfo info = new FeedBackInfo(); | |
| 124 | + info.setImageUrl(SEVEN + ((ArrayList) data).get(i)); | |
| 125 | + info.setImageWidth((Long) width.get(i)); | |
| 126 | + info.setImageHeight((Long) height.get(i)); | |
| 127 | + list.add(info); | |
| 128 | + } | |
| 129 | + return list; | |
| 130 | + }, callback)) | |
| 131 | + .start(event); | |
| 132 | + } | |
| 133 | + | |
| 134 | + public static void uploadPicInfo(Context context, String userId, String type, String text, String address, List<String> picPath, ArrayList width, ArrayList height, Event<BaseInfo> event, String gopath, String videotype) { | |
| 135 | + Logic.create() | |
| 136 | + .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | |
| 137 | + UploadProvider.getStorageInfo(context, callback)) | |
| 138 | + .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | |
| 139 | + UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) | |
| 140 | + ) | |
| 141 | + .action((data, callback) -> UploadProvider.zipFiles(context, picPath, (code, message, imgs) -> { | |
| 142 | + Map map = new HashMap(); | |
| 143 | + map.put("image", imgs); | |
| 144 | + map.put("tocken", ((BaseInfo<UploadAuthData>) data).getData().getToken()); | |
| 145 | + if (event.active) { | |
| 146 | + callback.callback(code, "", map); | |
| 147 | + } | |
| 148 | + })) | |
| 149 | + .action((Map<String, Object> map, DataCallback<ArrayList<String>> callback) -> { | |
| 150 | + UploadProvider.doUploadPic(context, (List<String>) map.get("image"), (String) (map.get("tocken")), callback, | |
| 151 | + progress -> { | |
| 152 | + if (event.active) { | |
| 153 | + event.onProgress(progress); | |
| 154 | + } | |
| 155 | + }); | |
| 156 | + return null; | |
| 157 | + }) | |
| 158 | + .action((ArrayList<String> data, DataCallback<Map<String, Object>> callback) -> | |
| 159 | + Logic.process(() -> { | |
| 160 | + JSONArray jsonArray = new JSONArray(); | |
| 161 | + for (int i = 0; i < ((ArrayList) data).size(); i++) { | |
| 162 | + JSONObject picobj = new JSONObject(); | |
| 163 | + int index = Integer.parseInt(data.get(i).substring(8, 9)); | |
| 164 | + try { | |
| 165 | + picobj.put("imageUrl", SEVEN + ((ArrayList) data).get(i)); | |
| 166 | + picobj.put("imageWidth", width.get(i)); | |
| 167 | + picobj.put("imageHeight", height.get(i)); | |
| 168 | + } catch (JSONException e) { | |
| 169 | + e.printStackTrace(); | |
| 170 | + } | |
| 171 | + try { | |
| 172 | + jsonArray.put(index, picobj); | |
| 173 | + } catch (JSONException e) { | |
| 174 | + e.printStackTrace(); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + if (jsonArray.length() == ((ArrayList) data).size()) { | |
| 178 | + Map<String, Object> requestData = new HashMap<>(); | |
| 179 | + requestData.put("appId", AppConfig.getAppId()); | |
| 180 | + requestData.put("sid", userId); | |
| 181 | + requestData.put("text", StringUtils.encode(text)); | |
| 182 | + requestData.put("address", address); | |
| 183 | + requestData.put("type", "1"); | |
| 184 | + requestData.put("picArray", jsonArray); | |
| 185 | + return requestData; | |
| 186 | + } else { | |
| 187 | + return null; | |
| 188 | + } | |
| 189 | + }, callback)) | |
| 190 | + .action((Map<String, Object> data, DataCallback<BaseInfo> callback) -> | |
| 191 | + SubscriptionRequest.service(ApiServiceMoment.class, service -> service.releaseMomentNe(gopath, data)) | |
| 192 | + .subscribe(context, callback)) | |
| 193 | + | |
| 194 | + /* ApiRequest.service(ApiServiceMoment.class, service -> gotype == 2 ? | |
| 195 | + service.releaseMomentNew(data) : service.releaseWitness(data)) | |
| 196 | + .subscribe(context, callback))*/ | |
| 197 | + .start(event); | |
| 198 | + } | |
| 199 | + | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * 张楠上传地图信息用 | |
| 203 | + */ | |
| 204 | + public static void uploadAddressPicInfo(Context context, List<String> picPath, Event<String> event) { | |
| 205 | + Logic.create() | |
| 206 | + .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | |
| 207 | + UploadProvider.getStorageInfo(context, callback)) | |
| 208 | + .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | |
| 209 | + UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) | |
| 210 | + ) | |
| 211 | + .action((data, callback) -> UploadProvider.zipFiles(context, picPath, (code, message, imgs) -> { | |
| 212 | + Map map = new HashMap(); | |
| 213 | + map.put("image", imgs); | |
| 214 | + map.put("tocken", ((BaseInfo<UploadAuthData>) data).getData().getToken()); | |
| 215 | + if (event.active) { | |
| 216 | + callback.callback(code, "", map); | |
| 217 | + } | |
| 218 | + })) | |
| 219 | + .action((Map<String, Object> map, DataCallback<ArrayList<String>> callback) -> { | |
| 220 | + UploadProvider.doUploadPic(context, (List<String>) map.get("image"), (String) (map.get("tocken")), callback, | |
| 221 | + progress -> { | |
| 222 | + if (event.active) { | |
| 223 | + event.onProgress(progress); | |
| 224 | + } | |
| 225 | + }); | |
| 226 | + return null; | |
| 227 | + }) | |
| 228 | + .action((ArrayList<String> data, DataCallback<String> callback) -> | |
| 229 | + Logic.process(() -> { | |
| 230 | + String addressImageUrl = SEVEN + ((ArrayList) data).get(0); | |
| 231 | + return addressImageUrl; | |
| 232 | + }, callback)) | |
| 233 | + | |
| 234 | + .start(event); | |
| 235 | + } | |
| 236 | + | |
| 237 | + public static void uploadSnowPicInfo(Context context, String userId, String text, String address, ArrayList picPath, ArrayList width, ArrayList height, Event<BaseInfo> event, String path, String videotype) { | |
| 238 | + //统计 | |
| 239 | + //Probe.probeUploadVideo(); | |
| 240 | + | |
| 241 | + Logic.create() | |
| 242 | + .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | |
| 243 | + UploadProvider.getStorageInfo(context, callback)) | |
| 244 | + .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | |
| 245 | + UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback)) | |
| 246 | + .action((BaseInfo<UploadAuthData> data, DataCallback<Map<String, Object>> callback) -> UploadProvider.zipFiles(context, (List<String>) picPath, (code, message, imgs) -> { | |
| 247 | + Map map = new HashMap(); | |
| 248 | + map.put("image", imgs); | |
| 249 | + map.put("tocken", data.getData().getToken()); | |
| 250 | + if (event.active) callback.callback(code, "", map); | |
| 251 | + })) | |
| 252 | + .action((Map<String, Object> map, DataCallback<ArrayList<String>> callback) -> { | |
| 253 | + UploadProvider.doUploadPic(context, (List<String>) map.get("image"), (String) (map.get("tocken")), callback, | |
| 254 | + progress -> { | |
| 255 | + if (event.active) { | |
| 256 | + event.onProgress(progress); | |
| 257 | + } | |
| 258 | + }); | |
| 259 | + return null; | |
| 260 | + }) | |
| 261 | + .action((ArrayList<String> data, DataCallback<Map<String, Object>> callback) -> | |
| 262 | + Logic.process(() -> { | |
| 263 | + JSONArray jsonArray = new JSONArray(); | |
| 264 | + for (int i = 0; i < ((ArrayList) data).size(); i++) { | |
| 265 | + JSONObject picobj = new JSONObject(); | |
| 266 | + int index = Integer.parseInt(data.get(i).substring(8, 9)); | |
| 267 | + try { | |
| 268 | + picobj.put("imageUrl", SEVEN + ((ArrayList) data).get(i)); | |
| 269 | + picobj.put("imageWidth", width.get(i)); | |
| 270 | + picobj.put("imageHeight", height.get(i)); | |
| 271 | + } catch (JSONException e) { | |
| 272 | + e.printStackTrace(); | |
| 273 | + } | |
| 274 | + try { | |
| 275 | + jsonArray.put(index, picobj); | |
| 276 | + } catch (JSONException e) { | |
| 277 | + e.printStackTrace(); | |
| 278 | + } | |
| 279 | + } | |
| 280 | + if (jsonArray.length() == ((ArrayList) data).size()) { | |
| 281 | + Log.e("werwwwwwwwwwwww123", jsonArray.toString() + " " + AppConfig.getAppId() + " " + userId); | |
| 282 | + Map<String, Object> requestData = new HashMap<>(); | |
| 283 | + requestData.put("appId", AppConfig.getAppId()); | |
| 284 | + requestData.put("sid", userId); | |
| 285 | + requestData.put("text", StringUtils.encode(text)); | |
| 286 | + requestData.put("address", address); | |
| 287 | + requestData.put("type", "1"); | |
| 288 | + requestData.put("picArray", jsonArray); | |
| 289 | + return requestData; | |
| 290 | + } else { | |
| 291 | + return null; | |
| 292 | + } | |
| 293 | +// return null; | |
| 294 | + }, callback)) | |
| 295 | + .action((Map<String, Object> data, DataCallback<BaseInfo> callback) -> | |
| 296 | + SubscriptionRequest.service(ApiServiceMoment.class, service -> service.releaseMomentNe(path, data)) | |
| 297 | + .subscribe(context, callback)) | |
| 298 | + .start(event); | |
| 299 | + } | |
| 300 | + | |
| 301 | + private static class SendMoment { | |
| 302 | + private String appId = AppConfig.getAppId(); | |
| 303 | + private String text; | |
| 304 | + private String sid; | |
| 305 | + private String type; | |
| 306 | + private String address; | |
| 307 | + private String debug; | |
| 308 | + private String ver; | |
| 309 | + private String plat; | |
| 310 | + private String tagId; | |
| 311 | + private String tagName; | |
| 312 | + | |
| 313 | + public SendMoment(String type, String sid, String text, String address, String ver, String plat, String tagId, String tagName) { | |
| 314 | + this.sid = sid; | |
| 315 | + this.text = StringUtils.encode(text); | |
| 316 | + this.address = address; | |
| 317 | + this.debug = AppConfig.isDebug() ? "0" : ""; | |
| 318 | + this.type = type; | |
| 319 | + this.ver = ver; | |
| 320 | + this.plat = plat; | |
| 321 | + this.tagId = tagId; | |
| 322 | + this.tagName = tagName; | |
| 323 | + } | |
| 324 | + } | |
| 325 | + | |
| 326 | + private static class SendImage { | |
| 327 | + private String imageUrl; | |
| 328 | + private Long imageWidth; | |
| 329 | + private Long imageHeight; | |
| 330 | + | |
| 331 | + | |
| 332 | + public SendImage(String imageUrl, Long imageWidth, Long imageHeight) { | |
| 333 | + this.imageUrl = imageUrl; | |
| 334 | + this.imageWidth = imageWidth; | |
| 335 | + this.imageHeight = imageHeight; | |
| 336 | + } | |
| 337 | + } | |
| 338 | + | |
| 339 | + private static String getPath(String cachePath) { | |
| 340 | + String path = Environment.getExternalStorageDirectory() + cachePath; | |
| 341 | + File file = new File(path); | |
| 342 | + if (file.mkdirs()) { | |
| 343 | + return path; | |
| 344 | + } | |
| 345 | + return path; | |
| 346 | + } | |
| 347 | + | |
| 348 | + public static void uploadInfo(Context context, String sid, String text, String address, | |
| 349 | + String key, List<String> imageFiles, ShareReleaseInfoUtil.ShareConfig shareConfig, | |
| 350 | + Event<BaseInfo> event, String gopath, String videotype) { | |
| 351 | + | |
| 352 | + Logic.create(imageFiles) | |
| 353 | + .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | |
| 354 | + UploadProvider.getStorageInfo(context, callback)) | |
| 355 | + .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | |
| 356 | + UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) | |
| 357 | + ) | |
| 358 | + .action((BaseInfo<UploadAuthData> data, DataCallback<Map<String, Object>> callback) -> | |
| 359 | + Logic.process(() -> { | |
| 360 | + Map map = new HashMap(); | |
| 361 | + File file = new File(getPath("/strike/cache/") + "share.jpg"); | |
| 362 | + if (file.exists()) { | |
| 363 | + src = getPath("/strike/cache/") + "share.jpg"; | |
| 364 | + } else { | |
| 365 | + src = getPath("/strike/cache/") + "sharefirst.jpg"; | |
| 366 | + } | |
| 367 | + map.put("image", src); | |
| 368 | + map.put("tocken", data.getData().getToken()); | |
| 369 | + return map; | |
| 370 | + }, callback)) | |
| 371 | + .action((Map<String, Object> map, DataCallback<ArrayList<String>> callback) -> { | |
| 372 | + ArrayList<String> objects = new ArrayList<>(); | |
| 373 | + objects.add(map.get("image") + ""); | |
| 374 | + UploadProvider.doUploadPic(context, objects, (String) (map.get("tocken")), callback, | |
| 375 | + progress -> { | |
| 376 | + if (event.active) { | |
| 377 | + event.onProgress(progress); | |
| 378 | + } | |
| 379 | + }); | |
| 380 | + return null; | |
| 381 | + }) | |
| 382 | + .action((ArrayList<String> data1, DataCallback<String> callback) -> | |
| 383 | + UploadProvider.uploadInfo(context, sid, text, address, key, null, shareConfig, gopath, SEVEN + ((ArrayList) data1).get(0), | |
| 384 | + (progress) -> { | |
| 385 | + if (!event.active) { | |
| 386 | + return; | |
| 387 | + } | |
| 388 | + event.onProgress(progress); | |
| 389 | + }, | |
| 390 | + (code, message, data) -> { | |
| 391 | + if (!event.active) { | |
| 392 | + return; | |
| 393 | + } | |
| 394 | + | |
| 395 | + event.onState(Config.STATE_IDLE); | |
| 396 | + if (code == 0) { | |
| 397 | + event.onSuccess(data); | |
| 398 | + } else { | |
| 399 | + event.onFailure(code, message); | |
| 400 | + } | |
| 401 | + }) | |
| 402 | + ) | |
| 403 | + .start(event); | |
| 404 | + } | |
| 405 | + | |
| 406 | + | |
| 407 | + public static void uploadHomeInfo(Context context, String sid, String text, String address, | |
| 408 | + String key, List<String> imageFiles, ShareReleaseInfoUtil.ShareConfig shareConfig, | |
| 409 | + Event<BaseInfo> event, String gopath, String videotype) { | |
| 410 | + Logic.create(imageFiles) | |
| 411 | + .action((List<String> data, DataCallback<List<String>> callback) -> | |
| 412 | + UploadProvider.zipFiles(context, data, callback)) | |
| 413 | + .action((List<String> list, DataCallback<String> callback) -> | |
| 414 | + UploadProvider.uploadInfo(context, sid, text, address, key, list, shareConfig, gopath, videotype, | |
| 415 | + (progress) -> { | |
| 416 | + if (!event.active) { | |
| 417 | + return; | |
| 418 | + } | |
| 419 | + event.onProgress(progress); | |
| 420 | + }, | |
| 421 | + (code, message, data) -> { | |
| 422 | + if (!event.active) { | |
| 423 | + return; | |
| 424 | + } | |
| 425 | + | |
| 426 | + event.onState(Config.STATE_IDLE); | |
| 427 | + if (code == 0) { | |
| 428 | + event.onSuccess(data); | |
| 429 | + } else { | |
| 430 | + event.onFailure(code, message); | |
| 431 | + } | |
| 432 | + }) | |
| 433 | + ) | |
| 434 | + .start(event); | |
| 435 | + } | |
| 436 | + | |
| 437 | + | |
| 438 | + private static void onError(String tag, int stateCode, int code, String message, Event event) { | |
| 439 | + if (event.active) { | |
| 440 | + event.onState(Config.STATE_IDLE); | |
| 441 | + if (code == -3) { | |
| 442 | + event.onFailure(code, message); | |
| 443 | + } else { | |
| 444 | + event.onFailure(stateCode, message); | |
| 445 | + } | |
| 446 | + } | |
| 447 | + Log.d(TAG, String.format(ERROR_DEF, tag, stateCode, code, message)); | |
| 448 | + } | |
| 449 | + | |
| 450 | + /** | |
| 451 | + * Im收藏的时候图片单张上传的方法 | |
| 452 | + * | |
| 453 | + * @param context | |
| 454 | + * @param isZip | |
| 455 | + * @param picPath | |
| 456 | + * @param event | |
| 457 | + */ | |
| 458 | + public static void uploadonePic(Context context, boolean isZip, List<String> picPath, Event<List<FeedBackInfo>> event) { | |
| 459 | + | |
| 460 | + Logic.create() | |
| 461 | + .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | |
| 462 | + UploadProvider.getStorageInfo(context, callback)) | |
| 463 | + .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | |
| 464 | + UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) | |
| 465 | + ) | |
| 466 | + .action((BaseInfo<UploadAuthData> data, DataCallback<Map<String, Object>> callback) -> | |
| 467 | + isZip ? UploadProvider.zipFiles(context, picPath, (code, message, imgs) -> { | |
| 468 | + Map map = new HashMap(); | |
| 469 | + map.put("image", imgs); | |
| 470 | + map.put("tocken", data.getData().getToken()); | |
| 471 | + if (event.active) callback.callback(code, "", map); | |
| 472 | + }) : Logic.process(() -> { | |
| 473 | + Map map = new HashMap(); | |
| 474 | + map.put("image", picPath); | |
| 475 | + map.put("tocken", data.getData().getToken()); | |
| 476 | + return map; | |
| 477 | + }, callback)) | |
| 478 | + .action((Map<String, Object> map, DataCallback<ArrayList<String>> callback) -> { | |
| 479 | + UploadProvider.doUploadPic(context, (List<String>) map.get("image"), (String) (map.get("tocken")), callback, | |
| 480 | + progress -> { | |
| 481 | + if (event.active) { | |
| 482 | + event.onProgress(progress); | |
| 483 | + } | |
| 484 | + }); | |
| 485 | + return null; | |
| 486 | + }) | |
| 487 | + .action((ArrayList<String> data, DataCallback<List<FeedBackInfo>> callback) -> | |
| 488 | + Logic.process(() -> { | |
| 489 | + List<FeedBackInfo> list = new ArrayList<>(); | |
| 490 | + for (int i = 0; i < ((ArrayList) data).size(); i++) { | |
| 491 | + FeedBackInfo info = new FeedBackInfo(); | |
| 492 | + info.setImageUrl(SEVEN + ((ArrayList) data).get(i)); | |
| 493 | + list.add(info); | |
| 494 | + } | |
| 495 | + return list; | |
| 496 | + }, callback)) | |
| 497 | + .start(event); | |
| 498 | + | |
| 499 | + } | |
| 500 | + | |
| 501 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/UploadProvider.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.upload; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.media.MediaMetadataRetriever; | |
| 6 | +import android.os.Build; | |
| 7 | +import android.os.Environment; | |
| 8 | +import android.text.TextUtils; | |
| 9 | +import android.util.Log; | |
| 10 | + | |
| 11 | +import com.cnlive.libs.base.application.AppConfig; | |
| 12 | +import com.cnlive.libs.base.logic.Config; | |
| 13 | +import com.cnlive.libs.base.logic.callback.DataCallback; | |
| 14 | +import com.cnlive.libs.base.logic.callback.ProgressCallback; | |
| 15 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 16 | +import com.cnlive.libs.base.util.ShareReleaseInfoUtil; | |
| 17 | +import com.cnlive.libs.base.util.StringUtils; | |
| 18 | +import com.cnlive.libs.data.network.Subscriber; | |
| 19 | +import com.cnlive.libs.data.network.body.CountingRequestBody; | |
| 20 | +import com.cnlive.libs.data.network.util.SignUtil; | |
| 21 | +import com.cnlive.libs.upload.listener.CNPutObjectResponseListener; | |
| 22 | +import com.cnlive.libs.upload.model.UploadError; | |
| 23 | +import com.cnlive.libs.upload.model.acl.CNCannedAccessControlList; | |
| 24 | +import com.cnlive.libs.upload.services.CNPutObjectRequest; | |
| 25 | +import com.cnlive.libs.upload.upload.CNUpload; | |
| 26 | +import com.cnlive.libs.upload.upload.callback.OnInitListener; | |
| 27 | +import com.cnlive.media.picker.utils.FileTypeUtil; | |
| 28 | +import com.cnlive.moudle.pedometer.net.ApiSubscriber; | |
| 29 | +import com.cnlive.moudle.pedometer.net.SubscriptionRequest; | |
| 30 | +import com.cnlive.moudle.pedometer.net.bean.BaseInfo; | |
| 31 | +import com.cnlive.moudle.pedometer.net.bean.upload.StorageInfoData; | |
| 32 | +import com.cnlive.moudle.pedometer.net.bean.upload.UploadAuthData; | |
| 33 | +import com.cnlive.moudle.pedometer.net.bean.upload.api.ApiServiceMoment; | |
| 34 | +import com.cnlive.moudle.pedometer.net.bean.upload.api.ApiServiceOpen; | |
| 35 | +import com.cnlive.moudle.pedometer.utils.FileUtil; | |
| 36 | +import com.cnlive.moudle.pedometer.utils.IDUtils; | |
| 37 | +import com.cnlive.moudle.pedometer.utils.MD5; | |
| 38 | +import com.qiniu.android.http.ResponseInfo; | |
| 39 | +import com.qiniu.android.storage.UpCompletionHandler; | |
| 40 | +import com.qiniu.android.storage.UpProgressHandler; | |
| 41 | +import com.qiniu.android.storage.UploadManager; | |
| 42 | +import com.qiniu.android.storage.UploadOptions; | |
| 43 | +import com.qiniu.pili.droid.shortvideo.PLShortVideoTranscoder; | |
| 44 | +import com.qiniu.pili.droid.shortvideo.PLVideoSaveListener; | |
| 45 | + | |
| 46 | +import org.apache.http.Header; | |
| 47 | +import org.json.JSONException; | |
| 48 | +import org.json.JSONObject; | |
| 49 | + | |
| 50 | +import java.io.File; | |
| 51 | +import java.util.ArrayList; | |
| 52 | +import java.util.Date; | |
| 53 | +import java.util.HashMap; | |
| 54 | +import java.util.List; | |
| 55 | +import java.util.Map; | |
| 56 | + | |
| 57 | +import io.reactivex.Observable; | |
| 58 | +import io.reactivex.disposables.Disposable; | |
| 59 | +import okhttp3.MediaType; | |
| 60 | +import okhttp3.MultipartBody; | |
| 61 | +import okhttp3.RequestBody; | |
| 62 | +import retrofit2.adapter.rxjava2.Result; | |
| 63 | +import top.zibin.luban.CompressionPredicate; | |
| 64 | +import top.zibin.luban.Luban; | |
| 65 | +import top.zibin.luban.OnCompressListener; | |
| 66 | +//import org.apache.http.Header; | |
| 67 | +import static com.cnlive.libs.base.logic.Config.ERROR_UPLOAD; | |
| 68 | +import static com.cnlive.libs.base.logic.Config.SUCCESS; | |
| 69 | + | |
| 70 | + | |
| 71 | +/** | |
| 72 | + * Created by xiansong on 2018/2/1. | |
| 73 | + */ | |
| 74 | + | |
| 75 | +public class UploadProvider { | |
| 76 | + | |
| 77 | + private static final String TAG = "UploadProvider"; | |
| 78 | + private static final String TEST_OBJECT_PIC__KEY = "802/img/%s/%s/%s.%s"; | |
| 79 | + private static final String RELEASE_OBJECT_PIC__KEY = "769/img/%s/%s/%s.%s"; | |
| 80 | + private static final String OBJECT_PIC_KEY = AppConfig.isDebug() ? TEST_OBJECT_PIC__KEY : RELEASE_OBJECT_PIC__KEY; | |
| 81 | + private static final String TYPE_IMAGE_PATH = "/strike/image/"; | |
| 82 | + private static final String TYPE_VIDEO_PATH = "/strike/cache/"; | |
| 83 | + | |
| 84 | + | |
| 85 | + public static void initUpload(Context context, DataCallback<CNUpload> callback) { | |
| 86 | + if (callback == null) return; | |
| 87 | + //实例化上传 | |
| 88 | + CNUpload cnUpload = new CNUpload(context); | |
| 89 | + //初始化上传 | |
| 90 | + cnUpload.initCNUpload(new OnInitListener() { | |
| 91 | + @Override | |
| 92 | + public void onError(String s, String s1) { | |
| 93 | + int errorCode = -1; | |
| 94 | + try { | |
| 95 | + errorCode = Integer.valueOf(s); | |
| 96 | + } catch (Exception e) { | |
| 97 | + Log.e(TAG, "initUpload error code is string. "); | |
| 98 | + } finally { | |
| 99 | + callback.callback(errorCode, s1, null); | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + @Override | |
| 104 | + public void onSuccess(String s) { | |
| 105 | + callback.callback(0, s, cnUpload); | |
| 106 | + } | |
| 107 | + }); | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * @param context | |
| 112 | + * @param callback | |
| 113 | + * @return | |
| 114 | + */ | |
| 115 | + public static Disposable uploadAuth(Context context, String bucketName, DataCallback<BaseInfo<UploadAuthData>> callback) { | |
| 116 | + Map<String, String> map = new HashMap<>(); | |
| 117 | + map.put("appId", AppConfig.getAppId()); | |
| 118 | + map.put("verb", "POST"); | |
| 119 | + map.put("md5", ""); | |
| 120 | + map.put("bucket", bucketName); | |
| 121 | + map.put("type", ""); | |
| 122 | + map.put("res", ""); | |
| 123 | + map.put("headers", ""); | |
| 124 | + map.put("date", ""); | |
| 125 | + map.put("storageType", "2"); | |
| 126 | + Subscriber<BaseInfo<UploadAuthData>> subscriber = new Subscriber<BaseInfo<UploadAuthData>>(context, ApiSubscriber.subscriberBuild) { | |
| 127 | + @Override | |
| 128 | + public void onCompleted(String s, String s1, BaseInfo<UploadAuthData> uploadAuthDataBaseInfo) { | |
| 129 | + if (callback == null) { | |
| 130 | + return; | |
| 131 | + } | |
| 132 | + callback.callback(SUCCESS, "", uploadAuthDataBaseInfo); | |
| 133 | + } | |
| 134 | + | |
| 135 | + @Override | |
| 136 | + public void onError(String s, String s1) { | |
| 137 | + if (callback == null) { | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + int errorCode = -1; | |
| 141 | + try { | |
| 142 | + errorCode = Integer.valueOf(s); | |
| 143 | + } catch (Exception ignored) { | |
| 144 | + } finally { | |
| 145 | + callback.callback(errorCode, s1, null); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + }; | |
| 149 | + Observable<Result<BaseInfo<UploadAuthData>>> observable = SubscriptionRequest.service(ApiServiceOpen.class).getUploadAuthForApp(map); | |
| 150 | + return SubscriptionRequest.subscribe(observable, subscriber); | |
| 151 | + } | |
| 152 | + | |
| 153 | + /** | |
| 154 | + * 获取存储信息 | |
| 155 | + * | |
| 156 | + * @param context | |
| 157 | + * @param callback | |
| 158 | + * @return | |
| 159 | + */ | |
| 160 | + public static Disposable getStorageInfo(Context context, DataCallback<BaseInfo<List<StorageInfoData>>> callback) { | |
| 161 | + Map<String, String> map = new HashMap<>(); | |
| 162 | + map.put("appId", AppConfig.getAppId()); | |
| 163 | + map.put("storageType", "2"); | |
| 164 | + map.put("state", "1"); | |
| 165 | + map.put("contentType", "1"); | |
| 166 | +// map.put("profile", AppConfig.isDebug() ? "2" : "1");//暂时不传这个参数 | |
| 167 | + Subscriber<BaseInfo<List<StorageInfoData>>> subscriber = new Subscriber<BaseInfo<List<StorageInfoData>>>(context, ApiSubscriber.subscriberBuild) { | |
| 168 | + @Override | |
| 169 | + public void onCompleted(String code, String message, BaseInfo<List<StorageInfoData>> data) { | |
| 170 | + if (callback == null) { | |
| 171 | + return; | |
| 172 | + } | |
| 173 | + if (data.getData().size() > 0 || data.getData() != null) { | |
| 174 | + callback.callback(SUCCESS, "", data); | |
| 175 | + } else { | |
| 176 | + callback.callback(-1, "storage info null", null); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + @Override | |
| 181 | + public void onError(String code, String message) { | |
| 182 | + if (callback == null) { | |
| 183 | + return; | |
| 184 | + } | |
| 185 | + int errorCode = -1; | |
| 186 | + try { | |
| 187 | + errorCode = Integer.valueOf(code); | |
| 188 | + } catch (Exception ignored) { | |
| 189 | + } finally { | |
| 190 | + callback.callback(errorCode, message, null); | |
| 191 | + } | |
| 192 | + } | |
| 193 | + }; | |
| 194 | + Observable<Result<BaseInfo<List<StorageInfoData>>>> observable = SubscriptionRequest.service(ApiServiceOpen.class).getStorageInfo(map); | |
| 195 | + return SubscriptionRequest.subscribe(observable, subscriber); | |
| 196 | + } | |
| 197 | + | |
| 198 | + // /** | |
| 199 | +// * 视频发布 - 视讯云数据同步接口 | |
| 200 | +// * | |
| 201 | +// * @param context | |
| 202 | +// * @param sid | |
| 203 | +// * @param text | |
| 204 | +// * @param address | |
| 205 | +// * @param key | |
| 206 | +// * @param callback | |
| 207 | +// * @return | |
| 208 | +// */ | |
| 209 | +// public static Disposable uploadInfo(Context context, String sid, String text, String address, String key, DataCallback<BaseInfo> callback) { | |
| 210 | +// svInputMamForAPP | |
| 211 | +// } | |
| 212 | + public static Disposable zipFiles(Context context, List<String> imageFiles, DataCallback<List<String>> callback) { | |
| 213 | + if (imageFiles == null || imageFiles.size() == 0) { | |
| 214 | + callback.callback(0, "", imageFiles); | |
| 215 | + } else { | |
| 216 | + List<String> files = new ArrayList<>(); | |
| 217 | + for (int i = 0; i < imageFiles.size(); i++) { | |
| 218 | + if ("gif".equals(FileTypeUtil.getFileType(imageFiles.get(i)))) { | |
| 219 | + files.add(imageFiles.get(i)); | |
| 220 | + if (files.size() == imageFiles.size()) { | |
| 221 | + callback.callback(0, "", files); | |
| 222 | + } | |
| 223 | + } else { | |
| 224 | + Luban.with(context) | |
| 225 | + .load(imageFiles.get(i)) | |
| 226 | + .ignoreBy(500) | |
| 227 | + .setTargetDir(getPath(TYPE_IMAGE_PATH)) | |
| 228 | + .filter(new CompressionPredicate() { | |
| 229 | + @Override | |
| 230 | + public boolean apply(String path) { | |
| 231 | + return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif")); | |
| 232 | + } | |
| 233 | + }) | |
| 234 | + .setCompressListener(new OnCompressListener() { | |
| 235 | + @Override | |
| 236 | + public void onStart() { | |
| 237 | + // TODO 压缩开始前调用,可以在方法内启动 loading UI | |
| 238 | + } | |
| 239 | + | |
| 240 | + @Override | |
| 241 | + public void onSuccess(File file) { | |
| 242 | + // TODO 压缩成功后调用,返回压缩后的图片文件 | |
| 243 | + files.add(file.getPath()); | |
| 244 | + if (files.size() == imageFiles.size()) { | |
| 245 | + callback.callback(0, "", files); | |
| 246 | + } | |
| 247 | + } | |
| 248 | + | |
| 249 | + @Override | |
| 250 | + public void onError(Throwable e) { | |
| 251 | + Log.e(TAG, "onError: 失败"+e.getMessage() ); | |
| 252 | + // TODO 当压缩过程出现问题时调用 | |
| 253 | + AlertUtil.showDeftToast(context, "图片压缩失败,请重新上传"); | |
| 254 | + } | |
| 255 | + }).launch(); | |
| 256 | + } | |
| 257 | + } | |
| 258 | + } | |
| 259 | + return null; | |
| 260 | + } | |
| 261 | + | |
| 262 | + public static boolean isHUAWEI() { | |
| 263 | + String manufacturer = Build.MANUFACTURER; | |
| 264 | + if ("huawei".equalsIgnoreCase(manufacturer)) { | |
| 265 | + return true; | |
| 266 | + } | |
| 267 | + return false; | |
| 268 | + } | |
| 269 | + | |
| 270 | + | |
| 271 | + public static Disposable zipVideo(Context context, String path, boolean compressed, DataCallback<String> callback) { | |
| 272 | + boolean huawei = isHUAWEI(); | |
| 273 | + if (TextUtils.isEmpty(path) || compressed) { | |
| 274 | + callback.callback(Config.FAIL, "", path); | |
| 275 | + } else { | |
| 276 | + try { | |
| 277 | + // String outPath = getPath(TYPE_VIDEO_PATH) + MD5Utils.getFileMD5(new File(path)) + ".mp4"; | |
| 278 | + // String outPath = getPath(TYPE_VIDEO_PATH) + MD5.getFileMD5(new File(path)) + ".mp4"; | |
| 279 | + compressVideoResouce(context, path, callback); | |
| 280 | + // TranscoderUtil.doTranscode(context, path, outPath, callback); | |
| 281 | + } catch (Exception e) { | |
| 282 | + callback.callback(0, "", path); | |
| 283 | + } | |
| 284 | + } | |
| 285 | + return null; | |
| 286 | + } | |
| 287 | + | |
| 288 | + | |
| 289 | + /** | |
| 290 | + * 压缩视频 | |
| 291 | + * | |
| 292 | + * @param mContext | |
| 293 | + * @param filepath | |
| 294 | + */ | |
| 295 | + public static void compressVideoResouce(Context mContext, String filepath, DataCallback<String> callback) { | |
| 296 | + if (TextUtils.isEmpty(filepath)) { | |
| 297 | + AlertUtil.showDeftToast(mContext, "请先选择转码文件!"); | |
| 298 | + return; | |
| 299 | + } | |
| 300 | + //PLShortVideoTranscoder初始化,三个参数,第一个context,第二个要压缩文件的路径,第三个视频压缩后输出的路径 | |
| 301 | + PLShortVideoTranscoder mShortVideoTranscoder = new PLShortVideoTranscoder(mContext, filepath, getPath(TYPE_VIDEO_PATH) + MD5.getFileMD5(new File(filepath)) + ".mp4"); | |
| 302 | + MediaMetadataRetriever retr = new MediaMetadataRetriever(); | |
| 303 | + retr.setDataSource(filepath); | |
| 304 | + String height = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); // 视频高度 | |
| 305 | + String width = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); // 视频宽度 | |
| 306 | + String rotation = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); // 视频旋转方向 | |
| 307 | + int transcodingBitrateLevel = 7;//我这里选择的4000*1000压缩,这里可以自己选择合适的压缩比例 | |
| 308 | + mShortVideoTranscoder.transcode(Integer.parseInt(width), Integer.parseInt(height), getEncodingBitrateLevel(transcodingBitrateLevel), new PLVideoSaveListener() { | |
| 309 | + @Override | |
| 310 | + public void onSaveVideoSuccess(String s) { | |
| 311 | + if (callback != null) { | |
| 312 | + callback.callback(Config.SUCCESS, "success", s); | |
| 313 | + } | |
| 314 | + } | |
| 315 | + | |
| 316 | + @Override | |
| 317 | + public void onSaveVideoFailed(final int errorCode) { | |
| 318 | + if (callback != null) { | |
| 319 | + callback.callback(Config.FAIL, "", filepath); | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 323 | + @Override | |
| 324 | + public void onSaveVideoCanceled() { | |
| 325 | +// LogUtil.e("onSaveVideoCanceled"); | |
| 326 | + } | |
| 327 | + | |
| 328 | + @Override | |
| 329 | + public void onProgressUpdate(float percentage) { | |
| 330 | +// LogUtil.e("onProgressUpdate==========" + percentage); | |
| 331 | + } | |
| 332 | + }); | |
| 333 | + } | |
| 334 | + | |
| 335 | + /** | |
| 336 | + * 设置压缩质量 | |
| 337 | + * | |
| 338 | + * @param position | |
| 339 | + * @return | |
| 340 | + */ | |
| 341 | + private static int getEncodingBitrateLevel(int position) { | |
| 342 | + return ENCODING_BITRATE_LEVEL_ARRAY[position]; | |
| 343 | + } | |
| 344 | + | |
| 345 | + /** | |
| 346 | + * 选的越高文件质量越大,质量越好 | |
| 347 | + */ | |
| 348 | + public static final int[] ENCODING_BITRATE_LEVEL_ARRAY = { | |
| 349 | + 500 * 1000, | |
| 350 | + 800 * 1000, | |
| 351 | + 1000 * 1000, | |
| 352 | + 1200 * 1000, | |
| 353 | + 1600 * 1000, | |
| 354 | + 2000 * 1000, | |
| 355 | + 2500 * 1000, | |
| 356 | + 4000 * 1000, | |
| 357 | + 8000 * 1000, | |
| 358 | + }; | |
| 359 | + | |
| 360 | + | |
| 361 | + private static String getPath(String cachePath) { | |
| 362 | + String path = Environment.getExternalStorageDirectory() + cachePath; | |
| 363 | + File file = new File(path); | |
| 364 | + if (file.mkdirs()) { | |
| 365 | + return path; | |
| 366 | + } | |
| 367 | + return path; | |
| 368 | + } | |
| 369 | + | |
| 370 | + public static Disposable uploadInfo(Context context, String sid, String text, String address, | |
| 371 | + String key, List<String> imageFiles, ShareReleaseInfoUtil.ShareConfig shareConfig, String gopath, String videotype, | |
| 372 | + ProgressCallback progressCallback, DataCallback<BaseInfo> callback) { | |
| 373 | + Map<String, String> map = new HashMap<>(); | |
| 374 | + | |
| 375 | + // if (imageFiles != null && imageFiles.size() > 0) map.put("type", "1"); | |
| 376 | + if (!TextUtils.isEmpty(key)) { | |
| 377 | + map.put("type", "2"); | |
| 378 | + } else if (shareConfig != null) { | |
| 379 | + map.put("type", "3"); | |
| 380 | + } else { | |
| 381 | + map.put("type", "0"); | |
| 382 | + } | |
| 383 | + map.put("appId", AppConfig.getAppId()); | |
| 384 | + map.put("sid", sid); | |
| 385 | + map.put("text", StringUtils.encode(text)); | |
| 386 | + if (!TextUtils.isEmpty(key)) { | |
| 387 | + map.put("key", key); | |
| 388 | + } | |
| 389 | + //if (!TextUtils.isEmpty(address)) map.put("address", StringUtils.encode(address)); | |
| 390 | + if (!TextUtils.isEmpty(address)) { | |
| 391 | + map.put("address", address); | |
| 392 | + } | |
| 393 | + if (shareConfig != null) { | |
| 394 | + map.put("title", shareConfig.getTitle() == null ? "" : StringUtils.encode(shareConfig.getTitle())); | |
| 395 | + map.put("icon", videotype.startsWith("http") ? videotype : shareConfig.getImage()); | |
| 396 | + // map.put("icon",shareConfig.getImage().contains("/favicon.ico") || shareConfig.getImage().contains("toutiao") ? shareConfig.getImage() : videotype.startsWith("http") ? videotype : shareConfig.getImage()); | |
| 397 | + map.put("url", shareConfig.getUrl()); | |
| 398 | + map.put("desc", shareConfig.getSubTitle() == null ? "" : StringUtils.encode(shareConfig.getSubTitle())); | |
| 399 | + map.put("shareType", "3"); | |
| 400 | + map.put("shareExtInfo", ""); | |
| 401 | + } | |
| 402 | + | |
| 403 | + Subscriber<BaseInfo> subscriber = new Subscriber<BaseInfo>(context, ApiSubscriber.subscriberBuild) { | |
| 404 | + @Override | |
| 405 | + public void onCompleted(String s, String s1, BaseInfo darenApplyModel) { | |
| 406 | + if (callback == null) { | |
| 407 | + return; | |
| 408 | + } | |
| 409 | + callback.callback(SUCCESS, "", darenApplyModel); | |
| 410 | + } | |
| 411 | + | |
| 412 | + @Override | |
| 413 | + public void onError(String code, String message) { | |
| 414 | + if (callback == null) { | |
| 415 | + return; | |
| 416 | + } | |
| 417 | + int errorCode = -1; | |
| 418 | + try { | |
| 419 | + errorCode = Integer.valueOf(code); | |
| 420 | + } catch (Exception ignored) { | |
| 421 | + } finally { | |
| 422 | + callback.callback(errorCode, message, null); | |
| 423 | + } | |
| 424 | + } | |
| 425 | + | |
| 426 | + }; | |
| 427 | + | |
| 428 | + return SignUtil.getRequestBodySignMapObservable(map).subscribe(requestBodyMap -> { | |
| 429 | + ApiServiceMoment service = SubscriptionRequest.service(ApiServiceMoment.class); | |
| 430 | + SubscriptionRequest.subscribe(service.releaseMomentText(gopath, map), subscriber); | |
| 431 | + }); | |
| 432 | + } | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + private static List<MultipartBody.Part> getImageParams(List<String> imageFiles, ProgressCallback callback) { | |
| 437 | + List<MultipartBody.Part> imageParams = new ArrayList<>(); | |
| 438 | + | |
| 439 | + if (imageFiles != null) { | |
| 440 | + for (String path : imageFiles) { | |
| 441 | + File file = new File(path); | |
| 442 | + RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | |
| 443 | + int index = imageFiles.indexOf(path); | |
| 444 | + int size = imageFiles.size(); | |
| 445 | + CountingRequestBody countingRequestBody = new CountingRequestBody(requestBody, (byteWrited, contentLength, done) -> { | |
| 446 | + float p = (float) index / (float) size + (float) byteWrited / (float) contentLength / (float) size; | |
| 447 | + if (callback != null) { | |
| 448 | + callback.onProgress((int) (p * 100)); | |
| 449 | + } | |
| 450 | + }); | |
| 451 | + imageParams.add(MultipartBody.Part.createFormData("Image" + (imageFiles.indexOf(path) + 1), file.getName(), countingRequestBody)); | |
| 452 | + } | |
| 453 | + } | |
| 454 | + return imageParams; | |
| 455 | + } | |
| 456 | + | |
| 457 | + /** | |
| 458 | + * 单块上传 | |
| 459 | + * | |
| 460 | + * @param file 自定义文件 | |
| 461 | + */ | |
| 462 | + public static void doUpload(CNUpload cnUpload, File file, String objectKey, DataCallback<Integer> callback, ProgressCallback progressCallback) { | |
| 463 | + CNPutObjectRequest request = new CNPutObjectRequest(objectKey, file); | |
| 464 | + //Bucket权限管理 | |
| 465 | + request.setCannedACL(CNCannedAccessControlList.PublicRead); | |
| 466 | + //设置上传的文件的内容类型 | |
| 467 | + request.setContentType("video/mp4"); | |
| 468 | + | |
| 469 | + cnUpload.putObject(request, new CNPutObjectResponseListener() { | |
| 470 | + /** | |
| 471 | + * 上传失败 | |
| 472 | + * @param code Http请求返回的状态码,200表示请求成功,400表示客户端请求错误,403表示签名错误或本地日期时间错误 | |
| 473 | + * @param uploadError 失败时返回的实体类,包含errorCode、errorMessage、serverError | |
| 474 | + * @param headers Http请求响应报头 | |
| 475 | + * @param message 失败时返回的响应正文 | |
| 476 | + * @param throwable 出错时抛出的异常 | |
| 477 | + */ | |
| 478 | + @Override | |
| 479 | + public void onTaskFailure(int code, UploadError uploadError, Header[] headers, String message, Throwable throwable) { | |
| 480 | + callback.callback(code, message, ERROR_UPLOAD); | |
| 481 | + } | |
| 482 | + | |
| 483 | + /** | |
| 484 | + * 上传成功 | |
| 485 | + * @param code Http请求返回的状态码 | |
| 486 | + * @param headers Http请求响应报头 | |
| 487 | + */ | |
| 488 | + @Override | |
| 489 | + public void onTaskSuccess(int code, Header[] headers) { | |
| 490 | + callback.callback(0, "", SUCCESS); | |
| 491 | + } | |
| 492 | + | |
| 493 | + /** | |
| 494 | + * 上传开始 | |
| 495 | + */ | |
| 496 | + @Override | |
| 497 | + public void onTaskStart() { | |
| 498 | + } | |
| 499 | + | |
| 500 | + /** | |
| 501 | + * 上传结束 包括上传成功结束与上传失败结束 | |
| 502 | + */ | |
| 503 | + @Override | |
| 504 | + public void onTaskFinish() { | |
| 505 | + } | |
| 506 | + | |
| 507 | + /** | |
| 508 | + * 上传取消 | |
| 509 | + * 目前无法取消上传操作~!!! | |
| 510 | + */ | |
| 511 | + @Override | |
| 512 | + public void onTaskCancel() { | |
| 513 | + } | |
| 514 | + | |
| 515 | + /** | |
| 516 | + * 上传进度 | |
| 517 | + * @param progress 返回上传进度 | |
| 518 | + */ | |
| 519 | + @Override | |
| 520 | + public void onTaskProgress(double progress) { | |
| 521 | + progressCallback.onProgress(progress); | |
| 522 | + } | |
| 523 | + }); | |
| 524 | + } | |
| 525 | + | |
| 526 | + public static void doUpload(Context context, File file, String objectKey, String uploadToken, DataCallback<Integer> callback, ProgressCallback progressCallback) { | |
| 527 | + UploadManager uploadManager = new UploadManager(); | |
| 528 | + uploadManager.put(file, objectKey, uploadToken, new UpCompletionHandler() { | |
| 529 | + @Override | |
| 530 | + public void complete(String key, ResponseInfo info, JSONObject response) { | |
| 531 | + ((Activity) context).runOnUiThread(() -> { | |
| 532 | + if (info.isOK()) { | |
| 533 | + callback.callback(0, "", SUCCESS); | |
| 534 | + } else { | |
| 535 | + callback.callback(info.statusCode, info.error, ERROR_UPLOAD); | |
| 536 | + } | |
| 537 | + }); | |
| 538 | + } | |
| 539 | + }, new UploadOptions(null, null, false, new UpProgressHandler() { | |
| 540 | + @Override | |
| 541 | + public void progress(String key, double percent) { | |
| 542 | + progressCallback.onProgress(percent); | |
| 543 | + } | |
| 544 | + }, null)); | |
| 545 | + } | |
| 546 | + | |
| 547 | + | |
| 548 | + public static void doUploadPic(Context context, List<String> file, String uploadToken, DataCallback<ArrayList<String>> callback, ProgressCallback progressCallback) { | |
| 549 | + ArrayList<String> netpiclist = new ArrayList<>(); | |
| 550 | + UploadManager uploadManager = new UploadManager(); | |
| 551 | + //正式环境:769/img/2018/01/29/"时间戳".jpg | |
| 552 | + //测试环境:802/img/2018/01/29/"时间戳".jpg | |
| 553 | + for (int i = 0; i < file.size(); i++) { | |
| 554 | + Date date = new Date(); | |
| 555 | + String date1 = StringUtils.formatDate(date, "yyyy/MM/dd"); | |
| 556 | + String id = IDUtils.createID(); | |
| 557 | + String extName = FileUtil.getExtensionName((String) file.get(0)); | |
| 558 | + String objectKey = String.format(OBJECT_PIC_KEY, i, date1, id, extName); | |
| 559 | + uploadManager.put(new File(file.get(i)), objectKey, uploadToken, new UpCompletionHandler() { | |
| 560 | + @Override | |
| 561 | + public void complete(String key, ResponseInfo info, JSONObject response) { | |
| 562 | + ((Activity) context).runOnUiThread(() -> { | |
| 563 | + | |
| 564 | + if (info.isOK()) { | |
| 565 | + try { | |
| 566 | + netpiclist.add((String) info.response.get("key")); | |
| 567 | + } catch (JSONException e) { | |
| 568 | + e.printStackTrace(); | |
| 569 | + } | |
| 570 | + if (netpiclist.size() == file.size()) { | |
| 571 | + callback.callback(0, "", netpiclist); | |
| 572 | + } | |
| 573 | + } else { | |
| 574 | + callback.callback(info.statusCode, info.error, null); | |
| 575 | + } | |
| 576 | + }); | |
| 577 | + } | |
| 578 | + }, new UploadOptions(null, null, false, new UpProgressHandler() { | |
| 579 | + @Override | |
| 580 | + public void progress(String key, double percent) { | |
| 581 | + progressCallback.onProgress(percent); | |
| 582 | + } | |
| 583 | + }, null)); | |
| 584 | + } | |
| 585 | + } | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + private static RequestBody getRequestString(String value) { | |
| 590 | + RequestBody requestString = RequestBody.create(MediaType.parse("text/plain"), value); | |
| 591 | + return requestString; | |
| 592 | + } | |
| 593 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/utils/FileUtil.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.upload.utils; | |
| 2 | + | |
| 3 | +import android.content.ContentValues; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.database.Cursor; | |
| 6 | +import android.graphics.Bitmap; | |
| 7 | +import android.net.Uri; | |
| 8 | +import android.os.Environment; | |
| 9 | +import android.provider.MediaStore; | |
| 10 | +import android.util.Log; | |
| 11 | + | |
| 12 | +import java.io.File; | |
| 13 | +import java.io.FileInputStream; | |
| 14 | +import java.io.FileOutputStream; | |
| 15 | +import java.io.IOException; | |
| 16 | +import java.io.InputStream; | |
| 17 | +import java.io.OutputStream; | |
| 18 | +import java.util.UUID; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * Created by xiansong on 2017/9/20. | |
| 22 | + */ | |
| 23 | + | |
| 24 | +public class FileUtil { | |
| 25 | + /** | |
| 26 | + * Java文件操作 获取文件扩展名 | |
| 27 | + */ | |
| 28 | + public static String getExtensionName(String filename) { | |
| 29 | + if ((filename != null) && (filename.length() > 0)) { | |
| 30 | + int dot = filename.lastIndexOf('.'); | |
| 31 | + if ((dot > -1) && (dot < (filename.length() - 1))) { | |
| 32 | + return filename.substring(dot + 1); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + return ""; | |
| 36 | + } | |
| 37 | + | |
| 38 | + | |
| 39 | + public static String getExternalStorageDirctory(Context context, String folderName) { | |
| 40 | + File storageDir = new File(Environment.getExternalStorageDirectory() + File.separator + context.getPackageName() + File.separator); | |
| 41 | + File folderDir = new File(Environment.getExternalStorageDirectory() + File.separator + context.getPackageName() + File.separator + folderName + File.separator); | |
| 42 | + if (!storageDir.exists()) storageDir.mkdirs(); | |
| 43 | + if (!folderDir.exists()) folderDir.mkdirs(); | |
| 44 | + return Environment.getExternalStorageDirectory() + File.separator + | |
| 45 | + context.getPackageName() + File.separator + | |
| 46 | + folderName + File.separator; | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 拷贝Logo 到 SD卡 | |
| 51 | + * | |
| 52 | + * @param context | |
| 53 | + * @param filename | |
| 54 | + */ | |
| 55 | + public static String copyAssetsFile(Context context, String folderName, String filename) { | |
| 56 | + String uri = getExternalStorageDirctory(context, folderName) + filename; | |
| 57 | + if (!new File(uri).exists()) { | |
| 58 | + try { | |
| 59 | + InputStream in = context.getAssets().open(filename); | |
| 60 | + OutputStream out = new FileOutputStream(uri); | |
| 61 | + byte[] buffer = new byte[1024]; | |
| 62 | + int read; | |
| 63 | + while ((read = in.read(buffer)) != -1) out.write(buffer, 0, read); | |
| 64 | + in.close(); | |
| 65 | + out.flush(); | |
| 66 | + out.close(); | |
| 67 | + } catch (Exception e) { | |
| 68 | + Log.e("tag", e.getMessage()); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + return uri; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * 转换 content:// uri | |
| 76 | + * | |
| 77 | + * @param imageFile | |
| 78 | + * @return | |
| 79 | + */ | |
| 80 | + public static Uri getImageContentUri(Context context, File imageFile) { | |
| 81 | + String filePath = imageFile.getAbsolutePath(); | |
| 82 | + Cursor cursor = context.getContentResolver().query( | |
| 83 | + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | |
| 84 | + new String[]{MediaStore.Images.Media._ID}, | |
| 85 | + MediaStore.Images.Media.DATA + "=? ", | |
| 86 | + new String[]{filePath}, null); | |
| 87 | + | |
| 88 | + if (cursor != null && cursor.moveToFirst()) { | |
| 89 | + int id = cursor.getInt(cursor | |
| 90 | + .getColumnIndex(MediaStore.MediaColumns._ID)); | |
| 91 | + Uri baseUri = Uri.parse("content://media/external/images/media"); | |
| 92 | + return Uri.withAppendedPath(baseUri, "" + id); | |
| 93 | + } else { | |
| 94 | + if (imageFile.exists()) { | |
| 95 | + ContentValues values = new ContentValues(); | |
| 96 | + values.put(MediaStore.Images.Media.DATA, filePath); | |
| 97 | + return context.getContentResolver().insert( | |
| 98 | + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); | |
| 99 | + } else { | |
| 100 | + return null; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * 复制单个文件 | |
| 107 | + * @param oldPath String 原文件路径 如:c:/fqf.txt | |
| 108 | + * @param newPath String 复制后路径 如:f:/fqf.txt | |
| 109 | + * @return boolean | |
| 110 | + */ | |
| 111 | + public static void copyFile(String oldPath, String newPath) { | |
| 112 | + try { | |
| 113 | + int bytesum = 0; | |
| 114 | + int byteread = 0; | |
| 115 | + File oldfile = new File(oldPath); | |
| 116 | + if (oldfile.exists()) { //文件存在时 | |
| 117 | + InputStream inStream = new FileInputStream(oldPath); //读入原文件 | |
| 118 | + FileOutputStream fs = new FileOutputStream(newPath); | |
| 119 | + byte[] buffer = new byte[1444]; | |
| 120 | + int length; | |
| 121 | + while ( (byteread = inStream.read(buffer)) != -1) { | |
| 122 | + bytesum += byteread; //字节数 文件大小 | |
| 123 | + System.out.println(bytesum); | |
| 124 | + fs.write(buffer, 0, byteread); | |
| 125 | + } | |
| 126 | + inStream.close(); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + catch (Exception e) { | |
| 130 | + System.out.println("复制单个文件操作出错"); | |
| 131 | + e.printStackTrace(); | |
| 132 | + | |
| 133 | + } | |
| 134 | + | |
| 135 | + } | |
| 136 | + | |
| 137 | + public static String isExistDir(String saveDir) throws IOException { | |
| 138 | + File downloadFile = new File(saveDir); | |
| 139 | + if (!downloadFile.mkdirs()) { | |
| 140 | + downloadFile.createNewFile(); | |
| 141 | + } | |
| 142 | + String savePath = downloadFile.getAbsolutePath(); | |
| 143 | + return savePath; | |
| 144 | + } | |
| 145 | + | |
| 146 | + public static String getRootPath(Context context,String filePath) { | |
| 147 | + File cacheRootFile = !isExternalStorageWritable() ? context.getFilesDir() : context.getExternalCacheDir(); | |
| 148 | + return cacheRootFile.getAbsolutePath()+ File.separator+filePath+File.separator; | |
| 149 | + } | |
| 150 | + | |
| 151 | + | |
| 152 | + public static boolean isExternalStorageWritable() { | |
| 153 | + String state = Environment.getExternalStorageState(); | |
| 154 | + if (Environment.MEDIA_MOUNTED.equals(state)) { | |
| 155 | + return true; | |
| 156 | + } | |
| 157 | + return false; | |
| 158 | + } | |
| 159 | + | |
| 160 | + /* | |
| 161 | + * 保存bitmap到本地 | |
| 162 | + * */ | |
| 163 | + public static String saveBitmap(Context context, Bitmap mBitmap) { | |
| 164 | + String savePath; | |
| 165 | + File filePic; | |
| 166 | + savePath = context.getCacheDir().getAbsolutePath(); | |
| 167 | + try { | |
| 168 | + filePic = new File(savePath + UUID.randomUUID().toString() + ".jpg"); | |
| 169 | + if (!filePic.exists()) { | |
| 170 | + filePic.getParentFile().mkdirs(); | |
| 171 | + filePic.createNewFile(); | |
| 172 | + } | |
| 173 | + FileOutputStream fos = new FileOutputStream(filePic); | |
| 174 | + mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); | |
| 175 | + fos.flush(); | |
| 176 | + fos.close(); | |
| 177 | + } catch (IOException e) { | |
| 178 | + // TODO Auto-generated catch block | |
| 179 | + e.printStackTrace(); | |
| 180 | + return null; | |
| 181 | + } | |
| 182 | + | |
| 183 | + return filePic.getAbsolutePath(); | |
| 184 | + } | |
| 185 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/utils/IDUtils.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.upload.utils; | |
| 2 | + | |
| 3 | +public class IDUtils { | |
| 4 | + private static byte[] lock = new byte[0]; | |
| 5 | + | |
| 6 | + // 位数,默认是8位 | |
| 7 | + private final static long w = 100000000; | |
| 8 | + | |
| 9 | + public static String createID() { | |
| 10 | + long r = 0; | |
| 11 | + synchronized (lock) { | |
| 12 | + r = (long) ((Math.random() + 1) * w); | |
| 13 | + } | |
| 14 | + | |
| 15 | + return System.currentTimeMillis() + String.valueOf(r).substring(1); | |
| 16 | + } | |
| 17 | +} | |
| 0 | 18 | \ No newline at end of file | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/utils/MD5.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.upload.utils; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.util.Log; | |
| 6 | + | |
| 7 | +import java.io.File; | |
| 8 | +import java.io.FileInputStream; | |
| 9 | +import java.math.BigInteger; | |
| 10 | +import java.security.MessageDigest; | |
| 11 | +import java.util.HashMap; | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Author by Yuansiwen.com, Date on 2018/11/29. | |
| 16 | + * PS: Not easy to write code, please indicate. | |
| 17 | + */ | |
| 18 | +public class MD5 extends Activity { | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + protected void onCreate(Bundle savedInstanceState) { | |
| 22 | + // TODO Auto-generated method stub | |
| 23 | + super.onCreate(savedInstanceState); | |
| 24 | + File file = new File("/mnt/sdcard/123.txt"); | |
| 25 | + Log.e("MD5", getFileMD5(file)); | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 获取单个文件的MD5值! | |
| 30 | + | |
| 31 | + * @param file | |
| 32 | + * @return | |
| 33 | + */ | |
| 34 | + | |
| 35 | + public static String getFileMD5(File file) { | |
| 36 | + if (!file.isFile()) { | |
| 37 | + return null; | |
| 38 | + } | |
| 39 | + MessageDigest digest = null; | |
| 40 | + FileInputStream in = null; | |
| 41 | + byte buffer[] = new byte[1024]; | |
| 42 | + int len; | |
| 43 | + try { | |
| 44 | + digest = MessageDigest.getInstance("MD5"); | |
| 45 | + in = new FileInputStream(file); | |
| 46 | + while ((len = in.read(buffer, 0, 1024)) != -1) { | |
| 47 | + digest.update(buffer, 0, len); | |
| 48 | + } | |
| 49 | + in.close(); | |
| 50 | + } catch (Exception e) { | |
| 51 | + e.printStackTrace(); | |
| 52 | + return null; | |
| 53 | + } | |
| 54 | + BigInteger bigInt = new BigInteger(1, digest.digest()); | |
| 55 | + return bigInt.toString(16); | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 获取文件夹中文件的MD5值 | |
| 60 | + * | |
| 61 | + * @param file | |
| 62 | + * @param listChild | |
| 63 | + * ;true递归子目录中的文件 | |
| 64 | + * @return | |
| 65 | + */ | |
| 66 | + public static Map<String, String> getDirMD5(File file, boolean listChild) { | |
| 67 | + if (!file.isDirectory()) { | |
| 68 | + return null; | |
| 69 | + } | |
| 70 | + Map<String, String> map = new HashMap<String, String>(); | |
| 71 | + String md5; | |
| 72 | + File files[] = file.listFiles(); | |
| 73 | + for (int i = 0; i < files.length; i++) { | |
| 74 | + File f = files[i]; | |
| 75 | + if (f.isDirectory() && listChild) { | |
| 76 | + map.putAll(getDirMD5(f, listChild)); | |
| 77 | + } else { | |
| 78 | + md5 = getFileMD5(f); | |
| 79 | + if (md5 != null) { | |
| 80 | + map.put(f.getPath(), md5); | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + return map; | |
| 85 | + } | |
| 86 | + | |
| 87 | +} | |
| 88 | + | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/upload/utils/MD5Utils.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.upload.utils; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by xiansong on 2018/3/28. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +import android.support.annotation.NonNull; | |
| 8 | + | |
| 9 | +import java.io.File; | |
| 10 | +import java.io.FileInputStream; | |
| 11 | +import java.io.FileNotFoundException; | |
| 12 | +import java.io.IOException; | |
| 13 | +import java.nio.ByteBuffer; | |
| 14 | +import java.nio.channels.FileChannel; | |
| 15 | +import java.security.MessageDigest; | |
| 16 | +import java.security.NoSuchAlgorithmException; | |
| 17 | +import java.util.Arrays; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * Created by Lynn on 6/28/2017. | |
| 21 | + */ | |
| 22 | + | |
| 23 | +public class MD5Utils { | |
| 24 | + | |
| 25 | + private static final char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | |
| 26 | + 'a', 'b', 'c', 'd', 'e', 'f'}; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get MD5 of a file (lower case) | |
| 30 | + * | |
| 31 | + * @return empty string if I/O error when get MD5 | |
| 32 | + */ | |
| 33 | + @NonNull | |
| 34 | + public static String getFileMD5(@NonNull File file) { | |
| 35 | + | |
| 36 | + FileInputStream in = null; | |
| 37 | + try { | |
| 38 | + in = new FileInputStream(file); | |
| 39 | + FileChannel ch = in.getChannel(); | |
| 40 | + return MD5(ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length())); | |
| 41 | + } catch (FileNotFoundException e) { | |
| 42 | + return ""; | |
| 43 | + } catch (IOException e) { | |
| 44 | + return ""; | |
| 45 | + } finally { | |
| 46 | + if (in != null) { | |
| 47 | + try { | |
| 48 | + in.close(); | |
| 49 | + } catch (IOException e) { | |
| 50 | + // 关闭流产生的错误一般都可以忽略 | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * MD5校验字符串 | |
| 59 | + * | |
| 60 | + * @param s String to be MD5 | |
| 61 | + * @return 'null' if cannot get MessageDigest | |
| 62 | + */ | |
| 63 | + @NonNull | |
| 64 | + public static String getStringMD5(@NonNull String s) { | |
| 65 | + MessageDigest mdInst; | |
| 66 | + try { | |
| 67 | + // 获得MD5摘要算法的 MessageDigest 对象 | |
| 68 | + mdInst = MessageDigest.getInstance("MD5"); | |
| 69 | + } catch (NoSuchAlgorithmException e) { | |
| 70 | + e.printStackTrace(); | |
| 71 | + return ""; | |
| 72 | + } | |
| 73 | + | |
| 74 | + byte[] btInput = s.getBytes(); | |
| 75 | + // 使用指定的字节更新摘要 | |
| 76 | + mdInst.update(btInput); | |
| 77 | + // 获得密文 | |
| 78 | + byte[] md = mdInst.digest(); | |
| 79 | + // 把密文转换成十六进制的字符串形式 | |
| 80 | + int length = md.length; | |
| 81 | + char str[] = new char[length * 2]; | |
| 82 | + int k = 0; | |
| 83 | + for (byte b : md) { | |
| 84 | + str[k++] = hexDigits[b >>> 4 & 0xf]; | |
| 85 | + str[k++] = hexDigits[b & 0xf]; | |
| 86 | + } | |
| 87 | + return new String(str); | |
| 88 | + } | |
| 89 | + | |
| 90 | + @NonNull | |
| 91 | + private static String getSubStr(@NonNull String str, int subNu, char replace) { | |
| 92 | + int length = str.length(); | |
| 93 | + if (length > subNu) { | |
| 94 | + str = str.substring(length - subNu, length); | |
| 95 | + } else if (length < subNu) { | |
| 96 | + // NOTE: padding字符填充在字符串的右侧,和服务器的算法是一致的 | |
| 97 | + str += createPaddingString(subNu - length, replace); | |
| 98 | + } | |
| 99 | + return str; | |
| 100 | + } | |
| 101 | + | |
| 102 | + @NonNull | |
| 103 | + private static String createPaddingString(int n, char pad) { | |
| 104 | + if (n <= 0) { | |
| 105 | + return ""; | |
| 106 | + } | |
| 107 | + | |
| 108 | + char[] paddingArray = new char[n]; | |
| 109 | + Arrays.fill(paddingArray, pad); | |
| 110 | + return new String(paddingArray); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 计算MD5校验 | |
| 115 | + * | |
| 116 | + * @param buffer | |
| 117 | + * @return 空串,如果无法获得 MessageDigest实例 | |
| 118 | + */ | |
| 119 | + @NonNull | |
| 120 | + private static String MD5(ByteBuffer buffer) { | |
| 121 | + String s = ""; | |
| 122 | + try { | |
| 123 | + MessageDigest md = MessageDigest.getInstance("MD5"); | |
| 124 | + md.update(buffer); | |
| 125 | + byte tmp[] = md.digest(); // MD5 的计算结果是一个 128 位的长整数, | |
| 126 | + // 用字节表示就是 16 个字节 | |
| 127 | + char str[] = new char[16 * 2]; // 每个字节用 16 进制表示的话,使用两个字符, | |
| 128 | + // 所以表示成 16 进制需要 32 个字符 | |
| 129 | + int k = 0; // 表示转换结果中对应的字符位置 | |
| 130 | + for (int i = 0; i < 16; i++) { // 从第一个字节开始,对 MD5 的每一个字节 | |
| 131 | + // 转换成 16 进制字符的转换 | |
| 132 | + byte byte0 = tmp[i]; // 取第 i 个字节 | |
| 133 | + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // 取字节中高 4 位的数字转换, >>>, | |
| 134 | + // 逻辑右移,将符号位一起右移 | |
| 135 | + str[k++] = hexDigits[byte0 & 0xf]; // 取字节中低 4 位的数字转换 | |
| 136 | + } | |
| 137 | + s = new String(str); // 换后的结果转换为字符串 | |
| 138 | + | |
| 139 | + } catch (NoSuchAlgorithmException e) { | |
| 140 | + e.printStackTrace(); | |
| 141 | + } | |
| 142 | + return s; | |
| 143 | + } | |
| 144 | +} | |
| 145 | + | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/FileUtil.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.utils; | |
| 2 | + | |
| 3 | +import android.content.ContentValues; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.database.Cursor; | |
| 6 | +import android.graphics.Bitmap; | |
| 7 | +import android.net.Uri; | |
| 8 | +import android.os.Environment; | |
| 9 | +import android.provider.MediaStore; | |
| 10 | +import android.util.Log; | |
| 11 | + | |
| 12 | +import java.io.File; | |
| 13 | +import java.io.FileInputStream; | |
| 14 | +import java.io.FileOutputStream; | |
| 15 | +import java.io.IOException; | |
| 16 | +import java.io.InputStream; | |
| 17 | +import java.io.OutputStream; | |
| 18 | +import java.util.UUID; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * Created by xiansong on 2017/9/20. | |
| 22 | + */ | |
| 23 | + | |
| 24 | +public class FileUtil { | |
| 25 | + /** | |
| 26 | + * Java文件操作 获取文件扩展名 | |
| 27 | + */ | |
| 28 | + public static String getExtensionName(String filename) { | |
| 29 | + if ((filename != null) && (filename.length() > 0)) { | |
| 30 | + int dot = filename.lastIndexOf('.'); | |
| 31 | + if ((dot > -1) && (dot < (filename.length() - 1))) { | |
| 32 | + return filename.substring(dot + 1); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + return ""; | |
| 36 | + } | |
| 37 | + | |
| 38 | + | |
| 39 | + public static String getExternalStorageDirctory(Context context, String folderName) { | |
| 40 | + File storageDir = new File(Environment.getExternalStorageDirectory() + File.separator + context.getPackageName() + File.separator); | |
| 41 | + File folderDir = new File(Environment.getExternalStorageDirectory() + File.separator + context.getPackageName() + File.separator + folderName + File.separator); | |
| 42 | + if (!storageDir.exists()) storageDir.mkdirs(); | |
| 43 | + if (!folderDir.exists()) folderDir.mkdirs(); | |
| 44 | + return Environment.getExternalStorageDirectory() + File.separator + | |
| 45 | + context.getPackageName() + File.separator + | |
| 46 | + folderName + File.separator; | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 拷贝Logo 到 SD卡 | |
| 51 | + * | |
| 52 | + * @param context | |
| 53 | + * @param filename | |
| 54 | + */ | |
| 55 | + public static String copyAssetsFile(Context context, String folderName, String filename) { | |
| 56 | + String uri = getExternalStorageDirctory(context, folderName) + filename; | |
| 57 | + if (!new File(uri).exists()) { | |
| 58 | + try { | |
| 59 | + InputStream in = context.getAssets().open(filename); | |
| 60 | + OutputStream out = new FileOutputStream(uri); | |
| 61 | + byte[] buffer = new byte[1024]; | |
| 62 | + int read; | |
| 63 | + while ((read = in.read(buffer)) != -1) out.write(buffer, 0, read); | |
| 64 | + in.close(); | |
| 65 | + out.flush(); | |
| 66 | + out.close(); | |
| 67 | + } catch (Exception e) { | |
| 68 | + Log.e("tag", e.getMessage()); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + return uri; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * 转换 content:// uri | |
| 76 | + * | |
| 77 | + * @param imageFile | |
| 78 | + * @return | |
| 79 | + */ | |
| 80 | + public static Uri getImageContentUri(Context context, File imageFile) { | |
| 81 | + String filePath = imageFile.getAbsolutePath(); | |
| 82 | + Cursor cursor = context.getContentResolver().query( | |
| 83 | + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | |
| 84 | + new String[]{MediaStore.Images.Media._ID}, | |
| 85 | + MediaStore.Images.Media.DATA + "=? ", | |
| 86 | + new String[]{filePath}, null); | |
| 87 | + | |
| 88 | + if (cursor != null && cursor.moveToFirst()) { | |
| 89 | + int id = cursor.getInt(cursor | |
| 90 | + .getColumnIndex(MediaStore.MediaColumns._ID)); | |
| 91 | + Uri baseUri = Uri.parse("content://media/external/images/media"); | |
| 92 | + return Uri.withAppendedPath(baseUri, "" + id); | |
| 93 | + } else { | |
| 94 | + if (imageFile.exists()) { | |
| 95 | + ContentValues values = new ContentValues(); | |
| 96 | + values.put(MediaStore.Images.Media.DATA, filePath); | |
| 97 | + return context.getContentResolver().insert( | |
| 98 | + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); | |
| 99 | + } else { | |
| 100 | + return null; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * 复制单个文件 | |
| 107 | + * @param oldPath String 原文件路径 如:c:/fqf.txt | |
| 108 | + * @param newPath String 复制后路径 如:f:/fqf.txt | |
| 109 | + * @return boolean | |
| 110 | + */ | |
| 111 | + public static void copyFile(String oldPath, String newPath) { | |
| 112 | + try { | |
| 113 | + int bytesum = 0; | |
| 114 | + int byteread = 0; | |
| 115 | + File oldfile = new File(oldPath); | |
| 116 | + if (oldfile.exists()) { //文件存在时 | |
| 117 | + InputStream inStream = new FileInputStream(oldPath); //读入原文件 | |
| 118 | + FileOutputStream fs = new FileOutputStream(newPath); | |
| 119 | + byte[] buffer = new byte[1444]; | |
| 120 | + int length; | |
| 121 | + while ( (byteread = inStream.read(buffer)) != -1) { | |
| 122 | + bytesum += byteread; //字节数 文件大小 | |
| 123 | + System.out.println(bytesum); | |
| 124 | + fs.write(buffer, 0, byteread); | |
| 125 | + } | |
| 126 | + inStream.close(); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + catch (Exception e) { | |
| 130 | + System.out.println("复制单个文件操作出错"); | |
| 131 | + e.printStackTrace(); | |
| 132 | + | |
| 133 | + } | |
| 134 | + | |
| 135 | + } | |
| 136 | + | |
| 137 | + public static String isExistDir(String saveDir) throws IOException { | |
| 138 | + File downloadFile = new File(saveDir); | |
| 139 | + if (!downloadFile.mkdirs()) { | |
| 140 | + downloadFile.createNewFile(); | |
| 141 | + } | |
| 142 | + String savePath = downloadFile.getAbsolutePath(); | |
| 143 | + return savePath; | |
| 144 | + } | |
| 145 | + | |
| 146 | + public static String getRootPath(Context context,String filePath) { | |
| 147 | + File cacheRootFile = !isExternalStorageWritable() ? context.getFilesDir() : context.getExternalCacheDir(); | |
| 148 | + return cacheRootFile.getAbsolutePath()+ File.separator+filePath+File.separator; | |
| 149 | + } | |
| 150 | + | |
| 151 | + | |
| 152 | + public static boolean isExternalStorageWritable() { | |
| 153 | + String state = Environment.getExternalStorageState(); | |
| 154 | + if (Environment.MEDIA_MOUNTED.equals(state)) { | |
| 155 | + return true; | |
| 156 | + } | |
| 157 | + return false; | |
| 158 | + } | |
| 159 | + | |
| 160 | + /* | |
| 161 | + * 保存bitmap到本地 | |
| 162 | + * */ | |
| 163 | + public static String saveBitmap(Context context, Bitmap mBitmap) { | |
| 164 | + String savePath; | |
| 165 | + File filePic; | |
| 166 | + savePath = context.getCacheDir().getAbsolutePath(); | |
| 167 | + try { | |
| 168 | + filePic = new File(savePath + UUID.randomUUID().toString() + ".jpg"); | |
| 169 | + if (!filePic.exists()) { | |
| 170 | + filePic.getParentFile().mkdirs(); | |
| 171 | + filePic.createNewFile(); | |
| 172 | + } | |
| 173 | + FileOutputStream fos = new FileOutputStream(filePic); | |
| 174 | + mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); | |
| 175 | + fos.flush(); | |
| 176 | + fos.close(); | |
| 177 | + } catch (IOException e) { | |
| 178 | + // TODO Auto-generated catch block | |
| 179 | + e.printStackTrace(); | |
| 180 | + return null; | |
| 181 | + } | |
| 182 | + | |
| 183 | + return filePic.getAbsolutePath(); | |
| 184 | + } | |
| 185 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/IDUtils.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.utils; | |
| 2 | + | |
| 3 | +public class IDUtils { | |
| 4 | + private static byte[] lock = new byte[0]; | |
| 5 | + | |
| 6 | + // 位数,默认是8位 | |
| 7 | + private final static long w = 100000000; | |
| 8 | + | |
| 9 | + public static String createID() { | |
| 10 | + long r = 0; | |
| 11 | + synchronized (lock) { | |
| 12 | + r = (long) ((Math.random() + 1) * w); | |
| 13 | + } | |
| 14 | + | |
| 15 | + return System.currentTimeMillis() + String.valueOf(r).substring(1); | |
| 16 | + } | |
| 17 | +} | |
| 0 | 18 | \ No newline at end of file | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MD5.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.utils; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.util.Log; | |
| 6 | + | |
| 7 | +import java.io.File; | |
| 8 | +import java.io.FileInputStream; | |
| 9 | +import java.math.BigInteger; | |
| 10 | +import java.security.MessageDigest; | |
| 11 | +import java.util.HashMap; | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Author by Yuansiwen.com, Date on 2018/11/29. | |
| 16 | + * PS: Not easy to write code, please indicate. | |
| 17 | + */ | |
| 18 | +public class MD5 extends Activity { | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + protected void onCreate(Bundle savedInstanceState) { | |
| 22 | + // TODO Auto-generated method stub | |
| 23 | + super.onCreate(savedInstanceState); | |
| 24 | + File file = new File("/mnt/sdcard/123.txt"); | |
| 25 | + Log.e("MD5", getFileMD5(file)); | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 获取单个文件的MD5值! | |
| 30 | + | |
| 31 | + * @param file | |
| 32 | + * @return | |
| 33 | + */ | |
| 34 | + | |
| 35 | + public static String getFileMD5(File file) { | |
| 36 | + if (!file.isFile()) { | |
| 37 | + return null; | |
| 38 | + } | |
| 39 | + MessageDigest digest = null; | |
| 40 | + FileInputStream in = null; | |
| 41 | + byte buffer[] = new byte[1024]; | |
| 42 | + int len; | |
| 43 | + try { | |
| 44 | + digest = MessageDigest.getInstance("MD5"); | |
| 45 | + in = new FileInputStream(file); | |
| 46 | + while ((len = in.read(buffer, 0, 1024)) != -1) { | |
| 47 | + digest.update(buffer, 0, len); | |
| 48 | + } | |
| 49 | + in.close(); | |
| 50 | + } catch (Exception e) { | |
| 51 | + e.printStackTrace(); | |
| 52 | + return null; | |
| 53 | + } | |
| 54 | + BigInteger bigInt = new BigInteger(1, digest.digest()); | |
| 55 | + return bigInt.toString(16); | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 获取文件夹中文件的MD5值 | |
| 60 | + * | |
| 61 | + * @param file | |
| 62 | + * @param listChild | |
| 63 | + * ;true递归子目录中的文件 | |
| 64 | + * @return | |
| 65 | + */ | |
| 66 | + public static Map<String, String> getDirMD5(File file, boolean listChild) { | |
| 67 | + if (!file.isDirectory()) { | |
| 68 | + return null; | |
| 69 | + } | |
| 70 | + Map<String, String> map = new HashMap<String, String>(); | |
| 71 | + String md5; | |
| 72 | + File files[] = file.listFiles(); | |
| 73 | + for (int i = 0; i < files.length; i++) { | |
| 74 | + File f = files[i]; | |
| 75 | + if (f.isDirectory() && listChild) { | |
| 76 | + map.putAll(getDirMD5(f, listChild)); | |
| 77 | + } else { | |
| 78 | + md5 = getFileMD5(f); | |
| 79 | + if (md5 != null) { | |
| 80 | + map.put(f.getPath(), md5); | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + return map; | |
| 85 | + } | |
| 86 | + | |
| 87 | +} | |
| 88 | + | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MD5Utils.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.utils; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by xiansong on 2018/3/28. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +import android.support.annotation.NonNull; | |
| 8 | + | |
| 9 | +import java.io.File; | |
| 10 | +import java.io.FileInputStream; | |
| 11 | +import java.io.FileNotFoundException; | |
| 12 | +import java.io.IOException; | |
| 13 | +import java.nio.ByteBuffer; | |
| 14 | +import java.nio.channels.FileChannel; | |
| 15 | +import java.security.MessageDigest; | |
| 16 | +import java.security.NoSuchAlgorithmException; | |
| 17 | +import java.util.Arrays; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * Created by Lynn on 6/28/2017. | |
| 21 | + */ | |
| 22 | + | |
| 23 | +public class MD5Utils { | |
| 24 | + | |
| 25 | + private static final char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | |
| 26 | + 'a', 'b', 'c', 'd', 'e', 'f'}; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get MD5 of a file (lower case) | |
| 30 | + * | |
| 31 | + * @return empty string if I/O error when get MD5 | |
| 32 | + */ | |
| 33 | + @NonNull | |
| 34 | + public static String getFileMD5(@NonNull File file) { | |
| 35 | + | |
| 36 | + FileInputStream in = null; | |
| 37 | + try { | |
| 38 | + in = new FileInputStream(file); | |
| 39 | + FileChannel ch = in.getChannel(); | |
| 40 | + return MD5(ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length())); | |
| 41 | + } catch (FileNotFoundException e) { | |
| 42 | + return ""; | |
| 43 | + } catch (IOException e) { | |
| 44 | + return ""; | |
| 45 | + } finally { | |
| 46 | + if (in != null) { | |
| 47 | + try { | |
| 48 | + in.close(); | |
| 49 | + } catch (IOException e) { | |
| 50 | + // 关闭流产生的错误一般都可以忽略 | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * MD5校验字符串 | |
| 59 | + * | |
| 60 | + * @param s String to be MD5 | |
| 61 | + * @return 'null' if cannot get MessageDigest | |
| 62 | + */ | |
| 63 | + @NonNull | |
| 64 | + public static String getStringMD5(@NonNull String s) { | |
| 65 | + MessageDigest mdInst; | |
| 66 | + try { | |
| 67 | + // 获得MD5摘要算法的 MessageDigest 对象 | |
| 68 | + mdInst = MessageDigest.getInstance("MD5"); | |
| 69 | + } catch (NoSuchAlgorithmException e) { | |
| 70 | + e.printStackTrace(); | |
| 71 | + return ""; | |
| 72 | + } | |
| 73 | + | |
| 74 | + byte[] btInput = s.getBytes(); | |
| 75 | + // 使用指定的字节更新摘要 | |
| 76 | + mdInst.update(btInput); | |
| 77 | + // 获得密文 | |
| 78 | + byte[] md = mdInst.digest(); | |
| 79 | + // 把密文转换成十六进制的字符串形式 | |
| 80 | + int length = md.length; | |
| 81 | + char str[] = new char[length * 2]; | |
| 82 | + int k = 0; | |
| 83 | + for (byte b : md) { | |
| 84 | + str[k++] = hexDigits[b >>> 4 & 0xf]; | |
| 85 | + str[k++] = hexDigits[b & 0xf]; | |
| 86 | + } | |
| 87 | + return new String(str); | |
| 88 | + } | |
| 89 | + | |
| 90 | + @NonNull | |
| 91 | + private static String getSubStr(@NonNull String str, int subNu, char replace) { | |
| 92 | + int length = str.length(); | |
| 93 | + if (length > subNu) { | |
| 94 | + str = str.substring(length - subNu, length); | |
| 95 | + } else if (length < subNu) { | |
| 96 | + // NOTE: padding字符填充在字符串的右侧,和服务器的算法是一致的 | |
| 97 | + str += createPaddingString(subNu - length, replace); | |
| 98 | + } | |
| 99 | + return str; | |
| 100 | + } | |
| 101 | + | |
| 102 | + @NonNull | |
| 103 | + private static String createPaddingString(int n, char pad) { | |
| 104 | + if (n <= 0) { | |
| 105 | + return ""; | |
| 106 | + } | |
| 107 | + | |
| 108 | + char[] paddingArray = new char[n]; | |
| 109 | + Arrays.fill(paddingArray, pad); | |
| 110 | + return new String(paddingArray); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 计算MD5校验 | |
| 115 | + * | |
| 116 | + * @param buffer | |
| 117 | + * @return 空串,如果无法获得 MessageDigest实例 | |
| 118 | + */ | |
| 119 | + @NonNull | |
| 120 | + private static String MD5(ByteBuffer buffer) { | |
| 121 | + String s = ""; | |
| 122 | + try { | |
| 123 | + MessageDigest md = MessageDigest.getInstance("MD5"); | |
| 124 | + md.update(buffer); | |
| 125 | + byte tmp[] = md.digest(); // MD5 的计算结果是一个 128 位的长整数, | |
| 126 | + // 用字节表示就是 16 个字节 | |
| 127 | + char str[] = new char[16 * 2]; // 每个字节用 16 进制表示的话,使用两个字符, | |
| 128 | + // 所以表示成 16 进制需要 32 个字符 | |
| 129 | + int k = 0; // 表示转换结果中对应的字符位置 | |
| 130 | + for (int i = 0; i < 16; i++) { // 从第一个字节开始,对 MD5 的每一个字节 | |
| 131 | + // 转换成 16 进制字符的转换 | |
| 132 | + byte byte0 = tmp[i]; // 取第 i 个字节 | |
| 133 | + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // 取字节中高 4 位的数字转换, >>>, | |
| 134 | + // 逻辑右移,将符号位一起右移 | |
| 135 | + str[k++] = hexDigits[byte0 & 0xf]; // 取字节中低 4 位的数字转换 | |
| 136 | + } | |
| 137 | + s = new String(str); // 换后的结果转换为字符串 | |
| 138 | + | |
| 139 | + } catch (NoSuchAlgorithmException e) { | |
| 140 | + e.printStackTrace(); | |
| 141 | + } | |
| 142 | + return s; | |
| 143 | + } | |
| 144 | +} | |
| 145 | + | ... | ... |