SpeedView icon indicating copy to clipboard operation
SpeedView copied to clipboard

change Low/Medium/High color in Recycler view at runtime

Open niteshgoel opened this issue 8 years ago • 11 comments

I have a recycle view whose view gets updated in every 30 seconds. I am able to change the color on Indicator but speed view color is changed to another color. I guess the issue is with the recycled views. first time image : (this is what it looks when the view is created for the first time.) img1

But after the refresh or down in the list view I see this ; img2

I have checked the code
this.mediumSpeedColor = mediumSpeedColor; if (!isAttachedToWindow()) return; updateBackgroundBitmap(); invalidate();

I guess the recycled view is already attached to the window.

Please suggest what to do?

niteshgoel avatar Jul 09 '18 15:07 niteshgoel

So you want to change indicator color or speedometer color? May you show me the code.

anastr avatar Jul 09 '18 16:07 anastr

i want to change both of them. as in first image. but when i scroll down or the list refresh only the color of indicator changes not the color of speedometer

niteshgoel avatar Jul 09 '18 19:07 niteshgoel

Try to call speedometer.invalidate() after you change the the bar color.

anastr avatar Jul 10 '18 02:07 anastr

It's not working. It is showing random behavior for bar color. I guess this method needs to get called updateBackgroundBitmap(); from setHighSpeedColor() before invalidate.

niteshgoel avatar Jul 10 '18 07:07 niteshgoel

That's weird! Give me xml tag for SpeedView and code where you change the color, i will try to fix it.

anastr avatar Jul 10 '18 13:07 anastr

java code (adapter's onBindViewHolder) ` switch (state) {

        case Running:

            vehileViewHolder.statusColour.setBackground(mContext.getResources().getDrawable(R.drawable.state_green_circle));

            vehileViewHolder.speedView.setLowSpeedColor(mContext.getResources().getColor(R.color.n_green_dot));
            vehileViewHolder.speedView.setMediumSpeedColor(mContext.getResources().getColor(R.color.n_green_dot));
            vehileViewHolder.speedView.setHighSpeedColor(mContext.getResources().getColor(R.color.n_green_dot));
            vehileViewHolder.speedView.setIndicatorColor(mContext.getResources().getColor(R.color.n_green_dot));

            vehileViewHolder.speedView.invalidate();
            break;
       
        case Overspeed:
            vehileViewHolder.statusColour.setBackground(mContext.getResources().getDrawable(R.drawable.state_red_circle));

            vehileViewHolder.speedView.setLowSpeedColor(mContext.getResources().getColor(R.color.n_red_dot));
            vehileViewHolder.speedView.setMediumSpeedColor(mContext.getResources().getColor(R.color.n_red_dot));
            vehileViewHolder.speedView.setHighSpeedColor(mContext.getResources().getColor(R.color.n_red_dot));
            vehileViewHolder.speedView.setIndicatorColor(mContext.getResources().getColor(R.color.n_red_dot));
            vehileViewHolder.speedView.invalidate();
            break;
       
    }`

XML ;

<com.github.anastr.speedviewlib.SpeedView android:id="@+id/speedView" android:layout_width="90dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_toLeftOf="@id/iv_blur_icon" android:paddingRight="10dp" app:sv_endDegree="360" app:sv_indicator="NeedleIndicator" app:sv_indicatorWidth="8dp" app:sv_lowSpeedColor="@color/four_f" app:sv_mediumSpeedColor="@color/four_f" app:sv_lowSpeedPercent="75" app:sv_maxSpeed="200" app:sv_mediumSpeedPercent="100" app:sv_minSpeed="0" app:sv_speedTextFormat="INTEGER" app:sv_speedTextPosition="CENTER" app:sv_speedTextSize="@dimen/home_list_item_content_text_size" app:sv_speedometerMode="TOP" app:sv_speedometerWidth="5dp" app:sv_startDegree="180" app:sv_trembleDegree="2" app:sv_unitTextSize="@dimen/home_list_item_address_bottom_margin" app:sv_withTremble="true" />

niteshgoel avatar Jul 10 '18 13:07 niteshgoel

By when this will be fixed and released? I really need this.

niteshgoel avatar Jul 20 '18 15:07 niteshgoel

I am so busy at this time, and there are too many issues need to handle... I don't know when i will finish it up, but if you are in a hurry you can extenda SpeedView and override onAttachedToWindow() method like this:

@Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        updateBackgroundBitmap();
        invalidate();
   }

Don't change anything else. This resolve your issue until next version.

anastr avatar Jul 21 '18 13:07 anastr

Thanks @anastr . It worked. One more thing is there any library like this in iOS?

niteshgoel avatar Jul 27 '18 14:07 niteshgoel

unfortunately No, you have to look for other lib.

anastr avatar Jul 28 '18 02:07 anastr

fixed in V 1.3.0.

anastr avatar Sep 21 '18 05:09 anastr