valueanimator,objectanimator work fine,modify layouttransition(change animation to animator)

This commit is contained in:
侯歌 2021-08-02 11:21:56 +08:00
parent 9eec782579
commit 6bfddb7370
13 changed files with 264 additions and 103 deletions

View File

@ -133,4 +133,8 @@ bool Animator::isInitialized() {
void Animator::animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, bool inReverse) {
}
AnimatorListenerAdapter::AnimatorListenerAdapter(){
onAnimationCancel=onAnimationRepeat=onAnimationPause=onAnimationResume=[](Animator&anim){};
onAnimationEnd=onAnimationStart=[](Animator&aim,bool reverse){};
}
}//endof namespace

View File

@ -76,7 +76,7 @@ public:
virtual Animator*clone();
virtual long getStartDelay()=0;
virtual void setStartDelay(long startDelay)=0;
Animator& setDuration(long duration);
virtual Animator& setDuration(long duration)=0;
virtual long getDuration()=0;
long getTotalDuration();
virtual void setInterpolator(TimeInterpolator value)=0;
@ -100,4 +100,8 @@ public:
virtual void reverse();
};
class AnimatorListenerAdapter:public Animator::AnimatorListener,Animator::AnimatorPauseListener{
public:
AnimatorListenerAdapter();
};
}

View File

