diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..2c5b9b7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8a8f75b..219b34f 100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b508389..755ad02 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -47,6 +47,14 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning"> + + + + + + @@ -100,10 +108,9 @@ android:screenOrientation="portrait" /> - + android:screenOrientation="portrait" /> + + @@ -118,18 +125,16 @@ android:screenOrientation="portrait" /> - + android:screenOrientation="portrait" /> + + - + android:windowSoftInputMode="adjustPan|stateHidden" /> + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -239,68 +241,66 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/base/MainActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/base/MainActivity.java index c458f43..9a1fe04 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/base/MainActivity.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/base/MainActivity.java @@ -1,12 +1,7 @@ package com.sucstepsoft.txrealtimelocation.activitys.base; -import android.app.ProgressDialog; -import android.content.BroadcastReceiver; -import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.graphics.Color; -import android.os.Build; import android.provider.Settings; import android.support.v7.app.AlertDialog; import android.support.v7.widget.GridLayoutManager; @@ -24,64 +19,44 @@ import com.bumptech.glide.request.RequestOptions; import com.google.gson.Gson; import com.sucstepsoft.cm_utils.constant.PathConfig; import com.sucstepsoft.cm_utils.constant.PermissionConstants; -import com.sucstepsoft.cm_utils.constant.TimeConstants; import com.sucstepsoft.cm_utils.core.beans.FuncBean; import com.sucstepsoft.cm_utils.core.network.update.CheckUpdateUtils; import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi; import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager; import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; -import com.sucstepsoft.cm_utils.utils.AppUtils; -import com.sucstepsoft.cm_utils.utils.FileUtils; import com.sucstepsoft.cm_utils.utils.LogUtils; import com.sucstepsoft.cm_utils.utils.PermissionUtils; -import com.sucstepsoft.cm_utils.utils.TimeUtils; import com.sucstepsoft.cm_utils.utils.ToastUtils; -import com.sucstepsoft.cm_utils.utils.UIUtil; import com.sucstepsoft.cm_utils.utils.UserLgUtils; import com.sucstepsoft.txrealtimelocation.R; import com.sucstepsoft.txrealtimelocation.ScreenManager; -import com.sucstepsoft.txrealtimelocation.activitys.addresslist.AddressListMainActivity; +import com.sucstepsoft.txrealtimelocation.activitys.companylib.CompanyLibActivity; import com.sucstepsoft.txrealtimelocation.activitys.issue.IssueCheckActivity; import com.sucstepsoft.txrealtimelocation.activitys.issue.IssueMineActivity; -import com.sucstepsoft.txrealtimelocation.activitys.issue.IssueRecordActivity; import com.sucstepsoft.txrealtimelocation.activitys.mine.UserActivity; import com.sucstepsoft.txrealtimelocation.activitys.notice.NoticeActivity; +import com.sucstepsoft.txrealtimelocation.activitys.trouble.TroubleReportActivity; import com.sucstepsoft.txrealtimelocation.adapters.FunctionAdapter; import com.sucstepsoft.txrealtimelocation.beans.AppTokenUser; -import com.sucstepsoft.txrealtimelocation.beans.BaseUserBean; -import com.sucstepsoft.txrealtimelocation.beans.CheckSignBean; -import com.sucstepsoft.txrealtimelocation.beans.CheckSignOffBean; -import com.sucstepsoft.txrealtimelocation.beans.LocationPosition; -import com.sucstepsoft.txrealtimelocation.beans.MainNumBean; -import com.sucstepsoft.txrealtimelocation.beans.PenLineBean; import com.sucstepsoft.txrealtimelocation.beans.SignTimeBean; -import com.sucstepsoft.txrealtimelocation.beans.SuccessBean; import com.sucstepsoft.txrealtimelocation.beans.VersionBean; import com.sucstepsoft.txrealtimelocation.broadcasts.ScreenBroadCastListener; import com.sucstepsoft.txrealtimelocation.net.LocationApiService; -import com.sucstepsoft.txrealtimelocation.services.GlobalProvider; -import com.sucstepsoft.txrealtimelocation.services.LocationService; -import com.sucstepsoft.txrealtimelocation.utils.ExceptionHandler; -import com.sucstepsoft.txrealtimelocation.utils.GpsUtils; -import com.sucstepsoft.txrealtimelocation.utils.IntentWrapper; import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.Unbinder; -import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.RequestBody; + +//import com.sucstepsoft.txrealtimelocation.services.LocationService; //import com.sucstepsoft.txrealtimelocation.activitys.issue.IssueReportActivity; //import com.sucstepsoft.txrealtimelocation.activitys.locus.LocusMapActivity; @@ -102,8 +77,6 @@ public class MainActivity extends BaseActivity { RelativeLayout mRlMainBg; @BindView(R.id.rl_title_count) RelativeLayout mRlTitleCount; - @BindView(R.id.tv_current_time) - TextView mTvCurrentTime; @BindView(R.id.tv_state) TextView mTvState; @BindView(R.id.iv_state) @@ -114,10 +87,6 @@ public class MainActivity extends BaseActivity { TextView mTvAvisoNum; @BindView(R.id.ll_day_aviso) LinearLayout mLlDayAviso; - @BindView(R.id.tv_issue_dis_num) - TextView mTvIssueDisNum; - @BindView(R.id.iv_issue_dis_num) - ImageView mIvIssueDisNum; @BindView(R.id.ll_issue_dis) LinearLayout mLlIssueDis; @BindView(R.id.tv_mine_issue_num) @@ -136,19 +105,8 @@ public class MainActivity extends BaseActivity { PermissionConstants.PHONE, PermissionConstants.MICROPHONE, }; - private MessageReceiver mMessageReceiver; -// private BitmapDescriptor mBitMap; - //TODO 默认坐标点 - private double latitude = 111.771815; - private double longitude = 40.823879; - //109.926934,40.574501 -// private BDLocation mCurrentLocation; private Unbinder mBind; private int userType = 2;//1是N员 2是片长 - public static final String MESSAGE_JPUSH = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION"; - public static final String KEY_TITLE = "title"; - public static final String KEY_MESSAGE = "message"; - public static final String KEY_EXTRAS = "extras"; private List mFuncs = new ArrayList<>(); private String[] mBtnStrs = new String[]{"企业信息", "隐患上报", "隐患复查", "法律法规"}; private int[] mBtnIds = new int[]{R.drawable.ic_issue_report, @@ -156,21 +114,9 @@ public class MainActivity extends BaseActivity { R.drawable.ic_issue_disp, R.drawable.ic_work_path}; private Gson mGson = null; - private boolean isSgin = false;//是否签到 - private boolean isSignOff = false;//是否签退 - private Disposable mTimeDis; - private boolean isForeg = true;//是否在前台 - private Disposable mGpsDis; - private SignTimeBean mSignTimeBean; -// private List> mPenLineList; private int mPrecisionDefault = 70; - private int mPrecMax = 150; - private int mPrecision = mPrecisionDefault; - private Disposable mGpsStateDis; private AlertDialog mGpsSettingDialog; private AlertDialog mGpsWeakDialog; - private long mCurrentLongTime; -// private LocationClient mLocationClient; @Override protected int setLayoutId() { @@ -183,16 +129,10 @@ public class MainActivity extends BaseActivity { refreshView(STATE_LOAD_SUCCESS); mRlTitleBar.setVisibility(View.GONE); initMainFuncs(); - //TODO 一像素保活 -// initScreenListener(); - mCurrentLongTime = 0; PermissionUtils.permission(permissions).callback(new PermissionUtils.SimpleCallback() { @Override public void onGranted() { -// registerMessageReceiver(); createCacheFile(); -// startListenLocation(); -// startSignLocation(); } @Override @@ -201,180 +141,9 @@ public class MainActivity extends BaseActivity { } }).request(); initBaseView(); - //TODO -// getPunchTime(123); -// setSignText(); -// getUserPenList(); -// interval(); -// registerGpsSignal(); -// checkLocalText(); -// registerGpsState(); } - private void checkLocalText() { - String filePath = PathConfig.CATCH_PATH + "testLocation.txt"; - boolean fileExists = FileUtils.isFileExists(filePath); - if (fileExists) { - File file = new File(filePath); - RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); - MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile); - RetrofitManager.getInstance() - .create(LocationApiService.class) - .uploadFile(body, UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(BaseUserBean baseUserBean) { - if (file.exists()) { - file.delete(); - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - - } - } - - /** - * 获取签到时间 - */ - private ProgressDialog progressDialog = null; - - private void getPunchTime(int i) { - if (i == 2) { - progressDialog = UIUtil.initDialog(MainActivity.this, "获取中..."); - progressDialog.show(); - } - RetrofitManager.getInstance() - .create(LocationApiService.class) - .getpunchTime(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(SignTimeBean signTimeBean) { - LogUtils.e(signTimeBean); - if (progressDialog != null && progressDialog.isShowing() && i == 2) { - progressDialog.dismiss(); - if (signTimeBean == null) { - ToastUtils.showShort("获取签到规则失败"); - } else { - mSignTimeBean = signTimeBean; - ToastUtils.showShort("获取签到规则成功,请重新签到或签退"); - } - } - if (signTimeBean != null) { - mSignTimeBean = signTimeBean; - } - if (mSignTimeBean != null) { - /** - * amStartPunchTime : 08:30:00 - * amStartWorkTime : 09:30:00 - * amEndWorkTime : 11:30:00 - * amEndPunchTime : 12:30:00 - * pmStartPunchTime : 13:30:00 - * pmStartWorkTime : 14:30:00 - * pmEndWorkTime : 16:30:00 - * pmEndPunchTime : 17:30:00 - * nStartPunchTime : 08:30:00 - * nStartWorkTime : 10:00:00 - * nEndWorkTime : 17:00:00 - * nEndPunchTime : 18:00:00 - */ - //保存签到时间 - mGson = new Gson(); - String loginInfo = UserLgUtils.getLoginInfo(); - if (!TextUtils.isEmpty(loginInfo)) { - AppTokenUser appTokenUser = mGson.fromJson(loginInfo, AppTokenUser.class); - if (appTokenUser.getRoles() != null && appTokenUser.getRoles().size() > 0) { - for (int i = 0; i < appTokenUser.getRoles().size(); i++) { - if (!TextUtils.isEmpty(appTokenUser.getRoles().get(i).getRoleName())) { - mTvDepart.setText(appTokenUser.getRoles().get(i).getRoleName()); - break; - } - } - } - if (appTokenUser.getRoles() != null && appTokenUser.getRoles().size() > 0) { - for (int i = 0; i < appTokenUser.getRoles().size(); i++) { - if (PathConfig.USER_TYPE_N.equals(appTokenUser.getRoles().get(i).getRoleId())) { - GlobalProvider.save(mActivity, "userType", "N"); - mTvDepart.setText(appTokenUser.getRoles().get(i).getRoleName()); - userType = 1; - break; - } - } - } else { - GlobalProvider.save(mActivity, "userType", "P"); - userType = 2; - } - } else { - GlobalProvider.save(mActivity, "userType", "P"); - userType = 2; - } - Intent intent = new Intent(); - intent.setAction(PathConfig.ACTION_PUNCH_TIME_MESSAGE); - intent.putExtra("timeBean", mSignTimeBean); - sendBroadcast(intent); - } - } - - @Override - public void onError(Throwable e) { - e.printStackTrace(); - if (progressDialog != null && progressDialog.isShowing() && i == 2) { - progressDialog.dismiss(); - ToastUtils.showShort("获取签到规则失败,请稍后重试"); - } - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 打开GPS - */ - private void openGpsSetting() { - if (mGpsSettingDialog == null) { - mGpsSettingDialog = new AlertDialog.Builder(this).setTitle("打开GPS") - .setMessage("定位需要打开GPS,请前往设置") - .setNegativeButton("取消", (dialogInterface, i) -> dialogInterface.dismiss()) - .setPositiveButton("前往", (dialogInterface, i) -> { - Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); - startActivityForResult(intent, GPS_REQUEST_CODE); - }) - .setCancelable(false) - .create(); - } - if (!mGpsSettingDialog.isShowing()) { - mGpsSettingDialog.show(); - } - } - /** * 初始化首页按钮 */ @@ -397,60 +166,26 @@ public class MainActivity extends BaseActivity { * @param bean */ private void chosePage(FuncBean bean) { -// "案件上报", "案件记录", "案件处理", "工作路径", "通讯录", "通知公告" +// 企业信息", "隐患上报", "隐患复查", "法律法规 + Intent intent = null; switch (bean.getText()) { - case "案件上报": -// startActivity(new Intent(MainActivity.this, IssueReportActivity.class)); + case "企业信息": + intent = new Intent(this, CompanyLibActivity.class); break; - case "案件记录"://案件记录 - startActivity(new Intent(MainActivity.this, IssueRecordActivity.class)); + case "隐患上报": + intent = new Intent(this, TroubleReportActivity.class); break; - case "案件处理"://案件处理 - startActivity(new Intent(MainActivity.this, IssueCheckActivity.class)); + case "隐患复查": break; - case "工作路径"://工作路径 -// if (userType == 1) { -// startActivity(new Intent(MainActivity.this, LocusManagerActivity.class)); -// } else { -// startActivity(new Intent(MainActivity.this, LocusMapActivity.class)); -// } - break; - case "通讯录"://通讯录 - Intent intent = new Intent(MainActivity.this, AddressListMainActivity.class); - intent.putExtra("uType", userType); - startActivity(intent); - break; - case "通知公告"://通知公告 - startActivity(new Intent(MainActivity.this, NoticeActivity.class)); + case "法律法规": break; } + startActivity(intent); } private void initBaseView() { mGson = new Gson(); String loginInfo = UserLgUtils.getLoginInfo(); - if (!TextUtils.isEmpty(loginInfo)) { - AppTokenUser appTokenUser = mGson.fromJson(loginInfo, AppTokenUser.class); - if (appTokenUser.getRoles() != null && appTokenUser.getRoles().size() > 0) { - for (int i = 0; i < appTokenUser.getRoles().size(); i++) { - if (!TextUtils.isEmpty(appTokenUser.getRoles().get(i).getRoleName())) { - mTvDepart.setText(appTokenUser.getRoles().get(i).getRoleName()); - break; - } - } - } - if (appTokenUser.getRoles() != null && appTokenUser.getRoles().size() > 0) { - for (int i = 0; i < appTokenUser.getRoles().size(); i++) { - if (PathConfig.USER_TYPE_N.equals(appTokenUser.getRoles().get(i).getRoleId())) { - mTvDepart.setText(appTokenUser.getRoles().get(i).getRoleName()); - userType = 1; - break; - } - } - } - } else { - userType = 2; - } mTvUserName.setText(UserLgUtils.getName() + " 个人中心"); Glide.with(mActivity) .load(BaseUrlApi.BASE_IMG_URL + UserLgUtils.getAvatar()) @@ -458,51 +193,14 @@ public class MainActivity extends BaseActivity { .error(R.drawable.ic_user_default) .placeholder(R.drawable.ic_user_default)) .into(mIvUserIcon); - mTvCurrentTime.setText("当前地址:定位中..."); Glide.with(mActivity) .load(R.drawable.ic_nomal) .into(mIvState); mTvState.setText("正常"); mTvState.setTextColor(Color.WHITE); -// checkAmSign(); checkPermission(); } - /** - * 显示片长签到规则 - */ - private void showRuleDialog() { - if (mSignTimeBean != null) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - String msg = "上午签到时间区间:" + mSignTimeBean.getAmStartPunchTime() + "-" + mSignTimeBean.getAmStartWorkTime() - + "\n上午签退时间区间:" + mSignTimeBean.getAmEndWorkTime() + "-" + mSignTimeBean.getAmEndPunchTime() - + "\n下午签到时间区间:" + mSignTimeBean.getPmStartPunchTime() + "-" + mSignTimeBean.getPmStartWorkTime() - + "\n下午签退时间区间:" + mSignTimeBean.getPmEndWorkTime() + "-" + mSignTimeBean.getPmEndPunchTime(); - builder.setTitle("签到规则") - .setMessage(msg) - .setPositiveButton("确定", (dialog, which) -> dialog.dismiss()); - builder.create().show(); - } else { - getPunchTime(2); - } - } - - /** - * 显示N员签到规则 - */ - private void showNRuleDialog() { - if (mSignTimeBean != null) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - String msg = "签到时间区间: " + mSignTimeBean.getNStartPunchTime() + " - " + mSignTimeBean.getNStartWorkTime() - + "\n签退时间区间:" + mSignTimeBean.getNEndWorkTime() + "-" + mSignTimeBean.getNEndPunchTime(); - builder.setTitle("签到规则") - .setMessage(msg) - .setPositiveButton("确定", (dialog, which) -> dialog.dismiss()); - builder.create().show(); - } else { - getPunchTime(2); - } - } private void checkPermission() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { @@ -570,710 +268,6 @@ public class MainActivity extends BaseActivity { }); } - private void uploadPoint() { - LocationPosition position = new LocationPosition(); -// position.setUserLatitude(mCurrentLocation.getLatitude() + ""); -// position.setUserLongitude(mCurrentLocation.getLongitude() + ""); -// position.setUserLocation(mCurrentLocation.getAddress().address); -// position.setUserSpeed(mCurrentLocation.getSpeed() + ""); - Gson gson = new Gson(); - String s = gson.toJson(position); - RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), s); - RetrofitManager.getInstance() - .create(LocationApiService.class) - .saveLocationData(body, UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(SuccessBean successBean) { - - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 检查是否签到 - */ - private void checkAmSign() { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .checkSign(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(CheckSignBean checkSignBean) { - if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData().getIsSign())) { - LogUtils.e(checkSignBean.getData()); - boolean b = Boolean.parseBoolean(checkSignBean.getData().getIsSign()); - if (!TextUtils.isEmpty(checkSignBean.getData().getStatus())) { - boolean late = Boolean.parseBoolean(checkSignBean.getData().getStatus()); - if (late) { - //迟到了 - Glide.with(mActivity) - .load(R.drawable.ic_late) - .into(mIvState); - mTvState.setText("迟到"); - mTvState.setTextColor(Color.RED); - } else { - //正常 - Glide.with(mActivity) - .load(R.drawable.ic_nomal) - .into(mIvState); - mTvState.setText("正常"); - mTvState.setTextColor(Color.WHITE); - } - } else { - //正常 - Glide.with(mActivity) - .load(R.drawable.ic_nomal) - .into(mIvState); - mTvState.setText("正常"); - mTvState.setTextColor(Color.WHITE); - } - if (b) { - isSgin = true; - mTvSign.setTextColor(Color.WHITE); - setSignOffText(); - checkSignOff(); - GlobalProvider.save(mActivity, "isUpload", "13"); - } else { - isSgin = false; - mTvSign.setTextColor(Color.WHITE); - setSignText(); - GlobalProvider.save(mActivity, "isUpload", "12"); - } - } - } - - @Override - public void onError(Throwable e) { - mTvSign.setTextColor(Color.WHITE); - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 校验是否签退 - */ - private void checkSignOff() { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .checkSignOff(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(CheckSignOffBean checkSignBean) { - LogUtils.e(checkSignBean); - if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData())) { - boolean b = Boolean.parseBoolean(checkSignBean.getData()); - if (b) { - //已经签退 - isSignOff = true; - mTvSign.setTextColor(Color.WHITE); - setSignCompleteText(); - GlobalProvider.save(mActivity, "isUpload", "12"); - } else { - //没有签退 - isSignOff = false; - mTvSign.setTextColor(Color.WHITE); - setSignOffText(); - GlobalProvider.save(mActivity, "isUpload", "13"); - } - } else { - //未签退 - mTvSign.setTextColor(Color.WHITE); - setSignOffText(); - GlobalProvider.save(mActivity, "isUpload", "13"); - } - } - - @Override - public void onError(Throwable e) { - mTvSign.setTextColor(Color.WHITE); - GlobalProvider.save(mActivity, "isUpload", "13"); - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 定时 - */ - private void interval() { - Observable.interval(5, 1, TimeUnit.MINUTES) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - mTimeDis = d; - } - - @Override - public void onNext(Long aLong) { - checkAmSign(); - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 显示签到dialog - */ - private void showSignDialog() { -// test(); -// if (mCurrentLocation == null) { -// ToastUtils.showShort("正在定位中,请稍后重试."); -// } else { -// if (2 == userType) { -// show();//片长签到退 -// } else { -// showN();//显示N员签到退 -// } -// } - } - - private void test() { - String nowHour = TimeUtils.getNowHourMM(); - boolean isAmPunch = TimeUtils.isInTime(mSignTimeBean.getAmEndWorkTime() + "-" + mSignTimeBean.getAmEndPunchTime(), nowHour); - boolean isPmPunch = TimeUtils.isInTime(mSignTimeBean.getPmEndWorkTime() + "-" + mSignTimeBean.getPmEndPunchTime(), nowHour); - if (isAmPunch || isPmPunch) { - LogUtils.e("在规则内"); - } else { - LogUtils.e("不在规则内"); - } - } - - /** - * 显示N员签到签退 - */ - private void showN() { - String nowHour = TimeUtils.getNowHour(); - if (mSignTimeBean != null) { - if (isSgin) { - //已经签到,显示签退 - if (isSignOff) { - ToastUtils.showShort("打开完成"); - } else { - boolean isTimeLegal = TimeUtils.isInTime(mSignTimeBean.getNEndWorkTime() + "-" + mSignTimeBean.getNEndPunchTime(), nowHour); - LogUtils.e("N员签到时间区间=" + mSignTimeBean.getNEndWorkTime() + "-" + mSignTimeBean.getNEndPunchTime()); -// if (isTimeLegal) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// if (checkCurrenPointIsBeyond(mCurrentLocation)) { -// showSignOffDialog(); -// } else { -// ToastUtils.showShort("当前位置不在所管辖片区内,请前往片区内进行签到或签退操作."); -// } -// } else { -// getPenList(); -// } -// } else { -// ToastUtils.showShort("未到签退时间"); -// } - } - } else { - //未签到 - boolean isLegalTime = TimeUtils.isInTime(mSignTimeBean.getNStartPunchTime() + "-" + mSignTimeBean.getNEndPunchTime(), nowHour); - if (isLegalTime) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// if (checkCurrenPointIsBeyond(mCurrentLocation)) { -// showSDialog(); -// } else { -// ToastUtils.showShort("当前位置不在所管辖片区内,请前往片区内进行签到或签退操作."); -// } -// } else { -// getPenList(); -// } - } else { - ToastUtils.showShort("未到签到时间"); - } - } - } else { - getPunchTime(2); - } - - } - - /** - * 显示片长签到签退 - */ - private void show() { - String nowHour = TimeUtils.getNowHour(); - if (mSignTimeBean != null) { - if (isSgin) { - //签到了 - if (isSignOff) { - //签退了 - boolean amOrPm = TimeUtils.isAmOrPm(); - if (!amOrPm) { - ToastUtils.showShort("今天打卡已经完成"); - } else { - //上午 签到了 也签退了 - boolean isPmPunch = TimeUtils.isInTime(mSignTimeBean.getPmStartPunchTime() + "-" + mSignTimeBean.getPmEndPunchTime(), nowHour); - if (isPmPunch) { - if (2 == userType) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// if (checkCurrenPointIsBeyond(mCurrentLocation)) { -// showSDialog(); -// } else { -// ToastUtils.showShort("当前位置不在所管辖片区内,请前往片区内进行签到或签退操作."); -// } -// } else { -// getPenList(); -// } - } else { - showSDialog(); - } - } else { - ToastUtils.showShort("当前时间不在签到时间规则范围内"); - } - } - } else { - //未签退 - boolean isAmPunch = TimeUtils.isInTime(mSignTimeBean.getAmEndWorkTime() + "-" + mSignTimeBean.getAmEndPunchTime(), nowHour); - boolean isPmPunch = TimeUtils.isInTime(mSignTimeBean.getPmEndWorkTime() + "-" + mSignTimeBean.getPmEndPunchTime(), nowHour); - if (isAmPunch || isPmPunch) { - if (2 == userType) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// if (checkCurrenPointIsBeyond(mCurrentLocation)) { -// showSignOffDialog(); -// } else { -// ToastUtils.showShort("当前位置不在所管辖片区内,请前往片区内进行签到或签退操作."); -// } -// } else { -// getPenList(); -// } - - } else { - showSignOffDialog(); - } - } else { - if (TimeUtils.compareToCurrent(mSignTimeBean.getAmEndPunchTime()) || TimeUtils.compareToCurrent(mSignTimeBean.getPmEndPunchTime())) { - ToastUtils.showShort("未到签退时间"); - } else { - ToastUtils.showShort("已过签退时间"); - } - } - } - } else { - //没有签到 - boolean isInAmTime = TimeUtils.isInTime(mSignTimeBean.getAmStartPunchTime() + "-" + mSignTimeBean.getAmEndPunchTime(), nowHour); - boolean isInPmTime = TimeUtils.isInTime(mSignTimeBean.getPmStartPunchTime() + "-" + mSignTimeBean.getPmEndPunchTime(), nowHour); - LogUtils.e("上午签到时间:" + mSignTimeBean.getAmStartPunchTime() + "-" + mSignTimeBean.getAmEndPunchTime()); - LogUtils.e("下午签到时间:" + mSignTimeBean.getPmStartPunchTime() + "-" + mSignTimeBean.getPmEndPunchTime()); - if (isInAmTime) { - if (2 == userType) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// if (checkCurrenPointIsBeyond(mCurrentLocation)) { -// showSDialog(); -// } else { -// ToastUtils.showShort("当前位置不在所管辖片区内,请前往片区内进行签到或签退操作."); -// } -// } else { -// getPenList(); -// } - } else { - showSDialog(); - } - } else { - if (isInPmTime) { - if (2 == userType) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// if (checkCurrenPointIsBeyond(mCurrentLocation)) { -// showSDialog(); -// } else { -// ToastUtils.showShort("当前位置不在所管辖片区内,请前往片区内进行签到或签退操作."); -// } -// } else { -// getPenList(); -// } - } else { - showSDialog(); - } - } else { - ToastUtils.showShort("未到签到时间"); - } - } - } - } else { - getPunchTime(2); - } - } - - /** - * 显示签到 - */ - private void showSDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage("确认要签到吗?"); - builder.setTitle("提示") - .setMessage("确认要签到吗?") - .setPositiveButton("确定", (dialog, which) -> { - dialog.dismiss(); - doSign(); - }) - .setNegativeButton("取消", (dialog, which) -> dialog.dismiss()); - builder.create().show(); - } - - - /** - * 显示签退 - */ - private void showSignOffDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("提示") - .setMessage("确认要签退吗?") - .setPositiveButton("确定", (dialog, which) -> { - dialog.dismiss(); - doSignOff(); - }) - .setNegativeButton("取消", (dialog, which) -> dialog.dismiss()); - builder.create().show(); - } - - /** - * 签退 - */ - private void doSignOff() { -// ProgressDialog dialog = UIUtil.initDialog(mActivity, "签退中..."); -// dialog.show(); -// SignOffBean bean = new SignOffBean(); -// bean.setSignoutLatitude(mCurrentLocation.getLatitude() + ""); -// bean.setSignoutLongitude(mCurrentLocation.getLongitude() + ""); -// Gson gson = new Gson(); -// String obj = gson.toJson(bean); -// RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj); -// RetrofitManager.getInstance() -// .create(LocationApiService.class) -// .doSignOff(body, UserLgUtils.getToken()) -// .subscribeOn(Schedulers.io()) -// .observeOn(AndroidSchedulers.mainThread()) -// .subscribe(new Observer() { -// @Override -// public void onSubscribe(Disposable d) { -// } -// -// @Override -// public void onNext(SuccessBean successBean) { -//// uploadPoint(); -// dialog.dismiss(); -// isSignOff = true; -// setSignCompleteText(); -// mTvSign.setTextColor(Color.WHITE); -// ToastUtils.showLong("签退成功"); -// GlobalProvider.save(mActivity, "isUpload", "12"); -// } -// -// @Override -// public void onError(Throwable e) { -// dialog.dismiss(); -// ExceptionHandler.handleException(e); -// } -// -// @Override -// public void onComplete() { -// -// } -// }); - } - - private void getUserPenList() { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .getUserPenList(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer>() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(List penLineBeans) { - if (penLineBeans != null && penLineBeans.size() > 0) { -// buildPenList(penLineBeans); - } - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onComplete() { - - } - }); - - } - - /** - * 手动获取围栏数据 - */ - private void getPenList() { - ProgressDialog dialog = UIUtil.initDialog(mActivity, "获取围栏数据中..."); - dialog.show(); - RetrofitManager.getInstance() - .create(LocationApiService.class) - .getUserPenList(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer>() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(List penLineBeans) { - dialog.dismiss(); -// if (penLineBeans != null && penLineBeans.size() > 0) { -// mPenLineList = new ArrayList<>(); -// for (int i = 0; i < penLineBeans.size(); i++) { -// List areaPoints = penLineBeans.get(i).getAreaPoints(); -// if (areaPoints != null && areaPoints.size() > 0) { -// List tempList = new ArrayList<>(); -// for (int j = 0; j < areaPoints.size(); j++) { -// LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(j).getLatitude()), Double.parseDouble(areaPoints.get(j).getLongitude())); -// tempList.add(latLng); -// } -// LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(0).getLatitude()), Double.parseDouble(areaPoints.get(0).getLongitude())); -// tempList.add(latLng); -// mPenLineList.add(tempList); -// } -// } -// ToastUtils.showShort("获取片区数据成功,请重新签到或签退"); -// } else { -// ToastUtils.showShort("暂无片区数据"); -// } - } - - @Override - public void onError(Throwable e) { - dialog.dismiss(); - ExceptionHandler.handleException(e); - } - - @Override - public void onComplete() { - - } - }); - - } - - /** - * 判断是否越界 - * - * @param bdLocation - */ -// private boolean checkCurrenPointIsBeyond(BDLocation bdLocation) { -// if (mPenLineList != null && mPenLineList.size() > 0) { -// for (int i = 0; i < mPenLineList.size(); i++) { -// LatLng latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); -// boolean inPolygon = PointUtils.isInPolygon(latLng, mPenLineList.get(i)); -// if (inPolygon) { -// return true; -// } -// } -// return false; -// } else { -// return false; -// } -// } - -// private void buildPenList(List penLineBeans) { -// mPenLineList = new ArrayList<>(); -// for (int i = 0; i < penLineBeans.size(); i++) { -// List areaPoints = penLineBeans.get(i).getAreaPoints(); -// if (areaPoints != null && areaPoints.size() > 0) { -// List tempList = new ArrayList<>(); -// for (int j = 0; j < areaPoints.size(); j++) { -// LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(j).getLatitude()), Double.parseDouble(areaPoints.get(j).getLongitude())); -// tempList.add(latLng); -// } -// LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(0).getLatitude()), Double.parseDouble(areaPoints.get(0).getLongitude())); -// tempList.add(latLng); -// mPenLineList.add(tempList); -// } -// } -// } - - /** - * 进行签到 - */ - private void doSign() { -// ProgressDialog dialog = UIUtil.initDialog(mActivity, "签到中..."); -// dialog.show(); -// SignBean bean = new SignBean(); -// bean.setSigninLatitude(mCurrentLocation.getLatitude() + ""); -// bean.setSigninLongitude(mCurrentLocation.getLongitude() + ""); -// Gson gson = new Gson(); -// String obj = gson.toJson(bean); -// RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj); -// RetrofitManager.getInstance() -// .create(LocationApiService.class) -// .doSign(body, UserLgUtils.getToken()) -// .subscribeOn(Schedulers.io()) -// .observeOn(AndroidSchedulers.mainThread()) -// .subscribe(new Observer() { -// @Override -// public void onSubscribe(Disposable d) { -// -// } -// -// @Override -// public void onNext(SignDataBean successBean) { -//// LogUtils.e(successBean); -//// uploadPoint(); -// isSgin = true; -// isSignOff = false; -// if (successBean.isData()) { -// Glide.with(mActivity) -// .load(R.drawable.ic_late) -// .into(mIvState); -// mTvState.setText("迟到"); -// mTvState.setTextColor(Color.RED); -// } else { -// Glide.with(mActivity) -// .load(R.drawable.ic_nomal) -// .into(mIvState); -// mTvState.setText("正常"); -// mTvState.setTextColor(Color.WHITE); -// } -// dialog.dismiss(); -// GlobalProvider.save(mActivity, "isUpload", "13"); -// setSignOffText(); -// mTvSign.setTextColor(Color.WHITE); -// ToastUtils.showLong("签到成功"); -// } -// -// @Override -// public void onError(Throwable e) { -// e.printStackTrace(); -// dialog.dismiss(); -// ExceptionHandler.handleException(e); -// } -// -// @Override -// public void onComplete() { -// -// } -// }); - } - - /** - * 设置未签到文字 - */ - private void setSignText() { - if (userType == 2) { - boolean amOrPm = TimeUtils.isAmOrPm(); - if (amOrPm) { - //上午 - mTvSign.setText("上午\n签到"); - } else { - //下午 - mTvSign.setText("下午\n签到"); - } - } else { - mTvSign.setText("签到"); - } - } - - /** - * 设置已签到文字 - */ - private void setSignOffText() { - if (userType == 2) { - //片长 - boolean amOrPm = TimeUtils.isAmOrPm(); - if (amOrPm) { - mTvSign.setText("上午\n签退"); - } else { - mTvSign.setText("下午\n签退"); - } - } else { - //N员 - mTvSign.setText("签退"); - } - } - - - /** - * 设置签到完成文字 - */ - private void setSignCompleteText() { - if (userType == 2) { - boolean amOrPm = TimeUtils.isAmOrPm(); - if (amOrPm) { - //未签到 - mTvSign.setText("下午\n签到"); - } else { - //下午 - mTvSign.setText("打卡\n完成"); - Glide.with(mActivity) - .load(R.drawable.ic_nomal) - .into(mIvState); - mTvState.setText("正常"); - mTvState.setTextColor(Color.WHITE); - } - } else { - mTvSign.setText("打卡\n完成"); - Glide.with(mActivity) - .load(R.drawable.ic_nomal) - .into(mIvState); - mTvState.setText("正常"); - mTvState.setTextColor(Color.WHITE); - } - } /** * 创建缓存文件夹 @@ -1291,31 +285,11 @@ public class MainActivity extends BaseActivity { } } - private void initScreenListener() { - final ScreenManager screenManager = ScreenManager.getInstance(MainActivity.this); - ScreenBroadCastListener listener = new ScreenBroadCastListener(this); - listener.addScreenStateListener(new ScreenBroadCastListener.ScreenStateListener() { - @Override - public void onScreenOn() { - screenManager.finishActivity(); - } - - @Override - public void onScreenOff() { - screenManager.startActivity(); - } - }); - } /** * report 案件上报 */ - @OnClick({/**R.id.rl_issue_report, - R.id.rl_issue_record, - R.id.rl_issue_dispose, - R.id.rl_address_list, - R.id.rl_notice, - R.id.rl_work_iocus,*/ + @OnClick({ R.id.ll_issue_dis, R.id.ll_mine_issue, R.id.tv_sign, @@ -1331,7 +305,6 @@ public class MainActivity extends BaseActivity { startActivity(new Intent(mActivity, IssueMineActivity.class)); break; case R.id.tv_sign://签到 - showSignDialog(); break; case R.id.ll_day_aviso://每日通报 Intent intent = new Intent(MainActivity.this, NoticeActivity.class); @@ -1342,11 +315,7 @@ public class MainActivity extends BaseActivity { startActivity(new Intent(MainActivity.this, UserActivity.class)); break; case R.id.tv_rule://签到规则 - if (2 == userType) { - showRuleDialog(); - } else { - showNRuleDialog(); - } + break; } } @@ -1355,10 +324,6 @@ public class MainActivity extends BaseActivity { @Override protected void onResume() { super.onResume(); - isForeground = true; - isForeg = true; - getMessageCount(); -// checkAmSign(); Glide.with(mActivity) .load(BaseUrlApi.BASE_IMG_URL + UserLgUtils.getAvatar()) .apply(RequestOptions.bitmapTransform(new CircleCrop()) @@ -1370,304 +335,23 @@ public class MainActivity extends BaseActivity { @Override protected void onPause() { super.onPause(); - isForeground = false; - isForeg = false; } @Override protected void onStart() { super.onStart(); - isForeground = true; - LogUtils.e("===OnStart==="); - checkAmSign(); - if (mSignTimeBean != null) { - Intent intent = new Intent(); - intent.setAction(PathConfig.ACTION_PUNCH_TIME_MESSAGE); - intent.putExtra("timeBean", mSignTimeBean); - intent.putExtra("uType", userType); - sendBroadcast(intent); - } - } - - private void getMessageCount() { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .getMainMessageNum(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(MainNumBean mainNumBean) { - if (mainNumBean != null) { - mTvAvisoNum.setText(mainNumBean.getCountOfDaily() + ""); - if (mainNumBean.getHandleOfMine() > 0) { - mIvIssueDisNum.setVisibility(View.VISIBLE); - } else { - mIvIssueDisNum.setVisibility(View.GONE); - } - mTvIssueDisNum.setText(mainNumBean.getHandleOfMine() + ""); - mTvMineIssueNum.setText(mainNumBean.getCaseOfMine() + ""); - } - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 启动定位 - */ - private void startListenLocation() { - - boolean isRuning = AppUtils.getProcessIsRuning(getApplicationContext(), "com.sucstepsoft.txrealtimelocation.services.LocationService"); - if (!isRuning) { - startLocation(); - } else { - Intent intent = new Intent(); - intent.setAction(PathConfig.ACTION_STOP_LOCATION); - sendBroadcast(intent); - } - } - - private void startLocation() { - boolean isSetting = UserLgUtils.getIsSetting(); - if (!isSetting) { -// IntentWrapper.jumpStartInterface(mActivity); - IntentWrapper.whiteListMatters(MainActivity.this, "应急管理局"); - } - GlobalProvider.save(mActivity, "isUpload", "12"); - Intent intent = new Intent(MainActivity.this, LocationService.class); - intent.putExtra("token", UserLgUtils.getToken()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } - } - - @Override - protected void onStop() { - super.onStop(); - LogUtils.e("====OnStop===="); - } - - public void registerMessageReceiver() { - mMessageReceiver = new MessageReceiver(); - IntentFilter filter = new IntentFilter(); -// filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); -// filter.addAction(PathConfig.ACTION_LOCATION_MESSAGE); - filter.addAction("com.sucstepsoft.realtimelocation.isonlone"); - registerReceiver(mMessageReceiver, filter); - } - - /** - * 检验GPS是否开启 5秒一次 - */ - private void registerGpsState() { - Observable.interval(5, TimeUnit.SECONDS) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - mGpsStateDis = d; - } - - @Override - public void onNext(Long aLong) { - if (isForeg) { - if (mCurrentLongTime != 0) { - long timeSpan = TimeUtils.getTimeSpan(System.currentTimeMillis(), mCurrentLongTime, TimeConstants.MIN); - if (timeSpan < 10) { - mTvOnline.setText("(在线)"); - } else { - mTvOnline.setText("(离线)"); - } - } - boolean oPen = GpsUtils.isOPen(mActivity); - if (!oPen) { - openGpsSetting(); - } - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * Gps信号不好的弹窗 - */ - private void registerGpsSignal() { - Observable.timer(10, TimeUnit.SECONDS) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - mGpsDis = d; - } - - @Override - public void onNext(Long aLong) { - if (isForeg) { - if (mGpsWeakDialog == null) { - AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); - builder.setMessage("当前GPS信号较弱,请调整当前所在位置,或检查手机GPS是否开启,将Wifi与蓝牙打开会提高定位精度.") - .setTitle("提示") - .setNegativeButton("确定", (dialog, which) -> dialog.dismiss()); - mGpsWeakDialog = builder.create(); - } - if (!mGpsWeakDialog.isShowing()) { - mGpsWeakDialog.show(); - } - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - - public class MessageReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - if ("com.sucstepsoft.realtimelocation.isonlone".equals(intent.getAction())) { - String uploadTime = intent.getStringExtra("uploadTime"); - if (!TextUtils.isEmpty(uploadTime)) { - long l = Long.parseLong(uploadTime); - mCurrentLongTime = l; - } - } - } - } @Override protected void onDestroy() { - if (mGpsStateDis != null && !mGpsStateDis.isDisposed()) { - mGpsStateDis.dispose(); - } - if (mGpsDis != null && !mGpsDis.isDisposed()) { - mGpsDis.dispose(); - } - if (mTimeDis != null && !mTimeDis.isDisposed()) { - mTimeDis.dispose(); - } - if (mMessageReceiver != null) { - unregisterReceiver(mMessageReceiver); - } + if (mBind != null) { mBind.unbind(); } - stopLocation(); super.onDestroy(); } - private void startSignLocation() { - stopLocation(); -// mLocationClient = new LocationClient(getApplicationContext()); -// LocationClientOption locationOption = new LocationClientOption(); -// SignLocationListener myLocationListener = new SignLocationListener(); -// mLocationClient.registerLocationListener(myLocationListener); -// locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); -// locationOption.setCoorType("bd09ll"); -// locationOption.setScanSpan(30 * 1000); -// locationOption.setIsNeedAddress(true); -// locationOption.setNeedDeviceDirect(false); -// locationOption.setLocationNotify(false); -// locationOption.setIgnoreKillProcess(true); -// locationOption.setIsNeedLocationDescribe(true); -// locationOption.setIsNeedLocationPoiList(true); -// locationOption.SetIgnoreCacheException(false); -// locationOption.setOpenGps(true); -// locationOption.setIsNeedAltitude(false); -//// locationOption.setLocationPurpose(LocationClientOption.BDLocationPurpose.SignIn); -// mLocationClient.setLocOption(locationOption); -// //开始定位 -// mLocationClient.start(); - } - - private void stopLocation() { -// if (null != mLocationClient) { -// mLocationClient.stop(); -// } - } - -// private class SignLocationListener extends BDAbstractLocationListener { -// @Override -// public void onReceiveLocation(BDLocation bdLocation) { -// if (bdLocation != null && bdLocation.getLatitude() != 0 && bdLocation.getLongitude() != 0) { -// checkPointIsLegal(bdLocation); -// } -// } -// } - -// private void checkPointIsLegal(BDLocation bdLocation) { -// if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode())) { -// if (bdLocation != null && bdLocation.getLatitude() != 0 && bdLocation.getLongitude() != 0) { -// if (mPrecision >= mPrecMax) { -// mPrecision = mPrecisionDefault; -// if (mGpsWeakDialog == null) { -// AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); -// builder.setMessage("当前GPS信号较弱,请调整当前所在位置,或检查手机GPS是否开启,将Wifi与蓝牙打开会提高定位精度.") -// .setTitle("提示") -// .setNegativeButton("确定", (dialog, which) -> dialog.dismiss()); -// mGpsWeakDialog = builder.create(); -// } -// if (!mGpsWeakDialog.isShowing()) { -// mGpsWeakDialog.show(); -// } -// } else { -// if (bdLocation.getRadius() <= mPrecision) { -// mPrecision = mPrecisionDefault; -// if (bdLocation.getLatitude() != Double.MIN_VALUE && bdLocation.getLongitude() != Double.MIN_VALUE) { -// mCurrentLocation = bdLocation; -// if (mGpsDis != null && !mGpsDis.isDisposed()) { -// mGpsDis.dispose(); -// } -// if (TextUtils.isEmpty(mCurrentLocation.getAddrStr())) { -// mTvCurrentTime.setText("当前地址:未知"); -// } else { -// mTvCurrentTime.setText("当前地址:" + mCurrentLocation.getAddrStr()); -// } -// } -// } else { -// mPrecision += 10; -// } -// } -// } -// } -// } @Override public void onBackPressed() { diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyDetailActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyDetailActivity.java new file mode 100644 index 0000000..5299606 --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyDetailActivity.java @@ -0,0 +1,39 @@ +package com.sucstepsoft.txrealtimelocation.activitys.companylib; + +import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; +import com.sucstepsoft.txrealtimelocation.R; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * 企业信息详情 + */ +public class CompanyDetailActivity extends BaseActivity { + + private Unbinder mBind; + + @Override + protected int setLayoutId() { + return R.layout.activity_company_detail; + } + + @Override + public void initData() { + mBind = ButterKnife.bind(this); + mTvBaseTitle.setText("企业详情"); + refreshView(STATE_LOAD_LOADING); + String mId = getIntent().getStringExtra("id"); + getCompanyDetailById(mId); + } + + private void getCompanyDetailById(String mId) { + + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mBind.unbind(); + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyInfoEditActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyInfoEditActivity.java new file mode 100644 index 0000000..92d8c35 --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyInfoEditActivity.java @@ -0,0 +1,41 @@ +package com.sucstepsoft.txrealtimelocation.activitys.companylib; + +import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; +import com.sucstepsoft.txrealtimelocation.R; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * 企业信息编辑 + */ +public class CompanyInfoEditActivity extends BaseActivity { + + private Unbinder mBind; + private String mId; + + + @Override + protected int setLayoutId() { + return R.layout.activity_company_info_edit; + } + + @Override + public void initData() { + mBind = ButterKnife.bind(this); + mTvBaseTitle.setText("企业信息编辑"); + refreshView(STATE_LOAD_LOADING); + mId = getIntent().getStringExtra("id"); + getCompanyDetail(mId); + } + + private void getCompanyDetail(String id) { + + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mBind.unbind(); + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyLibActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyLibActivity.java new file mode 100644 index 0000000..7dfd756 --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/CompanyLibActivity.java @@ -0,0 +1,143 @@ +package com.sucstepsoft.txrealtimelocation.activitys.companylib; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.view.View; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.jcodecraeer.xrecyclerview.ProgressStyle; +import com.jcodecraeer.xrecyclerview.XRecyclerView; +import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; +import com.sucstepsoft.txrealtimelocation.R; +import com.sucstepsoft.txrealtimelocation.adapters.CompanyLibAdapter; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * 企业信息首页 + */ +public class CompanyLibActivity extends BaseActivity { + + @BindView(R.id.et_company_name) + EditText mEtCompanyName; + @BindView(R.id.tv_com_type) + TextView mTvComType; + @BindView(R.id.pb_loading) + ProgressBar mPbLoading; + @BindView(R.id.iv_empty) + ImageView mIvEmpty; + @BindView(R.id.tv_error_hint) + TextView mTvErrorHint; + private Unbinder mBind; + @BindView(R.id.xlv_com_lib) + XRecyclerView mRlvComList; + private int mCurrentPage = 1; + private List mDatas = new ArrayList<>(); + private static final int STATE_LOADING = 333; + private static final int STATE_EMPTY = 433; + private static final int STATE_ERROR = 533; + + @Override + protected int setLayoutId() { + return R.layout.activity_company_lib; + } + + @Override + public void initData() { + refreshView(STATE_LOAD_SUCCESS); + mTvBaseTitle.setText("企业信息"); + mBind = ButterKnife.bind(this); + mTvPublish.setVisibility(View.VISIBLE); + mTvPublish.setText("录入"); + mTvPublish.setOnClickListener(v -> startActivity(new Intent(this, EnterCompanyInfoActivity.class))); + CompanyLibAdapter mAdapter = new CompanyLibAdapter(mActivity, mDatas); + LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity); + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + mRlvComList.setLayoutManager(layoutManager); + mRlvComList.setAdapter(mAdapter); + mAdapter.addOnItemClickListener(bean -> showDetail(bean)); + mRlvComList.setRefreshProgressStyle(ProgressStyle.BallGridBeat); + mRlvComList.setLoadingMoreProgressStyle(ProgressStyle.Pacman); + mRlvComList.setPullRefreshEnabled(true); + mRlvComList.setLoadingMoreEnabled(true); + mRlvComList.setLoadingListener(new XRecyclerView.LoadingListener() { + @Override + public void onRefresh() { + refreshData(); + } + + @Override + public void onLoadMore() { + getCompanyLibList(mCurrentPage); + } + }); + stateView(STATE_LOADING); + } + + private void stateView(int state) { + switch (state) { + case STATE_EMPTY: + mTvErrorHint.setText("暂无数据"); + mRlvComList.setVisibility(View.GONE); + mPbLoading.setVisibility(View.GONE); + mIvEmpty.setVisibility(View.VISIBLE); + break;//空数据 + case STATE_ERROR: + mTvErrorHint.setText("数据加载失败,请稍后重试."); + mRlvComList.setVisibility(View.GONE); + mPbLoading.setVisibility(View.GONE); + mIvEmpty.setVisibility(View.VISIBLE); + break;//加载错误 + case STATE_LOADING: + default: + mTvErrorHint.setText("数据加载中..."); + mRlvComList.setVisibility(View.GONE); + mPbLoading.setVisibility(View.VISIBLE); + mIvEmpty.setVisibility(View.GONE); + break; + } + } + + /** + * 显示详情 + * + * @param id + */ + private void showDetail(String id) { + Intent intent = new Intent(); + intent.setClass(mActivity, CompanyDetailActivity.class); + intent.putExtra("id", id); + startActivity(intent); + } + + /** + * 获取列表 + * + * @param currentPage + */ + private void getCompanyLibList(int currentPage) { + + } + + /** + * 刷新列表 + */ + private void refreshData() { + + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mBind.unbind(); + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/EnterCompanyInfoActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/EnterCompanyInfoActivity.java new file mode 100644 index 0000000..54e1e96 --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/companylib/EnterCompanyInfoActivity.java @@ -0,0 +1,315 @@ +package com.sucstepsoft.txrealtimelocation.activitys.companylib; + +import android.content.Intent; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build; +import android.provider.MediaStore; +import android.support.v4.content.FileProvider; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; +import android.view.Gravity; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import com.sucstepsoft.cm_utils.constant.PathConfig; +import com.sucstepsoft.cm_utils.core.beans.AddPhotoBean; +import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi; +import com.sucstepsoft.cm_utils.core.widget.base.AddPhotoAdapter; +import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; +import com.sucstepsoft.cm_utils.core.widget.views.ButtomDialogView; +import com.sucstepsoft.cm_utils.utils.ProiderUtil; +import com.sucstepsoft.txrealtimelocation.R; +import com.sucstepsoft.txrealtimelocation.activitys.common.PhotoActivity; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * 录入企业信息页面 + */ +public class EnterCompanyInfoActivity extends BaseActivity { + + @BindView(R.id.tv_issue_base_info) + TextView mTvIssueBaseInfo; + @BindView(R.id.et_company_name) + EditText mEtCompanyName; + @BindView(R.id.tv_com_type) + TextView mTvComType; + @BindView(R.id.et_register_address) + EditText mEtRegisterAddress; + @BindView(R.id.et_detail_address) + EditText mEtDetailAddress; + @BindView(R.id.tv_trade) + TextView mTvTrade; + @BindView(R.id.et_peo_count) + EditText mEtPeoCount; + @BindView(R.id.tv_risk) + TextView mTvRisk; + @BindView(R.id.et_pre) + EditText mEtPre; + @BindView(R.id.et_phone) + EditText mEtPhone; + @BindView(R.id.tv_issue_detail_info) + TextView mTvIssueDetailInfo; + @BindView(R.id.rlv_door) + RecyclerView mRlvDoor; + @BindView(R.id.rlv_place) + RecyclerView mRlvPlace; + @BindView(R.id.btn_submit) + Button mBtnSubmit; + private Unbinder mBind; + private List mDoorPhotos; + private List mPlacePhotos; + private AddPhotoBean mCurrentBean; + private String mPicPath; + private String mDoorPhotoIds = ""; + private String mPlacePhotoIds = ""; + + @Override + protected int setLayoutId() { + return R.layout.activity_enter_company_info; + } + + @Override + public void initData() { + mTvBaseTitle.setText("企业信息录入"); + refreshView(STATE_LOAD_SUCCESS); + mBind = ButterKnife.bind(this); + initPhotoView(); + + } + + private void initPhotoView() { + mDoorPhotos = new ArrayList<>(); + mPlacePhotos = new ArrayList<>(); + mDoorPhotos.add(new AddPhotoBean()); + mPlacePhotos.add(new AddPhotoBean()); + AddPhotoAdapter mDoorPhotoAdapter = new AddPhotoAdapter(this, mDoorPhotos); + mRlvDoor.setLayoutManager(new GridLayoutManager(mActivity, 4)); + mRlvDoor.setAdapter(mDoorPhotoAdapter); + //删除上传的相片 + mDoorPhotoAdapter.addOnDeleteListener(((bean, i) -> { + mDoorPhotoAdapter.removeItem(bean); + mDoorPhotoIds = mDoorPhotoIds.replace(bean.getId() + ",", ""); + })); + mDoorPhotoAdapter.addOnItemClickListener(bean -> { + if (TextUtils.isEmpty(bean.getPath())) { + //空数据 + showSelectPhoto(bean); + } else { + //预览 + ArrayList list = new ArrayList<>(); + list.add(bean.getPath()); + Intent intent = new Intent(); + intent.putExtra(PhotoActivity.TAG_IMGURL, list); + intent.setClass(EnterCompanyInfoActivity.this, PhotoActivity.class); + startActivity(intent); + } + }); + + AddPhotoAdapter mPlacePhotoAdapter = new AddPhotoAdapter(this, mPlacePhotos); + mRlvPlace.setLayoutManager(new GridLayoutManager(mActivity, 4)); + mRlvPlace.setAdapter(mPlacePhotoAdapter); + //删除上传的相片 + mPlacePhotoAdapter.addOnDeleteListener(((bean, i) -> { + mDoorPhotoAdapter.removeItem(bean); + mPlacePhotoIds = mPlacePhotoIds.replace(bean.getId() + ",", ""); + })); + mPlacePhotoAdapter.addOnItemClickListener(bean -> { + if (TextUtils.isEmpty(bean.getPath())) { + //空数据 + showSelectPhoto(bean); + } else { + //预览 + ArrayList list = new ArrayList<>(); + list.add(bean.getPath()); + Intent intent = new Intent(); + intent.putExtra(PhotoActivity.TAG_IMGURL, list); + intent.setClass(EnterCompanyInfoActivity.this, PhotoActivity.class); + startActivity(intent); + } + }); + } + + /** + * 显示选择图片 + * + * @param bean + */ + private void showSelectPhoto(AddPhotoBean bean) { + hideSoftKeyboard(); + ButtomDialogView buttomDialogView = new ButtomDialogView.DialogBuilder(mActivity) + .setIsBackCancelable(true) + .setIscancelable(true) + .setShowLocation(Gravity.BOTTOM) + .setIsShowFile(false) + .build(); + buttomDialogView.addOnChoseListener(new ButtomDialogView.OnChoseListener() { + @Override + public void choseFile() { + } + + @Override + public void choseAlbum() { + mCurrentBean = bean; + Intent intent = new Intent(Intent.ACTION_PICK, null); + intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + "image/*"); + startActivityForResult(intent, BaseUrlApi.PHOTO_REQUEST); + buttomDialogView.dismiss(); + } + + @Override + public void choseShoot() { + mCurrentBean = bean; + mPicPath = PathConfig.CATCH_PATH + System.currentTimeMillis() + ".jpg"; + File file = new File(mPicPath); + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + // 下面这句指定调用相机拍照后的照片存储的路径 + Uri uri; + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { + uri = Uri.fromFile(file); + } else { + uri = FileProvider.getUriForFile(mActivity, ProiderUtil.getFileProviderName(mActivity), file); + } + intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + startActivityForResult(intent, BaseUrlApi.CAMERA_REQUEST); + } + + @Override + public void loginOut() { + + } + + @Override + public void changePwd() { + + } + }); + buttomDialogView.show(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (resultCode == RESULT_OK) { + switch (requestCode) { + case BaseUrlApi.CAMERA_REQUEST://相机 + uploadImg(mPicPath, 1); + break; + case BaseUrlApi.PHOTO_REQUEST://相册 + try { + if (data == null) return; + Uri uri = data.getData(); + String[] proj = {MediaStore.Images.Media.DATA}; + Cursor cursor = managedQuery(uri, proj, null, null, null); + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + String srcPath = cursor.getString(column_index); + uploadImg(srcPath, 2); + } catch (Exception e) { + e.printStackTrace(); + } + break; + } + } + super.onActivityResult(requestCode, resultCode, data); + } + + /** + * 上传文件 + * + * @param picPath + */ + private void uploadImg(String picPath, int src) { +// File file = new File(picPath); +// if (!file.exists()) { +// showToast("图片路径错误."); +// return; +// } +// ProgressDialog progressDialog = UIUtil.initDialog(mActivity, "正在上传..."); +// progressDialog.show(); +// Luban.with(mActivity) +// .load(picPath) +// .ignoreBy(100) +// .setTargetDir(PathConfig.CATCH_PATH) +// .filter(path -> !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"))) +// .setCompressListener(new OnCompressListener() { +// @Override +// public void onStart() { +// +// } +// +// @Override +// public void onSuccess(File file) { +// RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); +// MultipartBody.Part body = MultipartBody.Part.createFormData("image", file.getName(), requestFile); +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .uploadImage(body, UserLgUtils.getToken()) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(BaseUserBean baseUserBean) { +// if (progressDialog != null && progressDialog.isShowing()) { +// progressDialog.dismiss(); +// } +// ToastUtils.showShort("上传成功"); +// mPhotoIds += (baseUserBean.getData() + ","); +// mCurrentBean.setId(baseUserBean.getData()); +// mCurrentBean.setPath(picPath); +// if (mPhotos.size() < 4) { +// mPhotos.add(new AddPhotoBean()); +// } +// mPhotoAdapter.notifyDataSetChanged(); +// mCurrentBean = null; +// } +// +// @Override +// public void onError(Throwable e) { +// if (progressDialog != null && progressDialog.isShowing()) { +// progressDialog.dismiss(); +// } +// ToastUtils.showShort("上传失败,请稍后重试."); +// if (file.exists()) { +// file.delete(); +// } +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// @Override +// public void onError(Throwable e) { +// if (progressDialog.isShowing()) { +// progressDialog.dismiss(); +// } +// ToastUtils.showShort("图片上传失败,请稍后重试"); +// } +// }) +// .launch(); + } + @Override + protected void onDestroy() { + super.onDestroy(); + mBind.unbind(); + } + +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueCheckActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueCheckActivity.java index f47a8d7..773d53e 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueCheckActivity.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueCheckActivity.java @@ -149,15 +149,15 @@ public class IssueCheckActivity extends BaseActivity { * @param bean */ private void showDetail(IssueSubBean.RowsBean bean) { - Intent intent = new Intent(mActivity, IssueDetailActivity.class); - //待处理处理 - intent.putExtra("mine", "1"); - intent.putExtra("bean", bean); - if (bean.getCaseStatus().equals("4")) { - //待检查 - intent.putExtra("check", "1"); - } - startActivity(intent); +// Intent intent = new Intent(mActivity, IssueDetailActivity.class); +// //待处理处理 +// intent.putExtra("mine", "1"); +// intent.putExtra("bean", bean); +// if (bean.getCaseStatus().equals("4")) { +// //待检查 +// intent.putExtra("check", "1"); +// } +// startActivity(intent); } @Override diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineActivity.java index c6fb380..3e35a40 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineActivity.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineActivity.java @@ -89,9 +89,9 @@ public class IssueMineActivity extends BaseActivity { * @param bean */ private void showDetail(IssueSubBean.RowsBean bean) { - Intent intent = new Intent(mActivity, IssueDetailActivity.class); - intent.putExtra("bean", bean); - startActivity(intent); +// Intent intent = new Intent(mActivity, IssueDetailActivity.class); +// intent.putExtra("bean", bean); +// startActivity(intent); } private void getMineDisList(int page) { diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineDisActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineDisActivity.java index 7b99677..3721d30 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineDisActivity.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/issue/IssueMineDisActivity.java @@ -87,10 +87,10 @@ public class IssueMineDisActivity extends BaseActivity { * @param bean */ private void showDetail(IssueSubBean.RowsBean bean) { - Intent intent = new Intent(IssueMineDisActivity.this, IssueDetailActivity.class); - intent.putExtra("mine", "1"); - intent.putExtra("bean", bean); - startActivity(intent); +// Intent intent = new Intent(IssueMineDisActivity.this, IssueDetailActivity.class); +// intent.putExtra("mine", "1"); +// intent.putExtra("bean", bean); +// startActivity(intent); } private void getMineDisList(int page) { diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/locus/LocusManagerActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/locus/LocusManagerActivity.java index 2e3e640..306e43d 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/locus/LocusManagerActivity.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/locus/LocusManagerActivity.java @@ -57,7 +57,7 @@ public class LocusManagerActivity extends BaseActivity { refreshView(STATE_LOAD_SUCCESS); mTvPublish.setVisibility(View.VISIBLE); mTvPublish.setText("个人"); - mTvPublish.setOnClickListener(v -> startActivity(new Intent(mActivity, LocusMapActivity.class))); +// mTvPublish.setOnClickListener(v -> startActivity(new Intent(mActivity, LocusMapActivity.class))); Gson gson = new Gson(); String loginInfo = UserLgUtils.getLoginInfo(); if (!TextUtils.isEmpty(loginInfo)) { diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/trouble/SelCompanyActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/trouble/SelCompanyActivity.java new file mode 100644 index 0000000..524cda1 --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/trouble/SelCompanyActivity.java @@ -0,0 +1,37 @@ +package com.sucstepsoft.txrealtimelocation.activitys.trouble; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; +import com.sucstepsoft.txrealtimelocation.R; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * 选择企业 + */ +public class SelCompanyActivity extends BaseActivity { + + + private Unbinder mBind; + + @Override + protected int setLayoutId() { + return R.layout.activity_sel_company; + } + + @Override + public void initData() { + mBind = ButterKnife.bind(this); + mTvBaseTitle.setText("选择企业"); + refreshView(STATE_LOAD_SUCCESS); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mBind.unbind(); + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/trouble/TroubleReportActivity.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/trouble/TroubleReportActivity.java new file mode 100644 index 0000000..cb4b49b --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/activitys/trouble/TroubleReportActivity.java @@ -0,0 +1,42 @@ +package com.sucstepsoft.txrealtimelocation.activitys.trouble; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.TextView; + +import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity; +import com.sucstepsoft.txrealtimelocation.R; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * 隐患上报 + */ +public class TroubleReportActivity extends BaseActivity { + + @BindView(R.id.tv_sel_company) + TextView mTvSelCompany; + private Unbinder mBind; + + @Override + protected int setLayoutId() { + return R.layout.activity_trouble_report; + } + + @Override + public void initData() { + mBind = ButterKnife.bind(this); + refreshView(STATE_LOAD_SUCCESS); + mTvBaseTitle.setText("企业隐患上报"); + mTvSelCompany.setOnClickListener(v -> startActivity(new Intent(this, SelCompanyActivity.class))); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mBind.unbind(); + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/adapters/CompanyLibAdapter.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/adapters/CompanyLibAdapter.java new file mode 100644 index 0000000..0b8745c --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/adapters/CompanyLibAdapter.java @@ -0,0 +1,35 @@ +package com.sucstepsoft.txrealtimelocation.adapters; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter; +import com.sucstepsoft.txrealtimelocation.R; +import com.sucstepsoft.txrealtimelocation.adapters.holders.CompanyHolder; + +import java.util.List; + +/** + * 作者: adam + * 日期: 2020/3/29 - 14:43 + * 邮箱: itgaojian@163.com + * 描述: + */ +public class CompanyLibAdapter extends BaseRecyclerAdapter { + public CompanyLibAdapter(Context ctx, List list) { + super(ctx, list); + } + + @Override + public CompanyHolder createHolder(ViewGroup parent, int viewType) { + View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_company_lib, parent, false); + return new CompanyHolder(itemView); + } + + @Override + public void bindHolder(CompanyHolder companyHolder, int i) { + + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/adapters/holders/CompanyHolder.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/adapters/holders/CompanyHolder.java new file mode 100644 index 0000000..20f20e0 --- /dev/null +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/adapters/holders/CompanyHolder.java @@ -0,0 +1,21 @@ +package com.sucstepsoft.txrealtimelocation.adapters.holders; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.TextView; + +/** + * 作者: adam + * 日期: 2020/3/29 - 14:41 + * 邮箱: itgaojian@163.com + * 描述: 企业信息 + */ +public class CompanyHolder extends RecyclerView.ViewHolder { + public TextView mTvCompanyName; + public TextView mTvCompanyPeo; + + public CompanyHolder(@NonNull View itemView) { + super(itemView); + } +} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationChangBroadcastReceiver.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationChangBroadcastReceiver.java index 8c084d4..889f926 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationChangBroadcastReceiver.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationChangBroadcastReceiver.java @@ -4,10 +4,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import com.baidu.location.BDLocation; -import com.sucstepsoft.cm_utils.constant.PathConfig; -import com.sucstepsoft.txrealtimelocation.activitys.base.MainActivity; - import java.text.SimpleDateFormat; import java.util.Locale; @@ -20,23 +16,23 @@ public class LocationChangBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (action.equals(RECEIVER_ACTION)) { - BDLocation location = (BDLocation) intent.getParcelableExtra(RECEIVER_DATA); - if (null != location) { - processCustomMessageA(context, location); - } - } +// String action = intent.getAction(); +// if (action.equals(RECEIVER_ACTION)) { +// BDLocation location = (BDLocation) intent.getParcelableExtra(RECEIVER_DATA); +// if (null != location) { +// processCustomMessageA(context, location); +// } +// } } - private void processCustomMessageA(Context context, BDLocation aMapLocation) { - if (MainActivity.isForeground) { - Intent msgIntent = new Intent(PathConfig.ACTION_LOCATION_MESSAGE); - if (aMapLocation != null) { - msgIntent.putExtra("data", aMapLocation); - } - context.sendBroadcast(msgIntent); - } - } +// private void processCustomMessageA(Context context, BDLocation aMapLocation) { +// if (MainActivity.isForeground) { +// Intent msgIntent = new Intent(PathConfig.ACTION_LOCATION_MESSAGE); +// if (aMapLocation != null) { +// msgIntent.putExtra("data", aMapLocation); +// } +// context.sendBroadcast(msgIntent); +// } +// } } diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationService.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationService.java index 5b69383..d2ce278 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationService.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/LocationService.java @@ -1,1326 +1,1330 @@ -package com.sucstepsoft.txrealtimelocation.services; - -import android.content.BroadcastReceiver; -import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; -import android.media.MediaPlayer; -import android.os.Build; -import android.text.TextUtils; - -import com.baidu.location.BDAbstractLocationListener; -import com.baidu.location.BDLocation; -import com.baidu.location.LocationClient; -import com.baidu.location.LocationClientOption; -import com.baidu.mapapi.model.LatLng; -import com.baidu.mapapi.utils.SpatialRelationUtil; -import com.cjt2325.cameralibrary.util.DeviceUtil; -import com.google.gson.Gson; -import com.sucstepsoft.cm_utils.constant.PathConfig; -import com.sucstepsoft.cm_utils.constant.TimeConstants; -import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager; -import com.sucstepsoft.cm_utils.core.widget.base.NotificationUtils; -import com.sucstepsoft.cm_utils.utils.AppUtils; -import com.sucstepsoft.cm_utils.utils.LogUtils; -import com.sucstepsoft.cm_utils.utils.TimeUtils; -import com.sucstepsoft.cm_utils.utils.UserLgUtils; -import com.sucstepsoft.txrealtimelocation.R; -import com.sucstepsoft.txrealtimelocation.beans.CheckSignBean; -import com.sucstepsoft.txrealtimelocation.beans.CheckSignOffBean; -import com.sucstepsoft.txrealtimelocation.beans.LocationPosition; -import com.sucstepsoft.txrealtimelocation.beans.PenLineBean; -import com.sucstepsoft.txrealtimelocation.beans.SignTimeBean; -import com.sucstepsoft.txrealtimelocation.beans.SuccessBean; -import com.sucstepsoft.txrealtimelocation.net.LocationApiService; -import com.sucstepsoft.txrealtimelocation.utils.GpsUtils; -import com.sucstepsoft.txrealtimelocation.utils.PointUtils; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.Disposable; -import io.reactivex.schedulers.Schedulers; -import okhttp3.RequestBody; +import com.sucstepsoft.txrealtimelocation.services.NotificationService; +//package com.sucstepsoft.txrealtimelocation.services; +// +//import android.content.BroadcastReceiver; +//import android.content.Context; +//import android.content.Intent; +//import android.content.IntentFilter; +//import android.media.MediaPlayer; +//import android.os.Build; +//import android.text.TextUtils; +// +//import com.baidu.location.BDAbstractLocationListener; +//import com.baidu.location.BDLocation; +//import com.baidu.location.LocationClient; +//import com.baidu.location.LocationClientOption; +//import com.baidu.mapapi.model.LatLng; +//import com.baidu.mapapi.utils.SpatialRelationUtil; +//import com.cjt2325.cameralibrary.util.DeviceUtil; +//import com.google.gson.Gson; +//import com.sucstepsoft.cm_utils.constant.PathConfig; +//import com.sucstepsoft.cm_utils.constant.TimeConstants; +//import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager; +//import com.sucstepsoft.cm_utils.core.widget.base.NotificationUtils; +//import com.sucstepsoft.cm_utils.utils.AppUtils; +//import com.sucstepsoft.cm_utils.utils.LogUtils; +//import com.sucstepsoft.cm_utils.utils.TimeUtils; +//import com.sucstepsoft.cm_utils.utils.UserLgUtils; +//import com.sucstepsoft.txrealtimelocation.R; +//import com.sucstepsoft.txrealtimelocation.beans.CheckSignBean; +//import com.sucstepsoft.txrealtimelocation.beans.CheckSignOffBean; +//import com.sucstepsoft.txrealtimelocation.beans.LocationPosition; +//import com.sucstepsoft.txrealtimelocation.beans.PenLineBean; +//import com.sucstepsoft.txrealtimelocation.beans.SignTimeBean; +//import com.sucstepsoft.txrealtimelocation.beans.SuccessBean; +//import com.sucstepsoft.txrealtimelocation.net.LocationApiService; +//import com.sucstepsoft.txrealtimelocation.utils.GpsUtils; +//import com.sucstepsoft.txrealtimelocation.utils.PointUtils; +// +//import java.util.ArrayList; +//import java.util.Collections; +//import java.util.List; +//import java.util.concurrent.TimeUnit; +// +//import io.reactivex.Observable; +//import io.reactivex.Observer; +//import io.reactivex.android.schedulers.AndroidSchedulers; +//import io.reactivex.disposables.Disposable; +//import io.reactivex.schedulers.Schedulers; +//import okhttp3.RequestBody; +// +// public class LocationService extends NotificationService { - private IWifiAutoCloseDelegate mWifiAutoCloseDelegate = new WifiAutoCloseDelegate(); - private boolean mIsWifiCloseable = false; - private LocationClient mLocationClient; - private MediaPlayer mMediaPlayer; - private List mTempList = new ArrayList<>(); - private int mPrecision = 100;//定位精度 - private boolean isFirst = true; - private boolean isSaveLocal = false;//TODO 是否保存到本地 - private List> mPenLineList; - private BDLocation mCurrentLocation;//当前点 - private long mCurTime; - private long mUploadPointTime; - private int mCount = 1; - private boolean isUpload = false; - private Disposable mMTimeDis; - private boolean mIsHolday = false; - private int mUType = 2; //登录用户类型 //1是N员 2是片长 - private String mAmStartPunchTime = "08:30:00";//上午开始打卡时间 - private String mAmStartWorkTime = "09:30:00";//上午工作开始时间 - private String mAmEndWorkTime = "11:30:00";//上午工作结束时间 - private String mAmEndPunchTime = "12:30:00";//上午结束打卡时间 - private String mPmStartPunchTime = "13:30:00";//下午开始打卡时间 - private String mPmStartWorkTime = "14:30:00";//下午开始工作时间 - private String mPmEndWorkTime = "16:30:00";//下午结束工作时间 - private String mPmEndPunchTime = "17:30:00";//下午结束打卡时间 - private String mNStartPunchTime = "08:30:00";//N员开始打卡时间 - private String mNStartWorkTime = "10:00:00";//N员开始工作时间 - private String mNEndWorkTime = "17:00:00";//N员结束工作时间 - private String mNEndPunchTime = "18:00:00";//N员结束打开时间 - +// private IWifiAutoCloseDelegate mWifiAutoCloseDelegate = new WifiAutoCloseDelegate(); +// private boolean mIsWifiCloseable = false; +// private LocationClient mLocationClient; +// private MediaPlayer mMediaPlayer; +// private List mTempList = new ArrayList<>(); +// private int mPrecision = 100;//定位精度 +// private boolean isFirst = true; +// private boolean isSaveLocal = false;//TODO 是否保存到本地 +// private List> mPenLineList; +// private BDLocation mCurrentLocation;//当前点 +// private long mCurTime; +// private long mUploadPointTime; +// private int mCount = 1; +// private boolean isUpload = false; +// private Disposable mMTimeDis; +// private boolean mIsHolday = false; +// private int mUType = 2; //登录用户类型 //1是N员 2是片长 +// private String mAmStartPunchTime = "08:30:00";//上午开始打卡时间 +// private String mAmStartWorkTime = "09:30:00";//上午工作开始时间 +// private String mAmEndWorkTime = "11:30:00";//上午工作结束时间 +// private String mAmEndPunchTime = "12:30:00";//上午结束打卡时间 +// private String mPmStartPunchTime = "13:30:00";//下午开始打卡时间 +// private String mPmStartWorkTime = "14:30:00";//下午开始工作时间 +// private String mPmEndWorkTime = "16:30:00";//下午结束工作时间 +// private String mPmEndPunchTime = "17:30:00";//下午结束打卡时间 +// private String mNStartPunchTime = "08:30:00";//N员开始打卡时间 +// private String mNStartWorkTime = "10:00:00";//N员开始工作时间 +// private String mNEndWorkTime = "17:00:00";//N员结束工作时间 +// private String mNEndPunchTime = "18:00:00";//N员结束打开时间 +// @Override public int onStartCommand(Intent intent, int flags, int startId) { - super.onStartCommand(intent, flags, startId); - mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.no_kill); - mMediaPlayer.setLooping(true); - registerIsSendNogify(); - applyNotiKeepMech(); //开启利用notification提高进程优先级的机制 - startPlayMusic(); - if (mWifiAutoCloseDelegate.isUseful(getApplicationContext())) { - mIsWifiCloseable = true; - mWifiAutoCloseDelegate.initOnServiceStarted(getApplicationContext()); - } - LogUtils.e("开启了"); - mUploadPointTime = System.currentTimeMillis(); - registerTimeReceiver(); - saveFile(12); - startLocation(); - //TODO 开启Socket -// startSocket(); - //获取电子围栏数据 - getUserPenList(); - registerGpsState(); - //校验是否签到 - checkSign(); - registerUploadPointListener(); - registerSi(); -// registerSignStateListener(); +// super.onStartCommand(intent, flags, startId); +// mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.no_kill); +// mMediaPlayer.setLooping(true); +// registerIsSendNogify(); +// applyNotiKeepMech(); //开启利用notification提高进程优先级的机制 +// startPlayMusic(); +// if (mWifiAutoCloseDelegate.isUseful(getApplicationContext())) { +// mIsWifiCloseable = true; +// mWifiAutoCloseDelegate.initOnServiceStarted(getApplicationContext()); +// } +// LogUtils.e("开启了"); +// mUploadPointTime = System.currentTimeMillis(); +// registerTimeReceiver(); +// saveFile(12); +// startLocation(); +// //TODO 开启Socket +//// startSocket(); +// //获取电子围栏数据 +// getUserPenList(); +// registerGpsState(); +// //校验是否签到 +// checkSign(); +// registerUploadPointListener(); +// registerSi(); +//// registerSignStateListener(); return START_STICKY; } - - private void registerSignStateListener() { - Observable.interval(1, TimeUnit.MINUTES) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Long aLong) { - int notifyType = getNotifyType(); - LogUtils.e(notifyType); - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - private void registerTimeReceiver() { - PunchTimeReceiver receiver = new PunchTimeReceiver(); - IntentFilter filter = new IntentFilter(); - filter.addAction(PathConfig.ACTION_PUNCH_TIME_MESSAGE); - filter.addAction(PathConfig.ACTION_STOP_LOCATION); - filter.addAction(PathConfig.ACTION_START_LOCATION); - registerReceiver(receiver, filter); - } - - private void registerGpsState() { - Observable.interval(5, TimeUnit.SECONDS) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Long aLong) { - checkGpsState(); - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - private void registerSi() { - Observable.interval(50, TimeUnit.SECONDS) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Long aLong) { - if (!mIsHolday) { - String chineseWeek = TimeUtils.getDayOfWeek(); - if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { - getIsSign(); - } - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - private static final int NOTIFY_TYPE_P_AM_SIGN_1 = 1221;//片长上午签到提前一分钟 - private static final int NOTIFY_TYPE_P_AM_SIGN_5 = 1222;//片长上午签到开始后五分钟 - private static final int NOTIFY_TYPE_P_AM_SIGN_OUT_1 = 1223;//片长上午签退提前一分钟 - private static final int NOTIFY_TYPE_P_AM_SIGN_OUT_5 = 1224;//片长上午签退开始后五分钟 - - private static final int NOTIFY_TYPE_P_PM_SIGN_1 = 1225;//片长下午签到提前一分钟 - private static final int NOTIFY_TYPE_P_PM_SIGN_5 = 1226;//片长下午签到开始后五分钟 - private static final int NOTIFY_TYPE_P_PM_SIGN_OUT_1 = 1227;//片长下午签退提前一分钟 - private static final int NOTIFY_TYPE_P_PM_SIGN_OUT_5 = 1228;//片长下午签退开始后五分钟 - - - private static final int NOTIFY_TYPE_N_SIGN_1 = 2321;//签到提前一分钟 - private static final int NOTIFY_TYPE_N_SIGN_5 = 2322;//签到开始后五分钟 - private static final int NOTIFY_TYPE_N_SIGN_OUT_1 = 2324;//签退开始前一分钟 - private static final int NOTIFY_TYPE_N_SIGN_OUT_5 = 2325;//签退开始后五分钟 - - - private int getNotifyType() { - //判断当前时间是开始打开前一分钟还是后五分钟 - int type = -1; - String nowHourMM = TimeUtils.getNowHourMM(); - LogUtils.e(nowHourMM); - if (mUType != 0) { - //判断是片长还是N员 - //1是N员 2是片长 - if (mUType == 1) { - //N员提醒 - String startTime = mNStartPunchTime; - String endTime = mNEndWorkTime; - String currentTimeOneSpan = TimeUtils.getCurrentTimeSpan(startTime, -1); - String curTimeFiveSpan = TimeUtils.getCurrentTimeSpan(startTime, 5); - String curEndTimeOneSpan = TimeUtils.getCurrentTimeSpan(endTime, -1); - String curEndTimeFiveSpan = TimeUtils.getCurrentTimeSpan(endTime, 5); - if (currentTimeOneSpan.equals(nowHourMM)) { - type = NOTIFY_TYPE_N_SIGN_1; - } - if (curTimeFiveSpan.equals(nowHourMM)) { - type = NOTIFY_TYPE_N_SIGN_5; - } - if (curEndTimeOneSpan.equals(nowHourMM)) { - type = NOTIFY_TYPE_N_SIGN_OUT_1; - } - if (curEndTimeFiveSpan.equals(nowHourMM)) { - type = NOTIFY_TYPE_N_SIGN_OUT_5; - } - } else { - String pAmStartTime = mAmStartPunchTime; - String pAmEndTime = mAmEndWorkTime; - String pPmStartTime = mPmStartPunchTime; - String pPmEndTime = mPmEndWorkTime; - String amStartTimeOne = TimeUtils.getCurrentTimeSpan(pAmStartTime, -1); - String amStartTimeFive = TimeUtils.getCurrentTimeSpan(pAmStartTime, 5); - String amEndTimeOne = TimeUtils.getCurrentTimeSpan(pAmEndTime, -1); - String amEndTimeFive = TimeUtils.getCurrentTimeSpan(pAmEndTime, 5); - - String pmStartTimeOne = TimeUtils.getCurrentTimeSpan(pPmStartTime, -1); - String pmStartTimeFive = TimeUtils.getCurrentTimeSpan(pPmStartTime, 5); - String pmEndTimeOne = TimeUtils.getCurrentTimeSpan(pPmEndTime, -1); - String pmEndTimeFive = TimeUtils.getCurrentTimeSpan(pPmEndTime, 5); - if (amStartTimeOne.equals(nowHourMM)) { - return NOTIFY_TYPE_P_AM_SIGN_1; - } - if (amStartTimeFive.equals(nowHourMM)) { - return NOTIFY_TYPE_P_AM_SIGN_5; - } - if (amEndTimeOne.equals(nowHourMM)) { - return NOTIFY_TYPE_P_AM_SIGN_OUT_1; - } - if (amEndTimeFive.equals(nowHourMM)) { - return NOTIFY_TYPE_P_AM_SIGN_OUT_5; - } - if (pmStartTimeOne.equals(nowHourMM)) { - return NOTIFY_TYPE_P_PM_SIGN_1; - } - if (pmStartTimeFive.equals(nowHourMM)) { - return NOTIFY_TYPE_P_PM_SIGN_5; - } - if (pmEndTimeOne.equals(nowHourMM)) { - return NOTIFY_TYPE_P_PM_SIGN_OUT_1; - } - if (pmEndTimeFive.equals(nowHourMM)) { - return NOTIFY_TYPE_P_PM_SIGN_OUT_5; - } - } - } - return type; - } - - private void getIsSign() { - String token = GlobalProvider.getString(LocationService.this, "token"); - if (!TextUtils.isEmpty(token)) { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .checkSign(token) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(CheckSignBean checkSignBean) { - if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData().getIsSign())) { - boolean b = Boolean.parseBoolean(checkSignBean.getData().getIsSign()); - if (!b) { - String nowHourMM = TimeUtils.getNowHourMM(); - String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); - if ("N".equals(userType)) { - //N员 - if (!TextUtils.isEmpty(nowHourMM)) { - if (!TextUtils.isEmpty(mNStartPunchTime)) { - String currentTime = TimeUtils.getCurrentTime(mNStartPunchTime); - if (nowHourMM.equals(currentTime)) { - sendNotifySignN(1); - } - } - } - } else { - if (!TextUtils.isEmpty(nowHourMM)) { - if (!TextUtils.isEmpty(mAmStartPunchTime)) { - String currentTime = TimeUtils.getCurrentTime(mAmStartPunchTime); - if (nowHourMM.equals(currentTime)) { - sendNotifySign(1); - } - } - if (!TextUtils.isEmpty(mPmStartPunchTime)) { - String currentTime = TimeUtils.getCurrentTime(mPmStartPunchTime); - if (nowHourMM.equals(currentTime)) { - sendNotifySign(3); - } - } - } - } - } else { - getIsSignOff(); - } - } - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onComplete() { - - } - }); - } - } - - private void getIsSignOff() { - String token = GlobalProvider.getString(LocationService.this, "token"); - if (!TextUtils.isEmpty(token)) { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .checkSignOff(UserLgUtils.getToken()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(CheckSignOffBean checkSignBean) { - if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData())) { - boolean b = Boolean.parseBoolean(checkSignBean.getData()); - if (!b) { - String nowHourMM = TimeUtils.getNowHourMM(); - String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); - if ("N".equals(userType)) { - //N员 - String currentTime = TimeUtils.getCurrentTime(mNEndWorkTime); - if (!TextUtils.isEmpty(nowHourMM)) { - if (nowHourMM.equals(currentTime)) { - sendNotifySignN(2); - } - } - } else { - //片长 - if (!TextUtils.isEmpty(mAmEndWorkTime)) { - String currentTime = TimeUtils.getCurrentTime(mAmEndWorkTime); - if (nowHourMM.equals(currentTime)) { - sendNotifySign(2); - } - } - if (!TextUtils.isEmpty(mPmEndWorkTime)) { - String currentTime = TimeUtils.getCurrentTime(mPmEndWorkTime); - if (nowHourMM.equals(currentTime)) { - sendNotifySign(4); - } - } - } - } - } - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onComplete() { - - } - }); - } - } - - private void registerIsSendNogify() { - Observable.interval(50, TimeUnit.SECONDS) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Long aLong) { - String isHolday = GlobalProvider.getString(LocationService.this, "isHolday", ""); - if (!TextUtils.isEmpty(isHolday)) { - if ("1".equals(isHolday)) { - mIsHolday = true; - } else { - mIsHolday = false; - } - } else { - mIsHolday = false; - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - - } - - /** - * 发送N员通知 - * - * @param i - */ - private void sendNotifySignN(int i) { - NotificationUtils utils = new NotificationUtils(LocationService.this); - String title = ""; - String content = ""; - switch (i) { - case 1: - title = "签到提醒"; - content = "请在" + mNStartPunchTime + "-" + mNStartWorkTime + "进行签到"; - break; - case 2: - title = "签退提醒"; - content = "请在" + mNEndWorkTime + "-" + mNEndPunchTime + "进行签退"; - break; - } - utils.sendNotification(666, title, content); - } - - private void sendNotifySign(int i) { - NotificationUtils utils = new NotificationUtils(LocationService.this); - String title = ""; - String content = ""; - switch (i) { - case 1: - title = "签到提醒"; - content = "请在" + mAmStartPunchTime + "-" + mAmStartWorkTime + "进行上午签到"; - break; - case 2: - title = "签退提醒"; - content = "请在" + mAmEndWorkTime + "-" + mAmEndPunchTime + "进行上午签退"; - break; - case 3: - title = "签到提醒"; - content = "请在" + mPmStartPunchTime + "-" + mPmStartWorkTime + "进行下午签到"; - break; - case 4: - title = "签退提醒"; - content = "请在" + mPmEndWorkTime + "-" + mPmEndPunchTime + "进行下午签退"; - break; - } - utils.sendNotification(555, title, content); - } - - private void registerUploadPointListener() { - Observable.interval(1, 1, TimeUnit.MINUTES) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Long aLong) { - if (mUploadPointTime != 0) { - long timeSpan = TimeUtils.getTimeSpan(System.currentTimeMillis(), mUploadPointTime, TimeConstants.MIN); - if (timeSpan >= 9) { - if (!mIsHolday) { - String chineseWeek = TimeUtils.getDayOfWeek(); - if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { - mUploadPointTime = System.currentTimeMillis(); - String nowHour = TimeUtils.getNowHour(); - if (TimeUtils.isInTime("08:30-12:30", nowHour) || TimeUtils.isInTime("13:30-17:30", nowHour)) { - if (canUpload()) { - startLocation(); - } - NotificationUtils utils = new NotificationUtils(LocationService.this); - utils.sendNotification(45, "应急管理", "您已较长时间未上传定位信息,可能当前位置信号弱,请检查GPS和数据开关设置或者移动到开阔位置."); - } - } - } - } - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - //保存 - private void saveFile(int i) { - if (i == 12) { - String start = "定位服务已经开启:" + GlobalProvider.getString(LocationService.this, "token") + "手机参数:" + DeviceUtil.getDeviceInfo() + "App版本:" + AppUtils.getAppVersionName(); - Utils.saveFile(start, "testLocation.txt", true); - } else { - String end = "定位服务关闭"; - Utils.saveFile(end, "testLocation.txt", true); - } - } - - /** - * 获取当前时间 - */ - private void checkSign() { - Observable.interval(0, 5, TimeUnit.MINUTES) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - mMTimeDis = d; - } - - @Override - public void onNext(Long aLong) { - checkIsSign(); - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - /** - * 校验是否签到 - */ - private void checkIsSign() { - String token = GlobalProvider.getString(LocationService.this, "token"); - if (!TextUtils.isEmpty(token)) { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .checkSign(token) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(CheckSignBean checkSignBean) { - if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData().getIsSign())) { - boolean b = Boolean.parseBoolean(checkSignBean.getData().getIsSign()); - if (b) { - //已经签到 - checkSignOff(); - } else { - //未签到 - if (!mIsHolday) { - String chineseWeek = TimeUtils.getDayOfWeek(); - if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { - String nowHourMM = TimeUtils.getNowHourMM(); - String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); - if ("N".equals(userType)) { - //N员 - String nStartPunchTime = mNStartPunchTime; - String nStartWorkTime = mNStartWorkTime; - if (TimeUtils.isInTime(nStartPunchTime + "-" + nStartWorkTime, nowHourMM)) { - sendNotif(1); - } - } else { - //片长 - String amStartPunchTime = mAmStartPunchTime; - String amStartWorkTime = mAmStartWorkTime; - String pmStartPunchTime = mPmStartPunchTime; - String pmStartWorkTime = mPmStartWorkTime; - if (TimeUtils.isInTime(amStartPunchTime + "-" + amStartWorkTime, nowHourMM) || TimeUtils.isInTime(pmStartPunchTime + "-" + pmStartWorkTime, nowHourMM)) { - sendNotif(1); - } - } - } - } - } - } - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onComplete() { - - } - }); - } - } - - //发送签提醒 - private void sendNotif(int i) { - if (!mIsHolday) { - if (isWeek()) { - NotificationUtils utils = new NotificationUtils(LocationService.this); - if (i == 1) { - utils.sendNotification(23, "签到提醒", "当前未签到,请进行签到."); - } else { - utils.sendNotification(23, "签退提醒", "当前未签退,请进行签退."); - } - } - } - } - - private boolean isWeek() { - String chineseWeek = TimeUtils.getDayOfWeek(); - if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { - return true; - } else { - return false; - } - } - - private void checkGpsState() { - boolean oPen = GpsUtils.isOPen(LocationService.this); - if (!oPen) { - if (!mIsHolday) { - String nowHour = TimeUtils.getNowHour(); - if (isWeek()) { - if (TimeUtils.isInTime("08:30-12:30", nowHour) || TimeUtils.isInTime("13:30-17:30", nowHour)) { - NotificationUtils utils = new NotificationUtils(LocationService.this); - utils.sendNotification(55, "GPS提醒", "当前GPS已关闭,请前往设置页面进行开启."); - } - } - } - } - } - - /** - * 校验是否签退 - */ - private void checkSignOff() { - String token = GlobalProvider.getString(LocationService.this, "token", ""); - if (!TextUtils.isEmpty(token)) { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .checkSignOff(token) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(CheckSignOffBean checkSignBean) { - if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData())) { - boolean b = Boolean.parseBoolean(checkSignBean.getData()); - if (b) { - //已经签退 - } else { - //没有签退 - if (!mIsHolday) { - String nowHourMM = TimeUtils.getNowHour(); - //时间段在12点与13点半之间或者17点与19点之间,提示签退 - String chineseWeek = TimeUtils.getDayOfWeek(); - if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { - String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); - if ("N".equals(userType)) { - //N员 - String nEndWorkTime = mNEndWorkTime;//GlobalProvider.getString(LocationService.this, "nEndWorkTime", "17:00:00"); - String nEndPunchTime = mNEndPunchTime;//GlobalProvider.getString(LocationService.this, "nEndPunchTime", "18:00:00"); - if (TimeUtils.isInTime(nEndWorkTime + "-" + nEndPunchTime, nowHourMM)) { - sendNotif(23); - } - } else { - //片长 - String amEndWorkTime = mAmEndWorkTime;//GlobalProvider.getString(LocationService.this, "amEndWorkTime", "11:30:00"); - String amEndPunchTime = mAmEndPunchTime; //GlobalProvider.getString(LocationService.this, "amEndPunchTime", "12:30:00"); - String pmEndWorkTime = mPmEndWorkTime;// GlobalProvider.getString(LocationService.this, "pmEndWorkTime", "16:30:00"); - String pmEndPunchTime = mPmEndPunchTime;// GlobalProvider.getString(LocationService.this, "pmEndPunchTime", "17:30:00"); - if (TimeUtils.isInTime(amEndWorkTime + "-" + amEndPunchTime, nowHourMM) || TimeUtils.isInTime(pmEndWorkTime + "-" + pmEndPunchTime, nowHourMM)) { - sendNotif(23); - } - } - } - } - } - } - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onComplete() { - - } - }); - } - - } - - - /** - * 电子围栏数据 - */ - private void getUserPenList() { - String token = GlobalProvider.getString(LocationService.this, "token"); - if (!TextUtils.isEmpty(token)) { - RetrofitManager.getInstance() - .create(LocationApiService.class) - .getUserPenList(token) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer>() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(List penLineBeans) { - if (penLineBeans != null && penLineBeans.size() > 0) { - buildPenList(penLineBeans); - } - } - - @Override - public void onError(Throwable e) { -// ToastUtils.showShort("获取围栏数据失败,请稍后重试"); - } - - @Override - public void onComplete() { - - } - }); - } - - } - - private void buildPenList(List penLineBeans) { - mPenLineList = new ArrayList<>(); - for (int i = 0; i < penLineBeans.size(); i++) { - List areaPoints = penLineBeans.get(i).getAreaPoints(); - if (areaPoints != null && areaPoints.size() > 0) { - List tempList = new ArrayList<>(); - for (int j = 0; j < areaPoints.size(); j++) { - LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(j).getLatitude()), Double.parseDouble(areaPoints.get(j).getLongitude())); - tempList.add(latLng); - } - LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(0).getLatitude()), Double.parseDouble(areaPoints.get(0).getLongitude())); - tempList.add(latLng); - mPenLineList.add(tempList); - } - } - } - - private void startPlayMusic() { - new Thread(() -> startPlaySong()).start(); - } - - private void startPlaySong() { - if (mMediaPlayer == null) { - mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.no_kill); - mMediaPlayer.start(); - } else { - mMediaPlayer.start(); - } - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - if (mMediaPlayer != null) { - mMediaPlayer.pause(); - } - } - - @Override - public void onDestroy() { - saveFile(13); - unApplyNotiKeepMech(); - stopLocation(); - stopPlaySong(); - if (mMTimeDis != null && !mMTimeDis.isDisposed()) { - mMTimeDis.dispose(); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(getApplicationContext(), LocationService.class)); - } else { - startService(new Intent(getApplicationContext(), LocationService.class)); - } - super.onDestroy(); - } - - private void stopPlaySong() { - if (mMediaPlayer != null) { - mMediaPlayer.pause(); - mMediaPlayer.stop(); - mMediaPlayer.release(); - mMediaPlayer = null; - } - } - - private class MyLocationListener extends BDAbstractLocationListener { - - @Override - public void onReceiveLocation(BDLocation bdLocation) { - if (bdLocation != null && bdLocation.getLatitude() != 0 && bdLocation.getLongitude() != 0) { - if (bdLocation.getLongitude() != Double.MIN_VALUE && bdLocation.getLongitude() != Double.MIN_VALUE) { - checkPointIs(bdLocation); - sendLocationBroadcast(bdLocation); - mWifiAutoCloseDelegate.onLocateSuccess(getApplicationContext(), PowerManagerUtil.getInstance().isScreenOn(getApplicationContext()), NetUtil.getInstance().isMobileAva(getApplicationContext())); - } - } else { - mWifiAutoCloseDelegate.onLocateFail(getApplicationContext(), 10, PowerManagerUtil.getInstance().isScreenOn(getApplicationContext()), NetUtil.getInstance().isWifiCon(getApplicationContext())); - } - } - - private void sendLocationBroadcast(BDLocation bdLocation) { - if (null != bdLocation) { - if (checkSinglePoint(bdLocation)) { - if (mTempList.size() >= 25) { - checkPoints(); - } else { - mTempList.add(bdLocation); - } - } - } - } - } - - private void checkPointIs(BDLocation bdLocation) { - if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode()) && bdLocation.getRadius() <= 300) { - Intent mIntent = new Intent(PathConfig.ACTION_LOCATION_MESSAGE); - mIntent.putExtra("data", bdLocation); - sendBroadcast(mIntent); -// LatLng latLng1 = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); -// LatLng latLng2 = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); -// boolean circleContainsPoint = SpatialRelationUtil.isCircleContainsPoint(latLng1, 50, latLng2); -// if (circleContainsPoint) { // -// } - } - } - - /** - * 校验定位点的合法性 - * - * @param bdLocation - * @return - */ - private boolean checkSinglePoint(BDLocation bdLocation) { - boolean isLegal = false; - if (isFirst) { - if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode())) { - isLegal = true; - } else { - isLegal = false; - } - } else { - if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode()) && bdLocation.getRadius() <= mPrecision) { - if (mCurrentLocation != null) { - LatLng latLng1 = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); - LatLng latLng2 = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); - boolean circleContainsPoint = SpatialRelationUtil.isCircleContainsPoint(latLng1, 50, latLng2); - if (circleContainsPoint) { - mCurrentLocation = bdLocation; - isLegal = true; - } else { - isLegal = false; - } - } else { - mCurrentLocation = bdLocation; - isLegal = true; - } - } else { - isLegal = false; - } - } - return isLegal; - } - - /** - * 根据定位精度取最小精度 - */ - private void checkPoints() { - Collections.sort(mTempList, (o1, o2) -> { - if (o1.getRadius() > o2.getRadius()) { - return 1; - } else if (o1.getRadius() < o2.getRadius()) { - return -1; - } else { - return 0; - } - }); - buildUploadPoint(); - } - - /** - * 存在网络上传 - */ - private void buildUploadPoint() { - isFirst = false; - if (mTempList.size() > 0) { - if (NetUtil.getInstance().isNetworkConnected(getApplicationContext())) { - LocationPosition position = new LocationPosition(); - position.setUserLatitude(mTempList.get(0).getLatitude() + ""); - position.setUserLongitude(mTempList.get(0).getLongitude() + ""); - position.setUserLocation(mTempList.get(0).getAddress().address); - position.setUserSpeed(mTempList.get(0).getSpeed() + ""); - Gson gson = new Gson(); - String s = gson.toJson(position); - uploadLocation(s); - checkCurrenPointIsBeyond(mTempList.get(0)); - } else { - //TODO 无网络状态下是否保存 - if (isSaveLocal) { - String textPoint = "{\"userLongitude\":" + mTempList.get(0).getLongitude() + ",\"userLatitude\":" + mTempList.get(0).getLatitude() + ",\"userLocation\":\"" + mTempList.get(0).getAddrStr() + "\",\"createTime\":\"" + Utils.formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\"}"; - Utils.saveFile(textPoint, "testLocation.txt", true); - } - } - } - } - - /** - * 是否在片区内 - * - * @param cur - * @return true 在片区内 false 不在片区内 - */ - private boolean isBeyond(LatLng cur) { - boolean isBeyond = false; - for (int i = 0; i < mPenLineList.size(); i++) { - boolean inPolygon = PointUtils.isInPolygon(cur, mPenLineList.get(i)); - if (inPolygon) { - isBeyond = true; - break; - } - } - return isBeyond; - } - - /** - * 判断是否越界 - * - * @param bdLocation - */ - private void checkCurrenPointIsBeyond(BDLocation bdLocation) { - if (!mIsHolday) { - String chineseWeek = TimeUtils.getDayOfWeek(); - if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { - if (mPenLineList != null && mPenLineList.size() > 0) { - LatLng latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); - boolean isByond = isBeyond(latLng); - if (!isByond) { - //越界了 - if (mCount > 3) { - if (mCurTime != 0) { - long timeSpan = TimeUtils.getTimeSpan(System.currentTimeMillis(), mCurTime, TimeConstants.MIN); - if (timeSpan > 30) { - String nowHour = TimeUtils.getNowHourMM(); - if (TimeUtils.isInTime("09:00-12:10", nowHour) || TimeUtils.isInTime("13:30-17:00", nowHour)) { - NotificationUtils utils = new NotificationUtils(LocationService.this); - utils.sendNotification("越界提醒", "你当前位置超过了所监管区域"); - } - mCurTime = TimeUtils.getNowMills(); - } - } else { - mCurTime = TimeUtils.getNowMills(); - } - } else { - ++mCount; - String nowHour = TimeUtils.getNowHourMM(); - if (TimeUtils.isInTime("09:00-12:10", nowHour) || TimeUtils.isInTime("13:30-17:00", nowHour)) { - NotificationUtils utils = new NotificationUtils(LocationService.this); - utils.sendNotification("越界提醒", "你当前位置超过了所监管区域"); - } - } - } - } - } - } - } - - private boolean canUpload() { - String nowHourMM = TimeUtils.getNowHourMM(); - String upStart = mAmStartPunchTime; - String upEnd = mNEndPunchTime; - boolean isup = TimeUtils.isInTime(upStart + "-" + upEnd, nowHourMM); - return isup; - } - - /** - * 上传数据 - * - * @param points - */ - private void uploadLocation(String points) { - isFirst = false; - String token = GlobalProvider.getString(LocationService.this, "token"); - if (!TextUtils.isEmpty(token)) { - if (isUpload) { - mCurrentLocation = null; - mTempList.clear(); - } else { - boolean canUp = canUpload(); - if (canUp) { - isUpload = true; - RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), points); - RetrofitManager.getInstance() - .create(LocationApiService.class) - .saveLocationData(body, token) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(SuccessBean successBean) { - isUpload = false; - mCurrentLocation = null; - mTempList.clear(); - mUploadPointTime = System.currentTimeMillis(); - Intent intent = new Intent(); - intent.setAction("com.sucstepsoft.realtimelocation.isonlone"); - intent.putExtra("uploadTime", mUploadPointTime + ""); - sendBroadcast(intent); - } - - @Override - public void onError(Throwable e) { - isUpload = false; - mCurrentLocation = null; - mTempList.clear(); - e.printStackTrace(); - } - - @Override - public void onComplete() { - - } - }); - } else { - mTempList.clear(); - } - } - } - } - - - /** - * 配置定位参数 - */ - private void startLocation() { - stopLocation(); - mLocationClient = new LocationClient(getApplicationContext()); - //声明LocationClient类实例并配置定位参数 - LocationClientOption locationOption = new LocationClientOption(); - MyLocationListener myLocationListener = new MyLocationListener(); - //注册监听函数 - mLocationClient.registerLocationListener(myLocationListener); - //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 - locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); - //可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll; - locationOption.setCoorType("bd09ll"); - //可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的 - locationOption.setScanSpan(5000); - //可选,设置是否需要地址信息,默认不需要 - locationOption.setIsNeedAddress(true); - //设置是否运行模拟GPS -// locationOption.setEnableSimulateGps(false); - //可选,设置是否需要设备方向结果 - locationOption.setNeedDeviceDirect(false); - //可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果 - locationOption.setLocationNotify(true); - //可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死 - locationOption.setIgnoreKillProcess(true); - //可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近” - locationOption.setIsNeedLocationDescribe(true); - //可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到 - locationOption.setIsNeedLocationPoiList(true); - //可选,默认false,设置是否收集CRASH信息,默认收集 - locationOption.SetIgnoreCacheException(false); - //可选,默认false,设置是否开启Gps定位 - locationOption.setOpenGps(true); - //可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用 - locationOption.setIsNeedAltitude(false); - //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者,该模式下开发者无需再关心定位间隔是多少,定位SDK本身发现位置变化就会及时回调给开发者 -// locationOption.setOpenAutoNotifyMode(); - //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 -// locationOption.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); - //需将配置好的LocationClientOption对象,通过setLocOption方法传递给LocationClient对象使用 - mLocationClient.setLocOption(locationOption); - //开始定位 - mLocationClient.start(); - } - - void stopLocation() { - if (null != mLocationClient) { - mLocationClient.stop(); - } - } - - - /** - * 签到时间改变 - */ - private class PunchTimeReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (PathConfig.ACTION_PUNCH_TIME_MESSAGE.equals(action)) { - SignTimeBean timeBean = (SignTimeBean) intent.getSerializableExtra("timeBean"); - mUType = intent.getIntExtra("uType", 2); - if (timeBean != null) { - mAmStartPunchTime = timeBean.getAmStartPunchTime();//上午开始打卡时间 - mAmStartWorkTime = timeBean.getAmStartWorkTime();//"09:30:00";//上午工作开始时间 - mAmEndWorkTime = timeBean.getAmEndWorkTime();//"11:30:00";//上午工作结束时间 - mAmEndPunchTime = timeBean.getAmEndPunchTime();//"12:30:00";//上午结束打卡时间 - mPmStartPunchTime = timeBean.getPmStartPunchTime();//"13:30:00";//下午开始打卡时间 - mPmStartWorkTime = timeBean.getPmStartWorkTime();//"14:30:00";//下午开始工作时间 - mPmEndWorkTime = timeBean.getPmEndWorkTime();//"16:30:00";//下午结束工作时间 - mPmEndPunchTime = timeBean.getPmEndPunchTime();//"17:30:00";//下午结束打卡时间 - mNStartPunchTime = timeBean.getNStartPunchTime();//"08:30:00";//N员开始打卡时间 - mNStartWorkTime = timeBean.getNStartWorkTime();//"10:00:00";//N员开始工作时间 - mNEndWorkTime = timeBean.getNEndWorkTime();// "17:00:00";//N员结束工作时间 - mNEndPunchTime = timeBean.getNEndPunchTime();// "18:00:00";//N员结束打开时间 - } - } else if (PathConfig.ACTION_STOP_LOCATION.equals(action)) { - startLocation(); - } else if (PathConfig.ACTION_START_LOCATION.equals(action)) { - startLocation(); - } - } - } -// 109.91829190601483 40.59518382351867 -// 109.91825597379443 40.59669718527541 -// 109.92120480199132 40.596745087745845 -// 109.92360987463378 40.596796480184544 -// 109.92366826449192 40.59486540000251 -// 109.9212017140661 40.59484141029425 -// 109.9197561439961 40.59517012777953 - -// private SocketActionAdapter socketListener = new SocketActionAdapter() { -// //当Socket连接建立成功后 -// @Override -// public void onSocketConnectionSuccess(ConnectionInfo info, String action) { -// LogUtils.e("当Socket连接建立成功后==" + action); -// mManager.send(new HandShakeBean()); -// mManager.getPulseManager().setPulseSendable(new PulseBean()); -// } +// private void registerSignStateListener() { +// Observable.interval(1, TimeUnit.MINUTES) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { // -// //Socket断开后进行的回调 -// @Override -// public void onSocketDisconnection(ConnectionInfo info, String action, Exception e) { -// LogUtils.e("Socket断开后进行的回调==" + action); -// } +// } // -// //当Socket连接失败时会进行回调 -// @Override -// public void onSocketConnectionFailed(ConnectionInfo info, String action, Exception e) { -// LogUtils.e("当Socket连接失败时会进行回调==" + action); -// } +// @Override +// public void onNext(Long aLong) { +// int notifyType = getNotifyType(); +// LogUtils.e(notifyType); +// } // -// //Socket通讯从服务器读取到消息后的响应 -// @Override -// public void onSocketReadResponse(ConnectionInfo info, String action, OriginalData data) { -// LogUtils.e("Socket通讯从服务器读取到消息后的响应==" + action); -// String str = new String(data.getBodyBytes(), Charset.forName("utf-8")); -// JsonObject jsonObject = new JsonParser().parse(str).getAsJsonObject(); -// int cmd = jsonObject.get("cmd").getAsInt(); -// if (cmd == 54) {//登陆成功 -// String handshake = jsonObject.get("handshake").getAsString(); -// } else if (cmd == 57) {//切换,重定向.(暂时无法演示,如有疑问请咨询github) -// LogUtils.e("=====重定向===="); -// } else if (cmd == 14) {//心跳 -// mManager.getPulseManager().feed(); -// LogUtils.e("心跳包发送"); +// @Override +// public void onError(Throwable e) { +// +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// private void registerTimeReceiver() { +// PunchTimeReceiver receiver = new PunchTimeReceiver(); +// IntentFilter filter = new IntentFilter(); +// filter.addAction(PathConfig.ACTION_PUNCH_TIME_MESSAGE); +// filter.addAction(PathConfig.ACTION_STOP_LOCATION); +// filter.addAction(PathConfig.ACTION_START_LOCATION); +// registerReceiver(receiver, filter); +// } +// +// private void registerGpsState() { +// Observable.interval(5, TimeUnit.SECONDS) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(Long aLong) { +// checkGpsState(); +// } +// +// @Override +// public void onError(Throwable e) { +// +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// private void registerSi() { +// Observable.interval(50, TimeUnit.SECONDS) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(Long aLong) { +// if (!mIsHolday) { +// String chineseWeek = TimeUtils.getDayOfWeek(); +// if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { +// getIsSign(); +// } +// } +// } +// +// @Override +// public void onError(Throwable e) { +// +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// private static final int NOTIFY_TYPE_P_AM_SIGN_1 = 1221;//片长上午签到提前一分钟 +// private static final int NOTIFY_TYPE_P_AM_SIGN_5 = 1222;//片长上午签到开始后五分钟 +// private static final int NOTIFY_TYPE_P_AM_SIGN_OUT_1 = 1223;//片长上午签退提前一分钟 +// private static final int NOTIFY_TYPE_P_AM_SIGN_OUT_5 = 1224;//片长上午签退开始后五分钟 +// +// private static final int NOTIFY_TYPE_P_PM_SIGN_1 = 1225;//片长下午签到提前一分钟 +// private static final int NOTIFY_TYPE_P_PM_SIGN_5 = 1226;//片长下午签到开始后五分钟 +// private static final int NOTIFY_TYPE_P_PM_SIGN_OUT_1 = 1227;//片长下午签退提前一分钟 +// private static final int NOTIFY_TYPE_P_PM_SIGN_OUT_5 = 1228;//片长下午签退开始后五分钟 +// +// +// private static final int NOTIFY_TYPE_N_SIGN_1 = 2321;//签到提前一分钟 +// private static final int NOTIFY_TYPE_N_SIGN_5 = 2322;//签到开始后五分钟 +// private static final int NOTIFY_TYPE_N_SIGN_OUT_1 = 2324;//签退开始前一分钟 +// private static final int NOTIFY_TYPE_N_SIGN_OUT_5 = 2325;//签退开始后五分钟 +// +// +// private int getNotifyType() { +// //判断当前时间是开始打开前一分钟还是后五分钟 +// int type = -1; +// String nowHourMM = TimeUtils.getNowHourMM(); +// LogUtils.e(nowHourMM); +// if (mUType != 0) { +// //判断是片长还是N员 +// //1是N员 2是片长 +// if (mUType == 1) { +// //N员提醒 +// String startTime = mNStartPunchTime; +// String endTime = mNEndWorkTime; +// String currentTimeOneSpan = TimeUtils.getCurrentTimeSpan(startTime, -1); +// String curTimeFiveSpan = TimeUtils.getCurrentTimeSpan(startTime, 5); +// String curEndTimeOneSpan = TimeUtils.getCurrentTimeSpan(endTime, -1); +// String curEndTimeFiveSpan = TimeUtils.getCurrentTimeSpan(endTime, 5); +// if (currentTimeOneSpan.equals(nowHourMM)) { +// type = NOTIFY_TYPE_N_SIGN_1; +// } +// if (curTimeFiveSpan.equals(nowHourMM)) { +// type = NOTIFY_TYPE_N_SIGN_5; +// } +// if (curEndTimeOneSpan.equals(nowHourMM)) { +// type = NOTIFY_TYPE_N_SIGN_OUT_1; +// } +// if (curEndTimeFiveSpan.equals(nowHourMM)) { +// type = NOTIFY_TYPE_N_SIGN_OUT_5; +// } // } else { +// String pAmStartTime = mAmStartPunchTime; +// String pAmEndTime = mAmEndWorkTime; +// String pPmStartTime = mPmStartPunchTime; +// String pPmEndTime = mPmEndWorkTime; +// String amStartTimeOne = TimeUtils.getCurrentTimeSpan(pAmStartTime, -1); +// String amStartTimeFive = TimeUtils.getCurrentTimeSpan(pAmStartTime, 5); +// String amEndTimeOne = TimeUtils.getCurrentTimeSpan(pAmEndTime, -1); +// String amEndTimeFive = TimeUtils.getCurrentTimeSpan(pAmEndTime, 5); +// +// String pmStartTimeOne = TimeUtils.getCurrentTimeSpan(pPmStartTime, -1); +// String pmStartTimeFive = TimeUtils.getCurrentTimeSpan(pPmStartTime, 5); +// String pmEndTimeOne = TimeUtils.getCurrentTimeSpan(pPmEndTime, -1); +// String pmEndTimeFive = TimeUtils.getCurrentTimeSpan(pPmEndTime, 5); +// if (amStartTimeOne.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_AM_SIGN_1; +// } +// if (amStartTimeFive.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_AM_SIGN_5; +// } +// if (amEndTimeOne.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_AM_SIGN_OUT_1; +// } +// if (amEndTimeFive.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_AM_SIGN_OUT_5; +// } +// if (pmStartTimeOne.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_PM_SIGN_1; +// } +// if (pmStartTimeFive.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_PM_SIGN_5; +// } +// if (pmEndTimeOne.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_PM_SIGN_OUT_1; +// } +// if (pmEndTimeFive.equals(nowHourMM)) { +// return NOTIFY_TYPE_P_PM_SIGN_OUT_5; +// } // } // } +// return type; +// } // -// //Socket通讯写出后的响应回调 -// @Override -// public void onSocketWriteResponse(ConnectionInfo info, String action, ISendable data) { -// mManager.getPulseManager().pulse(); -// LogUtils.e("Socket通讯写出后的响应回调==" + action); +// private void getIsSign() { +// String token = GlobalProvider.getString(LocationService.this, "token"); +// if (!TextUtils.isEmpty(token)) { +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .checkSign(token) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(CheckSignBean checkSignBean) { +// if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData().getIsSign())) { +// boolean b = Boolean.parseBoolean(checkSignBean.getData().getIsSign()); +// if (!b) { +// String nowHourMM = TimeUtils.getNowHourMM(); +// String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); +// if ("N".equals(userType)) { +// //N员 +// if (!TextUtils.isEmpty(nowHourMM)) { +// if (!TextUtils.isEmpty(mNStartPunchTime)) { +// String currentTime = TimeUtils.getCurrentTime(mNStartPunchTime); +// if (nowHourMM.equals(currentTime)) { +// sendNotifySignN(1); +// } +// } +// } +// } else { +// if (!TextUtils.isEmpty(nowHourMM)) { +// if (!TextUtils.isEmpty(mAmStartPunchTime)) { +// String currentTime = TimeUtils.getCurrentTime(mAmStartPunchTime); +// if (nowHourMM.equals(currentTime)) { +// sendNotifySign(1); +// } +// } +// if (!TextUtils.isEmpty(mPmStartPunchTime)) { +// String currentTime = TimeUtils.getCurrentTime(mPmStartPunchTime); +// if (nowHourMM.equals(currentTime)) { +// sendNotifySign(3); +// } +// } +// } +// } +// } else { +// getIsSignOff(); +// } +// } +// } +// +// @Override +// public void onError(Throwable e) { +// } +// +// @Override +// public void onComplete() { +// +// } +// }); // } +// } // +// private void getIsSignOff() { +// String token = GlobalProvider.getString(LocationService.this, "token"); +// if (!TextUtils.isEmpty(token)) { +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .checkSignOff(UserLgUtils.getToken()) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { // -// //Socket心跳发送后的回调 -// @Override -// public void onPulseSend(ConnectionInfo info, IPulseSendable data) { -// LogUtils.e("==Socket心跳发送后的回调=="); +// } +// +// @Override +// public void onNext(CheckSignOffBean checkSignBean) { +// if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData())) { +// boolean b = Boolean.parseBoolean(checkSignBean.getData()); +// if (!b) { +// String nowHourMM = TimeUtils.getNowHourMM(); +// String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); +// if ("N".equals(userType)) { +// //N员 +// String currentTime = TimeUtils.getCurrentTime(mNEndWorkTime); +// if (!TextUtils.isEmpty(nowHourMM)) { +// if (nowHourMM.equals(currentTime)) { +// sendNotifySignN(2); +// } +// } +// } else { +// //片长 +// if (!TextUtils.isEmpty(mAmEndWorkTime)) { +// String currentTime = TimeUtils.getCurrentTime(mAmEndWorkTime); +// if (nowHourMM.equals(currentTime)) { +// sendNotifySign(2); +// } +// } +// if (!TextUtils.isEmpty(mPmEndWorkTime)) { +// String currentTime = TimeUtils.getCurrentTime(mPmEndWorkTime); +// if (nowHourMM.equals(currentTime)) { +// sendNotifySign(4); +// } +// } +// } +// } +// } +// } +// +// @Override +// public void onError(Throwable e) { +// } +// +// @Override +// public void onComplete() { +// +// } +// }); // } -// }; - - +// } +// +// private void registerIsSendNogify() { +// Observable.interval(50, TimeUnit.SECONDS) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(Long aLong) { +// String isHolday = GlobalProvider.getString(LocationService.this, "isHolday", ""); +// if (!TextUtils.isEmpty(isHolday)) { +// if ("1".equals(isHolday)) { +// mIsHolday = true; +// } else { +// mIsHolday = false; +// } +// } else { +// mIsHolday = false; +// } +// } +// +// @Override +// public void onError(Throwable e) { +// +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// +// } +// // /** -// * 上传本地数据 +// * 发送N员通知 // * -// * @param bdLocation -// * @param file +// * @param i // */ -// private void uploadLocalPoint(BDLocation bdLocation, File file) { -// Gson gson = new Gson(); -// Type type = new TypeToken() { -// }.getType(); -// try { -// List pos = new ArrayList<>(); -// List strings = FileIOUtils.readFile2List(file); -// for (int i = 0; i < strings.size(); i++) { -// MapPosition bena = gson.fromJson(strings.get(i), type); -// pos.add(bena); +// private void sendNotifySignN(int i) { +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// String title = ""; +// String content = ""; +// switch (i) { +// case 1: +// title = "签到提醒"; +// content = "请在" + mNStartPunchTime + "-" + mNStartWorkTime + "进行签到"; +// break; +// case 2: +// title = "签退提醒"; +// content = "请在" + mNEndWorkTime + "-" + mNEndPunchTime + "进行签退"; +// break; +// } +// utils.sendNotification(666, title, content); +// } +// +// private void sendNotifySign(int i) { +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// String title = ""; +// String content = ""; +// switch (i) { +// case 1: +// title = "签到提醒"; +// content = "请在" + mAmStartPunchTime + "-" + mAmStartWorkTime + "进行上午签到"; +// break; +// case 2: +// title = "签退提醒"; +// content = "请在" + mAmEndWorkTime + "-" + mAmEndPunchTime + "进行上午签退"; +// break; +// case 3: +// title = "签到提醒"; +// content = "请在" + mPmStartPunchTime + "-" + mPmStartWorkTime + "进行下午签到"; +// break; +// case 4: +// title = "签退提醒"; +// content = "请在" + mPmEndWorkTime + "-" + mPmEndPunchTime + "进行下午签退"; +// break; +// } +// utils.sendNotification(555, title, content); +// } +// +// private void registerUploadPointListener() { +// Observable.interval(1, 1, TimeUnit.MINUTES) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(Long aLong) { +// if (mUploadPointTime != 0) { +// long timeSpan = TimeUtils.getTimeSpan(System.currentTimeMillis(), mUploadPointTime, TimeConstants.MIN); +// if (timeSpan >= 9) { +// if (!mIsHolday) { +// String chineseWeek = TimeUtils.getDayOfWeek(); +// if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { +// mUploadPointTime = System.currentTimeMillis(); +// String nowHour = TimeUtils.getNowHour(); +// if (TimeUtils.isInTime("08:30-12:30", nowHour) || TimeUtils.isInTime("13:30-17:30", nowHour)) { +// if (canUpload()) { +// startLocation(); +// } +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// utils.sendNotification(45, "应急管理", "您已较长时间未上传定位信息,可能当前位置信号弱,请检查GPS和数据开关设置或者移动到开阔位置."); +// } +// } +// } +// } +// } +// } +// +// @Override +// public void onError(Throwable e) { +// +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// //保存 +// private void saveFile(int i) { +// if (i == 12) { +// String start = "定位服务已经开启:" + GlobalProvider.getString(LocationService.this, "token") + "手机参数:" + DeviceUtil.getDeviceInfo() + "App版本:" + AppUtils.getAppVersionName(); +// Utils.saveFile(start, "testLocation.txt", true); +// } else { +// String end = "定位服务关闭"; +// Utils.saveFile(end, "testLocation.txt", true); +// } +// } +// +// /** +// * 获取当前时间 +// */ +// private void checkSign() { +// Observable.interval(0, 5, TimeUnit.MINUTES) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// mMTimeDis = d; +// } +// +// @Override +// public void onNext(Long aLong) { +// checkIsSign(); +// } +// +// @Override +// public void onError(Throwable e) { +// +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// /** +// * 校验是否签到 +// */ +// private void checkIsSign() { +// String token = GlobalProvider.getString(LocationService.this, "token"); +// if (!TextUtils.isEmpty(token)) { +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .checkSign(token) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(CheckSignBean checkSignBean) { +// if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData().getIsSign())) { +// boolean b = Boolean.parseBoolean(checkSignBean.getData().getIsSign()); +// if (b) { +// //已经签到 +// checkSignOff(); +// } else { +// //未签到 +// if (!mIsHolday) { +// String chineseWeek = TimeUtils.getDayOfWeek(); +// if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { +// String nowHourMM = TimeUtils.getNowHourMM(); +// String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); +// if ("N".equals(userType)) { +// //N员 +// String nStartPunchTime = mNStartPunchTime; +// String nStartWorkTime = mNStartWorkTime; +// if (TimeUtils.isInTime(nStartPunchTime + "-" + nStartWorkTime, nowHourMM)) { +// sendNotif(1); +// } +// } else { +// //片长 +// String amStartPunchTime = mAmStartPunchTime; +// String amStartWorkTime = mAmStartWorkTime; +// String pmStartPunchTime = mPmStartPunchTime; +// String pmStartWorkTime = mPmStartWorkTime; +// if (TimeUtils.isInTime(amStartPunchTime + "-" + amStartWorkTime, nowHourMM) || TimeUtils.isInTime(pmStartPunchTime + "-" + pmStartWorkTime, nowHourMM)) { +// sendNotif(1); +// } +// } +// } +// } +// } +// } +// } +// +// @Override +// public void onError(Throwable e) { +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// } +// +// //发送签提醒 +// private void sendNotif(int i) { +// if (!mIsHolday) { +// if (isWeek()) { +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// if (i == 1) { +// utils.sendNotification(23, "签到提醒", "当前未签到,请进行签到."); +// } else { +// utils.sendNotification(23, "签退提醒", "当前未签退,请进行签退."); +// } // } -// MapPosition current = new MapPosition(); -// current.setCreateTime(TimeUtils.getNowString()); -// current.setLatitude(bdLocation.getLatitude()); -// current.setLongitude(bdLocation.getLongitude()); -// String s = gson.toJson(pos); -// uploadLocation(s); -// } catch (Exception e) { +// } +// } +// +// private boolean isWeek() { +// String chineseWeek = TimeUtils.getDayOfWeek(); +// if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { +// return true; +// } else { +// return false; +// } +// } +// +// private void checkGpsState() { +// boolean oPen = GpsUtils.isOPen(LocationService.this); +// if (!oPen) { +// if (!mIsHolday) { +// String nowHour = TimeUtils.getNowHour(); +// if (isWeek()) { +// if (TimeUtils.isInTime("08:30-12:30", nowHour) || TimeUtils.isInTime("13:30-17:30", nowHour)) { +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// utils.sendNotification(55, "GPS提醒", "当前GPS已关闭,请前往设置页面进行开启."); +// } +// } +// } +// } +// } +// +// /** +// * 校验是否签退 +// */ +// private void checkSignOff() { +// String token = GlobalProvider.getString(LocationService.this, "token", ""); +// if (!TextUtils.isEmpty(token)) { +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .checkSignOff(token) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(CheckSignOffBean checkSignBean) { +// if (checkSignBean != null && !TextUtils.isEmpty(checkSignBean.getData())) { +// boolean b = Boolean.parseBoolean(checkSignBean.getData()); +// if (b) { +// //已经签退 +// } else { +// //没有签退 +// if (!mIsHolday) { +// String nowHourMM = TimeUtils.getNowHour(); +// //时间段在12点与13点半之间或者17点与19点之间,提示签退 +// String chineseWeek = TimeUtils.getDayOfWeek(); +// if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { +// String userType = GlobalProvider.getString(LocationService.this, "userType", "P"); +// if ("N".equals(userType)) { +// //N员 +// String nEndWorkTime = mNEndWorkTime;//GlobalProvider.getString(LocationService.this, "nEndWorkTime", "17:00:00"); +// String nEndPunchTime = mNEndPunchTime;//GlobalProvider.getString(LocationService.this, "nEndPunchTime", "18:00:00"); +// if (TimeUtils.isInTime(nEndWorkTime + "-" + nEndPunchTime, nowHourMM)) { +// sendNotif(23); +// } +// } else { +// //片长 +// String amEndWorkTime = mAmEndWorkTime;//GlobalProvider.getString(LocationService.this, "amEndWorkTime", "11:30:00"); +// String amEndPunchTime = mAmEndPunchTime; //GlobalProvider.getString(LocationService.this, "amEndPunchTime", "12:30:00"); +// String pmEndWorkTime = mPmEndWorkTime;// GlobalProvider.getString(LocationService.this, "pmEndWorkTime", "16:30:00"); +// String pmEndPunchTime = mPmEndPunchTime;// GlobalProvider.getString(LocationService.this, "pmEndPunchTime", "17:30:00"); +// if (TimeUtils.isInTime(amEndWorkTime + "-" + amEndPunchTime, nowHourMM) || TimeUtils.isInTime(pmEndWorkTime + "-" + pmEndPunchTime, nowHourMM)) { +// sendNotif(23); +// } +// } +// } +// } +// } +// } +// } +// +// @Override +// public void onError(Throwable e) { +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// } +// +// +// /** +// * 电子围栏数据 +// */ +// private void getUserPenList() { +// String token = GlobalProvider.getString(LocationService.this, "token"); +// if (!TextUtils.isEmpty(token)) { +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .getUserPenList(token) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer>() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(List penLineBeans) { +// if (penLineBeans != null && penLineBeans.size() > 0) { +// buildPenList(penLineBeans); +// } +// } +// +// @Override +// public void onError(Throwable e) { +//// ToastUtils.showShort("获取围栏数据失败,请稍后重试"); +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } +// +// } +// +// private void buildPenList(List penLineBeans) { +// mPenLineList = new ArrayList<>(); +// for (int i = 0; i < penLineBeans.size(); i++) { +// List areaPoints = penLineBeans.get(i).getAreaPoints(); +// if (areaPoints != null && areaPoints.size() > 0) { +// List tempList = new ArrayList<>(); +// for (int j = 0; j < areaPoints.size(); j++) { +// LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(j).getLatitude()), Double.parseDouble(areaPoints.get(j).getLongitude())); +// tempList.add(latLng); +// } +// LatLng latLng = new LatLng(Double.parseDouble(areaPoints.get(0).getLatitude()), Double.parseDouble(areaPoints.get(0).getLongitude())); +// tempList.add(latLng); +// mPenLineList.add(tempList); +// } +// } +// } +// +// private void startPlayMusic() { +// new Thread(() -> startPlaySong()).start(); +// } +// +// private void startPlaySong() { +// if (mMediaPlayer == null) { +// mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.no_kill); +// mMediaPlayer.start(); +// } else { +// mMediaPlayer.start(); +// } +// try { +// Thread.sleep(3000); +// } catch (InterruptedException e) { // e.printStackTrace(); // } -// } - // /** -// * 本地数据删除 -// */ -// private void deleteLocalCache() { -// String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backlocation.txt"; -// File locationFile = new File(filePath); -// if (locationFile.exists()) { -// locationFile.delete(); +// if (mMediaPlayer != null) { +// mMediaPlayer.pause(); // } // } - /** - * 开启socket - */ -// private void startSocket() { -// initSocketManager(); +// +// @Override +// public void onDestroy() { +// saveFile(13); +// unApplyNotiKeepMech(); +// stopLocation(); +// stopPlaySong(); +// if (mMTimeDis != null && !mMTimeDis.isDisposed()) { +// mMTimeDis.dispose(); +// } +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { +// startForegroundService(new Intent(getApplicationContext(), LocationService.class)); +// } else { +// startService(new Intent(getApplicationContext(), LocationService.class)); +// } +// super.onDestroy(); // } - -// /** -// * 初始化SocketManager -// */ -// private void initSocketManager() { -// Handler handler = new Handler(); -// mInfo = new ConnectionInfo(BaseUrlApi.SOCKET_IP, 8080); -// mOkOptions = new OkSocketOptions.Builder() -// .setReconnectionManager(OkSocketOptions.getDefault().getReconnectionManager())//重连 -// .setConnectTimeoutSecond(10) -// .setCallbackThreadModeToken(new OkSocketOptions.ThreadModeToken() { -// @Override -// public void handleCallbackEvent(ActionDispatcher.ActionRunnable runnable) { -// handler.post(runnable); +// +// private void stopPlaySong() { +// if (mMediaPlayer != null) { +// mMediaPlayer.pause(); +// mMediaPlayer.stop(); +// mMediaPlayer.release(); +// mMediaPlayer = null; +// } +// } +// +// private class MyLocationListener extends BDAbstractLocationListener { +// +// @Override +// public void onReceiveLocation(BDLocation bdLocation) { +// if (bdLocation != null && bdLocation.getLatitude() != 0 && bdLocation.getLongitude() != 0) { +// if (bdLocation.getLongitude() != Double.MIN_VALUE && bdLocation.getLongitude() != Double.MIN_VALUE) { +// checkPointIs(bdLocation); +// sendLocationBroadcast(bdLocation); +// mWifiAutoCloseDelegate.onLocateSuccess(getApplicationContext(), PowerManagerUtil.getInstance().isScreenOn(getApplicationContext()), NetUtil.getInstance().isMobileAva(getApplicationContext())); +// } +// } else { +// mWifiAutoCloseDelegate.onLocateFail(getApplicationContext(), 10, PowerManagerUtil.getInstance().isScreenOn(getApplicationContext()), NetUtil.getInstance().isWifiCon(getApplicationContext())); +// } +// } +// +// private void sendLocationBroadcast(BDLocation bdLocation) { +// if (null != bdLocation) { +// if (checkSinglePoint(bdLocation)) { +// if (mTempList.size() >= 25) { +// checkPoints(); +// } else { +// mTempList.add(bdLocation); // } -// }) -// .build(); -// mManager = OkSocket.open(mInfo).option(mOkOptions); -// mManager.registerReceiver(socketListener); -// mManager.connect(); +// } +// } +// } // } +// +// private void checkPointIs(BDLocation bdLocation) { +// if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode()) && bdLocation.getRadius() <= 300) { +// Intent mIntent = new Intent(PathConfig.ACTION_LOCATION_MESSAGE); +// mIntent.putExtra("data", bdLocation); +// sendBroadcast(mIntent); +//// LatLng latLng1 = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); +//// LatLng latLng2 = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); +//// boolean circleContainsPoint = SpatialRelationUtil.isCircleContainsPoint(latLng1, 50, latLng2); +//// if (circleContainsPoint) { +//// +//// } +// } +// } +// +// /** +// * 校验定位点的合法性 +// * +// * @param bdLocation +// * @return +// */ +// private boolean checkSinglePoint(BDLocation bdLocation) { +// boolean isLegal = false; +// if (isFirst) { +// if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode())) { +// isLegal = true; +// } else { +// isLegal = false; +// } +// } else { +// if (PathConfig.CITY_CODE_DEFAULT.equals(bdLocation.getCityCode()) && bdLocation.getRadius() <= mPrecision) { +// if (mCurrentLocation != null) { +// LatLng latLng1 = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); +// LatLng latLng2 = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); +// boolean circleContainsPoint = SpatialRelationUtil.isCircleContainsPoint(latLng1, 50, latLng2); +// if (circleContainsPoint) { +// mCurrentLocation = bdLocation; +// isLegal = true; +// } else { +// isLegal = false; +// } +// } else { +// mCurrentLocation = bdLocation; +// isLegal = true; +// } +// } else { +// isLegal = false; +// } +// } +// return isLegal; +// } +// +// /** +// * 根据定位精度取最小精度 +// */ +// private void checkPoints() { +// Collections.sort(mTempList, (o1, o2) -> { +// if (o1.getRadius() > o2.getRadius()) { +// return 1; +// } else if (o1.getRadius() < o2.getRadius()) { +// return -1; +// } else { +// return 0; +// } +// }); +// buildUploadPoint(); +// } +// +// /** +// * 存在网络上传 +// */ +// private void buildUploadPoint() { +// isFirst = false; +// if (mTempList.size() > 0) { +// if (NetUtil.getInstance().isNetworkConnected(getApplicationContext())) { +// LocationPosition position = new LocationPosition(); +// position.setUserLatitude(mTempList.get(0).getLatitude() + ""); +// position.setUserLongitude(mTempList.get(0).getLongitude() + ""); +// position.setUserLocation(mTempList.get(0).getAddress().address); +// position.setUserSpeed(mTempList.get(0).getSpeed() + ""); +// Gson gson = new Gson(); +// String s = gson.toJson(position); +// uploadLocation(s); +// checkCurrenPointIsBeyond(mTempList.get(0)); +// } else { +// //TODO 无网络状态下是否保存 +// if (isSaveLocal) { +// String textPoint = "{\"userLongitude\":" + mTempList.get(0).getLongitude() + ",\"userLatitude\":" + mTempList.get(0).getLatitude() + ",\"userLocation\":\"" + mTempList.get(0).getAddrStr() + "\",\"createTime\":\"" + Utils.formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\"}"; +// Utils.saveFile(textPoint, "testLocation.txt", true); +// } +// } +// } +// } +// +// /** +// * 是否在片区内 +// * +// * @param cur +// * @return true 在片区内 false 不在片区内 +// */ +// private boolean isBeyond(LatLng cur) { +// boolean isBeyond = false; +// for (int i = 0; i < mPenLineList.size(); i++) { +// boolean inPolygon = PointUtils.isInPolygon(cur, mPenLineList.get(i)); +// if (inPolygon) { +// isBeyond = true; +// break; +// } +// } +// return isBeyond; +// } +// +// /** +// * 判断是否越界 +// * +// * @param bdLocation +// */ +// private void checkCurrenPointIsBeyond(BDLocation bdLocation) { +// if (!mIsHolday) { +// String chineseWeek = TimeUtils.getDayOfWeek(); +// if (!TextUtils.isEmpty(chineseWeek) && !"六".equals(chineseWeek) && !"日".equals(chineseWeek)) { +// if (mPenLineList != null && mPenLineList.size() > 0) { +// LatLng latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); +// boolean isByond = isBeyond(latLng); +// if (!isByond) { +// //越界了 +// if (mCount > 3) { +// if (mCurTime != 0) { +// long timeSpan = TimeUtils.getTimeSpan(System.currentTimeMillis(), mCurTime, TimeConstants.MIN); +// if (timeSpan > 30) { +// String nowHour = TimeUtils.getNowHourMM(); +// if (TimeUtils.isInTime("09:00-12:10", nowHour) || TimeUtils.isInTime("13:30-17:00", nowHour)) { +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// utils.sendNotification("越界提醒", "你当前位置超过了所监管区域"); +// } +// mCurTime = TimeUtils.getNowMills(); +// } +// } else { +// mCurTime = TimeUtils.getNowMills(); +// } +// } else { +// ++mCount; +// String nowHour = TimeUtils.getNowHourMM(); +// if (TimeUtils.isInTime("09:00-12:10", nowHour) || TimeUtils.isInTime("13:30-17:00", nowHour)) { +// NotificationUtils utils = new NotificationUtils(LocationService.this); +// utils.sendNotification("越界提醒", "你当前位置超过了所监管区域"); +// } +// } +// } +// } +// } +// } +// } +// +// private boolean canUpload() { +// String nowHourMM = TimeUtils.getNowHourMM(); +// String upStart = mAmStartPunchTime; +// String upEnd = mNEndPunchTime; +// boolean isup = TimeUtils.isInTime(upStart + "-" + upEnd, nowHourMM); +// return isup; +// } +// +// /** +// * 上传数据 +// * +// * @param points +// */ +// private void uploadLocation(String points) { +// isFirst = false; +// String token = GlobalProvider.getString(LocationService.this, "token"); +// if (!TextUtils.isEmpty(token)) { +// if (isUpload) { +// mCurrentLocation = null; +// mTempList.clear(); +// } else { +// boolean canUp = canUpload(); +// if (canUp) { +// isUpload = true; +// RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), points); +// RetrofitManager.getInstance() +// .create(LocationApiService.class) +// .saveLocationData(body, token) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Observer() { +// @Override +// public void onSubscribe(Disposable d) { +// +// } +// +// @Override +// public void onNext(SuccessBean successBean) { +// isUpload = false; +// mCurrentLocation = null; +// mTempList.clear(); +// mUploadPointTime = System.currentTimeMillis(); +// Intent intent = new Intent(); +// intent.setAction("com.sucstepsoft.realtimelocation.isonlone"); +// intent.putExtra("uploadTime", mUploadPointTime + ""); +// sendBroadcast(intent); +// } +// +// @Override +// public void onError(Throwable e) { +// isUpload = false; +// mCurrentLocation = null; +// mTempList.clear(); +// e.printStackTrace(); +// } +// +// @Override +// public void onComplete() { +// +// } +// }); +// } else { +// mTempList.clear(); +// } +// } +// } +// } +// +// +// /** +// * 配置定位参数 +// */ +// private void startLocation() { +// stopLocation(); +// mLocationClient = new LocationClient(getApplicationContext()); +// //声明LocationClient类实例并配置定位参数 +// LocationClientOption locationOption = new LocationClientOption(); +// MyLocationListener myLocationListener = new MyLocationListener(); +// //注册监听函数 +// mLocationClient.registerLocationListener(myLocationListener); +// //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 +// locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); +// //可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll; +// locationOption.setCoorType("bd09ll"); +// //可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的 +// locationOption.setScanSpan(5000); +// //可选,设置是否需要地址信息,默认不需要 +// locationOption.setIsNeedAddress(true); +// //设置是否运行模拟GPS +//// locationOption.setEnableSimulateGps(false); +// //可选,设置是否需要设备方向结果 +// locationOption.setNeedDeviceDirect(false); +// //可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果 +// locationOption.setLocationNotify(true); +// //可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死 +// locationOption.setIgnoreKillProcess(true); +// //可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近” +// locationOption.setIsNeedLocationDescribe(true); +// //可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到 +// locationOption.setIsNeedLocationPoiList(true); +// //可选,默认false,设置是否收集CRASH信息,默认收集 +// locationOption.SetIgnoreCacheException(false); +// //可选,默认false,设置是否开启Gps定位 +// locationOption.setOpenGps(true); +// //可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用 +// locationOption.setIsNeedAltitude(false); +// //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者,该模式下开发者无需再关心定位间隔是多少,定位SDK本身发现位置变化就会及时回调给开发者 +//// locationOption.setOpenAutoNotifyMode(); +// //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 +//// locationOption.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); +// //需将配置好的LocationClientOption对象,通过setLocOption方法传递给LocationClient对象使用 +// mLocationClient.setLocOption(locationOption); +// //开始定位 +// mLocationClient.start(); +// } +// +// void stopLocation() { +// if (null != mLocationClient) { +// mLocationClient.stop(); +// } +// } +// +// +// /** +// * 签到时间改变 +// */ +// private class PunchTimeReceiver extends BroadcastReceiver { +// +// @Override +// public void onReceive(Context context, Intent intent) { +// String action = intent.getAction(); +// if (PathConfig.ACTION_PUNCH_TIME_MESSAGE.equals(action)) { +// SignTimeBean timeBean = (SignTimeBean) intent.getSerializableExtra("timeBean"); +// mUType = intent.getIntExtra("uType", 2); +// if (timeBean != null) { +// mAmStartPunchTime = timeBean.getAmStartPunchTime();//上午开始打卡时间 +// mAmStartWorkTime = timeBean.getAmStartWorkTime();//"09:30:00";//上午工作开始时间 +// mAmEndWorkTime = timeBean.getAmEndWorkTime();//"11:30:00";//上午工作结束时间 +// mAmEndPunchTime = timeBean.getAmEndPunchTime();//"12:30:00";//上午结束打卡时间 +// mPmStartPunchTime = timeBean.getPmStartPunchTime();//"13:30:00";//下午开始打卡时间 +// mPmStartWorkTime = timeBean.getPmStartWorkTime();//"14:30:00";//下午开始工作时间 +// mPmEndWorkTime = timeBean.getPmEndWorkTime();//"16:30:00";//下午结束工作时间 +// mPmEndPunchTime = timeBean.getPmEndPunchTime();//"17:30:00";//下午结束打卡时间 +// mNStartPunchTime = timeBean.getNStartPunchTime();//"08:30:00";//N员开始打卡时间 +// mNStartWorkTime = timeBean.getNStartWorkTime();//"10:00:00";//N员开始工作时间 +// mNEndWorkTime = timeBean.getNEndWorkTime();// "17:00:00";//N员结束工作时间 +// mNEndPunchTime = timeBean.getNEndPunchTime();// "18:00:00";//N员结束打开时间 +// } +// } else if (PathConfig.ACTION_STOP_LOCATION.equals(action)) { +// startLocation(); +// } else if (PathConfig.ACTION_START_LOCATION.equals(action)) { +// startLocation(); +// } +// } +// } +//// 109.91829190601483 40.59518382351867 +//// 109.91825597379443 40.59669718527541 +//// 109.92120480199132 40.596745087745845 +//// 109.92360987463378 40.596796480184544 +//// 109.92366826449192 40.59486540000251 +//// 109.9212017140661 40.59484141029425 +//// 109.9197561439961 40.59517012777953 +// +//// private SocketActionAdapter socketListener = new SocketActionAdapter() { +//// //当Socket连接建立成功后 +//// @Override +//// public void onSocketConnectionSuccess(ConnectionInfo info, String action) { +//// LogUtils.e("当Socket连接建立成功后==" + action); +//// mManager.send(new HandShakeBean()); +//// mManager.getPulseManager().setPulseSendable(new PulseBean()); +//// } +//// +//// //Socket断开后进行的回调 +//// @Override +//// public void onSocketDisconnection(ConnectionInfo info, String action, Exception e) { +//// LogUtils.e("Socket断开后进行的回调==" + action); +//// } +//// +//// //当Socket连接失败时会进行回调 +//// @Override +//// public void onSocketConnectionFailed(ConnectionInfo info, String action, Exception e) { +//// LogUtils.e("当Socket连接失败时会进行回调==" + action); +//// } +//// +//// //Socket通讯从服务器读取到消息后的响应 +//// @Override +//// public void onSocketReadResponse(ConnectionInfo info, String action, OriginalData data) { +//// LogUtils.e("Socket通讯从服务器读取到消息后的响应==" + action); +//// String str = new String(data.getBodyBytes(), Charset.forName("utf-8")); +//// JsonObject jsonObject = new JsonParser().parse(str).getAsJsonObject(); +//// int cmd = jsonObject.get("cmd").getAsInt(); +//// if (cmd == 54) {//登陆成功 +//// String handshake = jsonObject.get("handshake").getAsString(); +//// } else if (cmd == 57) {//切换,重定向.(暂时无法演示,如有疑问请咨询github) +//// LogUtils.e("=====重定向===="); +//// } else if (cmd == 14) {//心跳 +//// mManager.getPulseManager().feed(); +//// LogUtils.e("心跳包发送"); +//// } else { +//// } +//// } +//// +//// //Socket通讯写出后的响应回调 +//// @Override +//// public void onSocketWriteResponse(ConnectionInfo info, String action, ISendable data) { +//// mManager.getPulseManager().pulse(); +//// LogUtils.e("Socket通讯写出后的响应回调==" + action); +//// } +//// +//// +//// //Socket心跳发送后的回调 +//// @Override +//// public void onPulseSend(ConnectionInfo info, IPulseSendable data) { +//// LogUtils.e("==Socket心跳发送后的回调=="); +//// } +//// }; +// +// +//// /** +//// * 上传本地数据 +//// * +//// * @param bdLocation +//// * @param file +//// */ +//// private void uploadLocalPoint(BDLocation bdLocation, File file) { +//// Gson gson = new Gson(); +//// Type type = new TypeToken() { +//// }.getType(); +//// try { +//// List pos = new ArrayList<>(); +//// List strings = FileIOUtils.readFile2List(file); +//// for (int i = 0; i < strings.size(); i++) { +//// MapPosition bena = gson.fromJson(strings.get(i), type); +//// pos.add(bena); +//// } +//// MapPosition current = new MapPosition(); +//// current.setCreateTime(TimeUtils.getNowString()); +//// current.setLatitude(bdLocation.getLatitude()); +//// current.setLongitude(bdLocation.getLongitude()); +//// String s = gson.toJson(pos); +//// uploadLocation(s); +//// } catch (Exception e) { +//// e.printStackTrace(); +//// } +//// } +// // /** +//// * 本地数据删除 +//// */ +//// private void deleteLocalCache() { +//// String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backlocation.txt"; +//// File locationFile = new File(filePath); +//// if (locationFile.exists()) { +//// locationFile.delete(); +//// } +//// } +// /** +// * 开启socket +// */ +//// private void startSocket() { +//// initSocketManager(); +//// } +// +//// /** +//// * 初始化SocketManager +//// */ +//// private void initSocketManager() { +//// Handler handler = new Handler(); +//// mInfo = new ConnectionInfo(BaseUrlApi.SOCKET_IP, 8080); +//// mOkOptions = new OkSocketOptions.Builder() +//// .setReconnectionManager(OkSocketOptions.getDefault().getReconnectionManager())//重连 +//// .setConnectTimeoutSecond(10) +//// .setCallbackThreadModeToken(new OkSocketOptions.ThreadModeToken() { +//// @Override +//// public void handleCallbackEvent(ActionDispatcher.ActionRunnable runnable) { +//// handler.post(runnable); +//// } +//// }) +//// .build(); +//// mManager = OkSocket.open(mInfo).option(mOkOptions); +//// mManager.registerReceiver(socketListener); +//// mManager.connect(); +//// } } diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/Utils.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/Utils.java index 68f7e38..7342e92 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/Utils.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/Utils.java @@ -41,41 +41,41 @@ public class Utils { // private final static String PRIMARY_CHANNEL = "default"; private final static String PRIMARY_CHANNEL = "txrealtimelocation"; - public synchronized static String getLocationStr(BDLocation location) { - if (null == location) { - return null; - } - StringBuffer sb = new StringBuffer(); - if (location != null) { - sb.append("定位成功" + "\n"); - sb.append("定位类型: " + location.getLocType() + "\n"); - sb.append("经 度 : " + location.getLongitude() + "\n"); - sb.append("纬 度 : " + location.getLatitude() + "\n"); - sb.append("精 度 : " + location.getRadius() + "米" + "\n"); - - sb.append("海 拔 : " + location.getAltitude() + "米" + "\n"); - sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n"); - sb.append("角 度 : " + location.getDirection() + "\n"); - - //逆地理信息 - sb.append("国 家 : " + location.getCountry() + "\n"); - sb.append("省 : " + location.getProvince() + "\n"); - sb.append("市 : " + location.getCity() + "\n"); - sb.append("城市编码 : " + location.getCityCode() + "\n"); - sb.append("区 : " + location.getDistrict() + "\n"); - sb.append("区域 码 : " + location.getAdCode() + "\n"); - sb.append("地 址 : " + location.getAddress() + "\n"); - //定位完成的时间 - sb.append("定位时间: " + location.getTime() + "\n"); - - } else { - //定位失败 - sb.append("定位失败" + location.toString() + "\n"); - } - //定位之后的回调时间 - sb.append("回调时间: " + formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n"); - return sb.toString(); - } +// public synchronized static String getLocationStr(BDLocation location) { +// if (null == location) { +// return null; +// } +// StringBuffer sb = new StringBuffer(); +// if (location != null) { +// sb.append("定位成功" + "\n"); +// sb.append("定位类型: " + location.getLocType() + "\n"); +// sb.append("经 度 : " + location.getLongitude() + "\n"); +// sb.append("纬 度 : " + location.getLatitude() + "\n"); +// sb.append("精 度 : " + location.getRadius() + "米" + "\n"); +// +// sb.append("海 拔 : " + location.getAltitude() + "米" + "\n"); +// sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n"); +// sb.append("角 度 : " + location.getDirection() + "\n"); +// +// //逆地理信息 +// sb.append("国 家 : " + location.getCountry() + "\n"); +// sb.append("省 : " + location.getProvince() + "\n"); +// sb.append("市 : " + location.getCity() + "\n"); +// sb.append("城市编码 : " + location.getCityCode() + "\n"); +// sb.append("区 : " + location.getDistrict() + "\n"); +// sb.append("区域 码 : " + location.getAdCode() + "\n"); +// sb.append("地 址 : " + location.getAddress() + "\n"); +// //定位完成的时间 +// sb.append("定位时间: " + location.getTime() + "\n"); +// +// } else { +// //定位失败 +// sb.append("定位失败" + location.toString() + "\n"); +// } +// //定位之后的回调时间 +// sb.append("回调时间: " + formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n"); +// return sb.toString(); +// } public synchronized static String formatUTC(long l, String strPattern) { if (TextUtils.isEmpty(strPattern)) { diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/ExampleUtil.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/ExampleUtil.java index d715eb8..4c21ba0 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/ExampleUtil.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/ExampleUtil.java @@ -1,134 +1,134 @@ -package com.sucstepsoft.txrealtimelocation.services.jpush; - -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.os.Bundle; -import android.os.Looper; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.widget.Toast; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import cn.jpush.android.api.JPushInterface; -import cn.jpush.android.helper.Logger; - -public class ExampleUtil { - public static final String PREFS_NAME = "JPUSH_EXAMPLE"; - public static final String PREFS_DAYS = "JPUSH_EXAMPLE_DAYS"; - public static final String PREFS_START_TIME = "PREFS_START_TIME"; - public static final String PREFS_END_TIME = "PREFS_END_TIME"; - public static final String KEY_APP_KEY = "JPUSH_APPKEY"; - - public static boolean isEmpty(String s) { - if (null == s) - return true; - if (s.length() == 0) - return true; - if (s.trim().length() == 0) - return true; - return false; - } - /** - * 只能以 “+” 或者 数字开头;后面的内容只能包含 “-” 和 数字。 - * */ - private final static String MOBILE_NUMBER_CHARS = "^[+0-9][-0-9]{1,}$"; - public static boolean isValidMobileNumber(String s) { - if(TextUtils.isEmpty(s)) return true; - Pattern p = Pattern.compile(MOBILE_NUMBER_CHARS); - Matcher m = p.matcher(s); - return m.matches(); - } - // 校验Tag Alias 只能是数字,英文字母和中文 - public static boolean isValidTagAndAlias(String s) { - Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_!@#$&*+=.|]+$"); - Matcher m = p.matcher(s); - return m.matches(); - } - - // 取得AppKey - public static String getAppKey(Context context) { - Bundle metaData = null; - String appKey = null; - try { - ApplicationInfo ai = context.getPackageManager().getApplicationInfo( - context.getPackageName(), PackageManager.GET_META_DATA); - if (null != ai) - metaData = ai.metaData; - if (null != metaData) { - appKey = metaData.getString(KEY_APP_KEY); - if ((null == appKey) || appKey.length() != 24) { - appKey = null; - } - } - } catch (NameNotFoundException e) { - - } - return appKey; - } - - // 取得版本号 - public static String GetVersion(Context context) { - try { - PackageInfo manager = context.getPackageManager().getPackageInfo( - context.getPackageName(), 0); - return manager.versionName; - } catch (NameNotFoundException e) { - return "Unknown"; - } - } - - public static void showToast(final String toast, final Context context) - { - new Thread(new Runnable() { - - @Override - public void run() { - Looper.prepare(); - Toast.makeText(context, toast, Toast.LENGTH_SHORT).show(); - Looper.loop(); - } - }).start(); - } - - public static boolean isConnected(Context context) { - ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo info = conn.getActiveNetworkInfo(); - return (info != null && info.isConnected()); - } - - public static String getImei(Context context, String imei) { - String ret = null; - try { - TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - ret = telephonyManager.getDeviceId(); - } catch (Exception e) { - Logger.e(ExampleUtil.class.getSimpleName(), e.getMessage()); - } - if (isReadableASCII(ret)){ - return ret; - } else { - return imei; - } - } - - private static boolean isReadableASCII(CharSequence string){ - if (TextUtils.isEmpty(string)) return false; - try { - Pattern p = Pattern.compile("[\\x20-\\x7E]+"); - return p.matcher(string).matches(); - } catch (Throwable e){ - return true; - } - } - - public static String getDeviceId(Context context) { - return JPushInterface.getUdid(context); - } -} +//package com.sucstepsoft.txrealtimelocation.services.jpush; +// +//import android.content.Context; +//import android.content.pm.ApplicationInfo; +//import android.content.pm.PackageInfo; +//import android.content.pm.PackageManager; +//import android.content.pm.PackageManager.NameNotFoundException; +//import android.net.ConnectivityManager; +//import android.net.NetworkInfo; +//import android.os.Bundle; +//import android.os.Looper; +//import android.telephony.TelephonyManager; +//import android.text.TextUtils; +//import android.widget.Toast; +// +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +// +//import cn.jpush.android.api.JPushInterface; +//import cn.jpush.android.helper.Logger; +// +//public class ExampleUtil { +// public static final String PREFS_NAME = "JPUSH_EXAMPLE"; +// public static final String PREFS_DAYS = "JPUSH_EXAMPLE_DAYS"; +// public static final String PREFS_START_TIME = "PREFS_START_TIME"; +// public static final String PREFS_END_TIME = "PREFS_END_TIME"; +// public static final String KEY_APP_KEY = "JPUSH_APPKEY"; +// +// public static boolean isEmpty(String s) { +// if (null == s) +// return true; +// if (s.length() == 0) +// return true; +// if (s.trim().length() == 0) +// return true; +// return false; +// } +// /** +// * 只能以 “+” 或者 数字开头;后面的内容只能包含 “-” 和 数字。 +// * */ +// private final static String MOBILE_NUMBER_CHARS = "^[+0-9][-0-9]{1,}$"; +// public static boolean isValidMobileNumber(String s) { +// if(TextUtils.isEmpty(s)) return true; +// Pattern p = Pattern.compile(MOBILE_NUMBER_CHARS); +// Matcher m = p.matcher(s); +// return m.matches(); +// } +// // 校验Tag Alias 只能是数字,英文字母和中文 +// public static boolean isValidTagAndAlias(String s) { +// Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_!@#$&*+=.|]+$"); +// Matcher m = p.matcher(s); +// return m.matches(); +// } +// +// // 取得AppKey +// public static String getAppKey(Context context) { +// Bundle metaData = null; +// String appKey = null; +// try { +// ApplicationInfo ai = context.getPackageManager().getApplicationInfo( +// context.getPackageName(), PackageManager.GET_META_DATA); +// if (null != ai) +// metaData = ai.metaData; +// if (null != metaData) { +// appKey = metaData.getString(KEY_APP_KEY); +// if ((null == appKey) || appKey.length() != 24) { +// appKey = null; +// } +// } +// } catch (NameNotFoundException e) { +// +// } +// return appKey; +// } +// +// // 取得版本号 +// public static String GetVersion(Context context) { +// try { +// PackageInfo manager = context.getPackageManager().getPackageInfo( +// context.getPackageName(), 0); +// return manager.versionName; +// } catch (NameNotFoundException e) { +// return "Unknown"; +// } +// } +// +// public static void showToast(final String toast, final Context context) +// { +// new Thread(new Runnable() { +// +// @Override +// public void run() { +// Looper.prepare(); +// Toast.makeText(context, toast, Toast.LENGTH_SHORT).show(); +// Looper.loop(); +// } +// }).start(); +// } +// +// public static boolean isConnected(Context context) { +// ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); +// NetworkInfo info = conn.getActiveNetworkInfo(); +// return (info != null && info.isConnected()); +// } +// +// public static String getImei(Context context, String imei) { +// String ret = null; +// try { +// TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); +// ret = telephonyManager.getDeviceId(); +// } catch (Exception e) { +// Logger.e(ExampleUtil.class.getSimpleName(), e.getMessage()); +// } +// if (isReadableASCII(ret)){ +// return ret; +// } else { +// return imei; +// } +// } +// +// private static boolean isReadableASCII(CharSequence string){ +// if (TextUtils.isEmpty(string)) return false; +// try { +// Pattern p = Pattern.compile("[\\x20-\\x7E]+"); +// return p.matcher(string).matches(); +// } catch (Throwable e){ +// return true; +// } +// } +// +// public static String getDeviceId(Context context) { +// return JPushInterface.getUdid(context); +// } +//} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/MyReceiver.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/MyReceiver.java index 9f4d1cc..8b6d1b6 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/MyReceiver.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/MyReceiver.java @@ -1,128 +1,128 @@ -package com.sucstepsoft.txrealtimelocation.services.jpush; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.content.LocalBroadcastManager; -import android.text.TextUtils; - -import com.sucstepsoft.txrealtimelocation.activitys.base.MainActivity; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Iterator; - -import cn.jpush.android.api.JPushInterface; -import cn.jpush.android.helper.Logger; - -/** - * 自定义接收器 - *

- * 如果不定义这个 Receiver,则: - * 1) 默认用户会打开主界面 - * 2) 接收不到自定义消息 - */ -public class MyReceiver extends BroadcastReceiver { - private static final String TAG = "JIGUANG-Example"; - - @Override - public void onReceive(Context context, Intent intent) { - try { - Bundle bundle = intent.getExtras(); - Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle)); - - if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { - String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); - Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId); - //send the Registration Id to your server... - - } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { - Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)); - processCustomMessage(context, bundle); - - } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { - Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知"); - int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); - Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId); - - } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { - Logger.d(TAG, "[MyReceiver] 用户点击打开了通知"); -// //打开自定义的Activity -// Intent i = new Intent(context, MainActivity.class); -// i.putExtras(bundle); -// //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); -// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); -// context.startActivity(i); - } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { - Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); - //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. - } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { - boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); - Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); - } else { - Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); - } - } catch (Exception e) { - - } - - } - - // 打印所有的 intent extra 数据 - private static String printBundle(Bundle bundle) { - StringBuilder sb = new StringBuilder(); - for (String key : bundle.keySet()) { - if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { - sb.append("\nkey:" + key + ", value:" + bundle.getInt(key)); - } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) { - sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key)); - } else if (key.equals(JPushInterface.EXTRA_EXTRA)) { - if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) { - Logger.i(TAG, "This message has no Extra data"); - continue; - } - - try { - JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); - Iterator it = json.keys(); - - while (it.hasNext()) { - String myKey = it.next(); - sb.append("\nkey:" + key + ", value: [" + - myKey + " - " + json.optString(myKey) + "]"); - } - } catch (JSONException e) { - Logger.e(TAG, "Get message extra JSON error!"); - } - - } else { - sb.append("\nkey:" + key + ", value:" + bundle.get(key)); - } - } - return sb.toString(); - } - - //send msg to MainActivity - private void processCustomMessage(Context context, Bundle bundle) { - if (MainActivity.isForeground) { - String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); - String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); - Intent msgIntent = new Intent(MainActivity.MESSAGE_JPUSH); - msgIntent.putExtra(MainActivity.KEY_MESSAGE, message); - if (!ExampleUtil.isEmpty(extras)) { - try { - JSONObject extraJson = new JSONObject(extras); - if (extraJson.length() > 0) { - msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras); - } - } catch (JSONException e) { - - } - - } - LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent); - } - } -} +//package com.sucstepsoft.txrealtimelocation.services.jpush; +// +//import android.content.BroadcastReceiver; +//import android.content.Context; +//import android.content.Intent; +//import android.os.Bundle; +//import android.support.v4.content.LocalBroadcastManager; +//import android.text.TextUtils; +// +//import com.sucstepsoft.txrealtimelocation.activitys.base.MainActivity; +// +//import org.json.JSONException; +//import org.json.JSONObject; +// +//import java.util.Iterator; +// +//import cn.jpush.android.api.JPushInterface; +//import cn.jpush.android.helper.Logger; +// +///** +// * 自定义接收器 +// *

