com.squareup.picasso.Transformation Java Examples

The following examples show how to use com.squareup.picasso.Transformation. 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: BaseApplication.java    From conference-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mPicassoTransformation = new Transformation(){
        @Override
        public Bitmap transform(Bitmap source) {
            Bitmap bp = ImageManager.cropBitmapToCircle(source, BaseApplication.this);
            if (bp != source) {
                source.recycle();
            }
            return bp;
        }

        @Override
        public String key() {
            return "rounded";
        }
    };


}
 
Example #2
Source File: RoundedTransformationBuilder.java    From ClipCircleHeadLikeQQ with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link Transformation} for use with picasso.
 *
 * @return the {@link Transformation}
 */
public Transformation build() {
  return new Transformation() {
    @Override public Bitmap transform(Bitmap source) {
      Bitmap transformed = RoundedDrawable.fromBitmap(source)
          .setScaleType(mScaleType)
          .setCornerRadius(mCornerRadii[0], mCornerRadii[1], mCornerRadii[2], mCornerRadii[3])
          .setBorderWidth(mBorderWidth)
          .setBorderColor(mBorderColor)
          .setOval(mOval)
          .toBitmap();
      if (!source.equals(transformed)) {
        source.recycle();
      }
      return transformed;
    }

    @Override public String key() {
      return "r:" + Arrays.toString(mCornerRadii)
          + "b:" + mBorderWidth
          + "c:" + mBorderColor
          + "o:" + mOval;
    }
  };
}
 
Example #3
Source File: PicassoHook.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
/**
 * 注入到com.squareup.picasso.Request 构造方法中
 */
public static void proxy(Object request) {
    try {
        if (request instanceof Request) {
            Request requestObj = (Request) request;
            List<Transformation> transformations = requestObj.transformations;
            if (transformations == null) {
                transformations = new ArrayList<>();
                transformations.add(new DokitPicassoTransformation(requestObj.uri, requestObj.resourceId));
            } else {
                transformations.clear();
                transformations.add(new DokitPicassoTransformation(requestObj.uri, requestObj.resourceId));
            }
            ReflectUtils.reflect(request).field("transformations", transformations);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #4
Source File: RoundedTransformationBuilder.java    From Loop with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link Transformation} for use with picasso.
 *
 * @return the {@link Transformation}
 */
public Transformation build() {
    return new Transformation() {
        @Override public Bitmap transform(Bitmap source) {
            Bitmap transformed = RoundedDrawable.fromBitmap(source)
                    .setScaleType(mScaleType)
                    .setCornerRadius(mCornerRadii[0], mCornerRadii[1], mCornerRadii[2], mCornerRadii[3])
                    .setBorderWidth(mBorderWidth)
                    .setBorderColor(mBorderColor)
                    .setOval(mOval)
                    .toBitmap();
            if (!source.equals(transformed)) {
                source.recycle();
            }
            return transformed;
        }

        @Override public String key() {
            return "r:" + Arrays.toString(mCornerRadii)
                    + "b:" + mBorderWidth
                    + "c:" + mBorderColor
                    + "o:" + mOval;
        }
    };
}
 
Example #5
Source File: FullScreenImageFragment.java    From DismissibleImageView with Apache License 2.0 6 votes vote down vote up
private void loadLoadingUrl(@NonNull final String url, @NonNull final String loadingUrl, final boolean loadingBlur) {
    final List<Transformation> transformations = new ArrayList<>();

    if (loadingBlur) {
        transformations.add(new BlurTransformation(getContext()));
    }

    Picasso.with(getContext()).load(loadingUrl).transform(transformations).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            loadUrl(url, bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });
}
 
Example #6
Source File: HomeFragment.java    From android-spotify-demo with MIT License 6 votes vote down vote up
private void bindTrack(final TopTrack track){

            album_name_view.setText(track.getName());

            Picasso.with(getContext())
                    .load(track.getImg_url())
                    .transform(new Transformation() {
                        @Override
                        public Bitmap transform(Bitmap source) {
                            final Bitmap copy = source.copy(source.getConfig(), true);
                            source.recycle();

                            return copy;
                        }

                        @Override
                        public String key() {
                            return track.getName();
                        }
                    })
                    .into(album_image_field);

        }
 
Example #7
Source File: HomeFragment.java    From android-spotify-demo with MIT License 6 votes vote down vote up
private void bindArtist(final TopArtist artist){
    this.artist = artist;

    artist_name_view.setText(artist.getName());

    Picasso.with(getContext())
            .load(artist.getImg_url())
            .transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {
                    final Bitmap copy = source.copy(source.getConfig(), true);
                    source.recycle();

                    return copy;
                }

                @Override
                public String key() {
                    return artist.getName();
                }
            })
            .into(artist_image_field);


}
 
Example #8
Source File: HomeFragment.java    From android-spotify-demo with MIT License 6 votes vote down vote up
private void bindItem(final SimplePlaylist simple){
    titleView.setText(simple.getName());

    Picasso.with(getContext())
            .load(simple.getImg_url())
            .transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {
                    final Bitmap copy = source.copy(source.getConfig(), true);
                    source.recycle();

                    return copy;
                }

                @Override
                public String key() {
                    return simple.getName();
                }
            })
            .into(imageView);
}
 
Example #9
Source File: BlogDetailDelegate.java    From CoreModule with Apache License 2.0 6 votes vote down vote up
private Transformation getTransformation(final String t) {
    return new Transformation() {
        @Override
        public Bitmap transform(Bitmap b) {
            Palette.from(b).generate(new Palette.PaletteAsyncListener() {
                @Override
                public void onGenerated(final Palette palette) {
                    int defaultColor = rootView.getResources().getColor
                            (android.R.color.white);
                    int titleColor = palette.getLightVibrantColor
                            (defaultColor);
                    CollapsingToolbarLayout collapsingToolbar = get(R.id
                            .collapsing_toolbar);
                    collapsingToolbar.setExpandedTitleColor(titleColor);
                }
            });
            return b;
        }

        @Override
        public String key() {
            return t;
        }
    };
}
 
Example #10
Source File: RSGaussianBlurTransformationTest.java    From picasso-transformations with Apache License 2.0 5 votes vote down vote up
@Test
@Override
public void checkTransform() throws Exception {
    Transformation t = getTransformation();
    Bitmap copy = getCopyOfBitmap();
    Bitmap bm = t.transform(copy);
    assertThat(bm).isNotNull();
}
 
Example #11
Source File: BaseTransformationTest.java    From picasso-transformations with Apache License 2.0 5 votes vote down vote up
@Test
public void checkTransform() throws Exception {
    Transformation t = getTransformation();
    Bitmap copy = getCopyOfBitmap();
    Bitmap bm = t.transform(copy);
    assertThat(bm).isNotNull();
    assertThat(bm).isNotEqualTo(sBitmap);
    assertThat(copy).isRecycled();
}
 
Example #12
Source File: MainActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
private void setProfileInfoUI(){

        String accountName = DtubeAPI.getAccountName(this);
        if (accountName!=null){
            accountInfo = new Person();
            accountInfo.userName = accountName;

            steemWebView.login(DtubeAPI.getAccountName(MainActivity.this),DtubeAPI.getUserPrivateKey(MainActivity.this),false, false);
        }

        if (accountInfo!=null) {

            Transformation transformation = new RoundedTransformationBuilder()
                    .cornerRadiusDp(30)
                    .oval(false)
                    .build();

            Picasso.get().load(accountInfo.getImageURL()).placeholder(R.drawable.login).transform(transformation).into(
                    ((ImageView) findViewById(R.id.profile_image)));

            Picasso.get().load(DtubeAPI.PROFILE_IMAGE_MEDIUM_URL.replace("username",accountInfo.userName)).placeholder(R.drawable.login).transform(transformation).into(
                    (ImageView)navigationHeader.findViewById(R.id.header_icon));

            ((TextView)navigationHeader.findViewById(R.id.header_name)).setText(accountInfo.userName);
            ((TextView)navigationHeader.findViewById(R.id.header_status)).setText("");
            navigationHeader.findViewById(R.id.header_login_iv).setVisibility(View.GONE);

            steemWebView.getSubscriberCount(accountInfo.userName);
            steemWebView.getSubscriptions(accountInfo.userName);
        }

    }
 
Example #13
Source File: PicassoRequestBuilder.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given transformation to the requested image if the enabled flag is true.
 * @param transform
 * @param enabled
 * @return
 */
@NonNull
public PicassoRequestBuilder withTransform (Transformation transform, boolean enabled) {
    if (enabled) {
        this.transform.add(transform);
    }
    return this;
}
 
Example #14
Source File: MeFragment.java    From iMoney with Apache License 2.0 5 votes vote down vote up
private void doUser() {
    // 读取数据,得到内存中的User对象
    User user = ((BaseActivity) this.getActivity()).readUser();
    // 一方面,显示用户名
    if (!TextUtils.isEmpty(user.UF_ACC)) {
        textView11.setText(user.UF_ACC);
    }

    if (!TextUtils.isEmpty(user.UF_AVATAR_URL)) {
        // 另一方面,加载显示用户头像
        Picasso.with(getActivity()).load(user.UF_AVATAR_URL).transform(new Transformation() {
            @Override
            public Bitmap transform(Bitmap source) {
                // 对Bitmap进行压缩处理
                Bitmap zoom = BitmapUtils.zoom(source, UIUtils.dp2px(62), UIUtils.dp2px(62));
                // 对Bitmap进行圆形处理
                Bitmap circleBitmap = BitmapUtils.circleBitmap(zoom);
                source.recycle(); // 回收,否则会出现内存泄漏
                return circleBitmap;
            }

            @Override
            public String key() {
                return ""; // 此方法不能返回null否则报异常
            }
        }).into(imageView1);
    }

    // 如果在本地发现了用户设置了手势密码,则在此需要验证
    boolean isOpen = SpUtil.getInstance(mContext).getBoolean(SpKey.GESTURE_IS_OPEN, false);
    if (isOpen) {
        ((BaseActivity) this.getActivity()).goToActivity(GestureVerifyActivity.class, null);
    }
}
 
Example #15
Source File: UserImage.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public static RequestCreator getPicassoCorned(RequestCreator request) {
    final int radius = 5;
    final int margin = 5;
    final Transformation transformation = new RoundedCornersTransformation(radius, margin);
    request.transform(transformation);
    return request;
}
 
Example #16
Source File: ImageUtil.java    From overscroll-bouncy-android with MIT License 5 votes vote down vote up
/**
 * Get circle transformation
 * @param borderWidth in dp
 * @param borderColor color of the border
 */
public static Transformation getCircleTransformation(int borderWidth, int borderColor) {
    return new RoundedTransformationBuilder()
            .oval(true)
            .borderWidthDp(borderWidth)
            .borderColor(borderColor)
            .build();
}
 
Example #17
Source File: ImageViewController.java    From Carpaccio with Apache License 2.0 5 votes vote down vote up
protected void addTransformation(View view, Transformation transformation) {
    List<Transformation> list = transformations.get(view);
    if (list == null) {
        list = new ArrayList<>();
        transformations.put(view, list);
    }
    list.add(transformation);
}
 
Example #18
Source File: MainActivity.java    From Prodigal with Apache License 2.0 5 votes vote down vote up
public void loadBackground(SongBean bean) {
    if (bean == null ) {
        backgroundImage.setImageBitmap(null);
        return;
    }
    final Uri image = Uri.parse(MediaLibrary.getStaticInstance(getApplicationContext())
            .getCoverUriByAlbumId(bean.getAlbumId()));
    Picasso.with(this).load(image).resize(windowSize.x, windowSize.y)
            .centerCrop()
            .transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {
                    BlurFactor factor = new BlurFactor();
                    factor.radius = 25;
                    factor.sampling = 4;
                    factor.width = windowSize.x;
                    factor.height = windowSize.y;
                    factor.color = ColorUtils.setAlphaComponent(
                            ThemeManager.getInstance(getApplicationContext())
                            .loadCurrentTheme().getBackgroundColor(), 20);
                    Bitmap ret = Blur.of(getApplicationContext(), source, factor);
                    source.recycle();
                    return ret;
                }

                @Override
                public String key() {
                    return image.toString() + "/blured";
                }
            })
            .config(Bitmap.Config.RGB_565).into(backgroundImage);

}
 
