Correct way to trigger update on custom pull inside textSpan

I wrote a special range for SpannableStrings

" ImageURLSpan

" which expands ImageSpan

.

  • The ImageSpan is set up with a Drawable " RemoteImageDrawable

    " which renders a static placeholder, downloads the image from the web, and then when the image finishes loading, it should display the loaded bitmap instead of the placeholder. This will happen if the draw()

    drawable method is called again (by the parent view

    ?)

My problem is that at the output level, I have no idea how to trigger the "automatic update" at any point in the future (after the image is loaded). I tried calling the parent view invalidate

with inconsistent results: sometimes the drawable method gets called again so it updates correctly and sometimes it doesn't. This is completely random!

What's the correct approach for a drawable that changes its content to "invalid"? shouldn't the parent view be invalidated to invalidate all child drawings? Do I need to use Drawable callbacks or are they not related to my problem?

Enter the attached code:

public class ImageUrlSpan extends ImageSpan {

    public ImageUrlSpan(final View parentView, String imageUrl, int width, int height) {
            super(
                    new RemoteImageDrawable(
                            parentView, imageUrl, width, height, new ImageLoaders.OnDrawableDownloadListener() {

                                @Override
                                public void onDrawableLoaded(Drawable bitmap) {
                                    parentView.invalidate();
                                    // this works sometimes
                                    if (Conf.LOG_ON) Log.v(TAG, "Invalidating parent view... will that refresh myself? "+parentView);
                                }
                            }
                    ));
        }
    }

      

RemoteImageDrawable

You should only know about the code

  • this is a simple drawing that simply draws a placeholder, schedules the image to load, and then when the image is ready, calls the listener above.

  • Whenever its method draw

    is called again (presumably as a consequence of invalidation in the listener above), the loaded bitmap will be displayed instead of the placeholder.

  • I omit the source code for simplicity, the problem is as simple as the draw method, which is not called most of the time. What puzzles me is that it was sometimes called!

The following stack trace displays the stop call of the first Drawable DRAW call. You can see that this comes from View.draw () -> StaticLayout.draw () -> RemoteImageDrawable.draw ().

W/System.err(26142):    at com.regaliz.custom.RemoteImageDrawable.draw(RemoteImageDrawable.java:71)
W/System.err(26142):    at android.text.style.DynamicDrawableSpan.draw(DynamicDrawableSpan.java:107)
W/System.err(26142):    at android.text.TextLine.handleReplacement(TextLine.java:854)
W/System.err(26142):    at android.text.TextLine.handleRun(TextLine.java:937)
W/System.err(26142):    at android.text.TextLine.drawRun(TextLine.java:395)
W/System.err(26142):    at android.text.TextLine.draw(TextLine.java:193)
W/System.err(26142):    at android.text.Layout.drawText(Layout.java:348)
W/System.err(26142):    at android.text.Layout.draw(Layout.java:205)
W/System.err(26142):    at android.text.Layout.draw(Layout.java:183)
W/System.err(26142):    at com.regaliz.gui.views.SimpleTextView.drawTextLayout(SimpleTextView.java:347)
W/System.err(26142):    at com.regaliz.gui.views.SimpleTextView.onDraw(SimpleTextView.java:310)
W/System.err(26142):    at com.regaliz.gui.views.helper.SimpleTextViewMarquee.onDraw(SimpleTextViewMarquee.java:114)
W/System.err(26142):    at android.view.View.draw(View.java:13877)
W/System.err(26142):    at android.view.View.getDisplayList(View.java:12815)
W/System.err(26142):    at android.view.View.getDisplayList(View.java:12859)
W/System.err(26142):    at android.view.View.draw(View.java:13593)
W/System.err(26142):    at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
W/System.err(26142):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)

      

However, when I issue invalidate, drawable draw () is not called, so somewhere along that path, the view resolves everything already drawn :(

V/RemoteImageDrawable(26142): *** Remote bitmap loaded com.regaliz.util.AssetLoader$MeasuredBitmapDrawable@41d60798
V/ImageURLSpan(26142): Invalidating  parent view after loaded... will it work? com.regaliz.gui.views.helper.SimpleTextViewMarquee{41f6c898 GFED..CL ........ 0,0-719,663}
V/ImageURLSpan(26142): Invalidating parent view end.

      

+3


source to share





All Articles