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 @@