コード例 #1
0
  private static RequestQueue newRequestQueue(Context context, ImageCacheParams imageCacheParams) {

    Network network =
        new BasicNetwork(
            Utils.hasHoneycomb()
                ? new HurlStack()
                : new HttpClientStack(
                    AndroidHttpClient.newInstance(NetUtils.getUserAgent(context))));

    Cache cache;
    if (null != imageCacheParams) {
      cache = new DiskLruBasedCache(imageCacheParams);
    } else {
      cache = new DiskLruBasedCache(Utils.getDiskCacheDir(context, CACHE_DIR));
    }
    RequestQueue queue = new RequestQueue(cache, network);
    queue.start();
    return queue;
  }
コード例 #2
0
  /**
   * Sets a {@link Bitmap} to an {@link ImageView} using a fade-in animation. If there is a {@link
   * Drawable} already set on the ImageView then use that as the image to fade from. Otherwise fade
   * in from a transparent Drawable.
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
  private static void setImageBitmap(
      final ImageView imageView, final Bitmap bitmap, Resources resources, boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
      // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
      // ImageView
      imageView
          .animate()
          .scaleY(0.95f)
          .scaleX(0.95f)
          .alpha(0f)
          .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
          .setListener(
              new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                  imageView.setImageBitmap(bitmap);
                  imageView
                      .animate()
                      .alpha(1f)
                      .scaleY(1f)
                      .scaleX(1f)
                      .setDuration(HALF_FADE_IN_TIME)
                      .setListener(null);
                }
              });
    } else if (fadeIn) {
      // Otherwise use a TransitionDrawable to fade in
      Drawable initialDrawable;
      if (imageView.getDrawable() != null) {
        initialDrawable = imageView.getDrawable();
      } else {
        initialDrawable = transparentDrawable;
      }
      BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
      // Use TransitionDrawable to fade in
      final TransitionDrawable td =
          new TransitionDrawable(new Drawable[] {initialDrawable, bitmapDrawable});
      imageView.setImageDrawable(td);
      td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
      // No fade in, just set bitmap directly
      imageView.setImageBitmap(bitmap);
    }
  }