com.android.volley.toolbox.ImageLoader Java Examples

The following examples show how to use com.android.volley.toolbox.ImageLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CarouselImageFragment.java    From Android-SDK with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_carousel_dialog, container, false);

    image = (NetworkImageView) rootView.findViewById(R.id.carousel_image);

    String url = getArguments().getString("url");

    ImageLoader imgLoader = MyVolley.getInstance(getActivity().getApplicationContext())
            .getImageLoader();

    image.setImageUrl(url, imgLoader);

    return rootView;
}
 
Example #2
Source File: LyricsViewFragment.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
public void setCoverArt(String url, FadeInNetworkImageView coverView) {
    MainActivity mainActivity = (MainActivity) getActivity();
    if (mainActivity == null)
        return;
    mainActivity.findViewById(R.id.top_gradient).setVisibility(View.VISIBLE);
    mainActivity.findViewById(R.id.bottom_gradient).setVisibility(View.VISIBLE);
    if (coverView == null)
        coverView = mainActivity.findViewById(R.id.cover);
    if (url == null)
        url = "";
    if (mLyrics != null) {
        mLyrics.setCoverURL(url);
        coverView.setLyrics(mLyrics);
    }
    coverView.clearColorFilter();
    if (url.startsWith("/")) {
        coverView.setImageBitmap(BitmapFactory.decodeFile(url));
    } else {
        coverView.setImageUrl(url,
                new ImageLoader(Volley.newRequestQueue(mainActivity), CoverCache.instance()));
        if (!url.isEmpty() && mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT)
            DatabaseHelper.getInstance(getActivity()).updateCover(mLyrics.getArtist(), mLyrics.getTitle(), url);
    }
}
 
Example #3
Source File: FriendRecyclerAdapter.java    From kute with Apache License 2.0 6 votes vote down vote up
/************ Configuring View Holders ****************/
private void configureGeneralItem(PersonItemViewHolder vh, int position) {
    Person p = data_source.get(position - 1);
    vh.name.setText(p.name);
    /********* Test ******/
    RoundedImageView person_image =  vh.profile_pic;
    mImageLoader = VolleySingleton.getInstance(mcontext).getImageLoader();
    if(p.img_base64.equals("null") || p.img_base64==null){
        String img_url = String.format("https://graph.facebook.com/%s/picture?type=normal", p.id);
        //Log.d(TAG,"Image Url for ImageLoader is"+img_url);
        mImageLoader.get(img_url, ImageLoader.getImageListener(person_image,
                R.drawable.ic_person_black_36dp, R.drawable.ic_person_black_36dp));
    }else {
        //TODO This task of converting base64 to bitmap can be offloaded to a handler Thread
        Bitmap bm=base64ToBitmap(p.img_base64);
        person_image.setImageBitmap(bm);
    }



    /******** End of Test Data ********/
}
 
Example #4
Source File: CircleOf6Application.java    From OpenCircle with GNU General Public License v3.0 6 votes vote down vote up
public void setUpLogo(NetworkImageView logo, DBHelper dbHelper){

        //Get the set college
        String college_id = AppPreferences.getInstance(this).getCollegeLocation();
        if (!college_id.equals("")) {
            CollegeCountry collegeCountry;
            if (college_id.startsWith("c_")) {
                //this is campus, find parent
                collegeCountry = dbHelper.getParentCollege(college_id.replace("c_", ""));
            } else {
                collegeCountry = dbHelper.getCollege(college_id);
            }
            if (!isUniversalFlavor()) {
                logo.setVisibility(View.VISIBLE);

                ImageLoader imageLoader = getImageLoader();

                logo.setImageUrl(collegeCountry.getLogoUrl(), imageLoader);

            }
        }

    }
 
Example #5
Source File: MySingleton.java    From Netease with GNU General Public License v3.0 6 votes vote down vote up
private MySingleton(Context context) {
    mCtx = context;

    mRequestQueue = getRequestQueue();

    mImageLoader = new ImageLoader(mRequestQueue,
            //默认缓存20个单位的图片
            /*new ImageLoader.ImageCache() {
                private final LruCache<String, Bitmap>
                        cache = new LruCache<String, Bitmap>(20);

                @Override
                public Bitmap getBitmap(String url) {
                    return cache.get(url);
                }

                @Override
                public void putBitmap(String url, Bitmap bitmap) {
                    cache.put(url, bitmap);
                }
            });*/
            new MyLrnCache(mCtx), 1 * 3600 * 1000, 15 * 24 * 3600 * 1000, true);
}
 
