com.facebook.drawee.controller.BaseControllerListener Java Examples

The following examples show how to use com.facebook.drawee.controller.BaseControllerListener. 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: SplashActivity.java    From RunMap with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    GradleButterKnife.bind(this);
    Uri uri = Uri.parse("asset:///splash.webp");
    mSplashPresenter = new SplashPresenterImpl(this);
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setUri(uri)
            .setAutoPlayAnimations(true)
            .setControllerListener(new BaseControllerListener<ImageInfo>(){
                @Override
                public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
                    super.onFinalImageSet(id, imageInfo, animatable);
                    mSplashPresenter.startCountDown(1);
                }
            })
            .build();
    splashDraweee.setController(controller);
}
 
Example #2
Source File: InstrumentedDraweeView.java    From fresco with MIT License 6 votes vote down vote up
private void init() {
  mInstrumentation = new Instrumentation(this);
  mListener =
      new BaseControllerListener<Object>() {
        @Override
        public void onSubmit(String id, Object callerContext) {
          mInstrumentation.onStart();
        }

        @Override
        public void onFinalImageSet(
            String id, @Nullable Object imageInfo, @Nullable Animatable animatable) {
          mInstrumentation.onSuccess();
        }

        @Override
        public void onFailure(String id, Throwable throwable) {
          mInstrumentation.onFailure();
        }

        @Override
        public void onRelease(String id) {
          mInstrumentation.onCancellation();
        }
      };
}
 
Example #3
Source File: MediasAdapter.java    From meiShi with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindItemViewHolder(final ViewHolder holder, final int position) {
    MediaEntity entity = getItem(position);
    holder.mImageViewCover.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onItemClickListener.onItemClick(getItem(position));
        }
    });
    holder.mTextViewLikesCount.setTextImageStart(18, R.mipmap.ic_thumb_up_gray_18dp, " " + entity.getLikes_count());
    holder.mTextViewRecommendCaption.setText(entity.getCaption());

    String url = entity.getCover_pic().replace("!thumb320", "");
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setControllerListener(new BaseControllerListener<ImageInfo>() {
                @Override
                public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
                    float aspectRatio = (float)imageInfo.getWidth() / (float)imageInfo.getHeight();
                    holder.mImageViewCover.setAspectRatio(aspectRatio);
                }
            })
            .setUri(Uri.parse(url))
            .build();
    holder.mImageViewCover.setController(controller);
    AppUtils.loadSmallUserAvata(getItem(position).getUser(), holder.mImageViewAvatar);
}
 
Example #4
Source File: ViewPagerActivity.java    From PhotoDraweeView with Apache License 2.0 6 votes vote down vote up
@Override public Object instantiateItem(ViewGroup viewGroup, int position) {
    final PhotoDraweeView photoDraweeView = new PhotoDraweeView(viewGroup.getContext());
    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
    controller.setUri(Uri.parse("res:///" + mDrawables[position]));
    controller.setOldController(photoDraweeView.getController());
    controller.setControllerListener(new BaseControllerListener<ImageInfo>() {
        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
            super.onFinalImageSet(id, imageInfo, animatable);
            if (imageInfo == null) {
                return;
            }
            photoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight());
        }
    });
    photoDraweeView.setController(controller.build());

    try {
        viewGroup.addView(photoDraweeView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return photoDraweeView;
}
 
Example #5
Source File: PhotoShowActivity.java    From Elephant with Apache License 2.0 6 votes vote down vote up
@Override
public void initLoad() {
    super.initLoad();

    if (!TextUtils.isEmpty(mImageUrl)) {
        PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        controller.setUri(mImageUrl);
        controller.setOldController(mPhotoIv.getController());
        controller.setControllerListener(new BaseControllerListener<ImageInfo>() {
            @Override
            public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
                super.onFinalImageSet(id, imageInfo, animatable);
                if (imageInfo == null || mPhotoIv == null) {
                    return;
                }
                mPhotoIv.update(imageInfo.getWidth(), imageInfo.getHeight());
            }
        });
        mPhotoIv.setController(controller.build());
    }
}
 
Example #6
Source File: GalleryActivity.java    From phphub-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String imageUrl = getIntent().getStringExtra(IMAGE_URL);
    if (!TextUtils.isEmpty(imageUrl)) {
        PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder();
        builder.setUri(Uri.parse(imageUrl));
        builder.setOldController(photoView.getController());
        builder.setControllerListener(new BaseControllerListener<ImageInfo>() {
            @Override
            public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
                super.onFinalImageSet(id, imageInfo, animatable);
                if (imageInfo == null || photoView == null) {
                    return;
                }
                photoView.update(imageInfo.getWidth(), imageInfo.getHeight());
            }
        });
        photoView.setController(builder.build());
    }
}
 
Example #7
Source File: ImageViewerAdapter.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
private BaseControllerListener<ImageInfo>
getDraweeControllerListener(final ZoomableDraweeView drawee) {
	return new BaseControllerListener<ImageInfo>() {
		@Override
		public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
			super.onFinalImageSet(id, imageInfo, animatable);
			if (imageInfo == null) {
				return;
			}
			drawee.update(imageInfo.getWidth(), imageInfo.getHeight());
		}
	};
}
 
Example #8
Source File: InstrumentedDraweeView.java    From fresco with MIT License 5 votes vote down vote up
private void init() {
  mInstrumentation = new Instrumentation(this);
  if (mConfig.instrumentationEnabled) {
    mListener =
        new BaseControllerListener<Object>() {
          @Override
          public void onSubmit(String id, Object callerContext) {
            mInstrumentation.onStart();
          }

          @Override
          public void onFinalImageSet(
              String id, @Nullable Object imageInfo, @Nullable Animatable animatable) {
            mInstrumentation.onSuccess();
          }

          @Override
          public void onFailure(String id, Throwable throwable) {
            mInstrumentation.onFailure();
          }

          @Override
          public void onRelease(String id) {
            mInstrumentation.onCancellation();
          }
        };
  }
  DraweeUtil.setBgColor(this, mConfig);
}
 
Example #9
Source File: PostItemImageView.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
private ControllerListener<? super ImageInfo> getControllerListener() {
    ControllerListener controllerListener = new BaseControllerListener<ImageInfo>(){

        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
            imageLoaded = true;
        }

    };
    return controllerListener;
}
 
Example #10
Source File: UniversalDraweeView.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
private void loadImageURI(Uri uri, @Nullable Object callerContext, int width, int height) {
    // 对URL做格式转换、尺寸限制等处理
    uri = Uri.parse(ImageUtils.format(uri.toString(), DisplayInfo.getWidthPixels()));

    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
    imageRequestBuilder.setProgressiveRenderingEnabled(true);

    imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
    if (width > 0 && height > 0) {
        imageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
    }

    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder()
            .setCallerContext(callerContext)
            .setImageRequest(imageRequestBuilder.build())
            .setOldController(getController())
            .setAutoPlayAnimations(true)  // 自动播放动态图
            .setTapToRetryEnabled(true)  // 在加载失败时,可以点击重新加载
            .setControllerListener(new BaseControllerListener<ImageInfo>() {
                @Override
                public void onFinalImageSet(String id,
                                            ImageInfo imageInfo,
                                            Animatable animatable) {
                    super.onFinalImageSet(id, imageInfo, animatable);
                    onUpdateImage(imageInfo);
                }
            });
    if (AppUtils.isMainThread()) {
        setController(controller.build());
    } else {
        Observable.just(0)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(it -> setController(controller.build()));
    }
}
 
Example #11
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
  if (!shouldNotify) {
    mControllerListener = null;
  } else {
    final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher();

    mControllerListener = new BaseControllerListener<ImageInfo>() {
      @Override
      public void onSubmit(String id, Object callerContext) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START));
      }

      @Override
      public void onFinalImageSet(
        String id,
        @Nullable final ImageInfo imageInfo,
        @Nullable Animatable animatable) {
        if (imageInfo != null) {
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD,
              mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight()));
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
        }
      }

      @Override
      public void onFailure(String id, Throwable throwable) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR));
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
      }
    };
  }

  mIsDirty = true;
}
 