@ -1,18 +1,20 @@
#include <animation/layouttransition.h>
#include <widget/viewgroup.h>
#include <animation/objectanimator.h>
namespace cdroid{
TimeInterpolator* LayoutTransition::ACCEL_DECEL_INTERPOLATOR = new AccelerateDecelerateInterpolator();
TimeInterpolator* LayoutTransition::DECEL_INTERPOLATOR = new DecelerateInterpolator();
TimeInterpolator* LayoutTransition::sAppearingInterpolator = ACCEL_DECEL_INTERPOLATOR;
TimeInterpolator* LayoutTransition::sDisappearingInterpolator = ACCEL_DECEL_INTERPOLATOR;
TimeInterpolator* LayoutTransition::sChangingAppearingInterpolator = DECEL_INTERPOLATOR;
TimeInterpolator* LayoutTransition::sChangingDisappearingInterpolator= DECEL_INTERPOLATOR;
TimeInterpolator* LayoutTransition::sChangingInterpolator = DECEL_INTERPOLATOR;
TimeInterpolator LayoutTransition::ACCEL_DECEL_INTERPOLATOR = new AccelerateDecelerateInterpolator();
TimeInterpolator LayoutTransition::DECEL_INTERPOLATOR = new DecelerateInterpolator();
TimeInterpolator LayoutTransition::sAppearingInterpolator = ACCEL_DECEL_INTERPOLATOR;
TimeInterpolator LayoutTransition::sDisappearingInterpolator = ACCEL_DECEL_INTERPOLATOR;
TimeInterpolator LayoutTransition::sChangingAppearingInterpolator = DECEL_INTERPOLATOR;
TimeInterpolator LayoutTransition::sChangingDisappearingInterpolator= DECEL_INTERPOLATOR;
TimeInterpolator LayoutTransition::sChangingInterpolator = DECEL_INTERPOLATOR;
Animation* LayoutTransition::defaultChange = nullptr ;
Animation* LayoutTransition::defaultChangeIn = nullptr ;
Animation* LayoutTransition::defaultChangeOut= nullptr ;
Animator* LayoutTransition::defaultChange = nullptr ;
Animator* LayoutTransition::defaultChangeIn = nullptr ;
Animator* LayoutTransition::defaultChangeOut= nullptr ;
void LayoutTransition::setDuration(long duration) {
mChangingAppearingDuration = duration;
@ -180,7 +182,7 @@ long LayoutTransition::getStagger(int transitionType) {
return 0;
}
void LayoutTransition::setInterpolator(int transitionType, TimeInterpolator* interpolator) {
void LayoutTransition::setInterpolator(int transitionType, TimeInterpolator interpolator) {
switch (transitionType) {
case CHANGE_APPEARING:
mChangingAppearingInterpolator = interpolator;
@ -200,7 +202,7 @@ void LayoutTransition::setInterpolator(int transitionType, TimeInterpolator* int
}
}
TimeInterpolator* LayoutTransition::getInterpolator(int transitionType) {
TimeInterpolator LayoutTransition::getInterpolator(int transitionType) {
switch (transitionType) {
case CHANGE_APPEARING:
return mChangingAppearingInterpolator;
@ -217,7 +219,7 @@ TimeInterpolator* LayoutTransition::getInterpolator(int transitionType) {
return nullptr;
}
void LayoutTransition::setAnimator(int transitionType, Animation* animator) {
void LayoutTransition::setAnimator(int transitionType, Animator* animator) {
switch (transitionType) {
case CHANGE_APPEARING:
mChangingAppearingAnim = animator;
@ -237,7 +239,7 @@ void LayoutTransition::setAnimator(int transitionType, Animation* animator) {
}
}
Animation* LayoutTransition::getAnimator(int transitionType){
Animator* LayoutTransition::getAnimator(int transitionType){
switch (transitionType) {
case CHANGE_APPEARING:
return mChangingAppearingAnim;
@ -259,8 +261,8 @@ bool LayoutTransition::hasListeners()const{
}
void LayoutTransition::runChangeTransition(ViewGroup* parent, View* newView, int changeReason){
Animation* baseAnimator = nullptr;
Animation* parentAnimator= nullptr;
Animator* baseAnimator = nullptr;
Animator* parentAnimator= nullptr;
long duration;
switch (changeReason) {
case APPEARING:
@ -320,34 +322,36 @@ void LayoutTransition::runChangeTransition(ViewGroup* parent, View* newView, int
parent.addOnAttachStateChangeListener(callback);*/
}
void LayoutTransition::setupChangeAnimation(ViewGroup* parent, int changeReason, Animation* baseAnimator,long duration, View* child){
void LayoutTransition::setupChangeAnimation(ViewGroup* parent, int changeReason, Animator* baseAnimator,long duration, View* child){
if(layoutChangeListenerMap.find(child) ==layoutChangeListenerMap.end()){
return;
}
if (child->getWidth() == 0 && child->getHeight() == 0) {
return;
}
Animation* anim = baseAnimator;//->clone();
Animator* anim = baseAnimator;//->clone();
auto ita=pendingAnimations.find(child);
if (ita!=pendingAnimations.end()) {
Animation*currentAnimation=ita->second;
currentAnimation->cancel();
pendingAnimations.erase(ita);
Animator*currentAnimator=ita->second;
currentAnimator->cancel();
pendingAnimations.erase(ita);
}
// Cache the animation in case we need to cancel it later
pendingAnimations[child]=anim;
pendingAnimations[child]=anim;
}
void LayoutTransition::startChangingAnimations(){
for (auto ita : currentChangingAnimations) {
Animation*anim=ita.second;
anim->setStartTime(Animation::START_ON_FIRST_FRAME);//CurrentPlayTime(0);
Animator*anim=ita.second;
if(dynamic_cast<ObjectAnimator*>(anim)){
((ObjectAnimator*)anim)->setCurrentPlayTime(0);
}
anim->start();
}
}
void LayoutTransition::endChangingAnimations(){
for (auto ita : currentChangingAnimations) {
Animation*anim=ita.second;
Animator*anim=ita.second;
anim->start();
anim->cancel();//end
}
@ -422,23 +426,26 @@ void LayoutTransition::runAppearingTransition(ViewGroup* parent,View* child){
if(l.endTransition)l.endTransition(*this, parent, child, APPEARING);
return;
}
Animation* anim = mAppearingAnim;//->clone();
//anim.setTarget(child);
//anim.setStartDelay(mAppearingDelay);
Animator* anim = mAppearingAnim->clone();
anim->setTarget(child);
anim->setStartDelay(mAppearingDelay);
anim->setDuration(mAppearingDuration);
if (mAppearingInterpolator != sAppearingInterpolator) {
anim->setInterpolator(mAppearingInterpolator);
}
/*if (anim instanceof ObjectAnimator) {
((ObjectAnimator) anim).setCurrentPlayTime(0);
if (dynamic_cast<ObjectAnimator*>(anim)) {
((ObjectAnimator*) anim)->setCurrentPlayTime(0);
}
anim->addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
currentAppearingAnimations.remove(child);
for (auto l: mListeners)
if(l.endTransition)l.endTransition(*this, parent, child, APPEARING);
}
});*/
AnimatorListenerAdapter lis;
lis.onAnimationEnd=[&](Animator& anim,bool reverse){
auto it=currentAppearingAnimations.find(child);
if(it!=currentAppearingAnimations.end())
currentAppearingAnimations.erase(it);
for (auto l: mListeners)
if(l.endTransition)l.endTransition(*this, parent, child, APPEARING);
};
anim->addListener(lis);
currentAppearingAnimations[child]= anim;
anim->start();
}
@ -453,25 +460,28 @@ void LayoutTransition::runDisappearingTransition(ViewGroup* parent,View* child){
if(l.endTransition)l.endTransition(*this, parent, child, DISAPPEARING);
return;
}
Animation* anim = mDisappearingAnim;//.clone();
//anim->setStartDelay(mDisappearingDelay);
Animator* anim = mDisappearingAnim->clone();
anim->setStartDelay(mDisappearingDelay);
anim->setDuration(mDisappearingDuration);
if (mDisappearingInterpolator != sDisappearingInterpolator) {
anim->setInterpolator(mDisappearingInterpolator);
}
//anim->setTarget(child);
float preAnimAlpha = 1.0f;//child->getAlpha();
/*anim->addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
currentDisappearingAnimations.remove(child);
child.setAlpha(preAnimAlpha);
for (TransitionListener l :mListeners)
if(l.endTransition)l.endTransition(*this, parent, child, DISAPPEARING);
}
});
if (anim instanceof ObjectAnimator) {
((ObjectAnimator) anim).setCurrentPlayTime(0);
}*/
anim->setTarget(child);
float preAnimAlpha = child->getAlpha();
AnimatorListenerAdapter lis;
lis.onAnimationEnd=[&](Animator& anim,bool reverse){
auto it=currentDisappearingAnimations.find(child);
if(it!=currentDisappearingAnimations.end())
currentDisappearingAnimations.erase(it);
child->setAlpha(preAnimAlpha);
for (TransitionListener l :mListeners)
if(l.endTransition)l.endTransition(*this, parent, child, DISAPPEARING);
};
anim->addListener(lis);
if (dynamic_cast<ObjectAnimator*>(anim)) {
((ObjectAnimator*) anim)->setCurrentPlayTime(0);
}
currentDisappearingAnimations[child]= anim;
anim->start();
}

View File

@ -4,9 +4,10 @@
#include <functional>
#include <widget/viewgroup.h>
#include <interpolators.h>
#include <animation/animator.h>
namespace cdroid{
typedef Interpolator TimeInterpolator;
class LayoutTransition{
public:
struct TransitionListener{
@ -40,35 +41,35 @@ private:
bool mAnimateParentHierarchy = true;
std::vector<TransitionListener>mListeners;
static TimeInterpolator* ACCEL_DECEL_INTERPOLATOR;
static TimeInterpolator* DECEL_INTERPOLATOR ;
static TimeInterpolator* sAppearingInterpolator ;
static TimeInterpolator* sDisappearingInterpolator;
static TimeInterpolator* sChangingAppearingInterpolator;
static TimeInterpolator* sChangingDisappearingInterpolator;
static TimeInterpolator* sChangingInterpolator;
static TimeInterpolator ACCEL_DECEL_INTERPOLATOR;
static TimeInterpolator DECEL_INTERPOLATOR ;
static TimeInterpolator sAppearingInterpolator ;
static TimeInterpolator sDisappearingInterpolator;
static TimeInterpolator sChangingAppearingInterpolator;
static TimeInterpolator sChangingDisappearingInterpolator;
static TimeInterpolator sChangingInterpolator;
TimeInterpolator* mAppearingInterpolator = sAppearingInterpolator;
TimeInterpolator* mDisappearingInterpolator = sDisappearingInterpolator;
TimeInterpolator* mChangingAppearingInterpolator = sChangingAppearingInterpolator;
TimeInterpolator* mChangingDisappearingInterpolator = sChangingDisappearingInterpolator;
TimeInterpolator* mChangingInterpolator = sChangingInterpolator;
TimeInterpolator mAppearingInterpolator = sAppearingInterpolator;
TimeInterpolator mDisappearingInterpolator = sDisappearingInterpolator;
TimeInterpolator mChangingAppearingInterpolator = sChangingAppearingInterpolator;
TimeInterpolator mChangingDisappearingInterpolator = sChangingDisappearingInterpolator;
TimeInterpolator mChangingInterpolator = sChangingInterpolator;
static Animation* defaultChange;
static Animation* defaultChangeIn;
static Animation* defaultChangeOut;
static Animation* defaultFadeIn;
static Animation* defaultFadeOut;
Animation* mDisappearingAnim = nullptr;
Animation* mAppearingAnim = nullptr;
Animation* mChangingAppearingAnim = nullptr;
Animation* mChangingDisappearingAnim = nullptr;
Animation* mChangingAnim = nullptr;
static Animator* defaultChange;
static Animator* defaultChangeIn;
static Animator* defaultChangeOut;
static Animator* defaultFadeIn;
static Animator* defaultFadeOut;
Animator* mDisappearingAnim = nullptr;
Animator* mAppearingAnim = nullptr;
Animator* mChangingAppearingAnim = nullptr;
Animator* mChangingDisappearingAnim = nullptr;
Animator* mChangingAnim = nullptr;
std::map<View*, Animation*> pendingAnimations;
std::map<View*, Animation*> currentChangingAnimations;
std::map<View*, Animation*> currentAppearingAnimations;
std::map<View*, Animation*> currentDisappearingAnimations;
std::map<View*, Animator*> pendingAnimations;
std::map<View*, Animator*> currentChangingAnimations;
std::map<View*, Animator*> currentAppearingAnimations;
std::map<View*, Animator*> currentDisappearingAnimations;
std::map<View*, View::OnLayoutChangeListener> layoutChangeListenerMap;
public :
/**
@ -100,7 +101,7 @@ public :
private:
bool hasListeners()const;
void runChangeTransition(ViewGroup* parent, View* newView, int changeReason);
void setupChangeAnimation(ViewGroup* parent, int changeReason, Animation* baseAnimator,long duration, View* child);
void setupChangeAnimation(ViewGroup* parent, int changeReason, Animator* baseAnimator,long duration, View* child);
void runAppearingTransition(ViewGroup* parent,View* child);
void runDisappearingTransition(ViewGroup* parent,View* child);
void addChild(ViewGroup* parent, View* child, bool changesLayout);
@ -117,11 +118,11 @@ public:
void setStagger(int transitionType, long duration);
long getStagger(int transitionType);
void setInterpolator(int transitionType, TimeInterpolator* interpolator);
TimeInterpolator* getInterpolator(int transitionType);
void setInterpolator(int transitionType, TimeInterpolator interpolator);
TimeInterpolator getInterpolator(int transitionType);
void setAnimator(int transitionType, Animation* anim);
Animation* getAnimator(int transitionType);
void setAnimator(int transitionType, Animator* anim);
Animator* getAnimator(int transitionType);
void startChangingAnimations();
void endChangingAnimations();
bool isChangingLayout();

View File

@ -1,6 +1,45 @@
#include <animation/objectanimator.h>
#include <stdarg.h>
namespace cdroid{
void ObjectAnimator::setAutoCancel(bool cancel){
}
ObjectAnimator* ObjectAnimator::ofInt(void* target,const std::string& propertyName, int count,...){
ObjectAnimator*anim=new ObjectAnimator();
va_list ap;
std::vector<int>values;
va_start(ap,count);
for(int i=0;i<count;i++){
values.push_back(va_arg(ap,int));
}
va_end(ap);
anim->setIntValues(values);
return anim;
}
ObjectAnimator* ObjectAnimator::ofFloat(void* target,const std::string& propertyName, int count,...){
ObjectAnimator*anim=new ObjectAnimator();
va_list ap;
std::vector<float>values;
va_start(ap,count);
for(int i=0;i<count;i++){
values.push_back(va_arg(ap,int));
}
va_end(ap);
anim->setFloatValues(values);
return anim;
}
ObjectAnimator* ObjectAnimator::ofInt(void*target,Property*prop,int count,...){
ObjectAnimator*anim=new ObjectAnimator();
return anim;
}
ObjectAnimator*ObjectAnimator::ofFloat(void*target,Property*prop,int count,...){
ObjectAnimator*anim=new ObjectAnimator();
return anim;
}
}

View File

@ -4,8 +4,13 @@
namespace cdroid{
class ObjectAnimator:public ValueAnimator{
public:
static ObjectAnimator*ofInt(void* target,const std::string& propertyName, int,...);
static ObjectAnimator*ofFloat(void* target,const std::string& propertyName, int,...);
static ObjectAnimator*ofInt(void*target,Property*prop,int,...);
static ObjectAnimator*ofFloat(void*target,Property*prop,int,...);
void setAutoCancel(bool cancel);
};
}

View File

@ -4,8 +4,12 @@ namespace cdroid{
std::map<const std::string,std::map<const std::string,PropertyValuesHolder::PropertyGetter>>PropertyValuesHolder::sGetterPropertyMap;
std::map<const std::string,std::map<const std::string,PropertyValuesHolder::PropertySetter>>PropertyValuesHolder::sSetterPropertyMap;
static float FloatEvaluator(float fraction, float startValue, float endValue) {
return startValue + fraction * (endValue - startValue);
}
PropertyValuesHolder::PropertyValuesHolder(const std::string propertyName){
mPropertyName = propertyName;
mEvaluator=FloatEvaluator;
}
PropertyValuesHolder::PropertyValuesHolder(Property*prop){
@ -32,12 +36,24 @@ PropertyValuesHolder* PropertyValuesHolder::ofInt(Property*prop,const std::vecto
return pvh;
}
PropertyValuesHolder* PropertyValuesHolder::ofInt(const std::string&name,const std::vector<int>&values){
PropertyValuesHolder*pvh = new PropertyValuesHolder(name);
pvh->setIntValues(values);
return pvh;
}
PropertyValuesHolder* PropertyValuesHolder::ofFloat(Property*prop,const std::vector<float>&values){
PropertyValuesHolder*pvh = new PropertyValuesHolder(prop);
pvh->setFloatValues(values);
return pvh;
}
PropertyValuesHolder* ofFloat(const std::string&name,const std::vector<float>&values){
PropertyValuesHolder*pvh = new PropertyValuesHolder(name);
pvh->setFloatValues(values);
return pvh;
}
void PropertyValuesHolder::setIntValues(const std::vector<int>&values){
mKeyFrames.resize(values.size());
for(int i=0;i<values.size();i++){
@ -46,6 +62,7 @@ void PropertyValuesHolder::setIntValues(const std::vector<int>&values){
kf.value=values[i];
}
}
void PropertyValuesHolder::setFloatValues(const std::vector<float>&values){
mKeyFrames.resize(values.size());
for(int i=0;i<values.size();i++){
@ -55,6 +72,10 @@ void PropertyValuesHolder::setFloatValues(const std::vector<float>&values){
}
}
/*void PropertyValuesHolder::setConverter(TypeConverter converter){
mConverter=converter;
}*/
float PropertyValuesHolder::getValue(float fraction)const{
const KeyFrame &first = mKeyFrames[0];
const KeyFrame &last = mKeyFrames[mKeyFrames.size()-1];
@ -92,7 +113,11 @@ float PropertyValuesHolder::getValue(float fraction)const{
}
void PropertyValuesHolder::calculateValue(float fraction){
float value=getValue(fraction);
mAnimatedValue=getValue(fraction);
}
float PropertyValuesHolder::getAnimatedValue()const{
return mAnimatedValue;
}
}

View File

@ -16,7 +16,10 @@ private:
};
std::string mPropertyName;
TypeEvaluator mEvaluator;
//TypeConverter mConverter;
float mAnimatedValue;
std::vector<KeyFrame>mKeyFrames;
//TimeInterpolator mInterpolator;
protected:
Property* mProperty;
float getValue(float fraction)const;
@ -31,13 +34,17 @@ public:
PropertyValuesHolder(const std::string propertyName);
PropertyValuesHolder(Property*prop);
static PropertyValuesHolder* ofInt(Property*prop,const std::vector<int>&values);
static PropertyValuesHolder* ofInt(const std::string&,const std::vector<int>&);
static PropertyValuesHolder* ofFloat(Property*prop,const std::vector<float>&values);
static PropertyValuesHolder* ofFloat(const std::string&,const std::vector<float>&);
void setIntValues(const std::vector<int>&);
void setFloatValues(const std::vector<float>&);
void setPropertyName(const std::string& propertyName);
const std::string getPropertyName()const;
void setProperty(Property* property);
void calculateValue(float fraction);
float getAnimatedValue()const;
//void setConverter(TypeConverter converter);
};
}//endof namespace

View File

@ -2,6 +2,7 @@
#include <systemclock.h>
#include <cmath>
#include <stdarg.h>
#include <cdlog.h>
namespace cdroid{
@ -55,6 +56,7 @@ ValueAnimator* ValueAnimator::ofFloat(int count,...){
void ValueAnimator::setIntValues(const std::vector<int>&values){
PropertyValuesHolder*prop=new PropertyValuesHolder(std::string());
prop->setIntValues(values);
setValues(1,prop);
}
void ValueAnimator::setFloatValues(const std::vector<float>&values){
@ -208,12 +210,14 @@ long ValueAnimator::getFrameDelay(){
void ValueAnimator::setFrameDelay(long frameDelay){
}
void* ValueAnimator::getAnimatedValue(){
return nullptr;
float ValueAnimator::getAnimatedValue(){
if(mValuesMap.size())
return mValuesMap.begin()->second->getAnimatedValue();
return .0f;
}
void* ValueAnimator::getAnimatedValue(const std::string&propertyName){
return nullptr;
float ValueAnimator::getAnimatedValue(const std::string&propertyName){
return .0f;
}
void ValueAnimator::setRepeatCount(int value) {

View File

@ -34,7 +34,7 @@ private:
bool mSelfPulse = true;
bool mSuppressSelfPulseRequested = false;
float mDurationScale = -1.f;
TimeInterpolator mInterpolator=nullptr;
TimeInterpolator mInterpolator = nullptr;
std::vector<AnimatorUpdateListener> mUpdateListeners;
std::map<const std::string,PropertyValuesHolder*>mValuesMap;
protected:
@ -85,8 +85,8 @@ public:
void setStartDelay(long startDelay);
static long getFrameDelay();
static void setFrameDelay(long frameDelay);
void* getAnimatedValue();
void* getAnimatedValue(const std::string&propertyName);
float getAnimatedValue();
float getAnimatedValue(const std::string&propertyName);
void setRepeatCount(int value);
int getRepeatCount()const;
void setRepeatMode(int value);

View File

@ -1,4 +1,5 @@
#include <widget/progressbar.h>
#include <animation/objectanimator.h>
#include <cdlog.h>
#define MAX_LEVEL 10000
@ -155,18 +156,30 @@ void ProgressBar::setVisualProgress(int id, float progress){
onVisualProgressChanged(id, progress);
}
ProgressBar::ProgressProperty::ProgressProperty(const std::string&name):Property(name){}
float ProgressBar::ProgressProperty::get(void* target){
return ((ProgressBar*)target)->mVisualProgress;
}
void ProgressBar::ProgressProperty::set(void*target, float value){
((ProgressBar*)target)->mVisualProgress=value;
}
void ProgressBar::doRefreshProgress(int id, int progress, bool fromUser,bool callBackToApp, bool animate){
int range = mMax - mMin;
const float scale = range > 0 ? (progress - mMin) / (float) range : 0;
const bool isPrimary = id == ID_PRIMARY;//R.id.progress;
/*if (isPrimary && animate) {
ObjectAnimator animator = ObjectAnimator.ofFloat(this, VISUAL_PROGRESS, scale);
animator.setAutoCancel(true);
animator.setDuration(PROGRESS_ANIM_DURATION);
animator.setInterpolator(PROGRESS_ANIM_INTERPOLATOR);
animator.start();
} else*/ {
ProgressProperty*VISUAL_PROGRESS=new ProgressProperty("visual_progress");
if (isPrimary && animate) {
ObjectAnimator* animator = ObjectAnimator::ofFloat(this, VISUAL_PROGRESS, scale);
animator->setAutoCancel(true);
animator->setDuration(PROGRESS_ANIM_DURATION);
animator->setInterpolator(new DecelerateInterpolator());//PROGRESS_ANIM_INTERPOLATOR);
animator->start();
} else {
setVisualProgress(id, scale);
}

View File

@ -1,11 +1,14 @@
#ifndef __PROGRESS_BAR_H__
#define __PROGRESS_BAR_H__
#include <widget/view.h>
#include <animation/property.h>
namespace cdroid{
class ProgressBar:public View{
private:
static constexpr int MAX_LEVEL = 10000;
static constexpr int PROGRESS_ANIM_DURATION = 80;
struct RefreshData{
int id;
int progress;
@ -17,8 +20,15 @@ private:
fromUser=false;
}
};
class ProgressProperty:public Property{
public:
ProgressProperty(const std::string&);
float get(void*)override;
void set(void*,float)override;
};
friend class ProgressProperty;
bool mAttached;
int mVisualProgress;
float mVisualProgress;
int mDuration;
bool mOnlyIndeterminate;
bool mHasAnimation;

39
tests/gui/animator_tests.cc Executable file
View File

@ -0,0 +1,39 @@
#include <gtest/gtest.h>
#include <windows.h>
#include <ngl_os.h>
#include <ngl_timer.h>
#include <cdlog.h>
#include <animation/objectanimator.h>
class ANIMATOR:public testing::Test{
public :
virtual void SetUp(){
}
virtual void TearDown(){
}
};
TEST_F(ANIMATOR,ofInt){
ValueAnimator*anim=ValueAnimator::ofInt(2,0,100);
anim->addUpdateListener([](ValueAnimator&anim){
LOGD("value=%f",anim.getAnimatedValue());
});
anim->setDuration(100);
for(int i=0;i<=10;i++){
anim->setCurrentFraction((float)i/10.f);
}
}
TEST_F(ANIMATOR,ofFlot){
ObjectAnimator*anim=ObjectAnimator::ofFloat(this,"test",2,0,100);
anim->addUpdateListener([](ValueAnimator&anim){
LOGD("value=%f",anim.getAnimatedValue());
});
anim->setDuration(100);
for(int i=0;i<=10;i++){
anim->setCurrentFraction((float)i/10.f);
}
}