Example #6
Source File: HttpLoader.java    From seny-devpkg with Apache License 2.0 5 votes vote down vote up
/**
 * 发起图片网络请求
 *
 * @param requestUrl The url of the remote image
 * @param maxWidth   The maximum width of the returned image.
 * @param maxHeight  The maximum height of the returned image.
 * @param scaleType  The ImageViews ScaleType used to calculate the needed image size.
 * @return A container object that contains all of the properties of the request, as well as
 * the currently available image (default if remote is not loaded).
 */
public void display(final ImageView view, String requestUrl, final int defaultImageResId, final int errorImageResId, int maxWidth, int maxHeight, ImageView.ScaleType scaleType) {
    if (mImageContainers.containsKey(view)) {//如果已经在给该View请求一张网络图片
        mImageContainers.get(view).cancelRequest();//那么就把之前的取消掉,保证一个ImageView身上只有一个任务。
    }
    ImageLoader.ImageContainer imageContainer = mImageLoader.get(requestUrl, new ImageLoader.ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
                ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).setDuration(800).start();//渐变动画
            }
            mImageContainers.remove(view);//请求失败,移除
        }

        @Override
        public void onResponse(final ImageLoader.ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageBitmap(response.getBitmap());
                ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).setDuration(800).start();//渐变动画
                mImageContainers.remove(view);//请求成功,移除
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    }, maxWidth, maxHeight, scaleType);
    mImageContainers.put(view, imageContainer);//将View身上的请求任务进行保存
}
 
Example #7
Source File: UserSelfProfileFragment.java    From kute with Apache License 2.0 5 votes vote down vote up
private void setupProfileImage() {
    String profile_image_base64 = pref.getString("Profile_Image", "null");
    String id= pref.getString("Id","null");
    Log.d(TAG,"User Id is"+id);
    if (profile_image_base64.equals("null")){
        mImageLoader = VolleySingleton.getInstance(getContext()).getImageLoader();
        String img_url = String.format("https://graph.facebook.com/%s/picture?type=large",id);
        //Log.d(TAG,"Image Url for ImageLoader is"+img_url);
        mImageLoader.get(img_url, ImageLoader.getImageListener(profile_picture,
                R.drawable.ic_person_black_36dp, R.drawable.ic_person_black_36dp));
    }
    else {
        base64ToBitmap(profile_image_base64);
    }
}
 
Example #8
Source File: LocalPlayerActivity.java    From CastVideos-android with Apache License 2.0 5 votes vote down vote up
private void setCoverArtStatus(String url) {
    if (url != null) {
        mImageLoader = CustomVolleyRequest.getInstance(this.getApplicationContext())
                .getImageLoader();
        mImageLoader.get(url, ImageLoader.getImageListener(mCoverArt, 0, 0));
        mCoverArt.setImageUrl(url, mImageLoader);

        mCoverArt.setVisibility(View.VISIBLE);
        mVideoView.setVisibility(View.INVISIBLE);
    } else {
        mCoverArt.setVisibility(View.GONE);
        mVideoView.setVisibility(View.VISIBLE);
    }
}
 
Example #9
Source File: VideoListAdapter.java    From CastVideos-android with Apache License 2.0 5 votes vote down vote up
public void setImage(String imgUrl, Context context) {
    mImageLoader = CustomVolleyRequest.getInstance(context)
            .getImageLoader();

    mImageLoader.get(imgUrl, ImageLoader.getImageListener(mImgView, 0, 0));
    mImgView.setImageUrl(imgUrl, mImageLoader);
}
 
Example #10
Source File: RssListAdapter.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflator.inflate(R.layout.card_list, null);
        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.title);
        holder.entryImage = (ImageView) convertView
                .findViewById(R.id.entry_image);
        holder.description = (TextView) convertView
                .findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Item item = getItem(position);
    holder.text.setText(item.title);
    holder.description.setText(item.description);
    if (item.imageUrl != null) {
        ImageListener listener = ImageLoader.getImageListener(
                holder.entryImage, R.drawable.ic_launcher,
                R.drawable.ic_launcher);
        if (holder.container != null) {
            holder.container.cancelRequest();
        }
        holder.container = mImageLoader.get(item.imageUrl, listener);
        holder.entryImage.setVisibility(View.VISIBLE);
    } else {
        holder.entryImage.setVisibility(View.GONE);
    }

    return convertView;
}
 
Example #11
Source File: VolleyDraweeControllerBuilderSupplier.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public VolleyDraweeControllerBuilderSupplier(
    Context context,
    ImageLoader imageLoader,
    Set<ControllerListener> boundControllerListeners) {
  mContext = context;
  mImageLoader = imageLoader;
  mVolleyDraweeControllerFactory = new VolleyDraweeControllerFactory(
      context.getResources(),
      DeferredReleaser.getInstance(),
      UiThreadExecutorService.getInstance());
  mBoundControllerListeners = boundControllerListeners;
}
 
