Search in sources :

Example 1 with ScaleType

use of com.facebook.drawee.drawable.ScalingUtils.ScaleType in project fresco by facebook.

the class DraweeRoundedCornersFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    findDrawees(view);
    initColors();
    final ImageUriProvider imageUriProvider = sampleUris();
    mDraweeRound.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeRadius.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeSome.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeSomeRtl.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeFancy.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    final Spinner scaleType = view.findViewById(R.id.scaleType);
    final SimpleScaleTypeAdapter scaleTypeAdapter = SimpleScaleTypeAdapter.createForAllScaleTypes();
    scaleType.setAdapter(scaleTypeAdapter);
    scaleType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final SimpleScaleTypeAdapter.Entry spinnerEntry = (SimpleScaleTypeAdapter.Entry) scaleTypeAdapter.getItem(position);
            final ScaleType scaleType = spinnerEntry.scaleType;
            changeDraweeViewScaleType(mDraweeRound, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeRadius, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeSome, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeSomeRtl, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeFancy, scaleType, spinnerEntry.focusPoint);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mShowBordersCheck = view.findViewById(R.id.borders);
    mShowBordersCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    mScaleInsideBordersCheck = view.findViewById(R.id.scaleInside);
    mScaleInsideBordersCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    mColorOverlayCheck = view.findViewById(R.id.color_overlay);
    mColorOverlayCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    mFixRepeatedEdgesCheck = view.findViewById(R.id.fix_repeated_edges);
    mFixRepeatedEdgesCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    final Resources res = getResources();
    final RoundingParams fancyRoundingParams = RoundingParams.fromCornersRadii(res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_top_left), res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_top_right), res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_bottom_right), res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_bottom_left));
    mDraweeFancy.getHierarchy().setRoundingParams(fancyRoundingParams);
}
Also used : Spinner(android.widget.Spinner) ScaleType(com.facebook.drawee.drawable.ScalingUtils.ScaleType) SimpleScaleTypeAdapter(com.facebook.fresco.samples.showcase.common.SimpleScaleTypeAdapter) ImageUriProvider(com.facebook.fresco.samples.showcase.misc.ImageUriProvider) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) AdapterView(android.widget.AdapterView) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources) CompoundButton(android.widget.CompoundButton) RoundingParams(com.facebook.drawee.generic.RoundingParams)

Example 2 with ScaleType

use of com.facebook.drawee.drawable.ScalingUtils.ScaleType in project fresco by facebook.

the class GenericDraweeHierarchyTest method testSetActualImageScaleType.

@Test
public void testSetActualImageScaleType() {
    GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage).build();
    // actual image index in DH tree
    final int imageIndex = 2;
    FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
    ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) fadeDrawable.getDrawable(imageIndex);
    ScaleType scaleType1 = ScaleType.FOCUS_CROP;
    dh.setActualImageScaleType(scaleType1);
    assertEquals(scaleType1, scaleTypeDrawable.getScaleType());
    ScaleType scaleType2 = ScaleType.CENTER;
    dh.setActualImageScaleType(scaleType2);
    assertEquals(scaleType2, scaleTypeDrawable.getScaleType());
}
Also used : ScaleType(com.facebook.drawee.drawable.ScalingUtils.ScaleType) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Test(org.junit.Test)

Example 3 with ScaleType

use of com.facebook.drawee.drawable.ScalingUtils.ScaleType in project fresco by facebook.

the class PipelineDraweeController method updateDebugOverlay.

/**
 * updateDebugOverlay updates the debug overlay. Subclasses of {@link PipelineDraweeController}
 * can override this method (and call <code>super</code>) to provide additional debug information.
 */
protected void updateDebugOverlay(@Nullable CloseableImage image, DebugControllerOverlayDrawable debugOverlay) {
    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);
    // fill in image origin text and color hint
    final int origin = mDebugOverlayImageOriginListener.getImageOrigin();
    final String originText = ImageOriginUtils.toString(origin);
    final int originColor = DebugOverlayImageOriginColor.getImageOriginColor(origin);
    debugOverlay.setOrigin(originText, originColor);
    if (image != null) {
        debugOverlay.setDimensions(image.getWidth(), image.getHeight());
        debugOverlay.setImageSize(image.getSizeInBytes());
    } else {
        debugOverlay.reset();
    }
}
Also used : ScaleType(com.facebook.drawee.drawable.ScalingUtils.ScaleType) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) SettableDraweeHierarchy(com.facebook.drawee.interfaces.SettableDraweeHierarchy) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Aggregations

ScaleType (com.facebook.drawee.drawable.ScalingUtils.ScaleType)3 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)2 Resources (android.content.res.Resources)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 Spinner (android.widget.Spinner)1 FadeDrawable (com.facebook.drawee.drawable.FadeDrawable)1 RoundingParams (com.facebook.drawee.generic.RoundingParams)1 DraweeHierarchy (com.facebook.drawee.interfaces.DraweeHierarchy)1 SettableDraweeHierarchy (com.facebook.drawee.interfaces.SettableDraweeHierarchy)1 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)1 SimpleScaleTypeAdapter (com.facebook.fresco.samples.showcase.common.SimpleScaleTypeAdapter)1 ImageUriProvider (com.facebook.fresco.samples.showcase.misc.ImageUriProvider)1 Test (org.junit.Test)1