Utilize logic from lottie to determine animation scale.

This commit is contained in:
Alex Hart 2022-11-14 10:49:55 -04:00 committed by GitHub
parent c1b19390a2
commit e3954ab5e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 51 deletions

View file

@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.webrtc.AndroidTelecomUtil;
import org.thoughtcrime.securesms.util.AppSignatureUtil;
import org.thoughtcrime.securesms.util.ByteUnit;
import org.thoughtcrime.securesms.util.ContextUtil;
import org.thoughtcrime.securesms.util.DeviceProperties;
import org.thoughtcrime.securesms.util.NetworkUtil;
import org.thoughtcrime.securesms.util.ScreenDensity;
@ -56,6 +57,7 @@ public class LogSectionSystemInfo implements LogSection {
.append(ScreenDensity.get(context)).append(", ")
.append(getScreenRefreshRate(context)).append("\n");
builder.append("Font Scale : ").append(context.getResources().getConfiguration().fontScale).append("\n");
builder.append("Animation Scale: ").append(ContextUtil.getAnimationScale(context));
builder.append("Android : ").append(Build.VERSION.RELEASE).append(", API ")
.append(Build.VERSION.SDK_INT).append(" (")
.append(Build.VERSION.INCREMENTAL).append(", ")

View file

@ -19,7 +19,7 @@ import com.bumptech.glide.request.target.Target
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.blurhash.BlurHash
import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.util.areSystemAnimationsDisabled
import org.thoughtcrime.securesms.util.ContextUtil
import org.thoughtcrime.securesms.util.visible
class StoryFirstTimeNavigationView @JvmOverloads constructor(
@ -119,7 +119,7 @@ class StoryFirstTimeNavigationView @JvmOverloads constructor(
}
private fun startLottieAnimations() {
if (context.contentResolver.areSystemAnimationsDisabled()) {
if (ContextUtil.getAnimationScale(context) == 0f) {
return
}

View file

@ -1,17 +0,0 @@
package org.thoughtcrime.securesms.util
import android.animation.ValueAnimator
import android.content.ContentResolver
import android.os.Build
import android.provider.Settings
fun ContentResolver.areSystemAnimationsDisabled(): Boolean {
return if (Build.VERSION.SDK_INT >= 26) {
!ValueAnimator.areAnimatorsEnabled()
} else {
val durationScale = Settings.Global.getFloat(this, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f)
val transitionScale = Settings.Global.getFloat(this, Settings.Global.TRANSITION_ANIMATION_SCALE, 1.0f)
!(durationScale > 0f && transitionScale > 0f)
}
}

View file

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.util;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
@ -16,4 +17,10 @@ public final class ContextUtil {
return Objects.requireNonNull(AppCompatResources.getDrawable(context, drawable));
}
/**
* Implementation "borrowed" from com.airbnb.lottie.utils.Utils#getAnimationScale(android.content.Context)
*/
public static float getAnimationScale(Context context) {
return Settings.Global.getFloat(context.getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);
}
}