From 729d7828159cd1391d7be9bf4ab814736beb04d3 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Fri, 10 Feb 2023 17:41:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E7=AB=AF=E9=97=AE=E9=A2=98=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DIP=E5=9C=B0=E5=9D=80=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=BE=93=E5=85=A5=E7=AC=A6=E5=8F=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E5=B0=86=E6=97=B6=E9=97=B4=E6=88=B3=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=AF=AB=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../top/rrricardo/motioncapture/MainActivity.kt | 17 +++++++++++++---- .../motioncapture/models/PoseLandmark.kt | 5 ++++- app/src/main/res/layout/dialog_set_port.xml | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/top/rrricardo/motioncapture/MainActivity.kt b/app/src/main/java/top/rrricardo/motioncapture/MainActivity.kt index 6382924..277a50c 100644 --- a/app/src/main/java/top/rrricardo/motioncapture/MainActivity.kt +++ b/app/src/main/java/top/rrricardo/motioncapture/MainActivity.kt @@ -110,7 +110,7 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene Log.i(tag, getPoseLandmarksDebugString(landmarks))*/ val landmarks = PacketGetter.getProto(it, NormalizedLandmarkList.getDefaultInstance()) - val poseLandmarks = PoseLandmark.valueOf(landmarks, it.timestamp) + val poseLandmarks = PoseLandmark.valueOf(landmarks, System.currentTimeMillis()) val buffer = ByteBuffer.allocate( poseLandmarks.size * PoseLandmark.packetLength) @@ -176,8 +176,17 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene override fun onDialogPositiveClick(dialog: DialogFragment) { Log.i(tag, "Confirm Button Clicked.") - val ipInput = findViewById(R.id.targetIP).text.toString() - val portInput = findViewById(R.id.targetPort).text.toString() + val ipEditText = dialog.dialog?.findViewById(R.id.targetIP) + val portEditText = dialog.dialog?.findViewById(R.id.targetPort) + + if (ipEditText == null || portEditText == null) { + Log.e(tag, "Get EditText Failed.") + return + } + + val ipInput = ipEditText.text.toString() + val portInput = portEditText.text.toString() + try { val port = portInput.toInt() if (isSet) { @@ -188,7 +197,7 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene sender = UdpSender(ipInput, port) isSet = true - showToastMessage("Server set successfully!") + showToastMessage("Server $ipInput:$portInput set successfully! ") } catch (e: java.lang.NumberFormatException) { Log.e(tag, "Input error: $e") } diff --git a/app/src/main/java/top/rrricardo/motioncapture/models/PoseLandmark.kt b/app/src/main/java/top/rrricardo/motioncapture/models/PoseLandmark.kt index 620f610..4c65a3f 100644 --- a/app/src/main/java/top/rrricardo/motioncapture/models/PoseLandmark.kt +++ b/app/src/main/java/top/rrricardo/motioncapture/models/PoseLandmark.kt @@ -2,6 +2,7 @@ package top.rrricardo.motioncapture.models import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList import java.nio.ByteBuffer +import java.nio.ByteOrder class PoseLandmark( private val Type: Int, @@ -13,6 +14,7 @@ class PoseLandmark( fun toByteArray(): ByteArray { val result = ByteBuffer.allocate(packetLength) + result.order(ByteOrder.LITTLE_ENDIAN) result.putInt(Type) result.putFloat(X) @@ -25,10 +27,11 @@ class PoseLandmark( } companion object { - const val packetLength = 28; + const val packetLength = 28 fun valueOf(data: ByteArray): PoseLandmark { val buffer = ByteBuffer.wrap(data) + buffer.order(ByteOrder.LITTLE_ENDIAN) val type = buffer.int val x = buffer.float diff --git a/app/src/main/res/layout/dialog_set_port.xml b/app/src/main/res/layout/dialog_set_port.xml index 50507d4..e4e173b 100644 --- a/app/src/main/res/layout/dialog_set_port.xml +++ b/app/src/main/res/layout/dialog_set_port.xml @@ -12,7 +12,7 @@