コード例 #1
0
 private void loadWebView() {
   frescoImage.setVisibility(View.GONE);
   image.setVisibility(View.GONE);
   webView.setVisibility(View.VISIBLE);
   webView.loadUrl(gifArray[index]);
   // TODO: test this from file as well
 }
コード例 #2
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = _inflater.inflate(R.layout.fragment_main_item, null);
      Story s = lists.get(position);
      if (s != null) {
        TextView item_title = (TextView) view.findViewById(R.id.item_title);
        item_title.setText(s.getTitle());
        SimpleDraweeView draweeView = (SimpleDraweeView) view.findViewById(R.id.item_image);
        List<String> imgs = s.getImages();
        if (imgs != null && imgs.size() > 0) {
          Uri uri = Uri.parse(imgs.get(0));
          draweeView.setImageURI(uri);
        } else {
          draweeView.setVisibility(View.GONE);
        }
        view.setOnClickListener(new onItemClickListener(s.getId()));
      }

      return view;
    }
コード例 #3
0
  public void onClearCacheClick(View view) {
    next();

    image.setImageResource(android.R.color.white);
    webView.loadUrl(""); // so that previous image would not show on next load
    webView.setVisibility(View.GONE);
    frescoImage.setVisibility(View.GONE);
    image.setVisibility(View.VISIBLE);

    webCheck.setChecked(false);
    glideCheck.setChecked(false);
    frescoCheck.setChecked(false);
    text.setText("Clearing cache");

    imageUtil.clearCache(
        new Runnable() {
          @Override
          public void run() {
            Toast.makeText(GifActivity.this, "CacheCleared", Toast.LENGTH_SHORT).show();
            text.setText("Select service");
          }
        });
  }
コード例 #4
0
  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;
    }
  }