文件名填充器
This commit is contained in:
parent
8a8c09c589
commit
ec39947f58
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -33,6 +33,7 @@ import com.coldmint.rust.core.templateParser.IntroducingParser
|
|||
import com.coldmint.rust.core.templateParser.ListParser
|
||||
import com.coldmint.rust.core.tool.FileOperator
|
||||
import com.coldmint.rust.pro.databinding.ActivityTemplateParserBinding
|
||||
import com.coldmint.rust.pro.tool.UnitAutoCompleteHelper
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.google.gson.Gson
|
||||
import java.io.File
|
||||
|
@ -171,40 +172,8 @@ class TemplateParserActivity() : BaseActivity<ActivityTemplateParserBinding>() {
|
|||
}
|
||||
|
||||
private fun initAction() {
|
||||
viewBinding.fileNameInputView.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
val text = s.toString()
|
||||
val index = text.lastIndexOf('.')
|
||||
if (index > -1 && index != text.length - 1) {
|
||||
val type = text.substring(index + 1)
|
||||
if (fileTypeTip("ini", type, text))
|
||||
else if (fileTypeTip(
|
||||
"template",
|
||||
type,
|
||||
text
|
||||
)
|
||||
) else if (fileTypeTip("txt", type, text))
|
||||
else {
|
||||
viewBinding.fileTypeTip.isVisible = false
|
||||
|
||||
}
|
||||
viewBinding.fileNameInputLayout.helperText =
|
||||
String.format(getString(R.string.file_type_tip), type)
|
||||
|
||||
} else {
|
||||
viewBinding.fileNameInputLayout.helperText =
|
||||
getString(R.string.file_type_define)
|
||||
viewBinding.fileTypeTip.isVisible = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
val unitAutoCompleteHelper = UnitAutoCompleteHelper(this)
|
||||
unitAutoCompleteHelper.onBindAutoCompleteTextView(viewBinding.fileNameInputView)
|
||||
viewBinding.fab.setOnClickListener(object : View.OnClickListener {
|
||||
override fun onClick(v: View) {
|
||||
if (working) {
|
||||
|
@ -361,37 +330,6 @@ class TemplateParserActivity() : BaseActivity<ActivityTemplateParserBinding>() {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件名提示
|
||||
*/
|
||||
fun fileTypeTip(key: String, type: String, text: String): Boolean {
|
||||
if (key.startsWith(type) && key != type) {
|
||||
val spannableString =
|
||||
SpannableString(String.format(getString(R.string.file_type_tip2), key))
|
||||
val clickableSpan = object : ClickableSpan() {
|
||||
override fun onClick(widget: View) {
|
||||
val need = key.substring(type.length)
|
||||
val newText = text + need
|
||||
viewBinding.fileNameInputView.setText(newText)
|
||||
viewBinding.fileNameInputView.setSelection(newText.length)
|
||||
viewBinding.fileTypeTip.isVisible = false
|
||||
}
|
||||
}
|
||||
val start = spannableString.indexOf(key)
|
||||
val len = key.length
|
||||
spannableString.setSpan(
|
||||
clickableSpan,
|
||||
start,
|
||||
start + len,
|
||||
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
viewBinding.fileTypeTip.movementMethod = LinkMovementMethod.getInstance()
|
||||
viewBinding.fileTypeTip.text = spannableString
|
||||
viewBinding.fileTypeTip.isVisible = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun setErrorAndInput(
|
||||
editText: EditText,
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package com.coldmint.rust.pro.base
|
||||
|
||||
import android.R
|
||||
import android.content.Context
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.widget.ArrayAdapter
|
||||
import com.coldmint.rust.pro.interfaces.AutoCompleteHelper
|
||||
import com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
|
||||
/**
|
||||
* 基本附加提示列表
|
||||
* 附加提示列表用于在某些文本后附加特殊符号,例如文件和邮箱的自动补全
|
||||
* @property mDataList List<String>
|
||||
* @property mSymbol Char
|
||||
* @property adapter ArrayAdapter<String>
|
||||
* @property maxNum Int
|
||||
* @constructor
|
||||
*/
|
||||
abstract class BaseAppendAutoCompleteHelper(context: Context) : AutoCompleteHelper {
|
||||
abstract fun getDataList(): List<String>
|
||||
|
||||
abstract fun getSymbol(): Char
|
||||
|
||||
private val mDataList by lazy {
|
||||
getDataList()
|
||||
}
|
||||
|
||||
private val mSymbol by lazy {
|
||||
getSymbol()
|
||||
}
|
||||
|
||||
private val adapter = ArrayAdapter<String>(
|
||||
context,
|
||||
R.layout.simple_expandable_list_item_1
|
||||
)
|
||||
|
||||
//最大提示数量
|
||||
private var maxNum = 3
|
||||
|
||||
/**
|
||||
* 设置最大显示数量(数量必须大于0)
|
||||
* @param number Int
|
||||
*/
|
||||
fun setMaxNum(number: Int) {
|
||||
if (number > 0) {
|
||||
maxNum = number
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邮箱提示列表
|
||||
* @param string String
|
||||
* @return List<String>?
|
||||
*/
|
||||
|
||||
private fun updateList(string: String) {
|
||||
adapter.clear()
|
||||
val index = string.indexOf(mSymbol)
|
||||
if (index > -1) {
|
||||
val end = string.substring(index)
|
||||
var num = 0
|
||||
Log.d("附加提示列表", "截取 " + end)
|
||||
for (data in mDataList) {
|
||||
if (data.startsWith(end)) {
|
||||
num++
|
||||
val h1 = string.substring(0..index)
|
||||
val h2 = data.substring(
|
||||
1
|
||||
)
|
||||
val value = h1 + h2
|
||||
Log.d("附加提示列表", "提示 " + h1 + " | " + h2)
|
||||
adapter.add(value)
|
||||
}
|
||||
if (num == maxNum) {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var num = 0
|
||||
Log.d("附加提示列表", "没有符号 " + string)
|
||||
for (email in mDataList) {
|
||||
num++
|
||||
adapter.add(string + email)
|
||||
if (num == maxNum) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onBindAutoCompleteTextView(autoCompleteTextView: MaterialAutoCompleteTextView) {
|
||||
autoCompleteTextView.threshold = 0
|
||||
autoCompleteTextView.setAdapter(adapter)
|
||||
autoCompleteTextView.addTextChangedListener(object : TextWatcher {
|
||||
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
val text = p0.toString()
|
||||
if (text.isNotBlank()) {
|
||||
updateList(text)
|
||||
}else{
|
||||
adapter.clear()
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.coldmint.rust.pro.interfaces
|
||||
|
||||
import com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
|
||||
/**
|
||||
* 自动完成提示器
|
||||
*/
|
||||
interface AutoCompleteHelper {
|
||||
|
||||
/**
|
||||
* 需要实现绑定自动完成组件的方法
|
||||
* @param autoCompleteTextView MaterialAutoCompleteTextView
|
||||
*/
|
||||
fun onBindAutoCompleteTextView(autoCompleteTextView: MaterialAutoCompleteTextView)
|
||||
}
|
|
@ -5,14 +5,17 @@ import android.text.Editable
|
|||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.widget.ArrayAdapter
|
||||
import com.coldmint.rust.pro.base.BaseAppendAutoCompleteHelper
|
||||
import com.coldmint.rust.pro.interfaces.AutoCompleteHelper
|
||||
import com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
|
||||
/**
|
||||
* 邮箱自动完成助手
|
||||
*/
|
||||
class EmailAutoCompleteHelper(val context: Context) {
|
||||
private val emailList =
|
||||
listOf<String>(
|
||||
class EmailAutoCompleteHelper(val context: Context) : BaseAppendAutoCompleteHelper(context) {
|
||||
|
||||
override fun getDataList(): List<String> {
|
||||
return listOf<String>(
|
||||
"@qq.com",
|
||||
"@gmail.com",
|
||||
"@163.com",
|
||||
|
@ -24,79 +27,11 @@ class EmailAutoCompleteHelper(val context: Context) {
|
|||
"@126.com",
|
||||
"@aliyun.com", "@tom.com"
|
||||
)
|
||||
|
||||
private val adapter = ArrayAdapter<String>(
|
||||
context,
|
||||
android.R.layout.simple_expandable_list_item_1
|
||||
)
|
||||
|
||||
//最大提示数量
|
||||
val maxNum = 3
|
||||
|
||||
/**
|
||||
* 获取邮箱提示列表
|
||||
* @param string String
|
||||
* @return List<String>?
|
||||
*/
|
||||
|
||||
private fun updateList(string: String) {
|
||||
adapter.clear()
|
||||
val index = string.indexOf("@")
|
||||
if (index > -1) {
|
||||
val end = string.substring(index)
|
||||
var num = 0
|
||||
for (email in emailList) {
|
||||
if (email.startsWith(end)) {
|
||||
num++
|
||||
val value = string.substring(0..index) + email.substring(
|
||||
if (end.length > 1) {
|
||||
end.length - 1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
)
|
||||
adapter.add(value)
|
||||
}
|
||||
if (num == maxNum) {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var num = 0
|
||||
for (email in emailList) {
|
||||
num++
|
||||
adapter.add(string + email)
|
||||
if (num == maxNum) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定控件
|
||||
* @param autoCompleteTextView MaterialAutoCompleteTextView
|
||||
*/
|
||||
fun onBindAutoCompleteTextView(autoCompleteTextView: MaterialAutoCompleteTextView) {
|
||||
autoCompleteTextView.threshold = 0
|
||||
autoCompleteTextView.setAdapter(adapter)
|
||||
autoCompleteTextView.addTextChangedListener(object : TextWatcher {
|
||||
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
val text = p0.toString()
|
||||
if (text.isNotBlank()) {
|
||||
updateList(text)
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
override fun getSymbol(): Char {
|
||||
return '@'
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.coldmint.rust.pro.tool
|
||||
|
||||
import android.R
|
||||
import android.content.Context
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.widget.ArrayAdapter
|
||||
import com.coldmint.rust.pro.base.BaseAppendAutoCompleteHelper
|
||||
import com.coldmint.rust.pro.interfaces.AutoCompleteHelper
|
||||
import com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
|
||||
/**
|
||||
* 单位自动完成帮助
|
||||
*/
|
||||
class UnitAutoCompleteHelper(context: Context) : BaseAppendAutoCompleteHelper(context) {
|
||||
|
||||
|
||||
override fun getDataList(): List<String> {
|
||||
return listOf<String>(
|
||||
".ini", ".txt", ".template"
|
||||
)
|
||||
}
|
||||
|
||||
override fun getSymbol(): Char {
|
||||
return '.'
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -38,24 +38,16 @@
|
|||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fileTypeTip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:textSize="12dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/fileNameInputLayout"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:counterEnabled="true"
|
||||
app:counterMaxLength="255"
|
||||
app:helperText="@string/file_type_define">
|
||||
app:counterMaxLength="255">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
android:id="@+id/fileNameInputView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -342,9 +342,17 @@ object User {
|
|||
val data = response.body!!.string()
|
||||
val finalActivationInfo =
|
||||
gson.fromJson(data, ActivationInfo::class.java)
|
||||
handler.post {
|
||||
apiCallBack.onResponse(finalActivationInfo)
|
||||
if (finalActivationInfo==null)
|
||||
{
|
||||
handler.post {
|
||||
apiCallBack.onFailure(Exception("激活信息错误"))
|
||||
}
|
||||
}else{
|
||||
handler.post {
|
||||
apiCallBack.onResponse(finalActivationInfo)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
handler.post {
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
# Location of the SDK. This is only used by Gradle.
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
#Fri May 13 19:21:35 CST 2022
|
||||
sdk.dir=D\:\\Document\\AndroidSdk
|
||||
#Wed Jul 06 10:56:35 CST 2022
|
||||
sdk.dir=D\:\\Android_SDK
|
||||
|
|
Loading…
Reference in New Issue
Block a user