Skip to content

Commit

Permalink
修改输入地址弹窗,修改输入框光标位置。
Browse files Browse the repository at this point in the history
  • Loading branch information
lilongweidev committed Aug 24, 2022
1 parent 0667b95 commit 459e964
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 26 additions & 18 deletions app/src/main/java/com/llw/socket/ui/ClientActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.Log
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.LinearLayoutManager
import com.llw.socket.R
import com.llw.socket.adapter.MsgAdapter
import com.llw.socket.bean.Message
import com.llw.socket.client.ClientCallback
Expand All @@ -26,6 +27,7 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {

//消息列表
private val messages = ArrayList<Message>()

//消息适配器
private lateinit var msgAdapter: MsgAdapter

Expand All @@ -43,7 +45,7 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
//显示emoji
binding.ivEmoji.setOnClickListener {
//显示底部弹窗
showEmojiDialog(this,this)
showEmojiDialog(this, this)
}

//连接服务/断开连接 客户端处理
Expand All @@ -64,7 +66,7 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
showMsg("请输入要发送的信息");return@setOnClickListener
}
//检查是否能发送消息
val isSend = if (connectSocket) connectSocket else false
val isSend = if (connectSocket) connectSocket else false
if (!isSend) {
showMsg("当前未开启服务或连接服务");return@setOnClickListener
}
Expand All @@ -81,22 +83,25 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
}

private fun showEditDialog() {
val dialogBinding = DialogEditIpBinding.inflate(LayoutInflater.from(this@ClientActivity),null,false)
val dialog = AlertDialog.Builder(this@ClientActivity).create()
dialog.show()
dialog.window!!.setContentView(dialogBinding.root)
dialogBinding.tvCancel.setOnClickListener { dialog.dismiss() }
dialogBinding.tvSure.setOnClickListener {
val ip = dialogBinding.etIpAddress.text.toString()
if (ip.isEmpty()) {
showMsg("请输入Ip地址");return@setOnClickListener
val dialogBinding =
DialogEditIpBinding.inflate(LayoutInflater.from(this@ClientActivity), null, false)
AlertDialog.Builder(this@ClientActivity).apply {
setIcon(R.drawable.ic_connect)
setTitle("连接Ip地址")
setView(dialogBinding.root)
setPositiveButton("确定") { dialog, _ ->
val ip = dialogBinding.etIpAddress.text.toString()
if (ip.isEmpty()) {
showMsg("请输入Ip地址");return@setPositiveButton
}
connectSocket = true
SocketClient.connectServer(ip, this@ClientActivity)
showMsg("连接服务")
binding.tvConnectService.text = "关闭连接"
dialog.dismiss()
}
connectSocket = true
SocketClient.connectServer(ip, this@ClientActivity)
showMsg("连接服务")
binding.tvConnectService.text = "关闭连接"
dialog.dismiss()
}
setNegativeButton("取消") { dialog, _ -> dialog.dismiss() }
}.show()
}

/**
Expand All @@ -122,6 +127,9 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
}

override fun checkedEmoji(charSequence: CharSequence) {
binding.etMsg.setText(charSequence)
binding.etMsg.apply {
setText(text.toString() + charSequence)
setSelection(text.toString().length)//光标置于最后
}
}
}
5 changes: 4 additions & 1 deletion app/src/main/java/com/llw/socket/ui/ServerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class ServerActivity : BaseActivity(), ServerCallback, EmojiCallback {
}

override fun checkedEmoji(charSequence: CharSequence) {
binding.etMsg.setText(charSequence)
binding.etMsg.apply {
setText(text.toString() + charSequence)
setSelection(text.toString().length)//光标置于最后
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/ic_connect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24.0"
android:viewportHeight="24.0">

<path
android:fillColor="@android:color/white"
android:pathData="M7,4c0,-1.11 -0.89,-2 -2,-2S3,2.89 3,4s0.89,2 2,2S7,5.11 7,4zM10.19,4.5L10.19,4.5c-0.41,0 -0.76,0.25 -0.92,0.63C8.83,6.23 7.76,7 6.5,7h-3C2.67,7 2,7.67 2,8.5V11h6V8.74c1.43,-0.45 2.58,-1.53 3.12,-2.91C11.38,5.19 10.88,4.5 10.19,4.5zM19,17c1.11,0 2,-0.89 2,-2s-0.89,-2 -2,-2s-2,0.89 -2,2S17.89,17 19,17zM20.5,18h-3c-1.26,0 -2.33,-0.77 -2.77,-1.87c-0.15,-0.38 -0.51,-0.63 -0.92,-0.63h0c-0.69,0 -1.19,0.69 -0.94,1.33c0.55,1.38 1.69,2.46 3.12,2.91V22h6v-2.5C22,18.67 21.33,18 20.5,18zM17.25,11.09c0,0 0,-0.01 0.01,0c-1.06,0.27 -1.9,1.11 -2.17,2.17c0,0 0,-0.01 0,-0.01C14.98,13.68 14.58,14 14.11,14c-0.55,0 -1,-0.45 -1,-1c0,-0.05 0.02,-0.14 0.02,-0.14c0.43,-1.85 1.89,-3.31 3.75,-3.73c0.04,0 0.08,-0.01 0.12,-0.01c0.55,0 1,0.45 1,1C18,10.58 17.68,10.98 17.25,11.09zM18,6.06c0,0.51 -0.37,0.92 -0.86,0.99c0,0 0,0 0,0c-3.19,0.39 -5.7,2.91 -6.09,6.1c0,0 0,0 0,0C10.98,13.63 10.56,14 10.06,14c-0.55,0 -1,-0.45 -1,-1c0,-0.02 0,-0.04 0,-0.06c0,-0.01 0,-0.02 0,-0.03c0.5,-4.12 3.79,-7.38 7.92,-7.85c0,0 0.01,0 0.01,0C17.55,5.06 18,5.51 18,6.06z" />

</vector>
44 changes: 3 additions & 41 deletions app/src/main/res/layout/dialog_edit_ip.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:background="@drawable/shape_dialog_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="连接Ip地址"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Expand All @@ -27,42 +14,17 @@
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_ip_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="0123456789."
android:hint="连接Ip地址"
android:hint="Ip地址"
android:inputType="number"
android:lines="1"
android:singleLine="true"
android:text="192.168.0.120" />
</com.google.android.material.textfield.TextInputLayout>

<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="取消"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_sure"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />

<TextView
android:id="@+id/tv_sure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定"
android:padding="16dp"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="@+id/tv_cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/tv_cancel"
app:layout_constraintTop_toTopOf="@+id/tv_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 459e964

Please sign in to comment.