打击位置
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.DefenseApplication">
|
||||
<activity
|
||||
android:name=".liveVideo.StrikePositionActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".personal.FaceManagementActivity"
|
||||
android:exported="false" />
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.example.defenseapplication.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.defenseapplication.databinding.SetNameActivityBinding
|
||||
import com.example.defenseapplication.liveVideo.LiveVideoActivity
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
//设置名字页面
|
||||
class SetNameActivity : AppCompatActivity() {
|
||||
@@ -20,10 +22,9 @@ class SetNameActivity : AppCompatActivity() {
|
||||
binding.ivBack.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.btnConfirm.setOnClickListener {
|
||||
val deviceName = binding.etName.text.toString().trim()
|
||||
finish()
|
||||
startActivity(Intent(this, LiveVideoActivity::class.java).apply {})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.example.defenseapplication.liveVideo
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.StrikePositionActivityBinding
|
||||
import com.example.defenseapplication.view.CustomDialogFragment
|
||||
import com.example.defenseapplication.view.showDefenseDialog
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
|
||||
class StrikePositionActivity : AppCompatActivity() {
|
||||
private lateinit var binding: StrikePositionActivityBinding
|
||||
private lateinit var markerLayoutParams: RelativeLayout.LayoutParams
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = StrikePositionActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
ImmersionBar.with(this)
|
||||
.statusBarDarkFont(true)
|
||||
.titleBar(binding.topBar)
|
||||
.init()
|
||||
|
||||
binding.ivBack.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
showConfirmDialog()
|
||||
}
|
||||
// 获取准星的 LayoutParams,并移除居中约束
|
||||
markerLayoutParams = binding.ivStrikeMarker.layoutParams as RelativeLayout.LayoutParams
|
||||
markerLayoutParams.removeRule(RelativeLayout.CENTER_HORIZONTAL)
|
||||
markerLayoutParams.removeRule(RelativeLayout.CENTER_VERTICAL)
|
||||
binding.ivStrikeMarker.layoutParams = markerLayoutParams
|
||||
|
||||
// 设置人体图片的点击监听
|
||||
binding.ivHumanBody.setOnTouchListener { _, event ->
|
||||
if (event.action == android.view.MotionEvent.ACTION_DOWN) {
|
||||
moveMarkerTo(event.x, event.y)
|
||||
}
|
||||
true
|
||||
}
|
||||
// 初始化准星位置:人体头部(假设在图片宽度的1/2,高度的1/5处)
|
||||
binding.ivHumanBody.post {
|
||||
val humanWidth = binding.ivHumanBody.width
|
||||
val humanHeight = binding.ivHumanBody.height
|
||||
if (humanWidth > 0 && humanHeight > 0) {
|
||||
val headX = humanWidth / 2f
|
||||
val headY = humanHeight / 5f
|
||||
moveMarkerTo(headX, headY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showConfirmDialog() {
|
||||
val config = CustomDialogFragment.Config(
|
||||
title = getString(R.string.tip),
|
||||
message = getString(R.string.confirm_modify_strike_pos),
|
||||
positiveText = getString(R.string.confirm),
|
||||
negativeText = getString(R.string.cancel)
|
||||
)
|
||||
showDefenseDialog(config, onPositiveClick = {
|
||||
finish()
|
||||
// if(){
|
||||
// ToastUtils.showSuccess(this, getString(R.string.wifi_connection_success))
|
||||
// }else{
|
||||
// ToastUtils.showError(this, getString(R.string.wifi_connection_failed))
|
||||
// }
|
||||
})
|
||||
}
|
||||
private fun moveMarkerTo(x: Float, y: Float) {
|
||||
val marker = binding.ivStrikeMarker
|
||||
// 让准星中心对准点击位置
|
||||
val left = x - marker.width / 2f
|
||||
val top = y - marker.height / 2f
|
||||
|
||||
markerLayoutParams.leftMargin = left.toInt()
|
||||
markerLayoutParams.topMargin = top.toInt()
|
||||
marker.layoutParams = markerLayoutParams
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.defenseapplication.liveVideo
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import com.example.defenseapplication.R
|
||||
@@ -59,5 +60,8 @@ class WaterGunSettingsActivity : BaseActivity() {
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
binding.itemPosition.setOnClickListener {
|
||||
startActivity(Intent(this, StrikePositionActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/res/drawable/dajitubiao.png
Normal file
BIN
app/src/main/res/drawable/dajitubiao.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/drawable/human_body.png
Normal file
BIN
app/src/main/res/drawable/human_body.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
94
app/src/main/res/layout/strike_position_activity.xml
Normal file
94
app/src/main/res/layout/strike_position_activity.xml
Normal file
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/bg_gray"
|
||||
tools:context=".liveVideo.StrikePositionActivity">
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/topBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivBack"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/back" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/strike_position"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 提示文字 -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:paddingHorizontal="20dp"
|
||||
android:text="@string/click_model_select_strike_pos"
|
||||
android:textColor="@color/gray"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<!-- 人体模型区域 -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/bodyLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- 虚线边框 -->
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_scan_frame" />
|
||||
|
||||
<!-- 人体模型图片 -->
|
||||
<ImageView
|
||||
android:id="@+id/ivHumanBody"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/human_body" />
|
||||
|
||||
<!-- 打击位置标记 -->
|
||||
<ImageView
|
||||
android:id="@+id/ivStrikeMarker"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="30dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/dajitubiao" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<!-- 提交按钮 -->
|
||||
<android.widget.Button
|
||||
android:id="@+id/btnSubmit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:background="@drawable/rounded_blue_bg"
|
||||
android:text="@string/submit"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -191,6 +191,8 @@
|
||||
<string name="strike_interval">打击间隔</string>
|
||||
<string name="switch_container">切换容器</string>
|
||||
<string name="strike_position">打击位置</string>
|
||||
<string name="click_model_select_strike_pos">请点击下方人体模型,选择大致打击位置</string>
|
||||
<string name="confirm_modify_strike_pos">确定修改为该打击位置?</string>
|
||||
<string name="container_1">容器1</string>
|
||||
<string name="container_2">容器2</string>
|
||||
<string name="container_3">容器3</string>
|
||||
|
||||
@@ -363,6 +363,8 @@
|
||||
<string name="strike_interval">Strike Interval</string>
|
||||
<string name="switch_container">Switch Container</string>
|
||||
<string name="strike_position">Strike Position</string>
|
||||
<string name="click_model_select_strike_pos">Please click the human model below to select the approximate strike position</string>
|
||||
<string name="confirm_modify_strike_pos">Confirm to modify to this strike position?</string>
|
||||
<string name="container_1">Container 1</string>
|
||||
<string name="container_2">Container 2</string>
|
||||
<string name="container_3">Container 3</string>
|
||||
|
||||
Reference in New Issue
Block a user