Example #12
Source File: VolleyDataSource.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public VolleyDataSource(
    final ImageLoader imageLoader,
    final Uri imageRequest,
    final boolean bitmapCacheOnly) {

  // TODO: add VolleyImageRequest {uri, resizeOptions, bitmapCacheOnly, ...}
  String uriString = imageRequest.toString();
  int maxWidth = 0;
  int maxHeight = 0;

  if (bitmapCacheOnly) {
    if (!imageLoader.isCached(uriString, maxWidth, maxHeight)) {
      mImageContainer = null;
      setFailure(new NullPointerException("Image not found in bitmap-cache."));
      return;
    }
  }

  mImageContainer = imageLoader.get(
      uriString,
      new ImageLoader.ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          setFailure(error.getCause());
        }
        @Override
        public void onResponse(final ImageLoader.ImageContainer response, boolean isImmediate) {
          if (response.getBitmap() != null) {
            setResult(response.getBitmap(), true);
          }
        }
      },
      maxWidth,
      maxHeight);
}
 
Example #13
Source File: VolleyDraweeControllerBuilder.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public VolleyDraweeControllerBuilder(
    Context context,
    ImageLoader imageLoader,
    VolleyDraweeControllerFactory volleyDraweeControllerFactory,
    Set<ControllerListener> boundControllerListeners) {
  super(context, boundControllerListeners);
  mImageLoader = imageLoader;
  mVolleyDraweeControllerFactory = volleyDraweeControllerFactory;
}
 
Example #14
Source File: Huaban.java    From Presentation with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    mInstance = Huaban.this;

    mGson = new Gson();
    mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(getApplicationContext()));

    mDatabaseHelper = new DatabaseHelper(getApplicationContext());
    mPresentationsManager = new PstManager(getApplicationContext());
}
 
Example #15
Source File: CreditAdapter.java    From watchlist with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    Credit credit = creditList.get(position);
    final CreditViewHolder holder = (CreditViewHolder) viewHolder;
    int imageSize = (int) context.getResources().getDimension(R.dimen.detail_cast_image_width);

    if (TextUtil.isNullOrEmpty(credit.imagePath)) {
        holder.creditImage.setImageResource(R.drawable.default_cast_square);
    } else {
        VolleySingleton.getInstance().imageLoader.get(ApiHelper.getImageURL(credit.imagePath, imageSize),
                new ImageLoader.ImageListener() {
                    @Override
                    public void onResponse(ImageLoader.ImageContainer imageContainer, boolean b) {
                        holder.creditImage.setImageBitmap(imageContainer.getBitmap());
                    }
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        holder.creditImage.setImageResource(R.drawable.default_cast_square);
                    }
                });
    }

    holder.creditName.setText(credit.name);
    if (TextUtil.isNullOrEmpty(credit.role)) {
        holder.creditRole.setVisibility(View.GONE);
    } else {
        holder.creditRole.setText(credit.role);
        holder.creditRole.setVisibility(View.VISIBLE);
    }
}
 
Example #16
Source File: SearchAdapter.java    From watchlist with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    Movie movie = movieList.get(position);
    final SearchViewHolder holder = (SearchViewHolder) viewHolder;
    // Load image
    if (TextUtil.isNullOrEmpty(movie.backdropImage)) {
        holder.movieImage.setImageResource(R.drawable.default_backdrop_circle);
    } else {
        int imageSize = (int) context.getResources().getDimension(R.dimen.movie_compact_image_size);
        String imageUrl = ApiHelper.getImageURL(movie.backdropImage, imageSize);
        VolleySingleton.getInstance().imageLoader.get(imageUrl, new ImageLoader.ImageListener() {
            @Override
            public void onResponse(ImageLoader.ImageContainer imageContainer, boolean b) {
                holder.movieImage.setImageBitmap(imageContainer.getBitmap());
            }
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                holder.movieImage.setImageResource(R.drawable.default_backdrop_circle);
            }
        });
    }
    // Set text
    holder.movieName.setText(movie.title);
    holder.movieYear.setText(movie.year);
    if (TextUtil.isNullOrEmpty(movie.rating) || movie.rating.equals("0")) {
        holder.movieRatingHolder.setVisibility(View.GONE);
    } else {
        holder.movieRating.setText(movie.rating);
        holder.movieRatingHolder.setVisibility(View.VISIBLE);
    }
}
 
