diff --git a/imitate/src/main/java/com/engineer/imitate/ui/activity/GroundDuActivity.kt b/imitate/src/main/java/com/engineer/imitate/ui/activity/GroundDuActivity.kt new file mode 100644 index 00000000..4aaff7ea --- /dev/null +++ b/imitate/src/main/java/com/engineer/imitate/ui/activity/GroundDuActivity.kt @@ -0,0 +1,26 @@ +package com.engineer.imitate.ui.activity + +import android.os.Bundle +import android.view.LayoutInflater +import androidx.appcompat.app.AppCompatActivity +import com.engineer.imitate.databinding.ActivityGroundDuBinding + +class GroundDuActivity : AppCompatActivity() { + private lateinit var viewBinding: ActivityGroundDuBinding + + private var show = false + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + viewBinding = ActivityGroundDuBinding.inflate(layoutInflater) + setContentView(viewBinding.root) + + viewBinding.testButton.setOnClickListener { + if (show) { + viewBinding.loadingText.hide() + } else { + viewBinding.loadingText.show() + } + show = !show + } + } +} \ No newline at end of file diff --git a/imitate/src/main/java/com/engineer/imitate/ui/widget/custom/LoadingTextView.kt b/imitate/src/main/java/com/engineer/imitate/ui/widget/custom/LoadingTextView.kt new file mode 100644 index 00000000..a559222d --- /dev/null +++ b/imitate/src/main/java/com/engineer/imitate/ui/widget/custom/LoadingTextView.kt @@ -0,0 +1,54 @@ +package com.engineer.imitate.ui.widget.custom + +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView + +/** + * 用于显示 。。。 的 loading 态 TextView + */ +class LoadingTextView @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, style: Int = 0 +) : AppCompatTextView(context, attrs, style) { + + + private var dotCount = 0 + private val handler = Handler(Looper.getMainLooper()) + + init { + text = "" + } + + private val loadingTask = object : Runnable { + override fun run() { + if (dotCount < 4) { + this@LoadingTextView.append(".") + dotCount++ + } else { + dotCount = 1 + this@LoadingTextView.text = "."// 重置为单个点 + } + handler.postDelayed(this, 500); // 每 500 毫秒更新一次 + } + + } + + fun show() { + hide() + handler.post(loadingTask) + } + + fun hide() { + text = "" + handler.removeCallbacks(loadingTask) + text = "" + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + hide() + } + +} \ No newline at end of file diff --git a/imitate/src/main/module/AndroidManifest.xml b/imitate/src/main/module/AndroidManifest.xml index a34af4f6..328f6b63 100644 --- a/imitate/src/main/module/AndroidManifest.xml +++ b/imitate/src/main/module/AndroidManifest.xml @@ -116,6 +116,7 @@ + + + + + + + +