Skip to content

Commit

Permalink
Spinner Update (#3108)
Browse files Browse the repository at this point in the history
* Updated spinner animation and graph colors

* Fix permission request not being executed after data collection dialog
  • Loading branch information
keianhzo committed Apr 6, 2020
1 parent 0337684 commit 633529f
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -78,7 +80,7 @@ Canvas drawBegin() {
}
if (mSurface != null) {
try {
if (sUseHarwareAcceleration) {
if (sUseHardwareAcceleration && mIsHardwareAccelerationEnabled) {
mSurfaceCanvas = mSurface.lockHardwareCanvas();
} else {
mSurfaceCanvas = mSurface.lockCanvas(null);
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -435,4 +442,8 @@ protected float getWorldWidth() {
return mWorldWidth;
}

public void setIsHardwareAccelerationEnabled(boolean enabled) {
mIsHardwareAccelerationEnabled = enabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)));
}
}

Expand All @@ -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();
}

Expand All @@ -330,7 +325,7 @@ private void setResultState() {

postDelayed(() -> {
mBinding.setState(State.ERROR);
mBinding.voiceSearchAnimationSearching.clearAnimation();
mSearchingAnimation.stop();
mBinding.executePendingBindings();

startVoiceSearch();
Expand All @@ -339,7 +334,7 @@ private void setResultState() {

private void setPermissionNotGranted() {
mBinding.setState(State.PERMISSIONS);
mBinding.voiceSearchAnimationSearching.clearAnimation();
mSearchingAnimation.stop();
mBinding.executePendingBindings();
}

Expand Down

0 comments on commit 633529f

Please sign in to comment.