From e3943e95b5211babb1624009beed0aad524b37f6 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Thu, 9 Apr 2020 18:02:18 +0200 Subject: [PATCH] Fix for AnimatedVectorDrawables in Pico devices --- .../ui/widgets/WebXRInterstitialWidget.java | 8 ++++---- .../ui/widgets/dialogs/VoiceSearchWidget.java | 8 +++++--- .../org/mozilla/vrbrowser/utils/ViewUtils.java | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WebXRInterstitialWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WebXRInterstitialWidget.java index 3d4a2957cf..bd11f8a5fb 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WebXRInterstitialWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WebXRInterstitialWidget.java @@ -3,8 +3,6 @@ import android.content.Context; import android.graphics.drawable.AnimatedVectorDrawable; import android.view.LayoutInflater; -import android.view.animation.Animation; -import android.view.animation.RotateAnimation; import androidx.databinding.DataBindingUtil; @@ -12,6 +10,7 @@ import org.mozilla.vrbrowser.VRBrowserActivity; import org.mozilla.vrbrowser.databinding.WebxrInterstitialBinding; import org.mozilla.vrbrowser.utils.DeviceType; +import org.mozilla.vrbrowser.utils.ViewUtils; import java.util.ArrayList; @@ -43,12 +42,13 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { } private void initialize() { - // AnimatedVectorDrawable doesn't work with a Hardware Accelerated canvas, we disable it for this view. - setIsHardwareAccelerationEnabled(false); LayoutInflater inflater = LayoutInflater.from(getContext()); mBinding = DataBindingUtil.inflate(inflater, R.layout.webxr_interstitial, this, true); mBinding.setLifecycleOwner((VRBrowserActivity)getContext()); mSpinnerAnimation = (AnimatedVectorDrawable) mBinding.webxrSpinner.getDrawable(); + if (DeviceType.isPicoVR()) { + ViewUtils.forceAnimationOnUI(mSpinnerAnimation); + } mWidgetManager.addWebXRListener(this); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java index 305dbb2f5c..2432ae4c1d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java @@ -33,7 +33,9 @@ import org.mozilla.vrbrowser.databinding.VoiceSearchDialogBinding; import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement; +import org.mozilla.vrbrowser.utils.DeviceType; import org.mozilla.vrbrowser.utils.LocaleUtils; +import org.mozilla.vrbrowser.utils.ViewUtils; public class VoiceSearchWidget extends UIDialog implements WidgetManagerDelegate.PermissionListener, Application.ActivityLifecycleCallbacks { @@ -82,9 +84,6 @@ public VoiceSearchWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) { } private void initialize(Context aContext) { - // AnimatedVectorDrawable doesn't work with a Hardware Accelerated canvas, we disable it for this view. - setIsHardwareAccelerationEnabled(false); - updateUI(); mWidgetManager.addPermissionListener(this); @@ -94,6 +93,9 @@ private void initialize(Context aContext) { mMozillaSpeechService.setProductTag(getContext().getString(R.string.voice_app_id)); mSearchingAnimation = (AnimatedVectorDrawable) mBinding.voiceSearchAnimationSearching.getDrawable(); + if (DeviceType.isPicoVR()) { + ViewUtils.forceAnimationOnUI(mSearchingAnimation); + } mMozillaSpeechService.addListener(mVoiceSearchListener); ((Application)aContext.getApplicationContext()).registerActivityLifecycleCallbacks(this); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/utils/ViewUtils.java b/app/src/common/shared/org/mozilla/vrbrowser/utils/ViewUtils.java index a6e367e999..edf8368d5d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/utils/ViewUtils.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/utils/ViewUtils.java @@ -7,6 +7,7 @@ import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.drawable.AnimatedVectorDrawable; import android.os.Build; import android.text.Html; import android.text.Layout; @@ -15,6 +16,7 @@ import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.text.style.URLSpan; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -27,8 +29,12 @@ import org.mozilla.vrbrowser.ui.widgets.UIWidget; +import java.lang.reflect.Method; + public class ViewUtils { + private static final String LOGTAG = SystemUtils.createLogtag(ViewUtils.class); + public interface LinkClickableSpan { void onClick(@NonNull View widget, @NonNull String url); } @@ -238,4 +244,14 @@ public static Bitmap getRoundedCroppedBitmap(@NonNull Bitmap bitmap) { return output; } + + public static void forceAnimationOnUI(@NonNull AnimatedVectorDrawable drawable) { + try { + Method forceAnimationOnUI = AnimatedVectorDrawable.class.getMethod("forceAnimationOnUI"); + forceAnimationOnUI.invoke(drawable); + + } catch (Exception e) { + Log.e(LOGTAG, "Failed to call AnimatedVectorDrawable::forceAnimationOnUI: " + e); + } + } }