diff --git a/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt b/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt index bfc12c2..6e0d556 100644 --- a/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt @@ -1,31 +1,65 @@ package com.casic.electric.detector.view +import android.annotation.SuppressLint +import android.app.AlertDialog +import android.app.DatePickerDialog import android.content.Context +import android.content.DialogInterface +import android.content.Intent import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.Handler import android.os.Message +import android.provider.Settings import android.util.Log import android.view.KeyEvent +import android.view.View +import android.view.WindowManager +import android.widget.AdapterView +import androidx.lifecycle.ViewModelProvider +import com.amap.api.location.AMapLocation import com.casic.electric.detector.R +import com.casic.electric.detector.adapter.EditableImageAdapter import com.casic.electric.detector.base.SerialPortActivity -import com.casic.electric.detector.extensions.initLayoutImmersionBar -import com.casic.electric.detector.utils.GpioManager +import com.casic.electric.detector.bean.LabelBean +import com.casic.electric.detector.callback.ILocationListener +import com.casic.electric.detector.callback.OnImageCompressListener +import com.casic.electric.detector.extensions.* +import com.casic.electric.detector.utils.* +import com.casic.electric.detector.vm.TaskViewModel import com.gyf.immersionbar.ImmersionBar -import com.pengxh.kt.lite.extensions.convertColor +import com.luck.picture.lib.basic.PictureSelector +import com.luck.picture.lib.config.SelectMimeType +import com.luck.picture.lib.entity.LocalMedia +import com.luck.picture.lib.interfaces.OnResultCallbackListener +import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import com.pengxh.kt.lite.widget.dialog.NoNetworkDialog import kotlinx.android.synthetic.main.activity_install_label.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_label_marker_attribute.* +import kotlinx.android.synthetic.main.include_label_object_attribute.* +import kotlinx.android.synthetic.main.include_open_camera.* +import java.io.File +import java.io.IOException +import java.util.* +@SuppressLint("SetTextI18n") class InstallLabelActivity : SerialPortActivity(), Handler.Callback { private val kTag = "LabelActivity" private val context: Context = this@InstallLabelActivity private val gpioManager by lazy { GpioManager() } + private val calendar by lazy { Calendar.getInstance() } + private val realPaths: ArrayList = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt b/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt index bfc12c2..6e0d556 100644 --- a/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt @@ -1,31 +1,65 @@ package com.casic.electric.detector.view +import android.annotation.SuppressLint +import android.app.AlertDialog +import android.app.DatePickerDialog import android.content.Context +import android.content.DialogInterface +import android.content.Intent import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.Handler import android.os.Message +import android.provider.Settings import android.util.Log import android.view.KeyEvent +import android.view.View +import android.view.WindowManager +import android.widget.AdapterView +import androidx.lifecycle.ViewModelProvider +import com.amap.api.location.AMapLocation import com.casic.electric.detector.R +import com.casic.electric.detector.adapter.EditableImageAdapter import com.casic.electric.detector.base.SerialPortActivity -import com.casic.electric.detector.extensions.initLayoutImmersionBar -import com.casic.electric.detector.utils.GpioManager +import com.casic.electric.detector.bean.LabelBean +import com.casic.electric.detector.callback.ILocationListener +import com.casic.electric.detector.callback.OnImageCompressListener +import com.casic.electric.detector.extensions.* +import com.casic.electric.detector.utils.* +import com.casic.electric.detector.vm.TaskViewModel import com.gyf.immersionbar.ImmersionBar -import com.pengxh.kt.lite.extensions.convertColor +import com.luck.picture.lib.basic.PictureSelector +import com.luck.picture.lib.config.SelectMimeType +import com.luck.picture.lib.entity.LocalMedia +import com.luck.picture.lib.interfaces.OnResultCallbackListener +import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import com.pengxh.kt.lite.widget.dialog.NoNetworkDialog import kotlinx.android.synthetic.main.activity_install_label.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_label_marker_attribute.* +import kotlinx.android.synthetic.main.include_label_object_attribute.* +import kotlinx.android.synthetic.main.include_open_camera.* +import java.io.File +import java.io.IOException +import java.util.* +@SuppressLint("SetTextI18n") class InstallLabelActivity : SerialPortActivity(), Handler.Callback { private val kTag = "LabelActivity" private val context: Context = this@InstallLabelActivity private val gpioManager by lazy { GpioManager() } + private val calendar by lazy { Calendar.getInstance() } + private val realPaths: ArrayList = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt b/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt index bfc12c2..6e0d556 100644 --- a/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/InstallLabelActivity.kt @@ -1,31 +1,65 @@ package com.casic.electric.detector.view +import android.annotation.SuppressLint +import android.app.AlertDialog +import android.app.DatePickerDialog import android.content.Context +import android.content.DialogInterface +import android.content.Intent import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.Handler import android.os.Message +import android.provider.Settings import android.util.Log import android.view.KeyEvent +import android.view.View +import android.view.WindowManager +import android.widget.AdapterView +import androidx.lifecycle.ViewModelProvider +import com.amap.api.location.AMapLocation import com.casic.electric.detector.R +import com.casic.electric.detector.adapter.EditableImageAdapter import com.casic.electric.detector.base.SerialPortActivity -import com.casic.electric.detector.extensions.initLayoutImmersionBar -import com.casic.electric.detector.utils.GpioManager +import com.casic.electric.detector.bean.LabelBean +import com.casic.electric.detector.callback.ILocationListener +import com.casic.electric.detector.callback.OnImageCompressListener +import com.casic.electric.detector.extensions.* +import com.casic.electric.detector.utils.* +import com.casic.electric.detector.vm.TaskViewModel import com.gyf.immersionbar.ImmersionBar -import com.pengxh.kt.lite.extensions.convertColor +import com.luck.picture.lib.basic.PictureSelector +import com.luck.picture.lib.config.SelectMimeType +import com.luck.picture.lib.entity.LocalMedia +import com.luck.picture.lib.interfaces.OnResultCallbackListener +import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import com.pengxh.kt.lite.widget.dialog.NoNetworkDialog import kotlinx.android.synthetic.main.activity_install_label.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_label_marker_attribute.* +import kotlinx.android.synthetic.main.include_label_object_attribute.* +import kotlinx.android.synthetic.main.include_open_camera.* +import java.io.File +import java.io.IOException +import java.util.* +@SuppressLint("SetTextI18n") class InstallLabelActivity : SerialPortActivity(), Handler.Callback { private val kTag = "LabelActivity" private val context: Context = this@InstallLabelActivity private val gpioManager by lazy { GpioManager() } + private val calendar by lazy { Calendar.getInstance() } + private val realPaths: ArrayList = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + = ArrayList() //真实图片路径 private var soundResId = 0 private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var soundPool: SoundPool + private lateinit var imageAdapter: EditableImageAdapter + private lateinit var taskViewModel: TaskViewModel override fun initLayoutView(): Int = R.layout.activity_install_label @@ -41,6 +75,8 @@ } override fun initData(savedInstanceState: Bundle?) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + weakReferenceHandler = WeakReferenceHandler(this) val audioAttributes = AudioAttributes.Builder() @@ -51,14 +87,391 @@ .setMaxStreams(16) .setAudioAttributes(audioAttributes) .build() + + //设置上次填写过的值 + objectCodeView.setText("objectCodeView".getDefaultValue()) + objectNameView.setText("objectNameView".getDefaultValue()) + inlineNameView.setText("inlineNameView".getDefaultValue()) + capacityView.setText("capacityView".getDefaultValue()) + transformerSpecView.setText("transformerSpecView".getDefaultValue()) + sLengthView.setText("sLengthView".getDefaultValue()) + sWidthView.setText("sWidthView".getDefaultValue()) + sHeightView.setText("sHeightView".getDefaultValue()) + inlineCountView.setText("inlineCountView".getDefaultValue()) + outlineCountView.setText("outlineCountView".getDefaultValue()) + bottomDepthView.setText("bottomDepthView".getDefaultValue()) + rowCountView.setText("rowCountView".getDefaultValue()) + rowHoleCountView.setText("rowHoleCountView".getDefaultValue()) + coverDepthView.setText("coverDepthView".getDefaultValue()) + remainingChannelsView.setText("remainingChannelsView".getDefaultValue()) + tieCableView1.setText("tieCableView1".getDefaultValue()) + tieCableView2.setText("tieCableView2".getDefaultValue()) + jointCountView.setText("jointCountView".getDefaultValue()) + casingHoleCountView.setText("casingHoleCountView".getDefaultValue()) + casingHoleLengthView.setText("casingHoleLengthView".getDefaultValue()) + heightView.setText("heightView".getDefaultValue()) + lineNumberView.setText("lineNumberView".getDefaultValue()) + inspectionUnitView.setText("inspectionUnitView".getDefaultValue()) + areaView.setText("areaView".getDefaultValue()) + roadView.setText("roadView".getDefaultValue()) + objectRemarkView1.setText("objectRemarkView1".getDefaultValue()) + objectRemarkView2.setText("objectRemarkView2".getDefaultValue()) + objectRemarkView3.setText("objectRemarkView3".getDefaultValue()) + ownerView.setText("ownerView".getDefaultValue()) + markerDepthView.setText("markerDepthView".getDefaultValue()) + markerCountView.setText("markerCountView".getDefaultValue()) + remarkView1.setText("remarkView1".getDefaultValue()) + remarkView2.setText("remarkView2".getDefaultValue()) + remarkView3.setText("remarkView3".getDefaultValue()) + + //初始化图片九宫格 + imageAdapter = EditableImageAdapter(this, 3, 3f) + addImageRecyclerView.adapter = imageAdapter + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] } override fun observeRequestState() { + taskViewModel.loadState.observe(this) { + when (it) { + LoadState.Loading -> LoadingDialogHub.show(this, "标识器安装中,请稍后...") + LoadState.Success -> { + saveLabelInLocal() + LoadingDialogHub.dismiss() + finish() + } + else -> LoadingDialogHub.dismiss() + } + } + } + //TODO + //安装成功后将标识器保存在本地 + private fun saveLabelInLocal() { + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + + val labelBean = LabelBean() + + DataBaseManager.get.insertLabel(labelBean) } override fun initEvent() { + leftBackView.setOnClickListener { finish() } + /**************************************************************************************/ + objectTypeSpinner.show(this, LocaleConstant.CONTENT_ARRAY, 0) + objectTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + when (position) { + 0 -> { + //选择电缆井 + objectModeView.text = "类型:" + wellCoverMaterialView.text = "井盖材质:" + bottomDepthNameView.text = "井深:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 1 -> { + //选择电缆通道 + bottomDepthNameView.text = "底部深度:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.VISIBLE + pipeLineLayout.visibility = View.VISIBLE + jointCountLayout.visibility = View.VISIBLE + heightLayout.visibility = View.GONE + } + 2 -> { + //选择配电房 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.VISIBLE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 3 -> { + //选择开关站 + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.VISIBLE + inlineCountLayout.visibility = View.VISIBLE + outlineCountLayout.visibility = View.VISIBLE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 4 -> { + //选择台区 + objectModeView.text = "变压器型号:" + + objectModeLayout.visibility = View.VISIBLE + inlineNameLayout.visibility = View.VISIBLE + wellCoverMaterialLayout.visibility = View.GONE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.GONE + } + 5 -> { + //选择杆塔 + wellCoverMaterialView.text = "对象材质:" + + objectModeLayout.visibility = View.GONE + inlineNameLayout.visibility = View.GONE + wellCoverMaterialLayout.visibility = View.VISIBLE + capacityLayout.visibility = View.GONE + sizeLayout.visibility = View.GONE + inlineCountLayout.visibility = View.GONE + outlineCountLayout.visibility = View.GONE + wellDepthLayout.visibility = View.GONE + pipeLineLayout.visibility = View.GONE + jointCountLayout.visibility = View.GONE + heightLayout.visibility = View.VISIBLE + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + objectModeSpinner.show(this, LocaleConstant.OBJECT_MODE_ARRAY, 0) + wellCoverMaterialSpinner.show(this, LocaleConstant.WELL_COVER_MATERIAL_ARRAY, 0) + cabinetTypeSpinner.show(this, LocaleConstant.CABINET_TYPE_ARRAY, 0) + casingMaterialSpinner.show(this, LocaleConstant.PIPE_MATERIAL_ARRAY, 0) + markerTypeSpinner.show(this, LocaleConstant.MARKER_TYPE_ARRAY, 0) + + //电压等级-多选 + voltageLevelView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择电压等级") + .setMultiChoiceItems( + LocaleConstant.VOLTAGE_LEVEL_ARRAY, LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.VOLTAGE_LEVEL_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.VOLTAGE_LEVEL_STATE_ARRAY[index]) { + temp.add(s) + } + } + + voltageLevelView.text = temp.reformat() + }.show() + } + + //交叉管道类型-多选 + crossPipeLineView.setOnClickListener { + AlertDialog.Builder(context) + .setCancelable(false) + .setIcon(R.mipmap.ic_launcher) + .setTitle("请选择交叉管道类型") + .setMultiChoiceItems( + LocaleConstant.CROSS_PIPE_ARRAY, LocaleConstant.CROSS_PIPE_STATE_ARRAY + ) { _, which, isChecked -> + LocaleConstant.CROSS_PIPE_STATE_ARRAY[which] = isChecked + } + .setNegativeButton("取消") { dialog, _ -> dialog?.dismiss() } + .setPositiveButton("确定") { _, _ -> + val temp = ArrayList() + LocaleConstant.CROSS_PIPE_ARRAY.forEachIndexed { index, s -> + if (LocaleConstant.CROSS_PIPE_STATE_ARRAY[index]) { + temp.add(s) + } + } + + crossPipeLineView.text = temp.reformat() + }.show() + } + + constructDateView.setOnClickListener { + val datePicker = DatePickerDialog( + this, + null, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ) + datePicker.show() + + datePicker.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { + val year = datePicker.datePicker.year + val month = datePicker.datePicker.month + 1 + val day = datePicker.datePicker.dayOfMonth + val selectedDate = String.format( + "%s-%s-%s", year, month.appendZero(), day.appendZero() + ) + + //当前时间 + val current = System.currentTimeMillis().timestampToTime() + val today = "$selectedDate $current".dateToTimestamp() + if (Date(today).after(Date())) { + "建设年代不能早于当前日期".show(context) + } else { + datePicker.dismiss() + constructDateView.text = selectedDate + } + } + } + + installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() + LocationHub.getCurrentLocation(this, object : ILocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + lngView.text = location.longitude.toString() + latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { + override fun onAddImageClick() { + PictureSelector.create(this@InstallLabelActivity) + .openCamera(SelectMimeType.ofImage()) + .forResult(object : OnResultCallbackListener { + override fun onResult(result: ArrayList?) { + if (result == null) { + "拍照失败,请重试".show(context) + return + } + analyticalSelectResult(result[0]) + } + + override fun onCancel() { + + } + }) + } + + override fun onItemClick(position: Int) { + if (realPaths[position].isEmpty()) { + "图片加载失败,无法查看大图".show(context) + } else { + context.navigatePageTo(position, realPaths) + } + } + + override fun onItemLongClick(view: View?, position: Int) { + imageAdapter.deleteImage(position) + } + }) + + /**************************************************************************************/ + installButton.setOnClickListener { + if (isNetworkConnected()) { + val companyId = SaveKeyValues.getValue(LocaleConstant.USER_COMPANY_ID, "") as String + val objectId = SaveKeyValues.getValue(LocaleConstant.OBJECT_ID, "") as String + +// taskViewModel.installLabel() + + //保存默认值 +// "objectCodeView".setDefaultValue() +// "objectNameView".setDefaultValue() +// "inlineNameView".setDefaultValue() +// "capacityView".setDefaultValue() +// "transformerSpecView".setDefaultValue() +// "sLengthView".setDefaultValue() +// "sWidthView".setDefaultValue() +// "sHeightView".setDefaultValue() +// "inlineCountView".setDefaultValue() +// "outlineCountView".setDefaultValue() +// "bottomDepthView".setDefaultValue() +// "rowCountView".setDefaultValue() +// "rowHoleCountView".setDefaultValue() +// "coverDepthView".setDefaultValue() +// "remainingChannelsView".setDefaultValue() +// "tieCableView1".setDefaultValue() +// "tieCableView2".setDefaultValue() +// "jointCountView".setDefaultValue() +// "casingHoleCountView".setDefaultValue() +// "casingHoleLengthView".setDefaultValue() +// "heightView".setDefaultValue() +// "lineNumberView".setDefaultValue() +// "inspectionUnitView".setDefaultValue() +// "areaView".setDefaultValue() +// "roadView".setDefaultValue() +// "objectRemarkView1".setDefaultValue() +// "objectRemarkView2".setDefaultValue() +// "objectRemarkView3".setDefaultValue() +// "ownerView".setDefaultValue() +// "markerDepthView".setDefaultValue() +// "markerCountView".setDefaultValue() +// "remarkView1".setDefaultValue() +// "remarkView2".setDefaultValue() +// "remarkView3".setDefaultValue() + } else { + NoNetworkDialog.Builder() + .setContext(context) + .setOnDialogButtonClickListener(object : + NoNetworkDialog.OnDialogButtonClickListener { + override fun onButtonClick() { + val intent = Intent(Settings.ACTION_SETTINGS) + startActivity(intent) + } + }).build().show() + } + } + + readLabelButton.setOnClickListener { + gpioManager.setGpioHigh("18") + + LoadingDialogHub.show(this, "标识器读取中,请稍后...") + + soundResId = soundPool.load(this, R.raw.ring3, 1) + soundPool.setOnLoadCompleteListener { soundPool, _, _ -> + soundPool.play(soundResId, 1f, 1f, 0, -1, 1f) + } + + // 1000ms后发送读标识器或搜索信号 + weakReferenceHandler.postDelayed({ + try { + // 发送读标识器或搜索信号 + outputStream?.write("2".toByteArray()) + outputStream?.flush() + } catch (e: IOException) { + e.printStackTrace() + } + }, 1000) + } } override fun onDataReceived(buffer: ByteArray?, size: Int) { @@ -73,11 +486,43 @@ override fun handleMessage(msg: Message): Boolean { if (msg.what == 2023081701) { + soundPool.release() + val buffer = msg.obj as ByteArray + val hex = buffer.toHex() + + if (hex.length >= 20) { + val markerId = hex.substring(0, 20).hexToString() + + gpioManager.setGpioLow("18") + + //查本地库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isEmpty()) { + markerIdView.text = markerId + } else { + "此标识器已安装,请更换标识器!".show(this) + } + LoadingDialogHub.dismiss() + } } return true } + private fun analyticalSelectResult(result: LocalMedia) { + //压缩图片 + result.realPath.compressImage(this, object : OnImageCompressListener { + override fun onSuccess(file: File) { + realPaths.add(file.absolutePath) + imageAdapter.setupImage(realPaths) + } + + override fun onError(e: Throwable) { + e.printStackTrace() + } + }) + } + override fun onDestroy() { soundPool.release() gpioManager.setGpioLow("18") diff --git a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt index be778d3..f521ffd 100644 --- a/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt +++ b/app/src/main/java/com/casic/electric/detector/view/LoginActivity.kt @@ -1,6 +1,7 @@ package com.casic.electric.detector.view import android.os.Bundle +import android.util.Log import androidx.lifecycle.ViewModelProvider import com.amap.api.navi.NaviSetting import com.casic.electric.detector.R @@ -11,6 +12,8 @@ import com.casic.electric.detector.vm.UserViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.getScreenHeight +import com.pengxh.kt.lite.extensions.getScreenWidth import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.LoadState @@ -19,6 +22,7 @@ class LoginActivity : KotlinBaseActivity() { + private val kTag = "LoginActivity" private lateinit var userViewModel: UserViewModel private val gpioManager by lazy { GpioManager() } @@ -98,6 +102,8 @@ override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(true).init() initLayoutImmersionBar(rootView) + + Log.d(kTag, "setupTopBarLayout => [${getScreenWidth()}, ${getScreenHeight()}]") } override fun onResume() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 79d766a..5970be0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -96,18 +96,19 @@ @@ -122,6 +124,7 @@ @@ -161,52 +166,60 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + + - - - - - - - - - @@ -342,290 +365,311 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - - + - + - + + - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +