@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawee_transition_detail); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } SimpleDraweeView simpleDraweeView = (SimpleDraweeView) findViewById(R.id.image); simpleDraweeView.setImageURI(getIntent().getData()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setSharedElementEnterTransition(DraweeTransition.createTransitionSet( ScalingUtils.ScaleType.CENTER_CROP, ScalingUtils.ScaleType.FIT_CENTER)); getWindow().setSharedElementReturnTransition(DraweeTransition.createTransitionSet( ScalingUtils.ScaleType.FIT_CENTER, ScalingUtils.ScaleType.CENTER_CROP)); } }
private void displayImage(SimpleDraweeView draweeView, String url) { GenericDraweeHierarchy hierarchy = draweeView.getHierarchy(); //设置占位图 if (hierarchy == null) { hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()) .setPlaceholderImage(getResources().getDrawable(R.mipmap.ic_launcher) , ScalingUtils.ScaleType.CENTER).build(); draweeView.setHierarchy(hierarchy); } else { hierarchy.setPlaceholderImage(getResources().getDrawable(R.mipmap.ic_launcher) , ScalingUtils.ScaleType.CENTER); } //构建ImageRequestBuilder,传入请求Uri ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)); //构建Controller DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeView.getController()) .setImageRequest(requestBuilder.build()) .build(); //设置图片,Fresco设置显示图片都是通过Controller来实现 draweeView.setController(controller); }
private static ScalingUtils.ScaleType convertToFrescoScaleType(ImageView.ScaleType scaleType, ScalingUtils.ScaleType defaultScaleType) { switch (scaleType) { case CENTER: return ScalingUtils.ScaleType.CENTER; case CENTER_CROP: return ScalingUtils.ScaleType.CENTER_CROP; case CENTER_INSIDE: return ScalingUtils.ScaleType.CENTER_INSIDE; case FIT_CENTER: return ScalingUtils.ScaleType.FIT_CENTER; case FIT_START: return ScalingUtils.ScaleType.FIT_START; case FIT_END: return ScalingUtils.ScaleType.FIT_END; case FIT_XY: return ScalingUtils.ScaleType.FIT_XY; case MATRIX: //NOTE this case //you should set FocusPoint to make sentence return ScalingUtils.ScaleType.FOCUS_CROP; default: return defaultScaleType; } }
private ViewGroup generateImageLayout() { SquareDraweeView imageView = new SquareDraweeView(mContext); GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(mContext.getResources()); GenericDraweeHierarchy hierarchy = builder .setFadeDuration(300).setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) .build(); if (mPlaceholderImageResId > 0) { hierarchy.setPlaceholderImage(mPlaceholderImageResId); } if (mFailureImageResId > 0) { hierarchy.setFailureImage(mFailureImageResId); } imageView.setHierarchy(hierarchy); RelativeLayout.LayoutParams imgLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); imgLp.setMargins(mImageBorderThickness, mImageBorderThickness, mImageBorderThickness, mImageBorderThickness); RelativeLayout mainLayout = new RelativeLayout(mContext); mainLayout.setBackgroundColor(mImageBorderColor); mainLayout.addView(imageView, imgLp); return mainLayout; }
public Attacher(DraweeView<GenericDraweeHierarchy> draweeView) { mDraweeView = new WeakReference<>(draweeView); draweeView.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER); draweeView.setOnTouchListener(this); mScaleDragDetector = new ScaleDragDetector(draweeView.getContext(), this); mGestureDetector = new GestureDetectorCompat(draweeView.getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent e) { super.onLongPress(e); if (null != mLongClickListener) { mLongClickListener.onLongClick(getDraweeView()); } } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); }
private SimpleDraweeView createSimpleDraweeView() { SimpleDraweeView view = new SimpleDraweeView(itemView.getContext()); GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(itemView.getContext().getResources()); GenericDraweeHierarchy hierarchy = builder .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) .setPlaceholderImage(R.color.loading_color) .setPlaceholderImageScaleType(ScalingUtils.ScaleType.FIT_CENTER) .setFailureImage(R.mipmap.ic_failed) .setFailureImageScaleType(ScalingUtils.ScaleType.CENTER) .build(); view.setHierarchy(hierarchy); view.setTag(atomicInteger.getAndIncrement()); view.setOnClickListener(this); return view; }
/** * Converts JS resize modes into {@code ScalingUtils.ScaleType}. * See {@code ImageResizeMode.js}. */ public static ScalingUtils.ScaleType toScaleType(@Nullable String resizeModeValue) { if ("contain".equals(resizeModeValue)) { return ScalingUtils.ScaleType.FIT_CENTER; } if ("cover".equals(resizeModeValue)) { return ScalingUtils.ScaleType.CENTER_CROP; } if ("stretch".equals(resizeModeValue)) { return ScalingUtils.ScaleType.FIT_XY; } if ("center".equals(resizeModeValue)) { return ScalingUtils.ScaleType.CENTER_INSIDE; } if (resizeModeValue == null) { // Use the default. Never use null. return defaultValue(); } throw new JSApplicationIllegalArgumentException( "Invalid resize mode: '" + resizeModeValue + "'"); }
@Test public void testImageResizeMode() { assertThat(ImageResizeMode.toScaleType(null)) .isEqualTo(ScalingUtils.ScaleType.CENTER_CROP); assertThat(ImageResizeMode.toScaleType("contain")) .isEqualTo(ScalingUtils.ScaleType.FIT_CENTER); assertThat(ImageResizeMode.toScaleType("cover")) .isEqualTo(ScalingUtils.ScaleType.CENTER_CROP); assertThat(ImageResizeMode.toScaleType("stretch")) .isEqualTo(ScalingUtils.ScaleType.FIT_XY); assertThat(ImageResizeMode.toScaleType("center")) .isEqualTo(ScalingUtils.ScaleType.CENTER_INSIDE); // No resizeMode set assertThat(ImageResizeMode.defaultValue()) .isEqualTo(ScalingUtils.ScaleType.CENTER_CROP); }
/** * Converts JS resize modes into {@code ScalingUtils.ScaleType}. * See {@code ImageResizeMode.js}. */ public static ScalingUtils.ScaleType toScaleType(@Nullable String resizeModeValue) { if ("contain".equals(resizeModeValue)) { return ScalingUtils.ScaleType.CENTER_INSIDE; } if ("cover".equals(resizeModeValue)) { return ScalingUtils.ScaleType.CENTER_CROP; } if ("stretch".equals(resizeModeValue)) { return ScalingUtils.ScaleType.FIT_XY; } if (resizeModeValue == null) { // Use the default. Never use null. return defaultValue(); } throw new JSApplicationIllegalArgumentException( "Invalid resize mode: '" + resizeModeValue + "'"); }
@Test public void testImageResizeMode() { assertThat(ImageResizeMode.toScaleType(null)) .isEqualTo(ScalingUtils.ScaleType.CENTER_CROP); assertThat(ImageResizeMode.toScaleType("contain")) .isEqualTo(ScalingUtils.ScaleType.CENTER_INSIDE); assertThat(ImageResizeMode.toScaleType("cover")) .isEqualTo(ScalingUtils.ScaleType.CENTER_CROP); assertThat(ImageResizeMode.toScaleType("stretch")) .isEqualTo(ScalingUtils.ScaleType.FIT_XY); // No resizeMode set assertThat(ImageResizeMode.defaultValue()) .isEqualTo(ScalingUtils.ScaleType.CENTER_CROP); }
public void loadImage(String url,String lowurl, int placeHolderResId, int errorResId,ScalingUtils.ScaleType scaleType){ final boolean isHttp = url.startsWith("http"); Uri uri = isHttp ? Uri.parse(url) : Uri.fromFile(new File(url)); PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder() .setImageRequest(ImageRequest.fromUri(uri)); if(lowurl!=null && lowurl.startsWith("http")) { controller .setLowResImageRequest(ImageRequest.fromUri(lowurl)); } getHierarchy().setActualImageScaleType(scaleType); // controller.setUri(URI); getHierarchy().setPlaceholderImage(getResources().getDrawable( placeHolderResId ),scaleType); getHierarchy().setFailureImage(getResources().getDrawable(errorResId),scaleType); controller.setOldController(this.getController()) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { if (imageInfo == null) { return; } PhotoDraweeView.this.update(imageInfo.getWidth(), imageInfo.getHeight()); } }); this.setController(controller.build()); }
void getRadii(Bitmap source, float[] computedCornerRadii, float[] mappedRadii) { ScalingUtils.getTransform( sMatrix, new Rect(0, 0, source.getWidth(), source.getHeight()), source.getWidth(), source.getHeight(), 0.0f, 0.0f, mScaleType); sMatrix.invert(sInverse); mappedRadii[0] = sInverse.mapRadius(computedCornerRadii[0]); mappedRadii[1] = mappedRadii[0]; mappedRadii[2] = sInverse.mapRadius(computedCornerRadii[1]); mappedRadii[3] = mappedRadii[2]; mappedRadii[4] = sInverse.mapRadius(computedCornerRadii[2]); mappedRadii[5] = mappedRadii[4]; mappedRadii[6] = sInverse.mapRadius(computedCornerRadii[3]); mappedRadii[7] = mappedRadii[6]; }
@Override public View showThumbnail(BigImageView parent, Uri thumbnail, int scaleType) { SimpleDraweeView thumbnailView = (SimpleDraweeView) LayoutInflater.from(parent.getContext()) .inflate(R.layout.ui_fresco_thumbnail, parent, false); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(thumbnail) .build(); switch (scaleType) { case BigImageView.INIT_SCALE_TYPE_CENTER_CROP: thumbnailView.getHierarchy() .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP); break; case BigImageView.INIT_SCALE_TYPE_CENTER_INSIDE: thumbnailView.getHierarchy() .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE); break; case BigImageView.INIT_SCALE_TYPE_START: thumbnailView.getHierarchy() .setActualImageScaleType(ScalingUtils.ScaleType.FIT_START); break; default: break; } thumbnailView.setController(controller); return thumbnailView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_image); final SimpleDraweeView mImageView = (SimpleDraweeView) findViewById(R.id.view_image_image); final int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()) .setFadeDuration(shortAnimTime) .setProgressBarImage(new ImageLoadingDrawable(getResources())) .setFailureImage(getResources().getDrawable(R.drawable.ic_upload_failed), ScalingUtils.ScaleType.CENTER_INSIDE) .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER) .build(); mImageView.setHierarchy(hierarchy); mImageView.setImageURI(getIntent().getParcelableExtra(EXTRA_IMAGE_URI)); }
@Override public Object instantiateItem(ViewGroup container, int position) { ZoomableDraweeView view = new ZoomableDraweeView(container.getContext()); view.setController( Fresco.newDraweeControllerBuilder() .setUri(Uri.parse(items[position])) .build()); GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(container.getResources()) .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER) .setProgressBarImage(new ProgressBarDrawable()) .build(); view.setHierarchy(hierarchy); container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); return view; }
private void init() { if (isInEditMode()) { return; } GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); builder.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP); builder.setOverlay(new CoverOverlayDrawable(getContext())); if (ActorSDK.sharedActor().style.getAvatarBackgroundResourse() != 0) { builder.setPlaceholderImage(getResources() .getDrawable(ActorSDK.sharedActor().style.getAvatarBackgroundResourse()), ScalingUtils.ScaleType.CENTER_CROP); } else { builder.setPlaceholderImage(new ColorDrawable( ActorSDK.sharedActor().style.getAvatarBackgroundColor())); } builder.setFadeDuration(0); setHierarchy(builder.build()); }
private void init() { if (isInEditMode()) { return; } GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); GenericDraweeHierarchy hierarchy = builder .setFadeDuration(160) .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) // .setBackground(getResources().getDrawable(R.drawable.img_profile_avatar_default)) .setOverlay(new CoverOverlayDrawable(getContext())) .build(); setHierarchy(hierarchy); }
private void setup(Context context, AttributeSet attrs, int defStyle) { if (getScaleType() == ScaleType.FIT_CENTER) { setScaleType(ScaleType.CENTER_CROP); } Drawable placeholder = null; if (attrs != null) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShapedDrawee, defStyle, 0); shape = typedArray.getDrawable(R.styleable.ShapedDrawee_maskShape); placeholder = typedArray.getDrawable(R.styleable.ShapedDrawee_placeholder); typedArray.recycle(); } if (shape == null) { throw new IllegalArgumentException("maskShape must be specified in layout!"); } GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()).setPlaceholderImage(placeholder) .setPlaceholderImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) .build(); mDraweeHolder = DraweeHolder.create(hierarchy, getContext()); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_gallery_item, container, false); progressBar = rootView.findViewById(R.id.gallery_item_progress_bar); videoContainer = rootView.findViewById(R.id.gallery_video_container); videoView = rootView.findViewById(R.id.gallery_video); videoThumbnail = rootView.findViewById(R.id.gallery_video_thumbnail); videoPlayButton = rootView.findViewById(R.id.gallery_video_play_button); imageView = rootView.findViewById(R.id.gallery_image); imageView.setTapListener(new DoubleTapGestureListener(imageView) { @Override public boolean onSingleTapConfirmed(MotionEvent e) { parentActivity.toggleControls(); return true; } }); GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()) .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER) .build(); imageView.setHierarchy(hierarchy); return rootView; }
private void maybeUpdateDebugOverlay(@Nullable CloseableImage image) { if (!mDrawDebugOverlay) { return; } Drawable controllerOverlay = getControllerOverlay(); if (controllerOverlay == null) { controllerOverlay = new DebugControllerOverlayDrawable(); setControllerOverlay(controllerOverlay); } if (controllerOverlay instanceof DebugControllerOverlayDrawable) { DebugControllerOverlayDrawable debugOverlay = (DebugControllerOverlayDrawable) controllerOverlay; debugOverlay.setControllerId(getId()); final DraweeHierarchy draweeHierarchy = getHierarchy(); ScaleType scaleType = null; if (draweeHierarchy != null) { final ScaleTypeDrawable scaleTypeDrawable = ScalingUtils.getActiveScaleTypeDrawable(draweeHierarchy.getTopLevelDrawable()); scaleType = scaleTypeDrawable != null ? scaleTypeDrawable.getScaleType() : null; } debugOverlay.setScaleType(scaleType); if (image != null) { debugOverlay.setDimensions(image.getWidth(), image.getHeight()); debugOverlay.setImageSize(image.getSizeInBytes()); } else { debugOverlay.reset(); } } }
public static TransitionSet createTransitionSet( ScalingUtils.ScaleType fromScale, ScalingUtils.ScaleType toScale) { TransitionSet transitionSet = new TransitionSet(); transitionSet.addTransition(new ChangeBounds()); transitionSet.addTransition(new DraweeTransition(fromScale, toScale)); return transitionSet; }
@Test public void testOverlayWhenScaleTypeFitCenter() { helper.assertOverlayColorOk(100, 100, 100, 100, ScalingUtils.ScaleType.FIT_CENTER); helper.assertOverlayColorOk(100, 100, 1000, 100, ScalingUtils.ScaleType.FIT_CENTER); helper.assertOverlayColorOk(100, 100, 100, 1000, ScalingUtils.ScaleType.FIT_CENTER); helper.assertOverlayColorNotOk(100, 100, 1000, 1000, ScalingUtils.ScaleType.FIT_CENTER); helper.assertOverlayColorNotOk(100, 100, 10, 10, ScalingUtils.ScaleType.FIT_CENTER); }
@Test public void testOverlayWhenScaleTypeFitXY() { helper.assertOverlayColorOk(100, 100, 100, 100, ScalingUtils.ScaleType.FIT_XY); helper.assertOverlayColorNotOk(100, 100, 1000, 100, ScalingUtils.ScaleType.FIT_XY); helper.assertOverlayColorNotOk(100, 100, 100, 1000, ScalingUtils.ScaleType.FIT_XY); helper.assertOverlayColorNotOk(100, 100, 1000, 1000, ScalingUtils.ScaleType.FIT_XY); helper.assertOverlayColorNotOk(100, 100, 10, 10, ScalingUtils.ScaleType.FIT_XY); }
@Test public void testOverlayWhenScaleTypeCenter() { helper.assertOverlayColorOk(100, 100, 100, 100, ScalingUtils.ScaleType.CENTER); helper.assertOverlayColorOk(100, 100, 1000, 100, ScalingUtils.ScaleType.CENTER); helper.assertOverlayColorOk(100, 100, 100, 1000, ScalingUtils.ScaleType.CENTER); helper.assertOverlayColorOk(100, 100, 1000, 1000, ScalingUtils.ScaleType.CENTER); helper.assertOverlayColorNotOk(100, 100, 10, 10, ScalingUtils.ScaleType.CENTER); }