modify rippledrawable

This commit is contained in:
侯歌 2021-12-01 11:08:38 +08:00
parent 81b8d77220
commit 874624f18d
8 changed files with 28 additions and 11 deletions

View File

@ -139,7 +139,6 @@ void AnimationHandler::addOneShotCommitCallback(const AnimationFrameCallback* ca
void AnimationHandler::removeCallback(const AnimationFrameCallback* callback){
auto it1=std::find(mCommitCallbacks.begin(),mCommitCallbacks.end(),(AnimationFrameCallback*)callback);
auto it2=mDelayedCallbackStartTime.find((AnimationFrameCallback*)callback);
if(it1!=mCommitCallbacks.end())mCommitCallbacks.erase(it1);
if(it2!=mDelayedCallbackStartTime.end())mDelayedCallbackStartTime.erase(it2);

View File

@ -1,7 +1,8 @@
#include <animation/animator.h>
namespace cdroid{
Animator::~Animator(){
}
Animator*Animator::clone(){
return nullptr;
}

View File

@ -65,6 +65,7 @@ protected:
bool isInitialized();
virtual void animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, bool inReverse);
public:
virtual ~Animator();
virtual void start();
virtual void cancel();
virtual void end();

View File

@ -12,6 +12,7 @@ ValueAnimator::ValueAnimator(){
}
ValueAnimator::~ValueAnimator(){
removeAnimationCallback();
delete mInterpolator;
}

View File

@ -6,6 +6,7 @@ namespace cdroid{
RippleComponent::RippleComponent(RippleDrawable* owner,const Rect& bounds){
mOwner=owner;
mBounds = bounds;
mHasMaxRadius =false;
}
void RippleComponent::onBoundsChange() {

View File

@ -65,7 +65,6 @@ void RippleDrawable::jumpToCurrentState(){
if (mRipple) mRipple->end();
if (mBackground) mBackground->jumpToFinal();
cancelExitingRipples();
}

View File

@ -8,7 +8,8 @@ RippleForeground::RippleForeground(RippleDrawable* owner,const Rect& bounds, flo
mForceSoftware = forceSoftware;
mStartingX = startingX;
mStartingY = startingY;
mUsingProperties =false;
mHasFinishedExit =false;
// Take 60% of the maximum of the width and height, then divided half to get the radius.
mStartRadius = std::max(bounds.width, bounds.height) * 0.3f;
clampStartingPosition();
@ -18,8 +19,19 @@ RippleForeground::RippleForeground(RippleDrawable* owner,const Rect& bounds, flo
};
}
RippleForeground::~RippleForeground(){
mUsingProperties =true;
end();
}
void RippleForeground::onTargetRadiusChanged(float targetRadius){
clampStartingPosition();
LOGD("radius=%.2f",targetRadius);
for (auto animator:mRunningSwAnimators) {
animator->removeListener(mAnimationListener);
animator->end();
}
mRunningSwAnimators.clear();
invalidateSelf();//switchToUiThreadAnimation();
}
@ -35,11 +47,13 @@ void RippleForeground::drawSoftware(Canvas& c,float origAlpha) {
}
void RippleForeground::pruneSwFinished() {
for (auto it=mRunningSwAnimators.begin();it!=mRunningSwAnimators.end();){
if (!(*it)->isRunning()) {
Animator*anim=(*it);
it=mRunningSwAnimators.erase(it);
}else it++;
if( mRunningSwAnimators.size()==0)return;
for (int i=mRunningSwAnimators.size()-1;i>=0;i--){
Animator*anim=mRunningSwAnimators[i];
if (!anim->isRunning()) {
mRunningSwAnimators.erase(mRunningSwAnimators.begin()+i);
delete anim;
}
}
}
@ -78,7 +92,6 @@ void RippleForeground::startSoftwareEnter() {
delete anim;
}
mRunningSwAnimators.clear();
ValueAnimator* tweenRadius = ValueAnimator::ofFloat({.0f,1.f});//this, TWEEN_RADIUS, 1);
tweenRadius->setDuration(RIPPLE_ENTER_DURATION);
tweenRadius->setInterpolator(new DecelerateInterpolator());//DECELERATE_INTERPOLATOR);
@ -101,7 +114,7 @@ void RippleForeground::startSoftwareEnter() {
}));
tweenOrigin->start();
mRunningSwAnimators.push_back(tweenOrigin);
ValueAnimator* opacity = ValueAnimator::ofFloat({.0f,1.f});//this, OPACITY, 1);
opacity->setDuration(OPACITY_ENTER_DURATION);
opacity->setInterpolator(new LinearInterpolator());//LINEAR_INTERPOLATOR);
@ -153,6 +166,7 @@ float RippleForeground::getCurrentRadius() {
void RippleForeground::end(){
for (auto anim:mRunningSwAnimators) {
anim->end();
delete anim;
}
mRunningSwAnimators.clear();
}

View File

@ -54,6 +54,7 @@ protected:
void clampStartingPosition();
public:
RippleForeground(RippleDrawable* owner,const Rect& bounds, float startingX, float startingY, bool forceSoftware);
~RippleForeground();
void getBounds(Rect& bounds);
void move(float x, float y);
bool hasFinishedExit()const;