+// * 如果不定义这个 Receiver,则: +// * 1) 默认用户会打开主界面 +// * 2) 接收不到自定义消息 +// */ +//public class MyReceiver extends BroadcastReceiver { +// private static final String TAG = "JIGUANG-Example"; +// +// @Override +// public void onReceive(Context context, Intent intent) { +// try { +// Bundle bundle = intent.getExtras(); +// Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle)); +// +// if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { +// String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); +// Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId); +// //send the Registration Id to your server... +// +// } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { +// Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)); +// processCustomMessage(context, bundle); +// +// } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { +// Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知"); +// int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); +// Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId); +// +// } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { +// Logger.d(TAG, "[MyReceiver] 用户点击打开了通知"); +//// //打开自定义的Activity +//// Intent i = new Intent(context, MainActivity.class); +//// i.putExtras(bundle); +//// //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +//// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); +//// context.startActivity(i); +// } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { +// Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); +// //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. +// } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { +// boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); +// Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); +// } else { +// Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); +// } +// } catch (Exception e) { +// +// } +// +// } +// +// // 打印所有的 intent extra 数据 +// private static String printBundle(Bundle bundle) { +// StringBuilder sb = new StringBuilder(); +// for (String key : bundle.keySet()) { +// if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { +// sb.append("\nkey:" + key + ", value:" + bundle.getInt(key)); +// } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) { +// sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key)); +// } else if (key.equals(JPushInterface.EXTRA_EXTRA)) { +// if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) { +// Logger.i(TAG, "This message has no Extra data"); +// continue; +// } +// +// try { +// JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); +// Iterator it = json.keys(); +// +// while (it.hasNext()) { +// String myKey = it.next(); +// sb.append("\nkey:" + key + ", value: [" + +// myKey + " - " + json.optString(myKey) + "]"); +// } +// } catch (JSONException e) { +// Logger.e(TAG, "Get message extra JSON error!"); +// } +// +// } else { +// sb.append("\nkey:" + key + ", value:" + bundle.get(key)); +// } +// } +// return sb.toString(); +// } +// +// //send msg to MainActivity +// private void processCustomMessage(Context context, Bundle bundle) { +// if (MainActivity.isForeground) { +// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); +// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); +// Intent msgIntent = new Intent(MainActivity.MESSAGE_JPUSH); +// msgIntent.putExtra(MainActivity.KEY_MESSAGE, message); +// if (!ExampleUtil.isEmpty(extras)) { +// try { +// JSONObject extraJson = new JSONObject(extras); +// if (extraJson.length() > 0) { +// msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras); +// } +// } catch (JSONException e) { +// +// } +// +// } +// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent); +// } +// } +//} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushMessageReceiver.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushMessageReceiver.java index 3c2a934..7499761 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushMessageReceiver.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushMessageReceiver.java @@ -1,138 +1,138 @@ -package com.sucstepsoft.txrealtimelocation.services.jpush; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.content.LocalBroadcastManager; -import android.util.Log; - -import com.sucstepsoft.txrealtimelocation.activitys.base.LoginActivity; -import com.sucstepsoft.txrealtimelocation.activitys.base.MainActivity; - -import org.json.JSONException; -import org.json.JSONObject; - -import cn.jpush.android.api.CmdMessage; -import cn.jpush.android.api.CustomMessage; -import cn.jpush.android.api.JPushInterface; -import cn.jpush.android.api.JPushMessage; -import cn.jpush.android.api.NotificationMessage; -import cn.jpush.android.service.JPushMessageReceiver; - -public class PushMessageReceiver extends JPushMessageReceiver{ - private static final String TAG = "PushMessageReceiver"; - @Override - public void onMessage(Context context, CustomMessage customMessage) { - Log.e(TAG,"[onMessage] "+customMessage); - processCustomMessage(context,customMessage); - } - - @Override - public void onNotifyMessageOpened(Context context, NotificationMessage message) { - Log.e(TAG,"[onNotifyMessageOpened] "+message); - try{ - //打开自定义的Activity - Intent i = new Intent(context, LoginActivity.class); - Bundle bundle = new Bundle(); - bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE,message.notificationTitle); - bundle.putString(JPushInterface.EXTRA_ALERT,message.notificationContent); - i.putExtras(bundle); - //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP ); - context.startActivity(i); - }catch (Throwable throwable){ - - } - } - - @Override - public void onMultiActionClicked(Context context, Intent intent) { - Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮"); - String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA); - - //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。 - if(nActionExtra==null){ - Log.d(TAG,"ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null"); - return; - } - if (nActionExtra.equals("my_extra1")) { - Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一"); - } else if (nActionExtra.equals("my_extra2")) { - Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二"); - } else if (nActionExtra.equals("my_extra3")) { - Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三"); - } else { - Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义"); - } - } - - @Override - public void onNotifyMessageArrived(Context context, NotificationMessage message) { - Log.e(TAG,"[onNotifyMessageArrived] "+message); - } - - @Override - public void onNotifyMessageDismiss(Context context, NotificationMessage message) { - Log.e(TAG,"[onNotifyMessageDismiss] "+message); - } - - @Override - public void onRegister(Context context, String registrationId) { - Log.e(TAG,"[onRegister] "+registrationId); - } - - @Override - public void onConnected(Context context, boolean isConnected) { - Log.e(TAG,"[onConnected] "+isConnected); - } - - @Override - public void onCommandResult(Context context, CmdMessage cmdMessage) { - Log.e(TAG,"[onCommandResult] "+cmdMessage); - } - - @Override - public void onTagOperatorResult(Context context,JPushMessage jPushMessage) { - TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage); - super.onTagOperatorResult(context, jPushMessage); - } - @Override - public void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){ - TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage); - super.onCheckTagOperatorResult(context, jPushMessage); - } - @Override - public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { - TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage); - super.onAliasOperatorResult(context, jPushMessage); - } - - @Override - public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) { - TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage); - super.onMobileNumberOperatorResult(context, jPushMessage); - } - - //send msg to MainActivity - private void processCustomMessage(Context context, CustomMessage customMessage) { - if (MainActivity.isForeground) { - String message = customMessage.message; - String extras = customMessage.extra; - Intent msgIntent = new Intent(MainActivity.MESSAGE_JPUSH); - msgIntent.putExtra(MainActivity.KEY_MESSAGE, message); - if (!ExampleUtil.isEmpty(extras)) { - try { - JSONObject extraJson = new JSONObject(extras); - if (extraJson.length() > 0) { - msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras); - } - } catch (JSONException e) { - - } - - } - LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent); - } - } - -} +//package com.sucstepsoft.txrealtimelocation.services.jpush; +// +//import android.content.Context; +//import android.content.Intent; +//import android.os.Bundle; +//import android.support.v4.content.LocalBroadcastManager; +//import android.util.Log; +// +//import com.sucstepsoft.txrealtimelocation.activitys.base.LoginActivity; +//import com.sucstepsoft.txrealtimelocation.activitys.base.MainActivity; +// +//import org.json.JSONException; +//import org.json.JSONObject; +// +//import cn.jpush.android.api.CmdMessage; +//import cn.jpush.android.api.CustomMessage; +//import cn.jpush.android.api.JPushInterface; +//import cn.jpush.android.api.JPushMessage; +//import cn.jpush.android.api.NotificationMessage; +//import cn.jpush.android.service.JPushMessageReceiver; +// +//public class PushMessageReceiver extends JPushMessageReceiver{ +// private static final String TAG = "PushMessageReceiver"; +// @Override +// public void onMessage(Context context, CustomMessage customMessage) { +// Log.e(TAG,"[onMessage] "+customMessage); +// processCustomMessage(context,customMessage); +// } +// +// @Override +// public void onNotifyMessageOpened(Context context, NotificationMessage message) { +// Log.e(TAG,"[onNotifyMessageOpened] "+message); +// try{ +// //打开自定义的Activity +// Intent i = new Intent(context, LoginActivity.class); +// Bundle bundle = new Bundle(); +// bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE,message.notificationTitle); +// bundle.putString(JPushInterface.EXTRA_ALERT,message.notificationContent); +// i.putExtras(bundle); +// //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP ); +// context.startActivity(i); +// }catch (Throwable throwable){ +// +// } +// } +// +// @Override +// public void onMultiActionClicked(Context context, Intent intent) { +// Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮"); +// String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA); +// +// //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。 +// if(nActionExtra==null){ +// Log.d(TAG,"ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null"); +// return; +// } +// if (nActionExtra.equals("my_extra1")) { +// Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一"); +// } else if (nActionExtra.equals("my_extra2")) { +// Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二"); +// } else if (nActionExtra.equals("my_extra3")) { +// Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三"); +// } else { +// Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义"); +// } +// } +// +// @Override +// public void onNotifyMessageArrived(Context context, NotificationMessage message) { +// Log.e(TAG,"[onNotifyMessageArrived] "+message); +// } +// +// @Override +// public void onNotifyMessageDismiss(Context context, NotificationMessage message) { +// Log.e(TAG,"[onNotifyMessageDismiss] "+message); +// } +// +// @Override +// public void onRegister(Context context, String registrationId) { +// Log.e(TAG,"[onRegister] "+registrationId); +// } +// +// @Override +// public void onConnected(Context context, boolean isConnected) { +// Log.e(TAG,"[onConnected] "+isConnected); +// } +// +// @Override +// public void onCommandResult(Context context, CmdMessage cmdMessage) { +// Log.e(TAG,"[onCommandResult] "+cmdMessage); +// } +// +// @Override +// public void onTagOperatorResult(Context context,JPushMessage jPushMessage) { +// TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage); +// super.onTagOperatorResult(context, jPushMessage); +// } +// @Override +// public void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){ +// TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage); +// super.onCheckTagOperatorResult(context, jPushMessage); +// } +// @Override +// public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { +// TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage); +// super.onAliasOperatorResult(context, jPushMessage); +// } +// +// @Override +// public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) { +// TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage); +// super.onMobileNumberOperatorResult(context, jPushMessage); +// } +// +// //send msg to MainActivity +// private void processCustomMessage(Context context, CustomMessage customMessage) { +// if (MainActivity.isForeground) { +// String message = customMessage.message; +// String extras = customMessage.extra; +// Intent msgIntent = new Intent(MainActivity.MESSAGE_JPUSH); +// msgIntent.putExtra(MainActivity.KEY_MESSAGE, message); +// if (!ExampleUtil.isEmpty(extras)) { +// try { +// JSONObject extraJson = new JSONObject(extras); +// if (extraJson.length() > 0) { +// msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras); +// } +// } catch (JSONException e) { +// +// } +// +// } +// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent); +// } +// } +// +//} diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushService.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushService.java index f3d2cd0..569a0c2 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushService.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/PushService.java @@ -1,8 +1,11 @@ package com.sucstepsoft.txrealtimelocation.services.jpush; -import cn.jpush.android.service.JCommonService; +//import cn.jpush.android.service.JCommonService; -public class PushService extends JCommonService { +public class PushService { } +//public class PushService extends JCommonService { +// +//} \ No newline at end of file diff --git a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/TagAliasOperatorHelper.java b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/TagAliasOperatorHelper.java index b342ef9..2ba610b 100755 --- a/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/TagAliasOperatorHelper.java +++ b/app/src/main/java/com/sucstepsoft/txrealtimelocation/services/jpush/TagAliasOperatorHelper.java @@ -1,378 +1,378 @@ -package com.sucstepsoft.txrealtimelocation.services.jpush; - -import android.content.Context; -import android.os.Handler; -import android.os.Message; -import android.util.SparseArray; - -import com.sucstepsoft.cm_utils.utils.LogUtils; -import com.sucstepsoft.cm_utils.utils.UserLgUtils; - -import java.util.Locale; -import java.util.Set; - -import cn.jpush.android.api.JPushInterface; -import cn.jpush.android.api.JPushMessage; -import cn.jpush.android.helper.Logger; - -/** - * 处理tagalias相关的逻辑 - */ -public class TagAliasOperatorHelper { - private static final String TAG = "JIGUANG-TagAliasHelper"; - public static int sequence = 1; - /** - * 增加 - */ - public static final int ACTION_ADD = 1; - /** - * 覆盖 - */ - public static final int ACTION_SET = 2; - /** - * 删除部分 - */ - public static final int ACTION_DELETE = 3; - /** - * 删除所有 - */ - public static final int ACTION_CLEAN = 4; - /** - * 查询 - */ - public static final int ACTION_GET = 5; - - public static final int ACTION_CHECK = 6; - - public static final int DELAY_SEND_ACTION = 1; - - public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2; - - private Context context; - - private static TagAliasOperatorHelper mInstance; - - private TagAliasOperatorHelper() { - } - - public static TagAliasOperatorHelper getInstance() { - if (mInstance == null) { - synchronized (TagAliasOperatorHelper.class) { - if (mInstance == null) { - mInstance = new TagAliasOperatorHelper(); - } - } - } - return mInstance; - } - - public void init(Context context) { - if (context != null) { - this.context = context.getApplicationContext(); - } - } - - private SparseArray setActionCache = new SparseArray(); - - public Object get(int sequence) { - return setActionCache.get(sequence); - } - - public Object remove(int sequence) { - return setActionCache.get(sequence); - } - - public void put(int sequence, Object tagAliasBean) { - setActionCache.put(sequence, tagAliasBean); - } - - private Handler delaySendHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case DELAY_SEND_ACTION: - if (msg.obj != null && msg.obj instanceof TagAliasBean) { - Logger.i(TAG, "on delay time"); - sequence++; - TagAliasBean tagAliasBean = (TagAliasBean) msg.obj; - setActionCache.put(sequence, tagAliasBean); - if (context != null) { - handleAction(context, sequence, tagAliasBean); - } else { - Logger.e(TAG, "#unexcepted - context was null"); - } - } else { - Logger.w(TAG, "#unexcepted - msg obj was incorrect"); - } - break; - case DELAY_SET_MOBILE_NUMBER_ACTION: - if (msg.obj != null && msg.obj instanceof String) { - Logger.i(TAG, "retry set mobile number"); - sequence++; - String mobileNumber = (String) msg.obj; - setActionCache.put(sequence, mobileNumber); - if (context != null) { - handleAction(context, sequence, mobileNumber); - } else { - Logger.e(TAG, "#unexcepted - context was null"); - } - } else { - Logger.w(TAG, "#unexcepted - msg obj was incorrect"); - } - break; - } - } - }; - - public void handleAction(Context context, int sequence, String mobileNumber) { - put(sequence, mobileNumber); - Logger.d(TAG, "sequence:" + sequence + ",mobileNumber:" + mobileNumber); - JPushInterface.setMobileNumber(context, sequence, mobileNumber); - } - - /** - * 处理设置tag - */ - public void handleAction(Context context, int sequence, TagAliasBean tagAliasBean) { - init(context); - if (tagAliasBean == null) { - Logger.w(TAG, "tagAliasBean was null"); - return; - } - put(sequence, tagAliasBean); - if (tagAliasBean.isAliasAction) { - switch (tagAliasBean.action) { - case ACTION_GET: - JPushInterface.getAlias(context, sequence); - break; - case ACTION_DELETE: - JPushInterface.deleteAlias(context, sequence); - break; - case ACTION_SET: - JPushInterface.setAlias(context, sequence, tagAliasBean.alias); - break; - default: - Logger.w(TAG, "unsupport alias action type"); - return; - } - } else { - switch (tagAliasBean.action) { - case ACTION_ADD: - JPushInterface.addTags(context, sequence, tagAliasBean.tags); - break; - case ACTION_SET: - JPushInterface.setTags(context, sequence, tagAliasBean.tags); - break; - case ACTION_DELETE: - JPushInterface.deleteTags(context, sequence, tagAliasBean.tags); - break; - case ACTION_CHECK: - //一次只能check一个tag - String tag = (String) tagAliasBean.tags.toArray()[0]; - JPushInterface.checkTagBindState(context, sequence, tag); - break; - case ACTION_GET: - JPushInterface.getAllTags(context, sequence); - break; - case ACTION_CLEAN: - JPushInterface.cleanTags(context, sequence); - break; - default: - Logger.w(TAG, "unsupport tag action type"); - return; - } - } - } - - private boolean RetryActionIfNeeded(int errorCode, TagAliasBean tagAliasBean) { - if (!ExampleUtil.isConnected(context)) { - Logger.w(TAG, "no network"); - return false; - } - //返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试 - if (errorCode == 6002 || errorCode == 6014) { - Logger.d(TAG, "need retry"); - if (tagAliasBean != null) { - Message message = new Message(); - message.what = DELAY_SEND_ACTION; - message.obj = tagAliasBean; - delaySendHandler.sendMessageDelayed(message, 1000 * 60); - String logs = getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action, errorCode); - ExampleUtil.showToast(logs, context); - return true; - } - } - return false; - } - - private boolean RetrySetMObileNumberActionIfNeeded(int errorCode, String mobileNumber) { - if (!ExampleUtil.isConnected(context)) { - Logger.w(TAG, "no network"); - return false; - } - //返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试 - if (errorCode == 6002 || errorCode == 6024) { - Logger.d(TAG, "need retry"); - Message message = new Message(); - message.what = DELAY_SET_MOBILE_NUMBER_ACTION; - message.obj = mobileNumber; - delaySendHandler.sendMessageDelayed(message, 1000 * 60); - String str = "Failed to set mobile number due to %s. Try again after 60s."; - str = String.format(Locale.ENGLISH, str, (errorCode == 6002 ? "timeout" : "server internal error”")); - ExampleUtil.showToast(str, context); - return true; - } - return false; - - } - - private String getRetryStr(boolean isAliasAction, int actionType, int errorCode) { - String str = "Failed to %s %s due to %s. Try again after 60s."; - str = String.format(Locale.ENGLISH, str, getActionStr(actionType), (isAliasAction ? "alias" : " tags"), (errorCode == 6002 ? "timeout" : "server too busy")); - return str; - } - - private String getActionStr(int actionType) { - switch (actionType) { - case ACTION_ADD: - return "add"; - case ACTION_SET: - return "set"; - case ACTION_DELETE: - return "delete"; - case ACTION_GET: - return "get"; - case ACTION_CLEAN: - return "clean"; - case ACTION_CHECK: - return "check"; - } - return "unkonw operation"; - } - - public void onTagOperatorResult(Context context, JPushMessage jPushMessage) { - int sequence = jPushMessage.getSequence(); - Logger.i(TAG, "action - onTagOperatorResult, sequence:" + sequence + ",tags:" + jPushMessage.getTags()); - Logger.i(TAG, "tags size:" + jPushMessage.getTags().size()); - init(context); - //根据sequence从之前操作缓存中获取缓存记录 - TagAliasBean tagAliasBean = (TagAliasBean) setActionCache.get(sequence); - if (tagAliasBean == null) { -// ExampleUtil.showToast("获取缓存记录失败", context); - return; - } - if (jPushMessage.getErrorCode() == 0) { - Logger.i(TAG, "action - modify tag Success,sequence:" + sequence); - setActionCache.remove(sequence); - String logs = getActionStr(tagAliasBean.action) + " tags success"; - Logger.i(TAG, logs); - ExampleUtil.showToast(logs, context); - } else { - String logs = "Failed to " + getActionStr(tagAliasBean.action) + " tags"; - if (jPushMessage.getErrorCode() == 6018) { - //tag数量超过限制,需要先清除一部分再add - logs += ", tags is exceed limit need to clean"; - } - logs += ", errorCode:" + jPushMessage.getErrorCode(); - Logger.e(TAG, logs); - if (!RetryActionIfNeeded(jPushMessage.getErrorCode(), tagAliasBean)) { - ExampleUtil.showToast(logs, context); - } - } - } - - /** - * 设置别名回调 - * - * @param context - * @param jPushMessage - */ - public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) { - int sequence = jPushMessage.getSequence(); - Logger.i(TAG, "action - onCheckTagOperatorResult, sequence:" + sequence + ",checktag:" + jPushMessage.getCheckTag()); - init(context); - //根据sequence从之前操作缓存中获取缓存记录 - TagAliasBean tagAliasBean = (TagAliasBean) setActionCache.get(sequence); - if (tagAliasBean == null) { -// ExampleUtil.showToast("获取缓存记录失败", context); - return; - } - if (jPushMessage.getErrorCode() == 0) { - Logger.i(TAG, "tagBean:" + tagAliasBean); - setActionCache.remove(sequence); - String logs = getActionStr(tagAliasBean.action) + " tag " + jPushMessage.getCheckTag() + " bind state success,state:" + jPushMessage.getTagCheckStateResult(); - Logger.i(TAG, logs); - ExampleUtil.showToast(logs, context); - } else { - String logs = "Failed to " + getActionStr(tagAliasBean.action) + " tags, errorCode:" + jPushMessage.getErrorCode(); - Logger.e(TAG, logs); - if (!RetryActionIfNeeded(jPushMessage.getErrorCode(), tagAliasBean)) { - ExampleUtil.showToast(logs, context); - } - } - } - - public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { - int sequence = jPushMessage.getSequence(); - Logger.i(TAG, "action - onAliasOperatorResult, sequence:" + sequence + ",alias:" + jPushMessage.getAlias()); - init(context); - //根据sequence从之前操作缓存中获取缓存记录 - TagAliasBean tagAliasBean = (TagAliasBean) setActionCache.get(sequence); - if (tagAliasBean == null) { -// ExampleUtil.showToast("获取缓存记录失败", context); - return; - } - if (jPushMessage.getErrorCode() == 0) { - UserLgUtils.setAlias(true); - LogUtils.e("设置成功"); - Logger.i(TAG, "action - modify alias Success,sequence:" + sequence); - setActionCache.remove(sequence); - String logs = getActionStr(tagAliasBean.action) + " alias success"; - Logger.i(TAG, logs); - ExampleUtil.showToast(logs, context); - } else { - UserLgUtils.setAlias(false); - String logs = "Failed to " + getActionStr(tagAliasBean.action) + " alias, errorCode:" + jPushMessage.getErrorCode(); - Logger.e(TAG, logs); - if (!RetryActionIfNeeded(jPushMessage.getErrorCode(), tagAliasBean)) { - ExampleUtil.showToast(logs, context); - } - } - } - - //设置手机号码回调 - public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) { - int sequence = jPushMessage.getSequence(); - Logger.i(TAG, "action - onMobileNumberOperatorResult, sequence:" + sequence + ",mobileNumber:" + jPushMessage.getMobileNumber()); - init(context); - if (jPushMessage.getErrorCode() == 0) { - Logger.i(TAG, "action - set mobile number Success,sequence:" + sequence); - setActionCache.remove(sequence); - } else { - String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode(); - Logger.e(TAG, logs); - if (!RetrySetMObileNumberActionIfNeeded(jPushMessage.getErrorCode(), jPushMessage.getMobileNumber())) { - ExampleUtil.showToast(logs, context); - } - } - } - - public static class TagAliasBean { - int action; - Set tags; - String alias; - boolean isAliasAction; - - @Override - public String toString() { - return "TagAliasBean{" + - "action=" + action + - ", tags=" + tags + - ", alias='" + alias + '\'' + - ", isAliasAction=" + isAliasAction + - '}'; - } - } - - -} +//package com.sucstepsoft.txrealtimelocation.services.jpush; +// +//import android.content.Context; +//import android.os.Handler; +//import android.os.Message; +//import android.util.SparseArray; +// +//import com.sucstepsoft.cm_utils.utils.LogUtils; +//import com.sucstepsoft.cm_utils.utils.UserLgUtils; +// +//import java.util.Locale; +//import java.util.Set; +// +//import cn.jpush.android.api.JPushInterface; +//import cn.jpush.android.api.JPushMessage; +//import cn.jpush.android.helper.Logger; +// +///** +// * 处理tagalias相关的逻辑 +// */ +//public class TagAliasOperatorHelper { +// private static final String TAG = "JIGUANG-TagAliasHelper"; +// public static int sequence = 1; +// /** +// * 增加 +// */ +// public static final int ACTION_ADD = 1; +// /** +// * 覆盖 +// */ +// public static final int ACTION_SET = 2; +// /** +// * 删除部分 +// */ +// public static final int ACTION_DELETE = 3; +// /** +// * 删除所有 +// */ +// public static final int ACTION_CLEAN = 4; +// /** +// * 查询 +// */ +// public static final int ACTION_GET = 5; +// +// public static final int ACTION_CHECK = 6; +// +// public static final int DELAY_SEND_ACTION = 1; +// +// public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2; +// +// private Context context; +// +// private static TagAliasOperatorHelper mInstance; +// +// private TagAliasOperatorHelper() { +// } +// +// public static TagAliasOperatorHelper getInstance() { +// if (mInstance == null) { +// synchronized (TagAliasOperatorHelper.class) { +// if (mInstance == null) { +// mInstance = new TagAliasOperatorHelper(); +// } +// } +// } +// return mInstance; +// } +// +// public void init(Context context) { +// if (context != null) { +// this.context = context.getApplicationContext(); +// } +// } +// +// private SparseArray setActionCache = new SparseArray(); +// +// public Object get(int sequence) { +// return setActionCache.get(sequence); +// } +// +// public Object remove(int sequence) { +// return setActionCache.get(sequence); +// } +// +// public void put(int sequence, Object tagAliasBean) { +// setActionCache.put(sequence, tagAliasBean); +// } +// +// private Handler delaySendHandler = new Handler() { +// @Override +// public void handleMessage(Message msg) { +// switch (msg.what) { +// case DELAY_SEND_ACTION: +// if (msg.obj != null && msg.obj instanceof TagAliasBean) { +// Logger.i(TAG, "on delay time"); +// sequence++; +// TagAliasBean tagAliasBean = (TagAliasBean) msg.obj; +// setActionCache.put(sequence, tagAliasBean); +// if (context != null) { +// handleAction(context, sequence, tagAliasBean); +// } else { +// Logger.e(TAG, "#unexcepted - context was null"); +// } +// } else { +// Logger.w(TAG, "#unexcepted - msg obj was incorrect"); +// } +// break; +// case DELAY_SET_MOBILE_NUMBER_ACTION: +// if (msg.obj != null && msg.obj instanceof String) { +// Logger.i(TAG, "retry set mobile number"); +// sequence++; +// String mobileNumber = (String) msg.obj; +// setActionCache.put(sequence, mobileNumber); +// if (context != null) { +// handleAction(context, sequence, mobileNumber); +// } else { +// Logger.e(TAG, "#unexcepted - context was null"); +// } +// } else { +// Logger.w(TAG, "#unexcepted - msg obj was incorrect"); +// } +// break; +// } +// } +// }; +// +// public void handleAction(Context context, int sequence, String mobileNumber) { +// put(sequence, mobileNumber); +// Logger.d(TAG, "sequence:" + sequence + ",mobileNumber:" + mobileNumber); +// JPushInterface.setMobileNumber(context, sequence, mobileNumber); +// } +// +// /** +// * 处理设置tag +// */ +// public void handleAction(Context context, int sequence, TagAliasBean tagAliasBean) { +// init(context); +// if (tagAliasBean == null) { +// Logger.w(TAG, "tagAliasBean was null"); +// return; +// } +// put(sequence, tagAliasBean); +// if (tagAliasBean.isAliasAction) { +// switch (tagAliasBean.action) { +// case ACTION_GET: +// JPushInterface.getAlias(context, sequence); +// break; +// case ACTION_DELETE: +// JPushInterface.deleteAlias(context, sequence); +// break; +// case ACTION_SET: +// JPushInterface.setAlias(context, sequence, tagAliasBean.alias); +// break; +// default: +// Logger.w(TAG, "unsupport alias action type"); +// return; +// } +// } else { +// switch (tagAliasBean.action) { +// case ACTION_ADD: +// JPushInterface.addTags(context, sequence, tagAliasBean.tags); +// break; +// case ACTION_SET: +// JPushInterface.setTags(context, sequence, tagAliasBean.tags); +// break; +// case ACTION_DELETE: +// JPushInterface.deleteTags(context, sequence, tagAliasBean.tags); +// break; +// case ACTION_CHECK: +// //一次只能check一个tag +// String tag = (String) tagAliasBean.tags.toArray()[0]; +// JPushInterface.checkTagBindState(context, sequence, tag); +// break; +// case ACTION_GET: +// JPushInterface.getAllTags(context, sequence); +// break; +// case ACTION_CLEAN: +// JPushInterface.cleanTags(context, sequence); +// break; +// default: +// Logger.w(TAG, "unsupport tag action type"); +// return; +// } +// } +// } +// +// private boolean RetryActionIfNeeded(int errorCode, TagAliasBean tagAliasBean) { +// if (!ExampleUtil.isConnected(context)) { +// Logger.w(TAG, "no network"); +// return false; +// } +// //返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试 +// if (errorCode == 6002 || errorCode == 6014) { +// Logger.d(TAG, "need retry"); +// if (tagAliasBean != null) { +// Message message = new Message(); +// message.what = DELAY_SEND_ACTION; +// message.obj = tagAliasBean; +// delaySendHandler.sendMessageDelayed(message, 1000 * 60); +// String logs = getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action, errorCode); +// ExampleUtil.showToast(logs, context); +// return true; +// } +// } +// return false; +// } +// +// private boolean RetrySetMObileNumberActionIfNeeded(int errorCode, String mobileNumber) { +// if (!ExampleUtil.isConnected(context)) { +// Logger.w(TAG, "no network"); +// return false; +// } +// //返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试 +// if (errorCode == 6002 || errorCode == 6024) { +// Logger.d(TAG, "need retry"); +// Message message = new Message(); +// message.what = DELAY_SET_MOBILE_NUMBER_ACTION; +// message.obj = mobileNumber; +// delaySendHandler.sendMessageDelayed(message, 1000 * 60); +// String str = "Failed to set mobile number due to %s. Try again after 60s."; +// str = String.format(Locale.ENGLISH, str, (errorCode == 6002 ? "timeout" : "server internal error”")); +// ExampleUtil.showToast(str, context); +// return true; +// } +// return false; +// +// } +// +// private String getRetryStr(boolean isAliasAction, int actionType, int errorCode) { +// String str = "Failed to %s %s due to %s. Try again after 60s."; +// str = String.format(Locale.ENGLISH, str, getActionStr(actionType), (isAliasAction ? "alias" : " tags"), (errorCode == 6002 ? "timeout" : "server too busy")); +// return str; +// } +// +// private String getActionStr(int actionType) { +// switch (actionType) { +// case ACTION_ADD: +// return "add"; +// case ACTION_SET: +// return "set"; +// case ACTION_DELETE: +// return "delete"; +// case ACTION_GET: +// return "get"; +// case ACTION_CLEAN: +// return "clean"; +// case ACTION_CHECK: +// return "check"; +// } +// return "unkonw operation"; +// } +// +// public void onTagOperatorResult(Context context, JPushMessage jPushMessage) { +// int sequence = jPushMessage.getSequence(); +// Logger.i(TAG, "action - onTagOperatorResult, sequence:" + sequence + ",tags:" + jPushMessage.getTags()); +// Logger.i(TAG, "tags size:" + jPushMessage.getTags().size()); +// init(context); +// //根据sequence从之前操作缓存中获取缓存记录 +// TagAliasBean tagAliasBean = (TagAliasBean) setActionCache.get(sequence); +// if (tagAliasBean == null) { +//// ExampleUtil.showToast("获取缓存记录失败", context); +// return; +// } +// if (jPushMessage.getErrorCode() == 0) { +// Logger.i(TAG, "action - modify tag Success,sequence:" + sequence); +// setActionCache.remove(sequence); +// String logs = getActionStr(tagAliasBean.action) + " tags success"; +// Logger.i(TAG, logs); +// ExampleUtil.showToast(logs, context); +// } else { +// String logs = "Failed to " + getActionStr(tagAliasBean.action) + " tags"; +// if (jPushMessage.getErrorCode() == 6018) { +// //tag数量超过限制,需要先清除一部分再add +// logs += ", tags is exceed limit need to clean"; +// } +// logs += ", errorCode:" + jPushMessage.getErrorCode(); +// Logger.e(TAG, logs); +// if (!RetryActionIfNeeded(jPushMessage.getErrorCode(), tagAliasBean)) { +// ExampleUtil.showToast(logs, context); +// } +// } +// } +// +// /** +// * 设置别名回调 +// * +// * @param context +// * @param jPushMessage +// */ +// public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) { +// int sequence = jPushMessage.getSequence(); +// Logger.i(TAG, "action - onCheckTagOperatorResult, sequence:" + sequence + ",checktag:" + jPushMessage.getCheckTag()); +// init(context); +// //根据sequence从之前操作缓存中获取缓存记录 +// TagAliasBean tagAliasBean = (TagAliasBean) setActionCache.get(sequence); +// if (tagAliasBean == null) { +//// ExampleUtil.showToast("获取缓存记录失败", context); +// return; +// } +// if (jPushMessage.getErrorCode() == 0) { +// Logger.i(TAG, "tagBean:" + tagAliasBean); +// setActionCache.remove(sequence); +// String logs = getActionStr(tagAliasBean.action) + " tag " + jPushMessage.getCheckTag() + " bind state success,state:" + jPushMessage.getTagCheckStateResult(); +// Logger.i(TAG, logs); +// ExampleUtil.showToast(logs, context); +// } else { +// String logs = "Failed to " + getActionStr(tagAliasBean.action) + " tags, errorCode:" + jPushMessage.getErrorCode(); +// Logger.e(TAG, logs); +// if (!RetryActionIfNeeded(jPushMessage.getErrorCode(), tagAliasBean)) { +// ExampleUtil.showToast(logs, context); +// } +// } +// } +// +// public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { +// int sequence = jPushMessage.getSequence(); +// Logger.i(TAG, "action - onAliasOperatorResult, sequence:" + sequence + ",alias:" + jPushMessage.getAlias()); +// init(context); +// //根据sequence从之前操作缓存中获取缓存记录 +// TagAliasBean tagAliasBean = (TagAliasBean) setActionCache.get(sequence); +// if (tagAliasBean == null) { +//// ExampleUtil.showToast("获取缓存记录失败", context); +// return; +// } +// if (jPushMessage.getErrorCode() == 0) { +// UserLgUtils.setAlias(true); +// LogUtils.e("设置成功"); +// Logger.i(TAG, "action - modify alias Success,sequence:" + sequence); +// setActionCache.remove(sequence); +// String logs = getActionStr(tagAliasBean.action) + " alias success"; +// Logger.i(TAG, logs); +// ExampleUtil.showToast(logs, context); +// } else { +// UserLgUtils.setAlias(false); +// String logs = "Failed to " + getActionStr(tagAliasBean.action) + " alias, errorCode:" + jPushMessage.getErrorCode(); +// Logger.e(TAG, logs); +// if (!RetryActionIfNeeded(jPushMessage.getErrorCode(), tagAliasBean)) { +// ExampleUtil.showToast(logs, context); +// } +// } +// } +// +// //设置手机号码回调 +// public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) { +// int sequence = jPushMessage.getSequence(); +// Logger.i(TAG, "action - onMobileNumberOperatorResult, sequence:" + sequence + ",mobileNumber:" + jPushMessage.getMobileNumber()); +// init(context); +// if (jPushMessage.getErrorCode() == 0) { +// Logger.i(TAG, "action - set mobile number Success,sequence:" + sequence); +// setActionCache.remove(sequence); +// } else { +// String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode(); +// Logger.e(TAG, logs); +// if (!RetrySetMObileNumberActionIfNeeded(jPushMessage.getErrorCode(), jPushMessage.getMobileNumber())) { +// ExampleUtil.showToast(logs, context); +// } +// } +// } +// +// public static class TagAliasBean { +// int action; +// Set tags; +// String alias; +// boolean isAliasAction; +// +// @Override +// public String toString() { +// return "TagAliasBean{" + +// "action=" + action + +// ", tags=" + tags + +// ", alias='" + alias + '\'' + +// ", isAliasAction=" + isAliasAction + +// '}'; +// } +// } +// +// +//} diff --git a/app/src/main/res/drawable-xhdpi/bg_login.jpg b/app/src/main/res/drawable-xhdpi/bg_login.jpg new file mode 100644 index 0000000..81b4d16 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/bg_login.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/ic_checked.png b/app/src/main/res/drawable-xhdpi/ic_checked.png new file mode 100644 index 0000000..1a86b86 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_checked.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_uncheck.png b/app/src/main/res/drawable-xhdpi/ic_uncheck.png new file mode 100644 index 0000000..bddebdb Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_uncheck.png differ diff --git a/app/src/main/res/drawable/sel_remeber_pwd.xml b/app/src/main/res/drawable/sel_remeber_pwd.xml new file mode 100644 index 0000000..85338d7 --- /dev/null +++ b/app/src/main/res/drawable/sel_remeber_pwd.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_company_detail.xml b/app/src/main/res/layout/activity_company_detail.xml new file mode 100644 index 0000000..f587e54 --- /dev/null +++ b/app/src/main/res/layout/activity_company_detail.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_company_info_edit.xml b/app/src/main/res/layout/activity_company_info_edit.xml new file mode 100644 index 0000000..477f9ab --- /dev/null +++ b/app/src/main/res/layout/activity_company_info_edit.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_company_lib.xml b/app/src/main/res/layout/activity_company_lib.xml new file mode 100644 index 0000000..063f706 --- /dev/null +++ b/app/src/main/res/layout/activity_company_lib.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + +