jp.wasabeef.glide.transformations.CropCircleTransformation Java Examples

The following examples show how to use jp.wasabeef.glide.transformations.CropCircleTransformation. 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: UiUtil.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public static void setCircleImage(final ImageView imageView, String imageUrl, int length, int loadingRes, int errorRes) {
    if (imageView == null) return;

    Context context = imageView.getContext();
    if (context instanceof Activity) {
        if (((Activity) context).isFinishing()) {
            return;
        }
    }

    try {
        Glide.with(context).load(imageUrl)
                .placeholder(loadingRes)
                .error(errorRes)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .bitmapTransform(new CropCircleTransformation(context))
                .override(length, length)
                .into(imageView);
    } catch (Exception e) {
    }
}
 
Example #2
Source File: LiveListAdapter.java    From C9MJ with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder viewHolder, LiveListItemBean bean) {
    viewHolder.setText(R.id.tv_roomname, bean.getLive_title())//房间名称
            .setText(R.id.tv_nickname, bean.getLive_nickname())//主播昵称
            .setText(R.id.tv_online, String.valueOf(bean.getLive_online()))//在线人数
            .addOnClickListener(R.id.cardview);//添加子Item点击监听,在UI中实现回调接口

    Glide.with(mContext)//直播房间截图
            .load(bean.getLive_img())
            .crossFade()
            .centerCrop()
            .into((ImageView) viewHolder.getView(R.id.iv_roomsrc));

    Glide.with(mContext)//主播头像
            .load(bean.getLive_userimg())
            .placeholder(R.drawable.ic_avatar_default)
            .bitmapTransform(new CropCircleTransformation(mContext))
            .into((ImageView) viewHolder.getView(R.id.iv_avatar));
}
 
Example #3
Source File: ActivityRxPhoto.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
private File roadImageView(Uri uri, ImageView imageView) {
    Glide.with(mContext).
            load(uri).
            diskCacheStrategy(DiskCacheStrategy.RESULT).
            bitmapTransform(new CropCircleTransformation(mContext)).
            thumbnail(0.5f).
            placeholder(R.drawable.circle_elves_ball).
            priority(Priority.LOW).
            error(R.drawable.circle_elves_ball).
            fallback(R.drawable.circle_elves_ball).
            into(imageView);

    return (new File(RxPhotoTool.getImageAbsolutePath(this, uri)));
}
 
Example #4
Source File: ExampleRepoAdapter.java    From RecyclerAdapterBase with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBindItemViewHolder(ViewHolder viewHolder, int position) {
	RepoItemViewHolder vh = (RepoItemViewHolder) viewHolder;
	Context context = vh.itemView.getContext();
	GetRepoResult repoInfo = repoResultList.get(position);
	vh.titleText.setText(repoInfo.name);
	vh.ownerNameText.setText(repoInfo.ownerInfo.name);
	vh.starTextView.setText(String.valueOf(repoInfo.startedCount));
	Glide.with(context).load(repoInfo.ownerInfo.avatarUrl).bitmapTransform(new CropCircleTransformation(context)).into(vh.avatarImage);
}
 
Example #5
Source File: ImageLoader.java    From HttpRequest with Apache License 2.0 5 votes vote down vote up
/**
 * 图片加载
 * @author leibing
 * @createTime 2016/8/15
 * @lastModify 2016/8/15
 * @param context 上下文
 * @param imageView 图片显示控件
 * @param localPath 图片本地链接
 * @param defaultImage 默认占位图片
 * @param errorImage 加载失败后图片
 * @param  isCropCircle 是否圆角
 * @return
 */
public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){
    // 图片加载库采用Glide框架
    DrawableTypeRequest request = Glide.with(context).load(localPath);
    // 设置scaleType
    request.centerCrop();
    // 圆角裁切
    if (isCropCircle)
        request.bitmapTransform(new CropCircleTransformation(context));
    request.thumbnail(0.1f) //用原图的1/10作为缩略图
            .placeholder(defaultImage) //设置资源加载过程中的占位Drawable
            .crossFade() //设置加载渐变动画
            .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载,
            // 但不保证所有图片都按序加载
            // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW
            // 默认为Priority.NORMAL
            .fallback(null) //设置model为空时要显示的Drawable
            // 如果没设置fallback,model为空时将显示error的Drawable,
            // 如果error的Drawable也没设置,就显示placeholder的Drawable
            .error(errorImage) //设置load失败时显示的Drawable
            .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存
            // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中)
            .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE:
            // 缓存原始数据,DiskCacheStrategy.RESULT:
            // 缓存变换(如缩放、裁剪等)后的资源数据,
            // DiskCacheStrategy.NONE:什么都不缓存,
            // DiskCacheStrategy.ALL:缓存SOURC和RESULT。
            // 默认采用DiskCacheStrategy.RESULT策略,
            // 对于download only操作要使用DiskCacheStrategy.SOURCE
            .into(imageView);
}
 
Example #6
Source File: HtmlChatAdapter.java    From glide-support with The Unlicense 5 votes vote down vote up
@SuppressWarnings("unchecked")
void bind(ChatMessage message) {
	nameView.setText(message.getUserName());
	Context context = avatarView.getContext();
	glide.load(message.getAvatarUrl())
	     .bitmapTransform(new FitCenter(context), new CropCircleTransformation(context))
	     .listener(new LoggingListener<String, GlideDrawable>())
	     .into(avatarView);
	bindEmoticonMessage(messageView, message.getMessage());
}
 
Example #7
Source File: FeedEntryViewHolder.java    From glide-support with The Unlicense 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void bindAuthor(JSONObject author) throws JSONException {
	this.title.setText(author.getJSONObject("name").getString("$t"));
	String url = author.getJSONObject("gphoto$thumbnail").getString("$t");
	glide
			.load(url)
			.asBitmap()
			.transform(new CropCircleTransformation(this.author.getContext()))
			.into(this.author);
}
 
Example #8
Source File: ImageLoader.java    From GithubApp with Apache License 2.0 5 votes vote down vote up
public static void loadWithCircle(Context context, Object source, ImageView view) {
    Glide.with(context)
            .load(source)
            .bitmapTransform(new CropCircleTransformation(context))
            .placeholder(R.drawable.ic_github)
            .into(view);
}
 
Example #9
Source File: ImageLoader.java    From LbaizxfPulltoRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 图片加载
 * @author leibing
 * @createTime 2016/8/15
 * @lastModify 2016/8/15
 * @param context 上下文
 * @param imageView 图片显示控件
 * @param localPath 图片本地链接
 * @param defaultImage 默认占位图片
 * @param errorImage 加载失败后图片
 * @param  isCropCircle 是否圆角
 * @return
 */
public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){
    // 图片加载库采用Glide框架
    DrawableTypeRequest request = Glide.with(context).load(localPath);
    // 设置scaleType
    request.centerCrop();
    // 圆角裁切
    if (isCropCircle)
        request.bitmapTransform(new CropCircleTransformation(context));
    request.thumbnail(0.1f) //用原图的1/10作为缩略图
            .placeholder(defaultImage) //设置资源加载过程中的占位Drawable
            .crossFade() //设置加载渐变动画
            .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载,
            // 但不保证所有图片都按序加载
            // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW
            // 默认为Priority.NORMAL
            .fallback(null) //设置model为空时要显示的Drawable
            // 如果没设置fallback,model为空时将显示error的Drawable,
            // 如果error的Drawable也没设置,就显示placeholder的Drawable
            .error(errorImage) //设置load失败时显示的Drawable
            .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存
            // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中)
            .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE:
            // 缓存原始数据,DiskCacheStrategy.RESULT:
            // 缓存变换(如缩放、裁剪等)后的资源数据,
            // DiskCacheStrategy.NONE:什么都不缓存,
            // DiskCacheStrategy.ALL:缓存SOURC和RESULT。
            // 默认采用DiskCacheStrategy.RESULT策略,
            // 对于download only操作要使用DiskCacheStrategy.SOURCE
            .into(imageView);
}
 
Example #10
Source File: UsageExampleTransformations.java    From android-tutorials-glide with MIT License 5 votes vote down vote up
private void loadImageTransformationLibrary() {
    Glide
            .with(context)
            .load(eatFoodyImages[2])
            .bitmapTransform(new jp.wasabeef.glide.transformations.BlurTransformation(context, 25, 2), new CropCircleTransformation(context))
            .into(imageView4);
}
 
Example #11
Source File: GlideLoader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
private Transformation[] getBitmapTransFormations(SingleConfig config) {

        Transformation[] forms = null;
        int shapeMode = config.getShapeMode();
        List<Transformation> transformations = new ArrayList<>();

        if(config.isCropFace()){
            // transformations.add(new FaceCenterCrop());//脸部识别
        }

        if(config.getScaleMode() == ScaleMode.CENTER_CROP){
            transformations.add(new CenterCrop(config.getContext()));
        }else{
            transformations.add(new FitCenter(config.getContext()));
        }


        if(config.isNeedBlur()){
            transformations.add(new BlurTransformation(config.getContext(), config.getBlurRadius()));
        }

        switch (shapeMode){
            case ShapeMode.RECT:

                if(config.getBorderWidth()>0){

                }
                break;
            case ShapeMode.RECT_ROUND:
            case ShapeMode.RECT_ROUND_ONLY_TOP:

                RoundedCornersTransformation.CornerType cornerType = RoundedCornersTransformation.CornerType.ALL;
                if(shapeMode == ShapeMode.RECT_ROUND_ONLY_TOP){
                    cornerType = RoundedCornersTransformation.CornerType.TOP;
                }
                /*transformations.add(new BorderRoundTransformation2(config.getContext(),
                        config.getRectRoundRadius(), 0,config.getBorderWidth(),
                        config.getContext().getResources().getColor(config.getBorderColor()),0x0b1100));*/

                if(config.getBorderWidth() > 0 && config.getBorderColor() != 0){
                    transformations.add(new BorderRoundTransformation(config.getContext(),
                            config.getRectRoundRadius(), 0,config.getBorderWidth(),
                            config.getContext().getResources().getColor(config.getBorderColor()),0x0b1100));
                }else {
                    transformations.add(new RoundedCornersTransformation(config.getContext(),
                            config.getRectRoundRadius(),config.getBorderWidth(), cornerType));
                }

                break;
            case ShapeMode.OVAL:
                if(config.getBorderWidth() > 0 && config.getBorderColor() != 0){
                    transformations.add( new CropCircleWithBorderTransformation(config.getContext(),
                            config.getBorderWidth(),config.getContext().getResources().getColor(config.getBorderColor())));
                }else {
                    transformations.add( new CropCircleTransformation(config.getContext()));
                }


                break;
            default:break;
        }

        if(!transformations.isEmpty()){
             forms = new Transformation[transformations.size()];
            for (int i = 0; i < transformations.size(); i++) {
                forms[i] = transformations.get(i);
            }
           return forms;
        }
        return forms;

    }
 
Example #12
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
private Transformation[] getBitmapTransFormations(SingleConfig config) {

        Transformation[] forms = null;
        int shapeMode = config.getShapeMode();
        List<Transformation> transformations = new ArrayList<>();

        if(config.isCropFace()){
            // transformations.add(new FaceCenterCrop());//脸部识别
        }

        if(config.getScaleMode() == ScaleMode.CENTER_CROP){
            transformations.add(new CenterCrop());
        }else{
            transformations.add(new FitCenter());
        }


        if(config.isNeedBlur()){
            transformations.add(new BlurTransformation( config.getBlurRadius()));
        }

        switch (shapeMode){
            case ShapeMode.RECT:

                if(config.getBorderWidth()>0){

                }
                break;
            case ShapeMode.RECT_ROUND:
            case ShapeMode.RECT_ROUND_ONLY_TOP:

                RoundedCornersTransformation.CornerType cornerType = RoundedCornersTransformation.CornerType.ALL;
                if(shapeMode == ShapeMode.RECT_ROUND_ONLY_TOP){
                    cornerType = RoundedCornersTransformation.CornerType.TOP;
                }
                /*transformations.add(new BorderRoundTransformation2(config.getContext(),
                        config.getRectRoundRadius(), 0,config.getBorderWidth(),
                        config.getContext().getResources().getColor(config.getBorderColor()),0x0b1100));*/

                /*if(config.getBorderWidth() > 0 && config.getBorderColor() != 0){
                    transformations.add(new BorderRoundTransformation(config.getContext(),
                            config.getRectRoundRadius(), 0,config.getBorderWidth(),
                            config.getContext().getResources().getColor(config.getBorderColor()),0x0b1100));
                }else {*/
                    transformations.add(new RoundedCornersTransformation(
                            config.getRectRoundRadius(),config.getBorderWidth(), cornerType));
               // }

                break;
            case ShapeMode.OVAL:
                if(config.getBorderWidth() > 0 && config.getBorderColor() != 0){
                    transformations.add( new CropCircleWithBorderTransformation(
                            config.getBorderWidth(),config.getContext().getResources().getColor(config.getBorderColor())));
                }else {
                    transformations.add( new CropCircleTransformation());
                }


                break;
            default:break;
        }

        if(!transformations.isEmpty()){
             forms = new Transformation[transformations.size()];
            for (int i = 0; i < transformations.size(); i++) {
                forms[i] = transformations.get(i);
            }
           return forms;
        }
        return forms;

    }
 
Example #13
Source File: MusicAdapter.java    From PlayWidget with MIT License 4 votes vote down vote up
public MusicAdapter(@NonNull Context context) {
    super(context);
    cropCircleTransformation = new CropCircleTransformation(context);
}
 
Example #14
Source File: ImageLoader.java    From GithubApp with Apache License 2.0 4 votes vote down vote up
public static void loadWithCircle(Object source, ImageView view) {
    Glide.with(view.getContext())
            .load(source)
            .bitmapTransform(new CropCircleTransformation(view.getContext()))
            .into(view);
}
 
Example #15
Source File: MainActivity.java    From BeMusic with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout)findViewById(R.id.main_drawer);
    mCoorLayout = (CoordinatorLayout)findViewById(R.id.main_coordinator_layout);
    mTb = (Toolbar)findViewById(R.id.main_tool_bar);
    mVp = (ViewPager)findViewById(R.id.main_view_pager);
    mTl = (TabLayout)findViewById(R.id.main_tab_layout);

    mMiniPanel = findViewById(R.id.main_mini_panel);
    mMiniThumbIv = (ImageView)findViewById(R.id.main_mini_thumb);
    mSongInfoLayout = findViewById(R.id.main_mini_song_info_layout);
    mMiniTitleTv = (TextView)findViewById(R.id.main_mini_title);
    mMiniArtistAlbumTv = (TextView)findViewById(R.id.main_mini_artist_album);

    mPlayPauseIv = (ImageView)findViewById(R.id.main_mini_action_play_pause);
    mPreviousIv = (ImageView)findViewById(R.id.main_mini_action_previous);
    mNextIv = (ImageView)findViewById(R.id.main_mini_action_next);

    mMiniPb = (ProgressBar)findViewById(R.id.main_mini_progress_bar);

    mNavView = (NavigationView)findViewById(R.id.main_nav);
    mHeaderCover = (RatioImageView)mNavView.getHeaderView(0).findViewById(R.id.header_cover);
    mAvatarIv = (ImageView)mNavView.getHeaderView(0).findViewById(R.id.header_avatar);
    mHeaderCover.setOnClickListener(mClickListener);

    /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_FULLSCREEN
        );
    }*/

    setSupportActionBar(mTb);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mTb, R.string.app_name, R.string.title_song_list);

    mMiniPanel.setOnClickListener(mClickListener);
    mPlayPauseIv.setOnClickListener(mClickListener);
    mPreviousIv.setOnClickListener(mClickListener);
    mNextIv.setOnClickListener(mClickListener);

    mNavView.setNavigationItemSelectedListener(mNavListener);

    Glide.with(this).load(R.drawable.avatar).asBitmap()
            .transform(new CropCircleTransformation(this)).into(mAvatarIv);

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 100);
    } else {
        init();
        MediaUtils.getAlbumList(this);
    }
}
 
Example #16
Source File: RepositoryAdapter.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
Transformation<Bitmap> getTransform(int position, Context mContext) {
    if (position % 19 == 0) {
        return new CropCircleTransformation(mContext);
    } else if (position % 19 == 1) {
        return new RoundedCornersTransformation(mContext, 30, 0,
                RoundedCornersTransformation.CornerType.BOTTOM);

    } else if (position % 19 == 2) {
        return new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM);

    } else if (position % 19 == 3) {
        return new CropSquareTransformation(mContext);

    } else if (position % 19 == 4) {
        return new CropTransformation(mContext, 300, 100, CropTransformation.CropType.CENTER);

    } else if (position % 19 == 5) {
        return new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0));

    } else if (position % 19 == 6) {
        return new GrayscaleTransformation(mContext);

    } else if (position % 19 == 7) {
        return new CropTransformation(mContext, 300, 100);

    } else if (position % 19 == 8) {
        return new BlurTransformation(mContext, 25);
    } else if (position % 19 == 9) {
        return new ToonFilterTransformation(mContext);

    } else if (position % 19 == 10) {
        return new SepiaFilterTransformation(mContext);

    } else if (position % 19 == 11) {
        return new ContrastFilterTransformation(mContext, 2.0f);
    } else if (position % 19 == 12) {
        return new InvertFilterTransformation(mContext);
    } else if (position % 19 == 13) {
        return new PixelationFilterTransformation(mContext, 20);
    } else if (position % 19 == 14) {
        return new SketchFilterTransformation(mContext);
    } else if (position % 19 == 15) {
        return new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f));
    } else if (position % 19 == 16) {
        return new BrightnessFilterTransformation(mContext, 0.5f);
    } else if (position % 19 == 17) {
        return new KuwaharaFilterTransformation(mContext, 25);
    } else if (position % 19 == 18) {
        return new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
                new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f);
    }
    return null;
}