Example #19
Source File: ImageLoader.java    From Retrofit2SampleApp with MIT License 5 votes vote down vote up
@Override
public void loadImage(String url,final ImageView imageView) {

    Picasso.with(imageView.getContext()).load(url).transform(new Transformation() {
        @Override
        public Bitmap transform(Bitmap source) {
            Bitmap combinedBitmap;
            combinedBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight() / 3 + source.getHeight(), source.getConfig());

            Canvas combinedCanvas = new Canvas(combinedBitmap);
            combinedCanvas.drawBitmap(source, 0f, 0f, null);

            Matrix matrix = new Matrix();
            matrix.postRotate(180);
            matrix.preScale(-1, 1);
            matrix.postTranslate(0, source.getHeight() * 2);

            BlurTransformation blurTransformation = new BlurTransformation(imageView.getContext(), 15, 1);
            Bitmap bottom = blurTransformation.transform(source);

            combinedCanvas.setMatrix(matrix);
            combinedCanvas.drawBitmap(bottom, 0f, 0f, null);
            return combinedBitmap;
        }

        @Override
        public String key() {
            return ImageLoader.class.getName() + ".Transformation";
        }
    }).error(android.R.drawable.sym_contact_card).placeholder(android.R.drawable.sym_contact_card).
            into(imageView);
}
 
Example #20
Source File: PicassoImageLoader.java    From Nox with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the configuration previously applied using this ImageLoader builder to download a
 * resource asynchronously and notify the result to the listener.
 */
private void loadImage() {
  List<Transformation> transformations = getTransformations();
  boolean hasUrl = url != null;
  boolean hasResourceId = resourceId != null;
  boolean hasPlaceholder = placeholderId != null;
  ListenerTarget listenerTarget = getLinearTarget(listener);
  if (hasUrl) {
    RequestCreator bitmapRequest = Picasso.with(context).load(url).tag(PICASSO_IMAGE_LOADER_TAG);
    applyPlaceholder(bitmapRequest).resize(size, size)
        .transform(transformations)
        .into(listenerTarget);
  } else if (hasResourceId || hasPlaceholder) {
    Resources resources = context.getResources();
    Drawable placeholder = null;
    Drawable drawable = null;
    if (hasPlaceholder) {
      placeholder = resources.getDrawable(placeholderId);
      listenerTarget.onPrepareLoad(placeholder);
    }
    if (hasResourceId) {
      drawable = resources.getDrawable(resourceId);
      listenerTarget.onDrawableLoad(drawable);
    }
  } else {
    throw new IllegalArgumentException(
        "Review your request, you are trying to load an image without a url or a resource id.");
  }
}
 
Example #21
Source File: PicassoImageLoader.java    From Nox with Apache License 2.0 5 votes vote down vote up
/**
 * Lazy instantiation of the list of transformations used during the image download. This method
 * returns a List<Transformation> because Picasso doesn't support a null instance as
 * transformation.
 */
private List<Transformation> getTransformations() {
  if (transformations == null) {
    transformations = new LinkedList<Transformation>();
    if (useCircularTransformation) {
      transformations.add(new CircleTransformation());
    }
  }
  return transformations;
}
 
Example #22
Source File: RemoteImageView.java    From cathode with Apache License 2.0 5 votes vote down vote up
private void loadBitmap(boolean animate) {
  fraction = 0.0f;
  image = null;
  final int width = getWidth() - getPaddingStart() - getPaddingEnd();
  final int height = getHeight() - getPaddingTop() - getPaddingBottom();

  RequestCreator creator = null;
  if (imageUrl != null) {
    creator = picasso.load(imageUrl);
  } else if (imageResource > 0) {
    creator = picasso.load(imageResource);
  }

  if (creator != null) {
    creator.resize(width - resizeInsetX, height - resizeInsetY).centerCrop();

    if (PaletteTransformation.shouldTransform) {
      creator.transform(new PaletteTransformation());
    }

    for (Transformation transformation : transformations) {
      creator.transform(transformation);
    }
    creator.into(this);
  }

  if (!animate && image != null) {
    animating = false;
    startTimeMillis = 0;
    fraction = 1.0f;
  }
}
 
Example #23
Source File: EqualizeTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new EqualizeTransformation();
}
 
Example #24
Source File: LevelsTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new LevelsTransformation();
}
 
Example #25
Source File: ThresholdTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new ThresholdTransformation();
}
 
Example #26
Source File: ExposureTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new ExposureTransformation();
}
 
Example #27
Source File: MarbleTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new MarbleTransformation();
}
 
Example #28
Source File: GainTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new GainTransformation();
}
 
Example #29
Source File: HSBAdjustTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new HSBAdjustTransformation();
}
 
Example #30
Source File: ChannelMixTransformationTest.java    From picasso-transformations with Apache License 2.0 4 votes vote down vote up
@Override
protected Transformation getTransformation() {
    return new ChannelMixTransformation();
}