Example #17
Source File: NetworkMarker.java    From android-custom-markers with Apache License 2.0 5 votes vote down vote up
public NetworkMarker(Context context, LatLng position, ImageLoader imageLoader) {
    this.position = position;

    view = LayoutInflater.from(context).inflate(R.layout.view_network_marker, null);
    markerImage = (ImageView) view.findViewById(R.id.marker_image);
    markerBackground = (ImageView) view.findViewById(R.id.marker_background);

    this.imageLoader = imageLoader;
}
 
Example #18
Source File: NetworkMarker.java    From android-custom-markers with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {

    final Bitmap bitmap = response.getBitmap();

    // Set image and update view
    markerImage.setImageBitmap(bitmap);
    updateView();
}
 
Example #19
Source File: RssListNetworkImageViewAdapter.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
public RssListNetworkImageViewAdapter(Context context, List<Item> items) {
    super(context, 0, items);
    mItems = items;
    mInflator = (LayoutInflater) getContext().getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    mQueue = Volley.newRequestQueue(context);
    mImageLoader = new ImageLoader(mQueue, new LruImageCache());
}
 
Example #20
Source File: VolleyHolder.java    From fresco with MIT License 5 votes vote down vote up
public VolleyHolder(
    Context context,
    ImageLoader imageLoader,
    View layoutView,
    InstrumentedNetworkImageView view,
    PerfListener perfListener) {
  super(context, layoutView, view, perfListener);
  mImageLoader = imageLoader;
}
 
Example #21
Source File: CheckinHolder.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(Checkin checkin, ImageLoader imageLoader) {
    mName.setText(checkin.getAttendeeName());
    Context context = mDescription.getContext();
    long timestamp = checkin.getTimestamp();
    if (System.currentTimeMillis() - timestamp * 1000 < 60 * 1000) {
        mDescription.setText(R.string.just_now);
    } else {
        mDescription.setText(
                DateUtils.getRelativeDateTimeString(context, timestamp * 1000,
                        DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
    }
    // Load the icon
    ImageLoader.ImageContainer container = (ImageLoader.ImageContainer) mIcon.getTag();
    if (container != null) {
        container.cancelRequest();
    }
    String imageUrl = checkin.getAttendeeImageUrl();
    if (!TextUtils.isEmpty(imageUrl) && Patterns.WEB_URL.matcher(imageUrl).matches()) {
        mIcon.setTag(imageLoader.get(imageUrl,
                new RoundedImageListener(mIcon, R.drawable.ic_person,
                        R.drawable.ic_person)));
    } else {
        mIcon.setImageResource(R.drawable.ic_person);
    }
    if (mWillAnimate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mCheckin.setImageResource(R.drawable.checkin_anim);
    } else {
        mCheckin.setImageResource(R.drawable.checkin);
    }
}
 
Example #22
Source File: RssListAdapter.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflator.inflate(R.layout.card_list, null);
        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.title);
        holder.entryImage = (ImageView) convertView
                .findViewById(R.id.entry_image);
        holder.description = (TextView) convertView
                .findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Item item = getItem(position);
    holder.text.setText(item.title);
    holder.description.setText(item.description);
    if (item.imageUrl != null) {
        ImageListener listener = ImageLoader.getImageListener(
                holder.entryImage, R.drawable.ic_launcher,
                R.drawable.ic_launcher);
        if (holder.container != null) {
            holder.container.cancelRequest();
        }
        holder.container = mImageLoader.get(item.imageUrl, listener);
        holder.entryImage.setVisibility(View.VISIBLE);
    } else {
        holder.entryImage.setVisibility(View.GONE);
    }

    return convertView;
}
 
Example #23
Source File: AttendeeListFragment.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
public void bind(Cursor cursor, ImageLoader imageLoader) {
    itemView.setBackgroundDrawable(null);
    ViewCompat.setTranslationZ(itemView, 0.f);
    mName.setText(cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.NAME)));
    mEmail.setText(cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EMAIL)));
    String note = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.NOTE));
    mNote.setVisibility(TextUtils.isEmpty(note) ? View.GONE : View.VISIBLE);
    mNote.setText(note);
    mEventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID));
    mAttendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID));
    mAttendeeCheckedIn = !cursor.isNull(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN));
    mCheckin.setVisibility(mAttendeeCheckedIn ? View.VISIBLE : View.INVISIBLE);
    mActionCheck.setImageResource(mAttendeeCheckedIn ?
            R.drawable.ic_check_green : R.drawable.ic_check_gray);
    boolean modified = 0 != cursor.getInt(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN_MODIFIED));
    mSyncInProcess.setVisibility(modified && BuildConfig.DEBUG ?
            View.VISIBLE : View.INVISIBLE);
    mActions.setVisibility(View.GONE);
    itemView.setOnClickListener(this);
    mActionCheck.setOnClickListener(this);
    mActionEdit.setOnClickListener(this);
    // Icon
    ImageLoader.ImageContainer container = (ImageLoader.ImageContainer)
            mIcon.getTag();
    if (container != null) {
        container.cancelRequest();
    }
    int columnIndexImageUrl = cursor.getColumnIndexOrThrow(Table.Attendee.IMAGE_URL);
    if (!cursor.isNull(columnIndexImageUrl)) {
        mIcon.setTag(imageLoader.get(cursor.getString(columnIndexImageUrl),
                new RoundedImageListener(mIcon,
                        R.drawable.ic_person, R.drawable.ic_person)));
    } else {
        mIcon.setImageResource(R.drawable.ic_person);
    }
}
 