Example #12
Source File: PhotoHolder.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
public PhotoHolder(MessagesAdapter adapter, View itemView, Peer peer) {
    super(adapter, itemView, false);
    this.context = adapter.getMessagesFragment().getActivity();

    COLOR_PENDING = ActorSDK.sharedActor().style.getConvMediaStatePendingColor();
    COLOR_SENT = ActorSDK.sharedActor().style.getConvMediaStateSentColor();
    COLOR_RECEIVED = ActorSDK.sharedActor().style.getConvMediaStateDeliveredColor();
    COLOR_READ = ActorSDK.sharedActor().style.getConvMediaStateReadColor();
    COLOR_ERROR = ActorSDK.sharedActor().style.getConvMediaStateErrorColor();

    messageBubble = (FrameLayout) itemView.findViewById(R.id.bubbleContainer);
    overlay = itemView.findViewById(R.id.photoOverlay);

    // Content
    previewView = (SimpleDraweeView) itemView.findViewById(R.id.image);
    GenericDraweeHierarchyBuilder builder =
            new GenericDraweeHierarchyBuilder(context.getResources());

    GenericDraweeHierarchy hierarchy = builder
            .setFadeDuration(200)
            .setRoundingParams(new RoundingParams()
                    .setCornersRadius(Screen.dp(2))
                    .setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY))
            .build();
    previewView.setHierarchy(hierarchy);

    animationController = new BaseControllerListener<ImageInfo>() {
        @Override
        public void onFinalImageSet(
                String id,
                ImageInfo imageInfo,
                Animatable anim) {
            PhotoHolder.this.anim = anim;
            playAnimation();
        }
    };

    fastThumbLoader = new FastThumbLoader(previewView);
    time = (TextView) itemView.findViewById(R.id.time);
    duration = (TextView) itemView.findViewById(R.id.duration);

    stateIcon = (TintImageView) itemView.findViewById(R.id.stateIcon);

    progressContainer = itemView.findViewById(R.id.progressBg);
    progressValue = (TextView) itemView.findViewById(R.id.progressValue);
    progressValue.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    progressView = (CircularView) itemView.findViewById(R.id.progressView);
    progressView.setColor(Color.WHITE);
    progressIcon = (ImageView) itemView.findViewById(R.id.contentIcon);
    onConfigureViewHolder();
}
 
Example #13
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 3 votes vote down vote up
/**
 *  If the image has some ResizeOptions we put also the resized image into the cache with different key.
 *  currently don't support downsampling / resizing for GIFs.
 * @param url
 * @param draweeView
 * @param processor
 * @param width
 * @param height
 * @param listener
 */
public static void loadUrl(String url, SimpleDraweeView draweeView, BasePostprocessor processor, int width, int height,
                           BaseControllerListener listener){

    url = append(url);
   load(Uri.parse(url),draweeView,processor,width,height,listener);

}
 
Example #14
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 2 votes vote down vote up
public static void loadFile(File file, SimpleDraweeView draweeView,BasePostprocessor processor,int width,int height,
                            BaseControllerListener listener){

    load(getFileUri(file),draweeView,processor,width,height,listener);

}
 
Example #15
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 2 votes vote down vote up
public static void loadRes(int resId, SimpleDraweeView draweeView,BasePostprocessor processor,int width,int height,
                            BaseControllerListener listener){

    load(getResUri(resId),draweeView,processor,width,height,listener);

}
 
Example #16
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 2 votes vote down vote up
public static void loadFile(String file, SimpleDraweeView draweeView,BasePostprocessor processor,int width,int height,
                           BaseControllerListener listener){

    load(getFileUri(file),draweeView,processor,width,height,listener);

}
 
Example #17
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 2 votes vote down vote up
public static void loadRes(int resId, SimpleDraweeView draweeView, BasePostprocessor processor, int width, int height,
                           BaseControllerListener listener){

    load(getResUri(resId),draweeView,processor,width,height,listener);

}
 
Example #18
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 2 votes vote down vote up
public static void loadFile(File file, SimpleDraweeView draweeView, BasePostprocessor processor, int width, int height,
                            BaseControllerListener listener){

    load(getFileUri(file),draweeView,processor,width,height,listener);

}
 
Example #19
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 2 votes vote down vote up
public static void loadFile(String file, SimpleDraweeView draweeView, BasePostprocessor processor, int width, int height,
                            BaseControllerListener listener){

    load(getFileUri(file),draweeView,processor,width,height,listener);

}
 
Example #20
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 1 votes vote down vote up
/**
 *  If the image has some ResizeOptions we put also the resized image into the cache with different key.
 *  currently don't support downsampling / resizing for GIFs.
 * @param url
 * @param draweeView
 * @param processor
 * @param width
 * @param height
 * @param listener
 */
public static void loadUrl(String url, SimpleDraweeView draweeView,BasePostprocessor processor,int width,int height,
                           BaseControllerListener listener){

   load(Uri.parse(url),draweeView,processor,width,height,listener);

}