Esempio n. 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // GIF
    final ViewGroup gifControls = (ViewGroup) findViewById(R.id.gif_controls);
    updateAnimationControls(gifControls, null);

    mAnimatedGifView = (SimpleDraweeView) findViewById(R.id.animated_gif);
    Uri animatedGifUri =
        Uri.parse("http://s3.amazonaws.com/giphygifs/media/4aBQ9oNjgEQ2k/giphy.gif");

    final TextView gifInfo = (TextView) findViewById(R.id.gif_info);

    DraweeController gifController =
        Fresco.newDraweeControllerBuilder()
            .setUri(animatedGifUri)
            .setControllerListener(
                new BaseControllerListener<ImageInfo>() {
                  @Override
                  public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) {
                    updateAnimationControls(gifControls, anim);
                    gifInfo.setText(getAnimationInformation(anim));
                  }
                })
            .build();
    mAnimatedGifView.setController(gifController);

    // Animated WebP
    final ViewGroup webpControls = (ViewGroup) findViewById(R.id.webp_controls);
    updateAnimationControls(webpControls, null);

    mAnimatedWebpView = (SimpleDraweeView) findViewById(R.id.animated_webp);
    final TextView webpInfo = (TextView) findViewById(R.id.webp_info);

    Uri animatedWebpUri = Uri.parse("http://www.gstatic.com/webp/animated/1.webp");
    DraweeController webpController =
        Fresco.newDraweeControllerBuilder()
            .setUri(animatedWebpUri)
            .setControllerListener(
                new BaseControllerListener<ImageInfo>() {
                  @Override
                  public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) {
                    updateAnimationControls(webpControls, anim);
                    webpInfo.setText(getAnimationInformation(anim));
                  }
                })
            .build();
    mAnimatedWebpView.setController(webpController);
  }
  @Override
  public void onDataOk(String url, String data) {
    switch (url) {
      case Api.URL_HOME:
        Home home = JsonUtil.getEntity(data, Home.class);
        if (home == null) {
          return;
        }
        homeContent.setVisibility(View.VISIBLE);

        // 标题,如 VOL.1997
        sayingTitle.setText(home.strHpTitle);
        // 照片名称及作者简介
        textIllustrationAuthor.setText(home.strAuthor.replace("&", "\n"));
        // 日
        textDay.setText(TimeUtil.getDay(home.strMarketTime));
        // 月、年
        textMonth.setText(TimeUtil.getMonthAndYear(home.strMarketTime));
        // 内容
        textSaying.setText(home.strContent);
        // 喜欢的数量
        like_Saying.setText(home.strPn);
        // 插画

        ControllerListener controllerListener =
            new BaseControllerListener<ImageInfo>() {
              @Override
              public void onFailure(String id, Throwable throwable) {
                super.onFailure(id, throwable);
                TextToast.shortShow("加载失败:" + throwable.toString());
              }

              @Override
              public void onIntermediateImageSet(String id, ImageInfo imageInfo) {
                super.onIntermediateImageSet(id, imageInfo);
              }

              @Override
              public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
                super.onFinalImageSet(id, imageInfo, animatable);
                if (imageInfo == null) {
                  return;
                }
                float rate = (float) imageInfo.getWidth() / (float) imageInfo.getHeight();
                dvIllustrator.setAspectRatio(rate);
              }
            };
        DraweeController controller =
            Fresco.newDraweeControllerBuilder()
                .setUri(Uri.parse(home.strThumbnailUrl))
                .setControllerListener(controllerListener)
                .build();
        dvIllustrator.setController(controller);
        break;
    }
  }
Esempio n. 3
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_gif);
   mImageView = (SimpleDraweeView) findViewById(R.id.gifview);
   DraweeController controller =
       Fresco.newDraweeControllerBuilder()
           .setUri(Uri.parse(url))
           .setAutoPlayAnimations(true)
           .build();
   mImageView.setController(controller);
 }
Esempio n. 4
0
  private LDraweeView setControllerByType(final Uri uri, final String type) {
    uriPathTag = uri.toString();
    this.setImageFormat(uriPathTag);
    if (noRepeatLoadImage(uriPathTag)) {

      if ("NORMAL".equals(type)) {
        setHierarchy();
      } else if ("ROUND".equals(type)) {
        //                setRoundHierarchy();
      }

      final AbstractDraweeController controller =
          Fresco.newDraweeControllerBuilder()
              .setAutoPlayAnimations(this.getAutoPlayAnimations()) // 自动播放图片动画
              .setControllerListener(this.getControllerListener())
              .setImageRequest(getImageRequest(this, uri))
              .setOldController(this.getController())
              .build();
      super.setController(controller);
    }
    return this;
  }
  private void loadGif(ImageServiceProvider provider) {
    loadingSpinner.setVisibility(View.VISIBLE);
    webView.setVisibility(View.GONE);
    image.setImageResource(android.R.color.white);
    text.setText("Loading GIF with: " + provider.toString());

    QLog.d(TAG, "Start GIF load: %s", gifArray[index]);
    final long start = System.currentTimeMillis();

    switch (provider) {
      default:
      case GLIDE:
        frescoImage.setVisibility(View.GONE);
        image.setVisibility(View.VISIBLE);
        Glide.with(this)
            .load(gifArray[index])
            .asGif()
            .crossFade()
            .listener(
                new RequestListener<String, GifDrawable>() {

                  @Override
                  public boolean onException(
                      Exception e,
                      String model,
                      Target<GifDrawable> target,
                      boolean isFirstResource) {
                    QLog.e(e, TAG, "Glide onException");

                    loadingSpinner.setVisibility(View.GONE);
                    text.setText("Glide load error");
                    return false;
                  }

                  @Override
                  public boolean onResourceReady(
                      GifDrawable resource,
                      String model,
                      Target<GifDrawable> target,
                      boolean isFromMemoryCache,
                      boolean isFirstResource) {
                    int time = (int) (System.currentTimeMillis() - start);
                    QLog.i(TAG, "Glide image load ready in[%dms]", time);

                    loadingSpinner.setVisibility(View.GONE);
                    text.setText(String.format("Glide image ready in[%dms]", time));
                    return false;
                  }
                })
            .into(image);
        break;
      case FRESCO:
        frescoImage.setVisibility(View.VISIBLE);
        image.setVisibility(View.GONE);

        ControllerListener listener =
            new BaseControllerListener<ImageInfo>() {

              @Override
              public void onFailure(String id, Throwable throwable) {
                super.onFailure(id, throwable);
                QLog.w(throwable, TAG, "Fresco onFailure");
                loadingSpinner.setVisibility(View.GONE);
                text.setText("Fresco onFailure");
              }

              @Override
              public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
                super.onFinalImageSet(id, imageInfo, animatable);
                int time = (int) (System.currentTimeMillis() - start);
                QLog.i(TAG, "Fresco image load ready in[%dms]", time);

                loadingSpinner.setVisibility(View.GONE);
                text.setText(String.format("Fresco image ready in[%dms]", time));
              }
            };

        Uri uri = Uri.parse(gifArray[index]);
        DraweeController controller =
            Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setControllerListener(listener)
                .setAutoPlayAnimations(true)
                .build();
        frescoImage.setController(controller);
        break;
    }
  }