Example #24
Source File: MyVolley.java    From android_volley_examples with Apache License 2.0 5 votes vote down vote up
/**
 * Returns instance of ImageLoader initialized with {@see FakeImageCache} which effectively means
 * that no memory caching is used. This is useful for images that you know that will be show
 * only once.
 * 
 * @return
 */
public static ImageLoader getImageLoader() {
    if (mImageLoader != null) {
        return mImageLoader;
    } else {
        throw new IllegalStateException("ImageLoader not initialized");
    }
}
 
Example #25
Source File: RoundedImageListener.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
    if (response.getBitmap() != null) {
        Bitmap src = response.getBitmap();
        RoundedBitmapDrawable avatar = RoundedBitmapDrawableFactory.create(
                mImageView.getResources(), src);
        avatar.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
        mImageView.setImageDrawable(avatar);
    } else if (mDefaultImageResId != 0) {
        mImageView.setImageResource(mDefaultImageResId);
    }
}
 
Example #26
Source File: ListItemRecyclerViewHolder.java    From recyclerViewToTheRescue with MIT License 5 votes vote down vote up
public ListItemRecyclerViewHolder(View itemView, ImageLoader imageLoader, StringProvider stringProvider) {
    super(itemView);
    recyclerView = (RecyclerView)itemView.findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.HORIZONTAL, false));
    this.imageLoader = imageLoader;
    this.stringProvider = stringProvider;
}
 
Example #27
Source File: ApplicationTest.java    From soas with Apache License 2.0 5 votes vote down vote up
@SmallTest
public void testRequestQueuesCreation() throws Exception {
    RequestQueue requestQueue = SoasApplication.getRequestQueue(getContext());
    assertNotNull(requestQueue);

    ImageLoader imageLoader = SoasApplication.getImageLoader(getContext());
    assertNotNull(imageLoader);
}
 
Example #28
Source File: ListItemViewHolder.java    From recyclerViewToTheRescue with MIT License 5 votes vote down vote up
public void setImageUrl(String url, ImageLoader imageLoader) {
    if (imageView != null) {
        // Remove the old image
        imageView.setImageBitmap(null);
        imageView.setImageUrl(url, imageLoader);
    }
}
 
Example #29
Source File: FadeInNetworkImageView.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(21)
@Override
public void setImageUrl(String url, ImageLoader imageLoader) {
    mShowLocal = TextUtils.isEmpty(url);
    if (mDiskCache.get(url) == null && !OnlineAccessVerifier.check(getContext())) {
        this.setImageBitmap(null);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final ConnectivityManager cm = (ConnectivityManager)
                    getContext().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
            networkCallback = new ConnectivityManager.NetworkCallback() {
                @Override
                public void onAvailable(Network network) {
                    super.onAvailable(network);
                    new CoverArtLoader((MainActivity) FadeInNetworkImageView.this.getActivity()).execute(mLyrics);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && networkCallback != null)
                        try {
                            cm.unregisterNetworkCallback(networkCallback);
                        } catch (IllegalArgumentException ignored) {
                        }
                }
            };
            NetworkRequest request = new NetworkRequest.Builder()
                    .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
            cm.registerNetworkCallback(request, networkCallback);
        }
        defaultShown = true;
    } else {
        super.setImageUrl(url, imageLoader);
        if (!TextUtils.isEmpty(url))
            defaultShown = false;
    }
}
 
Example #30
Source File: MyVolley.java    From android_volley_examples with Apache License 2.0 5 votes vote down vote up
static void init(Context context) {
    mRequestQueue = Volley.newRequestQueue(context);

    int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
            .getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    int cacheSize = 1024 * 1024 * memClass / 8;
    mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(cacheSize));
}