[sweeper-cloud]通用加载中loading封装
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package com.mogo.och.sweepercloud.ui.dialog
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.view.animation.LinearInterpolator
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import com.elegant.utils.UiThreadHandler
|
||||
import com.mogo.eagle.core.function.hmi.dialog.BaseFloatDialog
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.sweepercloud.R
|
||||
import kotlinx.android.synthetic.main.dialog_sweeper_cloud_loading.*
|
||||
|
||||
/**
|
||||
* loading
|
||||
*/
|
||||
class SweeperCloudLoadingDialog : BaseFloatDialog, LifecycleObserver {
|
||||
private var objectAnimator: ObjectAnimator? = null
|
||||
private val mLoadingView by lazy { dialog_loading_view }
|
||||
private val mLoadingText by lazy { dialog_loading_text }
|
||||
private var mRunnable:Runnable= Runnable {
|
||||
ToastUtils.showLong("超时未响应,操作失败")
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
init {
|
||||
setContentView(R.layout.dialog_sweeper_cloud_loading)
|
||||
setCanceledOnTouchOutside(false)
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始旋转
|
||||
*/
|
||||
private fun startRotation() {
|
||||
objectAnimator = ObjectAnimator.ofFloat(mLoadingView, "rotation", 0f, 360f)
|
||||
objectAnimator?.let {
|
||||
it.duration = 1500
|
||||
it.repeatCount = -1
|
||||
it.interpolator = LinearInterpolator()
|
||||
it.start()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止旋转
|
||||
*/
|
||||
private fun stopRotation() {
|
||||
objectAnimator?.let {
|
||||
if (it.isRunning) {
|
||||
it.end()
|
||||
objectAnimator = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示dialog
|
||||
*/
|
||||
fun showLoading() {
|
||||
mLoadingText.text = "加载中..."
|
||||
startRotation()
|
||||
show()
|
||||
UiThreadHandler.getsUiHandler().postDelayed(mRunnable, 15000L)
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏dialog
|
||||
*/
|
||||
fun hideLoading() {
|
||||
UiThreadHandler.getsUiHandler().removeCallbacks(mRunnable)
|
||||
stopRotation()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/dp_200"
|
||||
android:layout_height="@dimen/dp_200"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_loading_view"
|
||||
android:layout_width="@dimen/dp_80"
|
||||
android:layout_height="@dimen/dp_80"
|
||||
android:src="@drawable/sweeper_loading_nor" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_loading_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="加载中..."
|
||||
android:textColor="#CCFFFFFF"
|
||||
android:layout_marginTop="@dimen/dp_10"/>
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user