From 94e7908fa67870b416a41b4c683111ea9f9733d0 Mon Sep 17 00:00:00 2001 From: houzh Date: Thu, 5 Oct 2023 11:45:53 +0800 Subject: [PATCH] make variant compatibale with C++17 --- src/gui/CMakeLists.txt | 2 - src/gui/animation/propertyvaluesholder.cc | 12 +- src/gui/animation/propertyvaluesholder.h | 5 + src/gui/drawables/ripplebackground.cc | 3 +- src/gui/drawables/rippleforeground.cc | 8 +- src/gui/view/swipehelper.cc | 4 +- src/gui/widget/datetimeview._cc | 363 ++++++++++++++++++++++ src/gui/widget/datetimeview.h | 30 ++ src/gui/widget/expandablelayout.cc | 2 +- src/gui/widget/progressbar.cc | 2 +- src/gui/widget/switch.cc | 2 +- src/gui/widget/tablayout.cc | 2 +- tests/gui/animator_tests.cc | 18 +- 13 files changed, 424 insertions(+), 29 deletions(-) create mode 100644 src/gui/widget/datetimeview._cc create mode 100644 src/gui/widget/datetimeview.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 7fc42183..15b3cc0d 100755 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,7 +1,5 @@ project(cdroid C CXX) -set(CMAKE_CXX_STANDARD 11) - option( GUI_STATIC "UI is static link" ON) if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") diff --git a/src/gui/animation/propertyvaluesholder.cc b/src/gui/animation/propertyvaluesholder.cc index b26e9147..9f03f737 100755 --- a/src/gui/animation/propertyvaluesholder.cc +++ b/src/gui/animation/propertyvaluesholder.cc @@ -39,17 +39,17 @@ void PropertyValuesHolder::evaluate(AnimateValue& out, const AnimateValue& from, float fraction) const{ switch(from.index()){ case 0: - out = (int)((1.f - fraction)*from.get() + fraction * to.get()); + out = (int)((1.f - fraction)*GET_VARIANT(from,int) + fraction * GET_VARIANT(to,int)); break; case 1:{ - float a=lerp((from.get()>>24)/255.f,(to.get()>>24)/255.f,fraction); - float r=lerp(((from.get()>>16)&0xFF)/255.f,((to.get()>>16)&0xFF)/255.f,fraction); - float g=lerp(((from.get()>>8)&0xFF)/255.f,((to.get()>>8)&0xFF)/255.f,fraction); - float b=lerp((from.get()&0xFF)/255.f,(to.get()&0xFF)/255.f,fraction); + float a=lerp((GET_VARIANT(from,uint32_t)>>24)/255.f,(GET_VARIANT(to,uint32_t)>>24)/255.f,fraction); + float r=lerp(((GET_VARIANT(from,uint32_t)>>16)&0xFF)/255.f,((GET_VARIANT(to,uint32_t)>>16)&0xFF)/255.f,fraction); + float g=lerp(((GET_VARIANT(from,uint32_t)>>8)&0xFF)/255.f,((GET_VARIANT(to,uint32_t)>>8)&0xFF)/255.f,fraction); + float b=lerp((GET_VARIANT(from,uint32_t)&0xFF)/255.f,(GET_VARIANT(to,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() * (1.f - fraction) + to.get() * fraction; + out = GET_VARIANT(from,float) * (1.f - fraction) + GET_VARIANT(to,float) * fraction; break; } } diff --git a/src/gui/animation/propertyvaluesholder.h b/src/gui/animation/propertyvaluesholder.h index aee14fae..50fc8bae 100755 --- a/src/gui/animation/propertyvaluesholder.h +++ b/src/gui/animation/propertyvaluesholder.h @@ -11,6 +11,11 @@ #include //reference: //http://androidxref.com/9.0.0_r3/xref/frameworks/base/libs/hwui/PropertyValuesHolder.h +#if variant_CPP17_OR_GREATER + #define GET_VARIANT(vt,type) std::get(vt) +#else + #define GET_VARIANT(vt,type) vt.get() +#endif namespace cdroid{ typedef nonstd::variantAnimateValue; diff --git a/src/gui/drawables/ripplebackground.cc b/src/gui/drawables/ripplebackground.cc index 3f9a8619..df5051ae 100755 --- a/src/gui/drawables/ripplebackground.cc +++ b/src/gui/drawables/ripplebackground.cc @@ -91,8 +91,7 @@ void RippleBackground::onStateChanged(){ mAnimator->setInterpolator(new LinearInterpolator());//LINEAR_INTERPOLATOR); mAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ PropertyValuesHolder*fp=anim.getValues(0); - LOGD("mOpacity=%f",fp->getAnimatedValue().get()); - mOpacity=fp->getAnimatedValue().get(); + mOpacity = GET_VARIANT(fp->getAnimatedValue(),float); invalidateSelf(); })); diff --git a/src/gui/drawables/rippleforeground.cc b/src/gui/drawables/rippleforeground.cc index 7010baa3..96939a25 100755 --- a/src/gui/drawables/rippleforeground.cc +++ b/src/gui/drawables/rippleforeground.cc @@ -102,7 +102,7 @@ void RippleForeground::startSoftwareEnter() { tweenRadius->setInterpolator(new DecelerateInterpolator());//DECELERATE_INTERPOLATOR); tweenRadius->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ LOGV("mTweenRadius=%f [%f,%f,%f] opacity=%f",getCurrentRadius(),mStartRadius,mTargetRadius,mOpacity); - mTweenRadius=anim.getAnimatedValue().get(); + mTweenRadius = GET_VARIANT(anim.getAnimatedValue(),float); onAnimationPropertyChanged(); })); tweenRadius->start(); @@ -112,7 +112,7 @@ void RippleForeground::startSoftwareEnter() { tweenOrigin->setDuration(RIPPLE_ORIGIN_DURATION); tweenOrigin->setInterpolator(new DecelerateInterpolator());//DECELERATE_INTERPOLATOR); tweenOrigin->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - mTweenX=mTweenY=anim.getAnimatedValue().get(); + mTweenX=mTweenY=GET_VARIANT(anim.getAnimatedValue(),float); onAnimationPropertyChanged(); })); tweenOrigin->start(); @@ -122,7 +122,7 @@ void RippleForeground::startSoftwareEnter() { opacity->setDuration(OPACITY_ENTER_DURATION); opacity->setInterpolator(new LinearInterpolator());//LINEAR_INTERPOLATOR); opacity->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - mOpacity=anim.getAnimatedValue().get(); + mOpacity=GET_VARIANT(anim.getAnimatedValue(),float); onAnimationPropertyChanged(); })); opacity->start(); @@ -136,7 +136,7 @@ void RippleForeground::startSoftwareExit() { opacity->addListener(mAnimationListener); opacity->setStartDelay(computeFadeOutDelay()); opacity->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - mOpacity=anim.getAnimatedValue().get(); + mOpacity=GET_VARIANT(anim.getAnimatedValue(),float); })); opacity->start(); diff --git a/src/gui/view/swipehelper.cc b/src/gui/view/swipehelper.cc index 90c8fcad..cba75289 100755 --- a/src/gui/view/swipehelper.cc +++ b/src/gui/view/swipehelper.cc @@ -18,7 +18,7 @@ SwipeHelper::SwipeHelper(Context*ctx) { mPreContentViewAnimator = ValueAnimator::ofFloat({.0f, 1.f}); mPreContentViewAnimator->setInterpolator(new AccelerateDecelerateInterpolator()); mPreContentViewAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - const float value = anim.getAnimatedValue().get(); + const float value = GET_VARIANT(anim.getAnimatedValue(),float); const int xx = mPrevStartX+(mPrevEndX-mPrevStartX)*value; Window* prev = (Window*)getPreContentView(); LOGV("move PrevWindow(%p) to %d cancel=%d",prev,xx,mCancel); @@ -28,7 +28,7 @@ SwipeHelper::SwipeHelper(Context*ctx) { mCurContentViewAnimator = ValueAnimator::ofFloat({.0f, 1.f}); mCurContentViewAnimator->setInterpolator(new AccelerateDecelerateInterpolator()); mCurContentViewAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - const float value = anim.getAnimatedValue().get(); + const float value = GET_VARIANT(anim.getAnimatedValue(),float); const int xx = mCurrentStartX+(mCurrentEndX-mCurrentStartX)*value; Window* cur = (Window*)getCurContentView(); LOGV("move CurrentWindow(%p) to %d cancel=%d",cur,xx,mCancel); diff --git a/src/gui/widget/datetimeview._cc b/src/gui/widget/datetimeview._cc new file mode 100644 index 00000000..de19172d --- /dev/null +++ b/src/gui/widget/datetimeview._cc @@ -0,0 +1,363 @@ +namespace cdroid{ + +DateTimeView::DateTimeView(Context context,const AttributeSet& attrs) { + :TextView(context, attrs); + setShowRelativeTime(attrs.getBoolean("showRelative",false); +} + +void DateTimeView::onAttachedToWindow() { + TextView::onAttachedToWindow(); + ReceiverInfo ri = sReceiverInfo.get(); + if (ri == null) { + ri = new ReceiverInfo(); + sReceiverInfo.set(ri); + } + ri.addView(this); + // The view may not be added to the view hierarchy immediately right after setTime() + // is called which means it won't get any update from intents before being added. + // In such case, the view might show the incorrect relative time after being added to the + // view hierarchy until the next update intent comes. + // So we update the time here if mShowRelativeTime is enabled to prevent this case. + if (mShowRelativeTime) { + update(); + } +} + +void DateTimeView::onDetachedFromWindow() { + TextView::onDetachedFromWindow(); + final ReceiverInfo ri = sReceiverInfo.get(); + if (ri != null) { + ri.removeView(this); + } +} + +void DateTimeView::setTime(long timeMillis) { + mTimeMillis = timeMillis; + LocalDateTime dateTime = toLocalDateTime(timeMillis, ZoneId.systemDefault()); + mLocalTime = dateTime.withSecond(0); + update(); +} + +void DateTimeView::setShowRelativeTime(bool showRelativeTime) { + mShowRelativeTime = showRelativeTime; + updateNowText(); + update(); +} + +bool DateTimeView::isShowRelativeTime() const{ + return mShowRelativeTime; +} + +void DateTimeView::setVisibility(int visibility) { + bool gotVisible = visibility != GONE && getVisibility() == GONE; + TextView::setVisibility(visibility); + if (gotVisible) { + update(); + } +} + +void DateTimeView::update() { + if (mLocalTime == null || getVisibility() == GONE) { + return; + } + if (mShowRelativeTime) { + updateRelativeTime(); + return; + } + + int display; + ZoneId zoneId = ZoneId.systemDefault(); + + // localTime is the local time for mTimeMillis but at zero seconds past the minute. + LocalDateTime localTime = mLocalTime; + LocalDateTime localStartOfDay = + LocalDateTime.of(localTime.toLocalDate(), LocalTime.MIDNIGHT); + LocalDateTime localTomorrowStartOfDay = localStartOfDay.plusDays(1); + // now is current local time but at zero seconds past the minute. + LocalDateTime localNow = LocalDateTime.now(zoneId).withSecond(0); + + long twelveHoursBefore = toEpochMillis(localTime.minusHours(12), zoneId); + long twelveHoursAfter = toEpochMillis(localTime.plusHours(12), zoneId); + long midnightBefore = toEpochMillis(localStartOfDay, zoneId); + long midnightAfter = toEpochMillis(localTomorrowStartOfDay, zoneId); + long time = toEpochMillis(localTime, zoneId); + long now = toEpochMillis(localNow, zoneId); + + // Choose the display mode + choose_display: { + if ((now >= midnightBefore && now < midnightAfter) + || (now >= twelveHoursBefore && now < twelveHoursAfter)) { + display = SHOW_TIME; + break choose_display; + } + // Else, show month day and year. + display = SHOW_MONTH_DAY_YEAR; + break choose_display; + } + + // Choose the format + DateFormat format; + if (display == mLastDisplay && mLastFormat != null) { + // use cached format + format = mLastFormat; + } else { + switch (display) { + case SHOW_TIME: + format = getTimeFormat(); + break; + case SHOW_MONTH_DAY_YEAR: + format = DateFormat.getDateInstance(DateFormat.SHORT); + break; + default: + throw new RuntimeException("unknown display value: " + display); + } + mLastFormat = format; + } + + // Set the text + String text = format.format(new Date(time)); + maybeSetText(text); + + // Schedule the next update + if (display == SHOW_TIME) { + // Currently showing the time, update at the later of twelve hours after or midnight. + mUpdateTimeMillis = twelveHoursAfter > midnightAfter ? twelveHoursAfter : midnightAfter; + } else { + // Currently showing the date + if (mTimeMillis < now) { + // If the time is in the past, don't schedule an update + mUpdateTimeMillis = 0; + } else { + // If hte time is in the future, schedule one at the earlier of twelve hours + // before or midnight before. + mUpdateTimeMillis = twelveHoursBefore < midnightBefore + ? twelveHoursBefore : midnightBefore; + } + } +} + +void DateTimeView::updateRelativeTime() { + long now = System.currentTimeMillis(); + long duration = Math.abs(now - mTimeMillis); + int count; + long millisIncrease; + boolean past = (now >= mTimeMillis); + String result; + if (duration < MINUTE_IN_MILLIS) { + maybeSetText(mNowText); + mUpdateTimeMillis = mTimeMillis + MINUTE_IN_MILLIS + 1; + return; + } else if (duration < HOUR_IN_MILLIS) { + count = (int)(duration / MINUTE_IN_MILLIS); + result = getContext().getResources().getString(past + ? com.android.internal.R.string.duration_minutes_shortest + : com.android.internal.R.string.duration_minutes_shortest_future, + count); + millisIncrease = MINUTE_IN_MILLIS; + } else if (duration < DAY_IN_MILLIS) { + count = (int)(duration / HOUR_IN_MILLIS); + result = getContext().getResources().getString(past + ? com.android.internal.R.string.duration_hours_shortest + : com.android.internal.R.string.duration_hours_shortest_future, + count); + millisIncrease = HOUR_IN_MILLIS; + } else if (duration < YEAR_IN_MILLIS) { + // In weird cases it can become 0 because of daylight savings + LocalDateTime localDateTime = mLocalTime; + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localNow = toLocalDateTime(now, zoneId); + + count = Math.max(Math.abs(dayDistance(localDateTime, localNow)), 1); + result = getContext().getResources().getString(past + ? com.android.internal.R.string.duration_days_shortest + : com.android.internal.R.string.duration_days_shortest_future, + count); + if (past || count != 1) { + mUpdateTimeMillis = computeNextMidnight(localNow, zoneId); + millisIncrease = -1; + } else { + millisIncrease = DAY_IN_MILLIS; + } + + } else { + count = (int)(duration / YEAR_IN_MILLIS); + result = getContext().getResources().getString(past + ? com.android.internal.R.string.duration_years_shortest + : com.android.internal.R.string.duration_years_shortest_future, + count); + millisIncrease = YEAR_IN_MILLIS; + } + if (millisIncrease != -1) { + if (past) { + mUpdateTimeMillis = mTimeMillis + millisIncrease * (count + 1) + 1; + } else { + mUpdateTimeMillis = mTimeMillis - millisIncrease * count + 1; + } + } + maybeSetText(result); +} + +void DateTimeView::maybeSetText(const std::string& text) { + if (TextUtils.equals(getText(), text)) { + return; + } + setText(text); +} + +long DateTimeView::computeNextMidnight(LocalDateTime time, ZoneId zoneId) { + // This ignores the chance of overflow: it should never happen. + LocalDate tomorrow = time.toLocalDate().plusDays(1); + LocalDateTime nextMidnight = LocalDateTime.of(tomorrow, LocalTime.MIDNIGHT); + return toEpochMillis(nextMidnight, zoneId); +} + +void DateTimeView::onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + updateNowText(); + update(); +} + +void DateTimeView::updateNowText() { + if (!mShowRelativeTime) { + return; + } + mNowText = getContext().getResources().getString( + com.android.internal.R.string.now_string_shortest); +} + +int DateTimeView::dayDistance(LocalDateTime start, LocalDateTime end) { + return (int) (end.getLong(JulianFields.JULIAN_DAY) + - start.getLong(JulianFields.JULIAN_DAY)); +} + +DateFormat DateTimeView::getTimeFormat() { + return android.text.format.DateFormat.getTimeFormat(getContext()); +} + +void DateTimeView::clearFormatAndUpdate() { + mLastFormat = null; + update(); +} + +void DateTimeView::setReceiverHandler(Handler handler) { + ReceiverInfo ri = sReceiverInfo.get(); + if (ri == null) { + ri = new ReceiverInfo(); + sReceiverInfo.set(ri); + } + ri.setHandler(handler); +} + +LocalDateTime DateTimeView::toLocalDateTime(long timeMillis, ZoneId zoneId) { + // java.time types like LocalDateTime / Instant can support the full range of "long millis" + // with room to spare so we do not need to worry about overflow / underflow and the rsulting + // exceptions while the input to this class is a long. + Instant instant = Instant.ofEpochMilli(timeMillis); + return LocalDateTime.ofInstant(instant, zoneId); +} + +long DateTimeView::toEpochMillis(LocalDateTime time, ZoneId zoneId) { + Instant instant = time.toInstant(zoneId.getRules().getOffset(time)); + return instant.toEpochMilli(); +} + +private static class ReceiverInfo { + private final ArrayList mAttachedViews = new ArrayList(); + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (Intent.ACTION_TIME_TICK.equals(action)) { + if (System.currentTimeMillis() < getSoonestUpdateTime()) { + // The update() function takes a few milliseconds to run because of + // all of the time conversions it needs to do, so we can't do that + // every minute. + return; + } + } + // ACTION_TIME_CHANGED can also signal a change of 12/24 hr. format. + updateAll(); + } +}; + +ContentObserver mObserver = new ContentObserver(new Handler()) { + void onChange(boolean selfChange) { + updateAll(); + } +}; + +Handler mHandler = new Handler(); + +void addView(DateTimeView v) { + synchronized (mAttachedViews) { + bool register = mAttachedViews.isEmpty(); + mAttachedViews.add(v); + if (register) { + register(getApplicationContextIfAvailable(v.getContext())); + } + } +} + +void removeView(DateTimeView v) { + synchronized (mAttachedViews) { + final bool removed = mAttachedViews.remove(v); + // Only unregister once when we remove the last view in the list otherwise we risk + // trying to unregister a receiver that is no longer registered. + if (removed && mAttachedViews.isEmpty()) { + unregister(getApplicationContextIfAvailable(v.getContext())); + } + } +} + +void updateAll() { + synchronized (mAttachedViews) { + final int count = mAttachedViews.size(); + for (int i = 0; i < count; i++) { + DateTimeView view = mAttachedViews.get(i); + view.post(() -> view.clearFormatAndUpdate()); + } + } +} + +long getSoonestUpdateTime() { + long result = Long.MAX_VALUE; + synchronized (mAttachedViews) { + final int count = mAttachedViews.size(); + for (int i = 0; i < count; i++) { + final long time = mAttachedViews.get(i).mUpdateTimeMillis; + if (time < result) { + result = time; + } + } + } + return result; +} + + static final Context getApplicationContextIfAvailable(Context context) { + final Context ac = context.getApplicationContext(); + return ac != null ? ac : ActivityThread.currentApplication().getApplicationContext(); + } + + void register(Context context) { + final IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_TIME_TICK); + filter.addAction(Intent.ACTION_TIME_CHANGED); + filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); + filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); + context.registerReceiver(mReceiver, filter, null, mHandler); + } + + void unregister(Context context) { + context.unregisterReceiver(mReceiver); + } + + public void setHandler(Handler handler) { + mHandler = handler; + synchronized (mAttachedViews) { + if (!mAttachedViews.isEmpty()) { + unregister(mAttachedViews.get(0).getContext()); + register(mAttachedViews.get(0).getContext()); + } + } + } + } +}/*endof namespace*/ diff --git a/src/gui/widget/datetimeview.h b/src/gui/widget/datetimeview.h new file mode 100644 index 00000000..e3e7b148 --- /dev/null +++ b/src/gui/widget/datetimeview.h @@ -0,0 +1,30 @@ +#ifndef __DATE_TIME_VIEW_H__ +#define __DATE_TIME_VIEW_H__ +namespace cdroid{ + +class DateTimeView public:TextView{ +private: + static constexpr int SHOW_TIME = 0; + static constexpr int SHOW_MONTH_DAY_YEAR = 1; +private: + long mTimeMillis; + // The LocalDateTime equivalent of mTimeMillis but truncated to minute, i.e. no seconds / nanos. + LocalDateTime mLocalTime; + + int mLastDisplay = -1; + DateFormat mLastFormat; + + long mUpdateTimeMillis; + //static final ThreadLocal sReceiverInfo = new ThreadLocal(); + std::string mNowText; + bool mShowRelativeTime; +protected: + void onAttachedToWindow()override; + void onDetachedFromWindow()override; +public: + DateTimeView(Context context,const AttributeSet& attrs); + void setTime(long timeMillis); +}; + +}/*endof namespace*/ +#endif diff --git a/src/gui/widget/expandablelayout.cc b/src/gui/widget/expandablelayout.cc index c2f6f162..6b2aa862 100755 --- a/src/gui/widget/expandablelayout.cc +++ b/src/gui/widget/expandablelayout.cc @@ -213,7 +213,7 @@ void ExpandableLayout::animateSize(int targetExpansion) { mAnimator->setDuration(mDuration); mAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim) { - setExpansion((float) anim.getAnimatedValue().get()); + setExpansion(GET_VARIANT(anim.getAnimatedValue(),float)); })); Animator::AnimatorListener ls; diff --git a/src/gui/widget/progressbar.cc b/src/gui/widget/progressbar.cc index f5101637..d28826d8 100644 --- a/src/gui/widget/progressbar.cc +++ b/src/gui/widget/progressbar.cc @@ -316,7 +316,7 @@ void ProgressBar::doRefreshProgress(int id, int progress, bool fromUser,bool cal mAnimator->setDuration(PROGRESS_ANIM_DURATION); mAnimator->setInterpolator(new DecelerateInterpolator()); mAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - setVisualProgress(R::id::progress,anim.getAnimatedValue().get()); + setVisualProgress(R::id::progress,GET_VARIANT(anim.getAnimatedValue(),float)); })); mAnimator->addListener(mAnimtorListener); } diff --git a/src/gui/widget/switch.cc b/src/gui/widget/switch.cc index d3b21f21..ed629798 100755 --- a/src/gui/widget/switch.cc +++ b/src/gui/widget/switch.cc @@ -564,7 +564,7 @@ void Switch::animateThumbToCheckedState(bool newCheckedState){ mPositionAnimator->setAutoCancel(true); mPositionAnimator->start(); mPositionAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - setThumbPosition(anim.getAnimatedValue().get()); + setThumbPosition(GET_VARIANT(anim.getAnimatedValue(),float)); })); } diff --git a/src/gui/widget/tablayout.cc b/src/gui/widget/tablayout.cc index 1a1719b1..c2bb91a9 100755 --- a/src/gui/widget/tablayout.cc +++ b/src/gui/widget/tablayout.cc @@ -618,7 +618,7 @@ void TabLayout::ensureScrollAnimator(){ mScrollAnimator->setDuration(ANIMATION_DURATION); mScrollAnimator->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim) { PropertyValuesHolder*ip=anim.getValues()[0]; - scrollTo(ip->getAnimatedValue().get(), 0); + scrollTo(GET_VARIANT(ip->getAnimatedValue(),float),0); })); } } diff --git a/tests/gui/animator_tests.cc b/tests/gui/animator_tests.cc index de0921cc..669beb97 100755 --- a/tests/gui/animator_tests.cc +++ b/tests/gui/animator_tests.cc @@ -25,7 +25,7 @@ TEST_F(ANIMATOR,callback){ TEST_F(ANIMATOR,ofInt1){ ValueAnimator*anim=ValueAnimator::ofInt({0,100}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - LOGD("value=%d",anim.getAnimatedValue().get()); + LOGD("value=%d",GET_VARIANT(anim.getAnimatedValue(),int)); })); for(int i=0;i<=10;i++){ anim->setCurrentFraction((float)i/10.f); @@ -37,7 +37,7 @@ TEST_F(ANIMATOR,ofInt2){ iprop.setValues(std::vector({0,100})); ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - LOGD("value=%d",anim.getAnimatedValue().get()); + LOGD("value=%d",GET_VARIANT(anim.getAnimatedValue(),int)); })); for(int i=0;i<=10;i++){ anim->setCurrentFraction((float)i/10.f); @@ -49,7 +49,7 @@ TEST_F(ANIMATOR,ofFloat){ fprop.setValues(std::vector({0,100})); ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - LOGD("value=%f",anim.getAnimatedValue().get()); + LOGD("value=%f",GET_VARIANT(anim.getAnimatedValue(),float)); })); for(int i=0;i<=10;i++){ anim->setCurrentFraction((float)i/10.f); @@ -62,7 +62,7 @@ TEST_F(ANIMATOR,start){ fprop.setValues(std::vector({0,100})); ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - LOGD("value=%f",anim.getAnimatedValue().get()); + LOGD("value=%f",GET_VARIANT(anim.getAnimatedValue(),float)); })); anim->setDuration(200); anim->start(); @@ -75,7 +75,7 @@ TEST_F(ANIMATOR,startDelay){ fprop.setValues(std::vector({0,100})); ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - LOGD("value=%f",anim.getAnimatedValue().get()); + LOGD("value=%f",GET_VARIANT(anim.getAnimatedValue(),float)); })); anim->setDuration(200); anim->setStartDelay(1000); @@ -107,7 +107,7 @@ TEST_F(ANIMATOR,loopdrivered){ ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){ - LOGD("value=%d",anim.getAnimatedValue().get()); + LOGD("value=%d",GET_VARIANT(anim.getAnimatedValue(),int)); })); anim->setDuration(2000); anim->start(); @@ -137,8 +137,8 @@ TEST_F(ANIMATOR,translate){ PropertyValuesHolder*xp=anim.getValues(0); PropertyValuesHolder*yp=anim.getValues(1); PropertyValuesHolder*cp=anim.getValues(2); - tv->setPos(xp->getAnimatedValue().get(),yp->getAnimatedValue().get()); - tv->setBackgroundColor(cp->getAnimatedValue().get()); + tv->setPos(GET_VARIANT(xp->getAnimatedValue(),int),GET_VARIANT(yp->getAnimatedValue(),int)); + tv->setBackgroundColor(GET_VARIANT(cp->getAnimatedValue(),uint32_t)); })); anim->setDuration(5000); @@ -158,7 +158,7 @@ TEST_F(ANIMATOR,scale){ ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop}); anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([tv](ValueAnimator&anim){ - const float scale=anim.getAnimatedValue().get(); + const float scale=GET_VARIANT(anim.getAnimatedValue(),float); tv->setScaleX(scale); tv->setScaleY(scale); }));