Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move duration not work when onSpeedChangeListener or onSpeedTextListener is setted #213

Closed
amir14a opened this issue Jul 25, 2021 · 8 comments
Labels
Bug bug!!

Comments

@amir14a
Copy link

amir14a commented Jul 25, 2021

Describe the bug
When I set onSpeedChangeListener or onSpeedTextListener , and after that I use speedTo function with moveDuration parameter, this parameter not apply and speed meter moves fast.

Smartphone : Mi A2

  • OS: Android 10
  • Version 1.5.51
@amir14a amir14a added the Bug report Participants report a bug label Jul 25, 2021
@amir14a
Copy link
Author

amir14a commented Jul 25, 2021

this bug only occurs when app:sv_withTremble="true"

@anastr
Copy link
Owner

anastr commented Jul 25, 2021

I've tested it with Android 11 and 10 on a PointerSpeedometer where withTremble = true and it has onSpeedChangeListener.
The test is passed when I call speedTo(speed = 100, moveDuration = 6000) it did take 6 seconds as expected!
Please share your speedview and the piece of code that runs it.

@amir14a
Copy link
Author

amir14a commented Jul 26, 2021

My Xml Code:

<com.github.anastr.speedviewlib.SpeedView
                           android:id="@+id/speedView"
                           android:layout_width="@dimen/_180sdp"
                           android:layout_height="wrap_content"
                           android:layout_gravity="center"
                           android:layout_marginTop="16dp"
                           android:layout_marginBottom="8dp"
                           android:paddingTop="@dimen/_12sdp"
                           app:sv_centerCircleColor="@color/black"
                           app:sv_centerCircleRadius="@dimen/_5sdp"
                           app:sv_endDegree="360"
                           app:sv_indicator="KiteIndicator"
                           app:sv_indicatorColor="@color/black"
                           app:sv_indicatorWidth="@dimen/_4sdp"
                           app:sv_markColor="@color/black"
                           app:sv_markStyle="ROUND"
                           app:sv_markWidth="1dp"
                           app:sv_marksNumber="3"
                           app:sv_maxSpeed="100"
                           app:sv_minSpeed="0"
                           app:sv_speedTextColor="@android:color/transparent"
                           app:sv_speedometerMode="TOP"
                           app:sv_startDegree="180"
                           app:sv_tickNumber="5"
                           app:sv_tickPadding="@dimen/_minus12sdp"
                           app:sv_trembleDegree="1"
                           app:sv_trembleDuration="250"
                           app:sv_unit="%"
                           app:sv_unitTextColor="@android:color/transparent" />

My kotlin code:

@AndroidEntryPoint
class ProfileFragment : BaseFragment<FragmentProfileBinding, ProfileFragmentViewModel>(
    R.layout.fragment_profile,
    ProfileFragmentViewModel::class.java
) {
    val score: MutableLiveData<String> by lazy { MutableLiveData("0") }
    val scoreColor: MutableLiveData<Int> by lazy { MutableLiveData() }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val sm = binding.speedView
        sm.clearSections()
        sm.addSections(
            listOf(
                Section(0f, .5f, Color.parseColor("#F2726F"), sm.speedometerWidth),
                Section(.5f, .75f, Color.parseColor("#FFC532"), sm.speedometerWidth),
                Section(.75f, 1f, Color.parseColor("#62B58F"), sm.speedometerWidth),
            )
        )
        sm.onSpeedChangeListener = { gauge, _, isT ->
            score.value = gauge.currentIntSpeed.toString()
        }
        sm.onSectionChangeListener = { _, newSection ->
            scoreColor.value = newSection?.color
        }
        Handler().postDelayed({
            sm.speedTo(79f,50000)
        }, 1000)
    }
}

@anastr
Copy link
Owner

anastr commented Jul 26, 2021

Again, not shown on my devices.
May you try the older version 1.5.5 .

@amir14a
Copy link
Author

amir14a commented Jul 27, 2021

No, My version is Version 1.5.51
I will test again in the next 2-3 days and share the full code and APK file

@amir14a
Copy link
Author

amir14a commented Jul 31, 2021

Hi again,
I have prepared a repo to report the problem:
https://github.com/amir14a/SpeedViewTest/

This problem is very confusing this only occurs when app:sv_withTremble="true" and use viewPager2 with FragmentStateAdapter, and use databinding to observe a liveDate which is changed by onSpeedChangeListener :O (see above repo)

@anastr
Copy link
Owner

anastr commented Aug 6, 2021

The far I've got for this issue is that onVisibilityAggregated method called frequently. In this method we expect a visibility change and stop/run tremble animation, but ViewPager2 keep calling it with visible = true.
Something isn't right about this behavior, it could be an issue in ViewPager2. Make sure that you apply ViewPager2 correctly and try to contact Android Developers about this issue.

@anastr anastr added Bug bug!! and removed Bug report Participants report a bug labels Oct 9, 2021
@anastr
Copy link
Owner

anastr commented Oct 9, 2021

We've released version 1.5.52, and I'm assuming that it'll fix your issue. I hope if anyone can confirm.

@anastr anastr closed this as completed Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug bug!!
Projects
None yet
Development

No branches or pull requests

2 participants