| | |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.drawable.BitmapDrawable; |
| | | import android.hardware.Camera; |
| | | import android.opengl.Visibility; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baidu.idl.main.facesdk.model.BDFaceSDKCommon; |
| | | import com.baidu.idl.main.facesdk.utils.StreamUtil; |
| | | import com.bigkoo.convenientbanner.holder.CBViewHolderCreator; |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.load.DataSource; |
| | |
| | | import com.bumptech.glide.request.target.Target; |
| | | import com.bumptech.glide.request.transition.Transition; |
| | | import com.doumee.keyCabinet.BuildConfig; |
| | | import com.doumee.keyCabinet.base.BannerPicResponsePara; |
| | | import com.doumee.keyCabinet.bean.CabinetConfigDataBean; |
| | | import com.doumee.keyCabinet.bean.DevConfigBean; |
| | | import com.doumee.keyCabinet.bean.FaceUserBean; |
| | | import com.doumee.keyCabinet.bean.LoginBean; |
| | | import com.doumee.keyCabinet.dao.CabinetGridDo; |
| | | import com.doumee.keyCabinet.dao.DaoManager; |
| | | import com.doumee.keyCabinet.databinding.MainActivityBinding; |
| | |
| | | import com.doumee.keyCabinet.event.GetKeyStatusEvent; |
| | | import com.doumee.keyCabinet.event.HeartEvent; |
| | | import com.doumee.keyCabinet.event.HttpEvent; |
| | | import com.doumee.keyCabinet.event.JiujinBeginEvent; |
| | | import com.doumee.keyCabinet.event.JiujinResultEvent; |
| | | import com.doumee.keyCabinet.event.KeyResultEvent; |
| | | import com.doumee.keyCabinet.event.ManageOpenGridResultEvent; |
| | | import com.doumee.keyCabinet.event.OpenAllGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridListEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridOneResultEvent; |
| | | import com.doumee.keyCabinet.event.ReLoginEvent; |
| | | import com.doumee.keyCabinet.event.TimeClockEvent; |
| | | import com.doumee.keyCabinet.ui.face.ActivationActivity; |
| | | import com.doumee.keyCabinet.ui.face.FaceActivity; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.ChangeUrlActivity; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.KeyCabinetActivity; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.ManageLoginActivity; |
| | |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | import java.util.TimerTask; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.Future; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import dagger.hilt.android.AndroidEntryPoint; |
| | | import timber.log.Timber; |
| | |
| | | if(!isFinishing()){ |
| | | switch (msg.what) { |
| | | case 0: |
| | | //initM(); |
| | | initM(); |
| | | TimeUtils.updateTimeUi(getVM().dayObs, getVM().timeObs); |
| | | handler.sendEmptyMessageDelayed(0, 1000); |
| | | EventBus.getDefault().post(new TimeClockEvent()); |
| | |
| | | SpUtil.initWH(this); |
| | | normalConfig(); |
| | | getDB().setModel(getVM()); |
| | | //initRGBCheck(); |
| | | initRGBCheck(); |
| | | handler.sendEmptyMessageDelayed(0, 1000); |
| | | //启动心跳 |
| | | Intent intent = new Intent(MainActivity.this, HeartbeatService.class); |
| | |
| | | startService(intent2); |
| | | getPermission(); |
| | | Timber.tag("====>").d(LMobileInfo.getDeviceUniqueId()); |
| | | initPort(); |
| | | } |
| | | |
| | | private void initM(){ |
| | |
| | | if((availableMemory<400&&showTime!=null&&(System.currentTimeMillis()-showTime>5000))|| |
| | | ("02:00:00".equals(StringUtil.getHM()))){ |
| | | //可用内存小于400M,或者每天凌晨2点,重启app |
| | | restartApp(); |
| | | //restartApp(); |
| | | } |
| | | } |
| | | |
| | |
| | | getDB().tvId.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(ManageLoginActivity.class); |
| | | //更改url |
| | | if(lastDownTime2!=null){ |
| | | if(System.currentTimeMillis()-lastDownTime2>1000){ |
| | |
| | | } |
| | | } |
| | | }); |
| | | getDB().tvVersion.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //todo 临时代码 |
| | | //setJiuConfig(); |
| | | SpUtil.saveString("rbgCameraId","0"); |
| | | } |
| | | }); |
| | | getDB().imgLeft.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //todo 临时代码 |
| | | if (getDB().nsv.getVisibility()== View.VISIBLE) { |
| | | getDB().nsv.setVisibility(View.GONE); |
| | | }else { |
| | | getDB().nsv.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | upErrInfo(); |
| | | getVM().devLogin(); |
| | | getVM().devHeart(); |
| | |
| | | setBanner(devConfigBean.getBannerList()); |
| | | } |
| | | setJiuConfig(); |
| | | initPort(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void setJiuConfig(){ |
| | | getVM().addInfo("酒精配置:"+(MApplication.getConfigBean().getCabinetConfigDataVO()!=null)+ |
| | | ",串口开启:"+(jiuPort!=null)); |
| | | if(MApplication.getConfigBean().getCabinetConfigDataVO()!=null&& |
| | | jiuPort!=null){ |
| | | setJiuConfig(0); |
| | |
| | | case 2: |
| | | case 3: { |
| | | //校验是否登录 |
| | | /*if(MApplication.getConfigBean().getId()==null){ |
| | | if(MApplication.getConfigBean().getId()==null){ |
| | | Toast.makeText(mContext, "设备未添加,无法操作", Toast.LENGTH_SHORT).show(); |
| | | getVM().devLogin(); |
| | | return; |
| | | } |
| | | MApplication.getLoginBean().setFlag(type==2?0:1); |
| | | startActivity(FaceActivity.class);*/ |
| | | /*if(type==2){ |
| | | send485(1,"A002010000000003"); |
| | | }else { |
| | | send485(1,"A001010000000002"); |
| | | }*/ |
| | | //send485(1,"A001010000000002"); |
| | | //send485(1,"A002010000000003"); |
| | | //startActivity(KeyCabinetActivity.class,b); |
| | | checkGridStatus(0); |
| | | List<CabinetGridDo> gridDos = getVM().getOpenGrids(); |
| | | if (gridDos.size() > 0) { |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | showUnCloseTip(gridDos); |
| | | return; |
| | | } |
| | | MApplication.setLoginBean(null); |
| | | MApplication.getLoginBean().setFlag(type == 2 ? 0 : 1); |
| | | if(type==3){ |
| | | startActivity(ManageLoginActivity.class); |
| | | return; |
| | | } |
| | | startActivity(KeyCabinetActivity.class); |
| | | startActivity(FaceActivity.class); |
| | | } |
| | | break; |
| | | case 4: |
| | |
| | | case 5: { |
| | | List<CabinetGridDo> gridDos = getVM().getOpenGrids(); |
| | | if (gridDos.size() > 0) { |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | showUnCloseTip(gridDos); |
| | | }else { |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | |
| | | } |
| | | } |
| | | |
| | | private void showUnCloseTip(List<CabinetGridDo> gridDos){ |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().tvTip23.setText(getErrPhoneText(), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | private SpannableString getErrPhoneText(){ |
| | | String phone = MApplication.getConfigBean().getLinkPhone(); |
| | | String text = "如有问题请联系管理员"+phone; |
| | | SpannableString styledText = new SpannableString(text); |
| | | styledText.setSpan(new TextAppearanceSpan(this, R.style.style_tip3), 0, text.length()-phone.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | styledText.setSpan(new TextAppearanceSpan(this,R.style.style_tip1), text.length()-phone.length()+1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | return styledText; |
| | | } |
| | | |
| | | private boolean isShowing = false; |
| | | @Override |
| | | protected void onResume() { |
| | |
| | | isShowing = true; |
| | | showTime = System.currentTimeMillis(); |
| | | if(!isFaceOk) { |
| | | //initLicense(); |
| | | initLicense(); |
| | | } |
| | | if(isHavePermission) { |
| | | checkUpdate(); |
| | |
| | | if (ret == 128) { |
| | | Timber.d("==UpdatingFace==>图片特征抽取成功: %s", JSON.toJSONString(bean)); |
| | | User user = new User(); |
| | | user.setUserId(bean.getMemberId()); |
| | | user.setUserId(bean.getMemberId().toString()); |
| | | user.setGroupId(bean.getGroupId()); |
| | | user.setUserName(bean.getMemberName()); |
| | | user.setImageName(bean.getFaceImg()); |
| | |
| | | popupWindow.showAtLocation(getDB().clRoot, Gravity.CENTER, 0, 0); |
| | | RelativeLayout relativeRegister = contentView.findViewById(R.id.relative_register); |
| | | RelativeLayout mPopRelativeManager = contentView.findViewById(R.id.relative_manager); |
| | | RelativeLayout mPopRelativeCamra = contentView.findViewById(R.id.relative_camra); |
| | | RelativeLayout mRlErr = contentView.findViewById(R.id.rl_err); |
| | | relativeRegister.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(UserManagerActivity.class); |
| | | } |
| | | }); |
| | | mPopRelativeCamra.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //startActivity(); |
| | | } |
| | | }); |
| | | mRlErr.setOnClickListener(new View.OnClickListener() { |
| | |
| | | } |
| | | |
| | | private void initRGBCheck(){ |
| | | if(true){ |
| | | return; |
| | | } |
| | | String index = SpUtil.getString("rbgCameraId"); |
| | | if(index==null){ |
| | | if(!"1".equals(index)){ |
| | | index = "0"; |
| | | } |
| | | setRgbCameraId(Integer.parseInt(index)); |
| | | /*if (isSetCameraId()){ |
| | | setRgbCameraId(SingleBaseConfig.getBaseConfig().getRBGCameraId()); |
| | | return; |
| | | } |
| | | int mCameraNum = Camera.getNumberOfCameras(); |
| | |
| | | } |
| | | |
| | | private void setRgbCameraId(int index){ |
| | | getVM().addInfo("设置相机:"+index); |
| | | //Toast.makeText(mContext, "设置相机"+index, Toast.LENGTH_SHORT).show(); |
| | | SpUtil.saveString("rbgCameraId",index+""); |
| | | BraceletLogUtils.saveLog("设置相机("+index+")"); |
| | |
| | | } |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void JiujinBeginEvent(JiujinBeginEvent e){ |
| | | if(!isFinishing()){ |
| | | //开启酒精检测 |
| | | sendPortHandlerMsg(3,"go_wnd:0",0); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Subscribe |
| | | public void CloseGridOneResultEvent(CloseGridOneResultEvent e){ |
| | |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", |
| | | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); |
| | | }else { |
| | | //todo 关门成功 |
| | | if(isShowTip){ |
| | | doRegister(5,null); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onResultBytes(byte[] bytes) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(bytes.length==0){ |
| | | return; |
| | | } |
| | |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("批量开门更新库数据:版号:" +bh+","+ addList.size()+","+updateList.size()); |
| | | }); |
| | | getVM().insertGrids(addList); |
| | | getVM().updateGrids(updateList); |
| | | if(!portHandler.hasMessages(1)){ |
| | | EventBus.getDefault().post(new ManageOpenGridResultEvent()); |
| | |
| | | gridDo.setIsOpen("1".equals(dm.substring(i-1,i))?0:1); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | updateList.add(gridDo); |
| | | }else { |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | | gridDo.setGridKey(key); |
| | | gridDo.setIsOpen("1".equals(dm.substring(i-1,i))?0:1); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | addList.add(gridDo); |
| | | } |
| | | } |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("更新库数据:版号:" +bh+","+ addList.size()+","+updateList.size()); |
| | | }); |
| | | getVM().insertGrids(addList); |
| | | getVM().updateGrids(updateList); |
| | | }catch (Exception exception){ |
| | | runOnUiThread(() -> { |
| | |
| | | |
| | | @Override |
| | | public void onResultBytes(byte[] bytes) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(bytes.length==0){ |
| | | return; |
| | | } |
| | |
| | | } |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | updateList.add(gridDo); |
| | | }else { |
| | | //新增 |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | | gridDo.setGridKey(key); |
| | | if("01".equals(isHaveKey)) { |
| | | gridDo.setCurKeyCode(keyCode); |
| | | }else { |
| | | gridDo.setCurKeyCode(""); |
| | | } |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | addList.add(gridDo); |
| | | } |
| | | } |
| | | } |
| | | getVM().insertGrids(addList); |
| | | getVM().updateGrids(updateList); |
| | | EventBus.getDefault().post(new KeyResultEvent()); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onResultBytes(byte[] bytes) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(bytes.length==0){ |
| | | return; |
| | | } |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("获取到酒精检测数据:" + new String(bytes)); |
| | | }); |
| | | try { |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("获取到酒精检测数据:"+StringUtil.DateToStrSS(new Date())+" " + new String(bytes)); |
| | | }); |
| | | String data = new String(bytes); |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("获取到酒精检测是否检测失败:" + (data.contains("blow fail"))); |
| | | }); |
| | | if(data.contains("blow fail")){ |
| | | //检测失败 |
| | | EventBus.getDefault().post(new JiujinResultEvent(false,null)); |
| | | }else if(data.startsWith("Result:")){ |
| | | Pattern pattern = Pattern.compile("([0-9]+\\.[0-9]+)"); |
| | | Matcher matcher = pattern.matcher(data); |
| | | if (matcher.find()) { |
| | | EventBus.getDefault().post(new JiujinResultEvent(true,new BigDecimal(matcher.group(1)))); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | getVM().addInfo("获取到酒精检测报错:" + e.getMessage()); |
| | | } |
| | | } |
| | | }; |
| | | private SerialPortModel chosePort; |
| | |
| | | sendPortHandlerMsg(3,"alarm:"+config.getConcentration(),time+600); |
| | | //浓度阈值单位 (1=mg/100ml;2=mg/L;3=%BAC) |
| | | sendPortHandlerMsg(3,"unit:"+config.getThreshold(),time+900); |
| | | |
| | | sendPortHandlerMsg(3,"read"+config.getThreshold(),time+1200); |
| | | } |
| | | |
| | | private void sendPortHandlerMsg(int what,String obj,long time){ |