Commit d5c912fb authored by wanglei's avatar wanglei

...

parent 306a172a
......@@ -34,6 +34,7 @@ import com.base.pdfviewerscannerwhite.databinding.ActivityMainBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.ui.appprocess.AppProcessActivity
import com.base.pdfviewerscannerwhite.ui.appprocess.AppProcessLoadingActivity
import com.base.pdfviewerscannerwhite.ui.cleanjunk.ScanJunkActivity
import com.base.pdfviewerscannerwhite.ui.document.excel.ExcelActivity
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfActivity
......@@ -57,6 +58,8 @@ import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkNotificationPer
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import com.base.pdfviewerscannerwhite.utils.ShortcutUtils.addDeskShortCut
import com.base.pdfviewerscannerwhite.utils.updateMediaStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
......@@ -104,6 +107,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
}
}
lifecycleScope.launch(Dispatchers.IO) {
ToolFragment.initAppVidePhotoMusicData(this@MainActivity)
}
}
......@@ -143,7 +149,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
}
if (actionId == NOTIFICATION_ACTION_APP_PROCESS) {
startActivity(Intent(this, AppProcessActivity::class.java))
startActivity(Intent(this, AppProcessLoadingActivity::class.java))
return
}
if (actionId == NOTIFICATION_ACTION_CLEAN_JUNK) {
......
......@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint
import android.app.usage.StorageStatsManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
......@@ -28,6 +29,7 @@ import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.ui.view.ProgressBean
import com.base.pdfviewerscannerwhite.ui.weather.WeatherInterface
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import com.base.pdfviewerscannerwhite.utils.getMediaAudioCountSize
import com.base.pdfviewerscannerwhite.utils.getMediaPhotoCountSize
......@@ -45,6 +47,7 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
FragmentToolBinding.inflate(layoutInflater)
}
@SuppressLint("SetTextI18n")
override fun setView() {
val bean = WeatherUtils.getWeatherEntity()?.list?.get(0)
......@@ -143,15 +146,54 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
}
}
var usedBytes: Long = 0
var totalBytes: Long = 0
private val progressList = arrayListOf<ProgressBean>()
@SuppressLint("SetTextI18n")
private fun refreshData() = lifecycleScope.launch(Dispatchers.IO) {
fun refreshData() {
if (preProgressList.isNullOrEmpty()) {
lifecycleScope.launch(Dispatchers.IO) {
LogEx.logDebug(TAG, "now load data")
initAppVidePhotoMusicData(requireContext(),
{
lifecycleScope.launch(Dispatchers.Main) {
binding.tvUsedStorage.text = usedBytes.toFormatSize()
binding.tvTotalStorage.text = " / ${totalBytes.toFormatSize()}"
binding.tvPercent.text = "${usedBytes * 100 / totalBytes}"
}
},
{
launch(Dispatchers.Main) {
binding.colorProgress.animateProgress(progressList)
}
})
}
} else {
lifecycleScope.launch(Dispatchers.Main) {
LogEx.logDebug(TAG, "preload data")
binding.tvUsedStorage.text = usedBytes.toFormatSize()
binding.tvTotalStorage.text = " / ${totalBytes.toFormatSize()}"
binding.tvPercent.text = "${usedBytes * 100 / totalBytes}"
binding.colorProgress.animateProgress(preProgressList ?: arrayListOf())
preProgressList = null
}
}
}
companion object {
private var preProgressList: ArrayList<ProgressBean>? = arrayListOf()
private val progressList = arrayListOf<ProgressBean>()
private var usedBytes: Long = 0
private var totalBytes: Long = 0
fun initAppVidePhotoMusicData(context: Context, vararg uiAction: () -> Unit) {
progressList.clear()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val storageStatsManager = requireContext().getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
val storageStatsManager =
context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
totalBytes = storageStatsManager.getTotalBytes(StorageManager.UUID_DEFAULT)
usedBytes = totalBytes - storageStatsManager.getFreeBytes(StorageManager.UUID_DEFAULT)
} else {
......@@ -162,15 +204,12 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
totalBytes = (stat1.totalBytes + stat2.totalBytes)
usedBytes = ((stat1.totalBytes + stat2.totalBytes) - (stat1.availableBytes + stat2.availableBytes))
}
lifecycleScope.launch(Dispatchers.Main) {
binding.tvUsedStorage.text = usedBytes.toFormatSize()
binding.tvTotalStorage.text = " / ${totalBytes.toFormatSize()}"
binding.tvPercent.text = "${usedBytes * 100 / totalBytes}"
}
val videoPair = requireContext().getMediaVideoCountSize()
val picturePair = requireContext().getMediaPhotoCountSize()
val audioPair = requireContext().getMediaAudioCountSize()
runCatching { uiAction[0].invoke() }
val videoPair = context.getMediaVideoCountSize()
val picturePair = context.getMediaPhotoCountSize()
val audioPair = context.getMediaAudioCountSize()
val totalAngle = (usedBytes.toFloat() / totalBytes.toFloat()) * 360f
val appSize = usedBytes - videoPair.second - picturePair.second - audioPair.second
......@@ -193,8 +232,10 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
progressList.add(audioBean)
progressList.reverse()
launch(Dispatchers.Main) {
binding.colorProgress.animateProgress(progressList)
if (preProgressList != null) {
preProgressList?.addAll(progressList)
}
runCatching { uiAction[1].invoke() }
}
}
......
......@@ -19,16 +19,20 @@ import com.base.pdfviewerscannerwhite.fcm.NotificationHoverUtils
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.helper.EventUtils
import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.helper.WeatherUtils
import com.base.pdfviewerscannerwhite.service.StayNotificationService.Companion.startStayNotification
import com.base.pdfviewerscannerwhite.ui.main.MainActivity
import com.base.pdfviewerscannerwhite.ui.permission.PermissionActivity
import com.base.pdfviewerscannerwhite.ui.set.SetLanguageActivity
import com.base.pdfviewerscannerwhite.utils.AnimationUtils
import com.base.pdfviewerscannerwhite.utils.BarUtils
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.UmpUtils
import com.base.pdfviewerscannerwhite.utils.UmpUtils.requestUMP
import com.base.pdfviewerscannerwhite.utils.UmpUtils.umpCalled
import com.base.pdfviewerscannerwhite.utils.UmpUtils.umpCanAd
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Calendar
import java.util.Locale
import java.util.concurrent.atomic.AtomicBoolean
......@@ -108,6 +112,8 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
if (BuildConfig.DEBUG) {
// toast("isHotLaunch=$isHotLaunch")
}
startWeatherAnimation()
ifAgreePrivacy = true
if (ifAgreePrivacy) {
if (isHotLaunch) {
......@@ -239,4 +245,35 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
}
@SuppressLint("SetTextI18n")
private fun startWeatherAnimation() = lifecycleScope.launch(Dispatchers.IO) {
if (!WeatherUtils.hasWeatherDataToday()) {
WeatherUtils.getWeatherData()
}
val weatherCityBean = WeatherUtils.getWeatherEntity()
val weather = weatherCityBean?.list?.random()
LogEx.logDebug(TAG, "weather=$weather")
if (weather != null) {
val icon = when (weather.iconDay) {
"Sunny day" -> R.mipmap.d_qing
"Cloudy day" -> R.mipmap.d_yin
"Rainy day" -> R.mipmap.d_dayu
"Snowy day" -> R.mipmap.d_xiaxue
"Greasy day" -> R.mipmap.d_wumaishachengbao
"Unknown" -> R.mipmap.d_qing
else -> R.mipmap.d_qing
}
binding.ivWeather.setImageResource(icon)
binding.tvWendu.text = weather.tempMin + "℃" + " / " + weather.tempMax + "℃"
launch(Dispatchers.Main) {
AnimationUtils.startAlphaAnimation(binding.ivWeather, 400, null) {
AnimationUtils.startAlphaAnimation(binding.tvWendu, 400, null) {
}
}
}
}
}
}
\ No newline at end of file
package com.base.pdfviewerscannerwhite.utils;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.view.View;
public class AnimationUtils {
/**
* 开始透明度渐变动画,并设置动画结束时的回调。
*
* @param view 要应用动画的视图。
* @param duration 动画持续时间(毫秒)。
* @param endCallback 动画结束时调用的回调接口。
*/
public static void startAlphaAnimation(final View view,
long duration,
final AnimationStartCallback startCallback,
final AnimationEndCallback endCallback) {
// 确保视图初始透明度为0
view.setAlpha(0f);
// 创建透明度从0到1的动画
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
alphaAnimator.setDuration(duration);
// 设置动画监听器,以便在动画结束时调用回调
alphaAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
if (startCallback != null) {
startCallback.onAnimationStart();
}
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
// 调用回调接口的onAnimationEnd方法
if (endCallback != null) {
endCallback.onAnimationEnd();
}
}
});
// 启动动画
alphaAnimator.start();
}
/**
* 动画结束时的回调接口。
*/
public interface AnimationEndCallback {
void onAnimationEnd();
}
/**
* 动画结束时的回调接口。
*/
public interface AnimationStartCallback {
void onAnimationStart();
}
}
\ No newline at end of file
......@@ -9,38 +9,42 @@
tools:context=".ui.splash.SplashActivity">
<ImageView
android:id="@+id/iv_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="82dp"
android:src="@mipmap/qdylogo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_month_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:textColor="#16151A"
android:textSize="25sp"
app:layout_constraintStart_toStartOf="@id/iv_logo"
app:layout_constraintTop_toBottomOf="@id/iv_logo"
tools:text="October 09" />
<TextView
android:id="@+id/tv_xingqi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginTop="180dp"
android:layout_marginTop="12dp"
android:textColor="#7D7D7F"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_month_day"
tools:text="Wednesday" />
<TextView
android:id="@+id/tv_month_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:textColor="#16151A"
android:textSize="45sp"
app:layout_constraintStart_toStartOf="@id/tv_xingqi"
app:layout_constraintTop_toBottomOf="@id/tv_xingqi"
tools:text="October 09" />
<View
android:layout_width="48dp"
android:layout_height="1dp"
......@@ -62,7 +66,31 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.45" />
app:layout_constraintVertical_bias="0.55" />
<ImageView
android:id="@+id/iv_weather"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:alpha="0"
android:src="@mipmap/duoyun"
app:layout_constraintBottom_toTopOf="@id/tv_wendu"
app:layout_constraintEnd_toEndOf="@id/tv_app_name"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_wendu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
android:alpha="0"
android:textColor="#16151A"
android:textSize="45sp"
app:layout_constraintBottom_toTopOf="@id/tv_app_name"
app:layout_constraintEnd_toEndOf="@id/tv_app_name"
tools:text="13℃/20℃" />
<ImageView
android:id="@+id/iv_document"
......@@ -72,7 +100,9 @@
android:src="@mipmap/document_all"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_app_name" />
app:layout_constraintTop_toBottomOf="@id/tv_app_name"
app:layout_constraintVertical_bias="0.45"
tools:ignore="ContentDescription" />
<FrameLayout
......
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