Delayed loading of images on cards

I specifically look at this in CardScrollAdapter, but it would be nice to find out in the situation with LiveCard when publishing a map on the timeline. Is there a way to use volleyball or any other network library to upload images using a common class Card?

+4
source share
4 answers

β€œThere’s an additional complication that the current XE12 GDK only supports card.addImage (Uri) with local resources and file URIs. Therefore, in addition to the warning above, you must load the image into the file before you can add it as a map image.”

, XE16 + card.addImage(bitmap), .

+1

Volley NetworkImageView Card ( Card ), Volley .

:

  • Card, , (- ). Card - (, ).
  • .
  • , URL file:.
  • Card.toView() , .
+3

"UPDATE: 10 . , updateViews() ."

, getView() CardScrollAdapter .

:

   @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if ( getCards() == null ) return null;

        MyCard card = getCards().get(position);

        if (! card.isImageLoaded()) {
                    CardImageLoader.loadCardImage(...);     
        }

           return card.toView();

    }
+2

, , . , getView() , Android. , , ImageView, card.toView(), GC'd . , GDK, , , , , .

, XE12 GDK card.addImage(Uri) URI . , , , .

Android Universal Image Loader, . , :

public class CardImageLoader {

    private static final String TAG = CardImageLoader.class.getSimpleName(); 
    private static final boolean DEBUG = false;

    private static final int MAX_IMAGE_LOAD_RETRIES = 3;
    private static Map<String, Integer> mLoadFailures = new ConcurrentHashMap<String, Integer>();

    public static void init(Context context) {
        File cacheDir = StorageUtils.getCacheDirectory(context);
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .cacheOnDisc(true)
                .build();
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .discCache(new UnlimitedDiscCache(cacheDir))
                .defaultDisplayImageOptions(options)
                .build();
        ImageLoader.getInstance().init(config);
    }

    public static void loadCardImage(final Card card, final String imageUri, final CardScrollView cardScrollView) {
        card.setImageLayout(Card.ImageLayout.FULL);
        int failures = mLoadFailures.containsKey(imageUri) ? mLoadFailures.get(imageUri) : 0;
        if (failures > MAX_IMAGE_LOAD_RETRIES) {
            if (DEBUG) Log.i(TAG, "Exceeded max retries on imageUri=" + imageUri);
            return;
        }
        File file = ImageLoader.getInstance().getDiscCache().get(imageUri);
        if (file != null && file.exists() && file.length() > 0) {
            Uri uri = Uri.fromFile(file);
            card.addImage(uri);
        }
        else {
            ImageLoader.getInstance().loadImage(imageUri, new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    if (DEBUG) Log.i(TAG, "onLoadingStarted");
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    if (DEBUG) Log.i(TAG, "onLoadingFailed");
                    int failures = mLoadFailures.containsKey(imageUri) ? mLoadFailures.get(imageUri) : 0;
                    mLoadFailures.put(imageUri, ++failures);
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    File file = ImageLoader.getInstance().getDiscCache().get(imageUri);
                    if (DEBUG) Log.i(TAG, "onLoadingComplete uri=" + imageUri + " file=" + file
                            + " len=" + (file == null ? 0 : file.length()));
                    if (file != null && file.exists() && file.length() > 0) {
                        if (DEBUG) Log.i(TAG, "onLoadingComplete scheduling update of scroll views");
                        if (cardScrollView != null)
                            cardScrollView.updateViews(true);
                    }
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                    if (DEBUG) Log.i(TAG, "onLoadingCancelled");
                }
            });
        }
    }
}

. getView() URL-, . , . , Uri card.addImage(Uri), . , displayImage() , . loadImage()' and if successful, ask the CardScrollView ' ( , final, ). , getView() , . , , .

, CardScrollView .

? . onCreate() :

CardImageLoader.init(this);

-, getView(), , :

CardImageLoader.loadCardImage(card, url, mCardScrollView);

. , , 20 , . 150 , . , .

UPDATE: 10 + . , updateViews() .

+1
source

All Articles