From 633529ffb471a8373c7c4c4e55532c596ebd970a Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 6 Apr 2020 16:34:01 +0200 Subject: [PATCH] Spinner Update (#3108) * Updated spinner animation and graph colors * Fix permission request not being executed after data collection dialog --- .../ui/widgets/UISurfaceTextureRenderer.java | 16 +- .../vrbrowser/ui/widgets/UIWidget.java | 11 + .../ui/widgets/dialogs/VoiceSearchWidget.java | 33 +- .../drawable/ic_voice_search_volume_input.xml | 361 ++++++++++-------- app/src/main/res/drawable/spinner.xml | 141 +++++++ .../main/res/layout/voice_search_dialog.xml | 8 +- 6 files changed, 388 insertions(+), 182 deletions(-) create mode 100644 app/src/main/res/drawable/spinner.xml diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java index df45f433f..fd1a93149 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java @@ -20,11 +20,12 @@ public class UISurfaceTextureRenderer { private SurfaceTexture mSurfaceTexture; private Surface mSurface; private Canvas mSurfaceCanvas; - private static boolean sUseHarwareAcceleration; + private boolean mIsHardwareAccelerationEnabled; + private static boolean sUseHardwareAcceleration; private static boolean sRenderActive = true; public static void setUseHardwareAcceleration(boolean aEnabled) { - sUseHarwareAcceleration = aEnabled; + sUseHardwareAcceleration = aEnabled; } public static void setRenderActive(boolean aActive) { @@ -37,6 +38,7 @@ public static void setRenderActive(boolean aActive) { mSurfaceTexture = aTexture; mSurfaceTexture.setDefaultBufferSize(aWidth, aHeight); mSurface = new Surface(mSurfaceTexture); + mIsHardwareAccelerationEnabled = sUseHardwareAcceleration; } UISurfaceTextureRenderer(Surface aSurface, int aWidth, int aHeight) { @@ -78,7 +80,7 @@ Canvas drawBegin() { } if (mSurface != null) { try { - if (sUseHarwareAcceleration) { + if (sUseHardwareAcceleration && mIsHardwareAccelerationEnabled) { mSurfaceCanvas = mSurface.lockHardwareCanvas(); } else { mSurfaceCanvas = mSurface.lockCanvas(null); @@ -112,4 +114,12 @@ int height() { return mTextureHeight; } + /** + * Override global hardware acceleration per view. + * @param aEnabled Enable/Disable Hardware acceleration for this view. + */ + public void setIsHardwareAccelerationEnabled(boolean aEnabled) { + mIsHardwareAccelerationEnabled = aEnabled; + } + } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java index d48ace2c5..96669a241 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java @@ -52,6 +52,7 @@ public interface Delegate { private Runnable mFirstDrawCallback; protected boolean mResizing = false; protected boolean mReleased = false; + private Boolean mIsHardwareAccelerationEnabled; public UIWidget(Context aContext) { super(aContext); @@ -132,6 +133,9 @@ public void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final i } if (aTexture != null) { mRenderer = new UISurfaceTextureRenderer(aTexture, aWidth, aHeight); + if (mIsHardwareAccelerationEnabled != null) { + mRenderer.setIsHardwareAccelerationEnabled(mIsHardwareAccelerationEnabled); + } } setWillNotDraw(mRenderer == null); } @@ -145,6 +149,9 @@ public void setSurface(Surface aSurface, final int aWidth, final int aHeight, Ru } if (aSurface != null) { mRenderer = new UISurfaceTextureRenderer(aSurface, aWidth, aHeight); + if (mIsHardwareAccelerationEnabled != null) { + mRenderer.setIsHardwareAccelerationEnabled(mIsHardwareAccelerationEnabled); + } } setWillNotDraw(mRenderer == null); } @@ -435,4 +442,8 @@ protected float getWorldWidth() { return mWorldWidth; } + public void setIsHardwareAccelerationEnabled(boolean enabled) { + mIsHardwareAccelerationEnabled = enabled; + } + } 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 6733fe210..cf171084d 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 @@ -6,17 +6,17 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Configuration; +import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.ClipDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; -import android.view.animation.Animation; -import android.view.animation.LinearInterpolator; -import android.view.animation.RotateAnimation; import androidx.core.app.ActivityCompat; import androidx.databinding.DataBindingUtil; @@ -61,7 +61,7 @@ public interface VoiceSearchDelegate { private MozillaSpeechService mMozillaSpeechService; private VoiceSearchDelegate mDelegate; private ClipDrawable mVoiceInputClipDrawable; - private RotateAnimation mSearchingAnimation; + private AnimatedVectorDrawable mSearchingAnimation; private boolean mIsSpeechRecognitionRunning = false; private boolean mWasSpeechRecognitionRunning = false; @@ -81,6 +81,9 @@ 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); @@ -89,13 +92,7 @@ private void initialize(Context aContext) { mMozillaSpeechService.setGeckoWebExecutor(EngineProvider.INSTANCE.createGeckoWebExecutor(getContext())); mMozillaSpeechService.setProductTag(getContext().getString(R.string.voice_app_id)); - mSearchingAnimation = new RotateAnimation(0, 360f, - Animation.RELATIVE_TO_SELF, 0.5f, - Animation.RELATIVE_TO_SELF, 0.5f); - - mSearchingAnimation.setInterpolator(new LinearInterpolator()); - mSearchingAnimation.setDuration(ANIMATION_DURATION); - mSearchingAnimation.setRepeatCount(Animation.INFINITE); + mSearchingAnimation = (AnimatedVectorDrawable) mBinding.voiceSearchAnimationSearching.getDrawable(); mMozillaSpeechService.addListener(mVoiceSearchListener); ((Application)aContext.getApplicationContext()).registerActivityLifecycleCallbacks(this); @@ -297,11 +294,9 @@ public void show(@ShowFlags int aShowFlags) { if (index == PromptDialogWidget.POSITIVE) { SettingsStore.getInstance(getContext()).setSpeechDataCollectionEnabled(true); } - post(() -> show(aShowFlags)); + new Handler(Looper.getMainLooper()).post(() -> show(aShowFlags)); }, - () -> { - mWidgetManager.openNewTabForeground(getResources().getString(R.string.private_policy_url)); - }); + () -> mWidgetManager.openNewTabForeground(getResources().getString(R.string.private_policy_url))); } } @@ -315,13 +310,13 @@ public void hide(@HideFlags int aHideFlags) { private void setStartListeningState() { mBinding.setState(State.LISTENING); - mBinding.voiceSearchAnimationSearching.clearAnimation(); + mSearchingAnimation.stop(); mBinding.executePendingBindings(); } private void setDecodingState() { mBinding.setState(State.SEARCHING); - mBinding.voiceSearchAnimationSearching.startAnimation(mSearchingAnimation); + mSearchingAnimation.start(); mBinding.executePendingBindings(); } @@ -330,7 +325,7 @@ private void setResultState() { postDelayed(() -> { mBinding.setState(State.ERROR); - mBinding.voiceSearchAnimationSearching.clearAnimation(); + mSearchingAnimation.stop(); mBinding.executePendingBindings(); startVoiceSearch(); @@ -339,7 +334,7 @@ private void setResultState() { private void setPermissionNotGranted() { mBinding.setState(State.PERMISSIONS); - mBinding.voiceSearchAnimationSearching.clearAnimation(); + mSearchingAnimation.stop(); mBinding.executePendingBindings(); } diff --git a/app/src/main/res/drawable/ic_voice_search_volume_input.xml b/app/src/main/res/drawable/ic_voice_search_volume_input.xml index b59006e72..ac34451bb 100644 --- a/app/src/main/res/drawable/ic_voice_search_volume_input.xml +++ b/app/src/main/res/drawable/ic_voice_search_volume_input.xml @@ -1,157 +1,206 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + android:width="247.05733dp" + android:height="52.652084dp" + android:viewportWidth="247.05733" + android:viewportHeight="52.652084"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/spinner.xml b/app/src/main/res/drawable/spinner.xml new file mode 100644 index 000000000..76f905392 --- /dev/null +++ b/app/src/main/res/drawable/spinner.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/voice_search_dialog.xml b/app/src/main/res/layout/voice_search_dialog.xml index 5b5eada4f..d2dbe50cd 100644 --- a/app/src/main/res/layout/voice_search_dialog.xml +++ b/app/src/main/res/layout/voice_search_dialog.xml @@ -37,12 +37,12 @@ + tools:src="@drawable/spinner" />