mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
modify propertyvaluesholder(impl by variant)
This commit is contained in:
parent
27a6f0b4ff
commit
81b8d77220
68
apps/samples/listview4.cc
Executable file
68
apps/samples/listview4.cc
Executable file
@ -0,0 +1,68 @@
|
||||
#include <windows.h>
|
||||
#include <cdlog.h>
|
||||
|
||||
class MyAdapter:public ArrayAdapter<std::string>{
|
||||
public:
|
||||
MyAdapter():ArrayAdapter(){
|
||||
}
|
||||
View*getView(int position, View* convertView, ViewGroup* parent)override{
|
||||
TextView*tv=(TextView*)convertView;
|
||||
if(convertView==nullptr){
|
||||
tv=new TextView("",600,40);
|
||||
tv->setPadding(20,0,0,0);
|
||||
tv->setFocusable(false);
|
||||
}
|
||||
if(tv->getBackground())
|
||||
tv->getBackground()->setLevel(0);
|
||||
tv->setId(position);
|
||||
tv->setText("position :"+std::to_string(position));
|
||||
tv->setTextColor(0xFFFFFFFF);
|
||||
tv->setTextSize(30);
|
||||
return tv;
|
||||
}
|
||||
};
|
||||
|
||||
View*createHeader(){
|
||||
LinearLayout*ll=new LinearLayout(-1,200);
|
||||
ll->setOrientation(LinearLayout::VERTICAL);
|
||||
for(int i=0;i<4;i++){
|
||||
std::string txt;
|
||||
TextView*tv;
|
||||
if(i%2){
|
||||
txt="Button"+std::to_string(i/2);
|
||||
tv=new Button(txt,200,40);
|
||||
}else{
|
||||
txt="CheckItem"+std::to_string(i/2);
|
||||
tv=new CheckBox(txt,200,40);
|
||||
tv->setClickable(true);
|
||||
}
|
||||
ll->addView(tv);
|
||||
}
|
||||
return ll;
|
||||
}
|
||||
int main(int argc,const char*argv[]){
|
||||
App app;
|
||||
Window*w=new Window(50,50,1200,640);
|
||||
MyAdapter*adapter=new MyAdapter();
|
||||
ListView*lv=(ListView*)&w->addView(new ListView(460,500));
|
||||
lv->setPos(10,10);
|
||||
lv->setDivider(new ColorDrawable(0x66008800));
|
||||
lv->setVerticalScrollBarEnabled(true);
|
||||
lv->setOverScrollMode(View::OVER_SCROLL_ALWAYS);
|
||||
lv->setDividerHeight(1);
|
||||
for(int i=0;i<32;i++){
|
||||
adapter->add("");
|
||||
}
|
||||
lv->addHeaderView(createHeader(),nullptr,false);
|
||||
lv->addFooterView(createHeader(),nullptr,true);
|
||||
lv->setAdapter(adapter);
|
||||
adapter->notifyDataSetChanged();
|
||||
lv->setSelector(new ColorDrawable(0x8800FF00));
|
||||
lv->setSelection(2);
|
||||
lv->setOnItemClickListener([](AdapterView&lv,View&v,int pos,long id){
|
||||
LOGD("clicked %d",pos);
|
||||
});
|
||||
lv->requestLayout();
|
||||
app.exec();
|
||||
return 0;
|
||||
};
|
@ -19,7 +19,7 @@ int main(int argc,const char*argv[]){
|
||||
pb2->setProgress(34);
|
||||
pb2->setMirrorForRtl(true);
|
||||
pb2->setLayoutDirection(View::LAYOUT_DIRECTION_RTL);
|
||||
//pb->setSecondaryProgress(15);
|
||||
pb->setSecondaryProgress(15);
|
||||
w->addView(pb).setPos(150,50);
|
||||
w->addView(pb2).setPos(150,100);
|
||||
Runnable progress;
|
||||
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
class Property{
|
||||
private:
|
||||
std::string mName;
|
||||
public:
|
||||
Property(const std::string&name){
|
||||
mName=name;
|
||||
}
|
||||
virtual float get(void* t){return .0;};
|
||||
virtual void set(void* object, float value){};
|
||||
const std::string getName()const{return mName;}
|
||||
};
|
||||
|
||||
}
|
@ -34,54 +34,84 @@ Property*PropertyValuesHolder::getProperty(){
|
||||
return mProperty;
|
||||
}
|
||||
|
||||
void PropertyValuesHolder::evaluate(Variant& out, const Variant& from, const Variant& to,
|
||||
float fraction) const{
|
||||
switch(from.index()){
|
||||
case 0:
|
||||
out = (1.f - fraction)*from.get<int>() + fraction * to.get<int>();
|
||||
break;
|
||||
case 1:{
|
||||
float a=lerp((from.get<uint32_t>()>>24)/255.f,(to.get<uint32_t>()>>24)/255.f,fraction);
|
||||
float r=lerp(((from.get<uint32_t>()>>16)&0xFF)/255.f,((to.get<uint32_t>()>>16)&0xFF)/255.f,fraction);
|
||||
float g=lerp(((from.get<uint32_t>()>>8)&0xFF)/255.f,((to.get<uint32_t>()>>8)&0xFF)/255.f,fraction);
|
||||
float b=lerp((from.get<uint32_t>()&0xFF)/255.f,(to.get<uint32_t>()&0xFF)/255.f,fraction);
|
||||
out=((uint32_t)(a*255.f)<<24)|((uint32_t)(r*255)<<16)|((uint32_t)(g*255)<<8)|((uint32_t)(b*255));
|
||||
}break;
|
||||
case 2:
|
||||
out = from.get<float>() * (1 - fraction) + to.get<float>() * fraction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PropertyValuesHolder::setValues(const std::vector<int>&values){
|
||||
mDataSource.resize(values.size());
|
||||
for(size_t i=0;i<values.size();i++)
|
||||
mDataSource[i].emplace<int>(values.at(i));
|
||||
}
|
||||
|
||||
void PropertyValuesHolder::setValues(const std::vector<uint32_t>&values){
|
||||
mDataSource.resize(values.size());
|
||||
for(size_t i=0;i<values.size();i++)
|
||||
mDataSource[i].emplace<uint32_t>(values.at(i));
|
||||
}
|
||||
|
||||
void PropertyValuesHolder::setValues(const std::vector<float>&values){
|
||||
mDataSource.resize(values.size());
|
||||
for(size_t i=0;i<values.size();i++)
|
||||
mDataSource[i].emplace<float>(values.at(i));
|
||||
}
|
||||
|
||||
void PropertyValuesHolder::setFraction(void*target,float fraction){
|
||||
if (mDataSource.size()==0) evaluate(mAnimateValue, mStartValue, mEndValue, fraction);
|
||||
else if (fraction <= 0.0f) mAnimateValue=mDataSource.front();
|
||||
else if (fraction >= 1.0f) mAnimateValue=mDataSource.back();
|
||||
else{
|
||||
fraction *= mDataSource.size() - 1;
|
||||
int lowIndex = std::floor(fraction);
|
||||
fraction -= lowIndex;
|
||||
evaluate(mAnimateValue, mDataSource[lowIndex], mDataSource[lowIndex + 1], fraction);
|
||||
}
|
||||
if(mProperty)mProperty->set(target,fraction);
|
||||
}
|
||||
const Variant& PropertyValuesHolder::getAnimatedValue()const{
|
||||
return mAnimateValue;
|
||||
}
|
||||
|
||||
PropertyValuesHolder* PropertyValuesHolder::ofInt(const std::string&name,const std::vector<int>&values){
|
||||
IntPropertyValuesHolder*ip=new IntPropertyValuesHolder(name);
|
||||
PropertyValuesHolder*ip=new PropertyValuesHolder(name);
|
||||
ip->setValues(values);
|
||||
return ip;
|
||||
}
|
||||
|
||||
PropertyValuesHolder* PropertyValuesHolder::ofInt(Property*prop,const std::vector<int>&values){
|
||||
IntPropertyValuesHolder*ip=new IntPropertyValuesHolder(prop);
|
||||
PropertyValuesHolder*ip=new PropertyValuesHolder(prop);
|
||||
ip->setValues(values);
|
||||
return ip;
|
||||
}
|
||||
|
||||
PropertyValuesHolder* PropertyValuesHolder::ofFloat(const std::string&name,const std::vector<float>&values){
|
||||
FloatPropertyValuesHolder*fp=new FloatPropertyValuesHolder(name);
|
||||
PropertyValuesHolder*fp=new PropertyValuesHolder(name);
|
||||
fp->setValues(values);
|
||||
return fp;
|
||||
}
|
||||
|
||||
PropertyValuesHolder* PropertyValuesHolder::ofFloat(Property*prop,const std::vector<float>&values){
|
||||
FloatPropertyValuesHolder*fp=new FloatPropertyValuesHolder(prop);
|
||||
PropertyValuesHolder*fp=new PropertyValuesHolder(prop);
|
||||
fp->setValues(values);
|
||||
return fp;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
IntPropertyValuesHolder::IntPropertyValuesHolder():PropertyValuesHolderImpl<int>(){
|
||||
mEvaluator=new IntEvaluator();
|
||||
}
|
||||
|
||||
IntPropertyValuesHolder::IntPropertyValuesHolder(const std::string&name):PropertyValuesHolderImpl<int>(name){
|
||||
mEvaluator=new IntEvaluator();
|
||||
}
|
||||
|
||||
IntPropertyValuesHolder::IntPropertyValuesHolder(Property*prop):PropertyValuesHolderImpl<int>(prop){
|
||||
mEvaluator=new IntEvaluator();
|
||||
}
|
||||
|
||||
FloatPropertyValuesHolder::FloatPropertyValuesHolder():PropertyValuesHolderImpl<float>(){
|
||||
mEvaluator=new FloatEvaluator();
|
||||
}
|
||||
|
||||
FloatPropertyValuesHolder::FloatPropertyValuesHolder(const std::string&name):PropertyValuesHolderImpl<float>(name){
|
||||
mEvaluator=new FloatEvaluator();
|
||||
}
|
||||
|
||||
FloatPropertyValuesHolder::FloatPropertyValuesHolder(Property*prop):PropertyValuesHolderImpl<float>(prop){
|
||||
mEvaluator=new FloatEvaluator();
|
||||
}
|
||||
|
||||
|
||||
}//endof namespace
|
||||
|
@ -3,20 +3,46 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <animation/property.h>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <cdtypes.h>
|
||||
#include <cdlog.h>
|
||||
#include <core/color.h>
|
||||
#include <core/variant.h>
|
||||
//reference:
|
||||
//http://androidxref.com/9.0.0_r3/xref/frameworks/base/libs/hwui/PropertyValuesHolder.h
|
||||
namespace cdroid{
|
||||
typedef nonstd::variant<int,uint32_t,float>Variant;
|
||||
|
||||
inline constexpr float lerp(float fromValue, float toValue, float fraction) {
|
||||
return float(fromValue * (1.f - fraction) + toValue * fraction);
|
||||
}
|
||||
inline int lerp(int startValue, int endValue, float fraction) {
|
||||
return startValue + std::round(fraction * (endValue - startValue));
|
||||
}
|
||||
|
||||
class Property{
|
||||
private:
|
||||
std::string mName;
|
||||
public:
|
||||
Property(const std::string&name){
|
||||
mName=name;
|
||||
}
|
||||
virtual float get(void* t){return .0;};
|
||||
virtual void set(void* object, float value){};
|
||||
const std::string getName()const{return mName;}
|
||||
};
|
||||
|
||||
class PropertyValuesHolder{
|
||||
protected:
|
||||
std::string mPropertyName;
|
||||
Property*mProperty;
|
||||
std::vector<Variant>mDataSource;
|
||||
Variant mStartValue;
|
||||
Variant mEndValue;
|
||||
Variant mAnimateValue;
|
||||
virtual void evaluate(Variant& out, const Variant& from, const Variant& to, float fraction)const;
|
||||
public:
|
||||
PropertyValuesHolder();
|
||||
virtual ~PropertyValuesHolder();
|
||||
@ -26,113 +52,22 @@ public:
|
||||
const std::string getPropertyName()const;
|
||||
void setProperty(Property*p);
|
||||
Property*getProperty();
|
||||
virtual void setFraction(void*target,float fraction)=0;
|
||||
|
||||
void setValues(const std::vector<int>&values);
|
||||
void setValues(const std::vector<uint32_t>&values);
|
||||
void setValues(const std::vector<float>&values);
|
||||
virtual void setFraction(void*target,float fraction);
|
||||
const Variant& getAnimatedValue()const;
|
||||
|
||||
static PropertyValuesHolder*ofInt(const std::string&name,const std::vector<int>&);
|
||||
static PropertyValuesHolder*ofInt(Property*,const std::vector<int>&);
|
||||
static PropertyValuesHolder*ofFloat(const std::string&name,const std::vector<float>&);
|
||||
static PropertyValuesHolder*ofFloat(Property*prop,const std::vector<float>&);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Evaluator {
|
||||
public:
|
||||
virtual void evaluate(T* out, const T& from, const T& to, float fraction) const {};
|
||||
virtual ~Evaluator() {}
|
||||
};
|
||||
|
||||
class IntEvaluator:public Evaluator<int> {
|
||||
public:
|
||||
virtual void evaluate(int* out, const int& from, const int& to, float fraction) const override{
|
||||
*out = (1.f - fraction)*from + fraction * to;
|
||||
}
|
||||
};
|
||||
|
||||
class FloatEvaluator : public Evaluator<float> {
|
||||
public:
|
||||
virtual void evaluate(float* out, const float& from, const float& to,
|
||||
float fraction) const override {
|
||||
*out = from * (1 - fraction) + to * fraction;
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr float lerp(float fromValue, float toValue, float fraction) {
|
||||
return float(fromValue * (1.f - fraction) + toValue * fraction);
|
||||
}
|
||||
inline int lerp(int startValue, int endValue, float fraction) {
|
||||
return startValue + std::round(fraction * (endValue - startValue));
|
||||
}
|
||||
|
||||
class ColorEvaluator : public Evaluator<uint32_t> {
|
||||
public:
|
||||
virtual void evaluate(uint32_t* outColor, const uint32_t& from, const uint32_t& to,
|
||||
float fraction) const override{
|
||||
float a=lerp((from>>24)/255.f,(to>>24)/255.f,fraction);
|
||||
float r=lerp(((from>>16)&0xFF)/255.f,((to>>16)&0xFF)/255.f,fraction);
|
||||
float g=lerp(((from>>8)&0xFF)/255.f,((to>>8)&0xFF)/255.f,fraction);
|
||||
float b=lerp((from&0xFF)/255.f,(to&0xFF)/255.f,fraction);
|
||||
*outColor=((int)(a*255.f)<<24)|((int)(r*255)<<16)|((int)(g*255)<<8)|((int)(b*255));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class PropertyValuesHolderImpl:public PropertyValuesHolder{
|
||||
protected:
|
||||
Evaluator<T>* mEvaluator;
|
||||
std::vector<T>mDataSource;
|
||||
T mStartValue;
|
||||
T mEndValue;
|
||||
T mAnimateValue;
|
||||
public:
|
||||
PropertyValuesHolderImpl(){
|
||||
mEvaluator=nullptr;
|
||||
}
|
||||
PropertyValuesHolderImpl(const std::string&name):PropertyValuesHolder(name){}
|
||||
PropertyValuesHolderImpl(Property*prop):PropertyValuesHolder(prop){}
|
||||
PropertyValuesHolderImpl(const T& startValue, const T& endValue)
|
||||
: mStartValue(startValue), mEndValue(endValue) {}
|
||||
void setValues(const T* dataSource, int length) {
|
||||
mDataSource.insert(mDataSource.begin(), dataSource, dataSource + length);
|
||||
}
|
||||
void setValues(const std::vector<T>&values){
|
||||
mDataSource=values;
|
||||
}
|
||||
void setFraction(void*target,float fraction)override{
|
||||
if (mDataSource.size()==0) mEvaluator->evaluate(&mAnimateValue, mStartValue, mEndValue, fraction);
|
||||
else if (fraction <= 0.0f) mAnimateValue=mDataSource.front();
|
||||
else if (fraction >= 1.0f) mAnimateValue=mDataSource.back();
|
||||
else{
|
||||
fraction *= mDataSource.size() - 1;
|
||||
int lowIndex = std::floor(fraction);
|
||||
fraction -= lowIndex;
|
||||
mEvaluator->evaluate(&mAnimateValue, mDataSource[lowIndex], mDataSource[lowIndex + 1], fraction);
|
||||
}
|
||||
}
|
||||
T getAnimatedValue()const{return mAnimateValue;}
|
||||
};
|
||||
|
||||
#if 1
|
||||
class IntPropertyValuesHolder:public PropertyValuesHolderImpl<int>{
|
||||
public:
|
||||
IntPropertyValuesHolder();
|
||||
IntPropertyValuesHolder(const std::string&);
|
||||
IntPropertyValuesHolder(Property*);
|
||||
};
|
||||
|
||||
class FloatPropertyValuesHolder:public PropertyValuesHolderImpl<float>{
|
||||
public:
|
||||
FloatPropertyValuesHolder();
|
||||
FloatPropertyValuesHolder(const std::string&);
|
||||
FloatPropertyValuesHolder(Property*);
|
||||
};
|
||||
class ColorPropertyValuesHolder:public PropertyValuesHolderImpl<uint32_t>{
|
||||
public:
|
||||
ColorPropertyValuesHolder():PropertyValuesHolderImpl<uint32_t>(){
|
||||
mEvaluator=new ColorEvaluator();
|
||||
}
|
||||
};
|
||||
#else
|
||||
typedef PropertyValuesHolderImpl<int> IntPropertyValuesHolder;
|
||||
typedef PropertyValuesHolderImpl<float> FloatPropertyValuesHolder;
|
||||
typedef PropertyValuesHolder IntPropertyValuesHolder;
|
||||
typedef PropertyValuesHolder FloatPropertyValuesHolder;
|
||||
#endif
|
||||
|
||||
}//endof namespace
|
||||
|
2742
src/gui/core/variant.h
Executable file
2742
src/gui/core/variant.h
Executable file
File diff suppressed because it is too large
Load Diff
@ -89,9 +89,9 @@ void RippleBackground::onStateChanged(){
|
||||
mAnimator->setDuration(OPACITY_DURATION);
|
||||
mAnimator->setInterpolator(new LinearInterpolator());//LINEAR_INTERPOLATOR);
|
||||
mAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
LOGD("mOpacity=%f",fp->getAnimatedValue());
|
||||
mOpacity=fp->getAnimatedValue();
|
||||
mOpacity=fp->getAnimatedValue().get<float>();
|
||||
invalidateSelf();
|
||||
}));
|
||||
|
||||
|
@ -83,9 +83,9 @@ void RippleForeground::startSoftwareEnter() {
|
||||
tweenRadius->setDuration(RIPPLE_ENTER_DURATION);
|
||||
tweenRadius->setInterpolator(new DecelerateInterpolator());//DECELERATE_INTERPOLATOR);
|
||||
tweenRadius->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
LOGV("mTweenRadius=%f [%f,%f,%f] opacity=%f",fp->getAnimatedValue(),getCurrentRadius(),mStartRadius,mTargetRadius,mOpacity);
|
||||
mTweenRadius=fp->getAnimatedValue();
|
||||
mTweenRadius=fp->getAnimatedValue().get<float>();
|
||||
onAnimationPropertyChanged();
|
||||
}));
|
||||
tweenRadius->start();
|
||||
@ -95,8 +95,8 @@ void RippleForeground::startSoftwareEnter() {
|
||||
tweenOrigin->setDuration(RIPPLE_ORIGIN_DURATION);
|
||||
tweenOrigin->setInterpolator(new DecelerateInterpolator());//DECELERATE_INTERPOLATOR);
|
||||
tweenOrigin->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
mTweenX=mTweenY=fp->getAnimatedValue();
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
mTweenX=mTweenY=fp->getAnimatedValue().get<float>();
|
||||
onAnimationPropertyChanged();
|
||||
}));
|
||||
tweenOrigin->start();
|
||||
@ -106,8 +106,8 @@ void RippleForeground::startSoftwareEnter() {
|
||||
opacity->setDuration(OPACITY_ENTER_DURATION);
|
||||
opacity->setInterpolator(new LinearInterpolator());//LINEAR_INTERPOLATOR);
|
||||
opacity->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
mOpacity=fp->getAnimatedValue();
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
mOpacity=fp->getAnimatedValue().get<float>();
|
||||
onAnimationPropertyChanged();
|
||||
}));
|
||||
opacity->start();
|
||||
@ -121,8 +121,8 @@ void RippleForeground::startSoftwareExit() {
|
||||
opacity->addListener(mAnimationListener);
|
||||
opacity->setStartDelay(computeFadeOutDelay());
|
||||
opacity->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
mOpacity=fp->getAnimatedValue();
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
mOpacity=fp->getAnimatedValue().get<float>();
|
||||
}));
|
||||
|
||||
opacity->start();
|
||||
|
@ -193,17 +193,17 @@ void ProgressBar::doRefreshProgress(int id, int progress, bool fromUser,bool cal
|
||||
if (isPrimary && animate) {
|
||||
FloatPropertyValuesHolder*prop=nullptr;
|
||||
if(mAnimator==nullptr){
|
||||
mAnimator = ObjectAnimator::ofFloat(this,"progress",{scale});
|
||||
mAnimator = ObjectAnimator::ofFloat(this,"progress",{0,scale});
|
||||
mAnimator->setAutoCancel(true);
|
||||
mAnimator->setDuration(PROGRESS_ANIM_DURATION);
|
||||
mAnimator->setInterpolator(new DecelerateInterpolator());
|
||||
mAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
setVisualProgress(ID_PRIMARY,fp->getAnimatedValue());
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
setVisualProgress(ID_PRIMARY,fp->getAnimatedValue().get<float>());
|
||||
}));
|
||||
}
|
||||
prop=(FloatPropertyValuesHolder*)mAnimator->getValues(0);
|
||||
prop->setValues({scale});
|
||||
prop->setValues(std::vector<float>({scale}));
|
||||
mAnimator->start();
|
||||
} else {
|
||||
setVisualProgress(id, scale);
|
||||
|
@ -511,8 +511,8 @@ void TabLayout::ensureScrollAnimator(){
|
||||
mScrollAnimator->setInterpolator(new FastOutSlowInInterpolator());
|
||||
mScrollAnimator->setDuration(ANIMATION_DURATION);
|
||||
mScrollAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim) {
|
||||
IntPropertyValuesHolder*ip=(IntPropertyValuesHolder*)anim.getValues()[0];
|
||||
scrollTo(ip->getAnimatedValue(), 0);
|
||||
PropertyValuesHolder*ip=anim.getValues()[0];
|
||||
scrollTo(ip->getAnimatedValue().get<int>(), 0);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ TEST_F(ANIMATOR,callback){
|
||||
TEST_F(ANIMATOR,ofInt1){
|
||||
ValueAnimator*anim=ValueAnimator::ofInt({0,100});
|
||||
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
IntPropertyValuesHolder*ip=(IntPropertyValuesHolder*)anim.getValues(0);
|
||||
LOGD("value=%d",ip->getAnimatedValue());
|
||||
PropertyValuesHolder*ip=anim.getValues(0);
|
||||
LOGD("value=%d",ip->getAnimatedValue().get<int>());
|
||||
}));
|
||||
for(int i=0;i<=10;i++){
|
||||
anim->setCurrentFraction((float)i/10.f);
|
||||
@ -35,11 +35,11 @@ TEST_F(ANIMATOR,ofInt1){
|
||||
|
||||
TEST_F(ANIMATOR,ofInt2){
|
||||
IntPropertyValuesHolder iprop;
|
||||
iprop.setValues({0,100});
|
||||
iprop.setValues(std::vector<int>({0,100}));
|
||||
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop});
|
||||
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
IntPropertyValuesHolder*ip=(IntPropertyValuesHolder*)anim.getValues(0);
|
||||
LOGD("value=%d",ip->getAnimatedValue());
|
||||
PropertyValuesHolder*ip=anim.getValues(0);
|
||||
LOGD("value=%d",ip->getAnimatedValue().get<int>());
|
||||
}));
|
||||
for(int i=0;i<=10;i++){
|
||||
anim->setCurrentFraction((float)i/10.f);
|
||||
@ -48,11 +48,11 @@ TEST_F(ANIMATOR,ofInt2){
|
||||
|
||||
TEST_F(ANIMATOR,ofFloat){
|
||||
FloatPropertyValuesHolder fprop;
|
||||
fprop.setValues({0,100});
|
||||
fprop.setValues(std::vector<float>({0,100}));
|
||||
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
||||
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
LOGD("value=%f",fp->getAnimatedValue());
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
LOGD("value=%f",fp->getAnimatedValue().get<float>());
|
||||
}));
|
||||
for(int i=0;i<=10;i++){
|
||||
anim->setCurrentFraction((float)i/10.f);
|
||||
@ -78,12 +78,12 @@ TEST_F(ANIMATOR,ofProperty){
|
||||
TEST_F(ANIMATOR,loopdrivered){
|
||||
App app;
|
||||
IntPropertyValuesHolder iprop;
|
||||
iprop.setValues({0,100});
|
||||
iprop.setValues(std::vector<int>({0,100}));
|
||||
|
||||
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop});
|
||||
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
||||
IntPropertyValuesHolder*fp=(IntPropertyValuesHolder*)anim.getValues(0);
|
||||
LOGD("value=%d",fp->getAnimatedValue());
|
||||
PropertyValuesHolder*fp=anim.getValues(0);
|
||||
LOGD("value=%d",fp->getAnimatedValue().get<int>());
|
||||
}));
|
||||
anim->setDuration(2000);
|
||||
anim->start();
|
||||
@ -99,23 +99,22 @@ TEST_F(ANIMATOR,translate){
|
||||
|
||||
IntPropertyValuesHolder xprop;
|
||||
xprop.setPropertyName("x");
|
||||
xprop.setValues({0,100,300});
|
||||
xprop.setValues(std::vector<int>({0,100,300}));
|
||||
|
||||
IntPropertyValuesHolder yprop;
|
||||
yprop.setPropertyName("y");
|
||||
yprop.setValues({0,200,200});
|
||||
yprop.setValues(std::vector<int>({0,200,200}));
|
||||
|
||||
ColorPropertyValuesHolder cprop;
|
||||
cprop.setValues({0xFF000000,0xFFFF8844});
|
||||
PropertyValuesHolder cprop;
|
||||
cprop.setValues(std::vector<uint32_t>({0xFF000000,0xFFFF8844}));
|
||||
|
||||
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&xprop,&yprop,&cprop});
|
||||
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([tv](ValueAnimator&anim){
|
||||
IntPropertyValuesHolder*xp=(IntPropertyValuesHolder*)anim.getValues(0);
|
||||
IntPropertyValuesHolder*yp=(IntPropertyValuesHolder*)anim.getValues(1);
|
||||
ColorPropertyValuesHolder*cp=(ColorPropertyValuesHolder*)anim.getValues(2);
|
||||
tv->setPos(xp->getAnimatedValue(),tv->getTop());
|
||||
tv->setPos(tv->getLeft(),yp->getAnimatedValue());
|
||||
tv->setBackgroundColor(cp->getAnimatedValue());
|
||||
PropertyValuesHolder*xp=anim.getValues(0);
|
||||
PropertyValuesHolder*yp=anim.getValues(1);
|
||||
PropertyValuesHolder*cp=anim.getValues(2);
|
||||
tv->setPos(xp->getAnimatedValue().get<int>(),yp->getAnimatedValue().get<int>());
|
||||
tv->setBackgroundColor(cp->getAnimatedValue().get<uint32_t>());
|
||||
}));
|
||||
|
||||
anim->setDuration(5000);
|
||||
@ -131,12 +130,12 @@ TEST_F(ANIMATOR,scale){
|
||||
|
||||
FloatPropertyValuesHolder fprop;
|
||||
fprop.setPropertyName("scale");
|
||||
fprop.setValues({0,2.0});
|
||||
fprop.setValues(std::vector<float>({0,2.0}));
|
||||
|
||||
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
||||
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([tv](ValueAnimator&anim){
|
||||
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
||||
float scale=fp->getAnimatedValue();
|
||||
const float scale=fp->getAnimatedValue().get<float>();
|
||||
tv->setScaleX(scale);
|
||||
tv->setScaleY(scale);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user