Commit 11202e0a authored by mengcuiguang's avatar mengcuiguang

add 清理动画

parent 9faec8a2
......@@ -19,8 +19,7 @@
<activity android:name=".ui.albumClean.AlbumCleanActivity" />
<activity
android:name=".ui.multiClean.MultiCleanActivity"
android:launchMode="singleTop">
android:name=".ui.multiClean.MultiCleanActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -62,6 +62,8 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
)
}
clv_loading.showLoading()
initRecyclerView()
btn_clean.setOnClickListener {
......@@ -77,7 +79,6 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
multiAdapter.cleanSelectImage()
multiAdapter.notifyDataSetChanged()
}
}
private fun initRecyclerView() {
......@@ -108,6 +109,11 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
}
override fun onDestroy() {
super.onDestroy()
clv_loading.hideLoading()
}
override fun onImageSelect(selectCount: Int) {
// 改变 删除按钮数据
updateBtnText(selectCount)
......
package com.mints.cleaner.widget
import android.animation.AnimatorSet
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.mints.cleaner.R
/**
* 清理界面-加载中
*/
class CleanLoadingView : LinearLayout {
// 时间单位 1000=1秒
private val TIME_INTERVAL: Long = 1000
// 默认展示时间1.5秒
private val DEFAULT_LOAD_TIME: Long = 1500
private var tvLoadingProgress: TextView? = null
private var ivLoading: ImageView? = null
private var set: AnimatorSet? = null
private var animator: ValueAnimator? = null
private var circleAnimator: Animation? = null
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init()
}
private fun init() {
val view =
LayoutInflater.from(context).inflate(R.layout.view_clean_loading, this)
tvLoadingProgress = view.findViewById(R.id.tv_loading_progress)
ivLoading = view.findViewById(R.id.iv_loading)
}
/**
* 显示加载框
*
* 默认1.5秒
*/
fun showLoading() {
start(DEFAULT_LOAD_TIME)
}
/**
* 显示加载框
*
* 指定时间 time - 1s
*/
fun showLoading(time: Long) {
start(time * TIME_INTERVAL)
}
/**
* 隐藏
*/
fun hideLoading() {
this.visibility = View.GONE
if (animator != null) {
animator!!.cancel()
animator!!.removeAllListeners()
animator = null
}
if (set != null) {
set!!.cancel()
set = null
}
if (circleAnimator != null) {
circleAnimator!!.cancel()
circleAnimator = null
}
}
@SuppressLint("ObjectAnimatorBinding")
private fun start(time: Long) {
if (circleAnimator == null) {
circleAnimator = RotateAnimation(
0f,
359f,
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f
)
}
circleAnimator?.let {
it.interpolator = LinearInterpolator()
it.duration = 500
it.repeatCount = -1
it.fillAfter = false
ivLoading?.startAnimation(it)
}
// 根据传入的time计算1-100的时间进度
if (animator == null) {
animator = ValueAnimator.ofInt(0, 101)
}
animator?.addUpdateListener { valueAnimator ->
tvLoadingProgress?.text = valueAnimator.getAnimatedValue().toString() + "%"
// 101目的->防止隐藏时显示进度为99
if (valueAnimator.getAnimatedValue() == 101) {
hideLoading()
}
}
if (set == null) {
set = AnimatorSet()
}
set?.let {
it.playTogether(animator)
it.duration = time
it.start()
}
}
}
\ No newline at end of file
......@@ -19,6 +19,15 @@
layout="@layout/clean_header_bar"
app:title="@{title}" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_multi"
android:layout_width="match_parent"
......@@ -47,7 +56,13 @@
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<com.mints.cleaner.widget.CleanLoadingView
android:id="@+id/clv_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout>
......
<?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="match_parent"
android:layout_height="match_parent"
android:background="@color/theme">
<FrameLayout
android:id="@+id/fl_loading_root"
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/iv_loading"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@mipmap/ic_clean_loading">
</ImageView>
<TextView
android:id="@+id/tv_loading_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0%"
android:textColor="@color/white"
android:textSize="18sp" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="@string/empty_text"
android:textColor="@color/white"
android:textSize="18sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fl_loading_root" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -41,4 +41,6 @@
<string name="selector_all_image">全部图片</string>
<string name="empty_text">正在扫描...</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment