<commit_before>package com.displayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.bitmaphandler.R;

public class RoundedBitmapDisplayer extends ImageView {

	private int roundPixels = 10;

	public RoundedBitmapDisplayer(Context context) {
        super(context);
        roundPixels = 10;
    }

    public RoundedBitmapDisplayer(Context context, AttributeSet attrs) {
        super(context, attrs);
        roundPixels = 10;
        TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.com_displayer_RoundedBitmapDisplayer);
        roundPixels = a.getInt(R.styleable.com_displayer_RoundedBitmapDisplayer_round_pixel, 10);
        a.recycle();
    }
    
    public RoundedBitmapDisplayer(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        roundPixels = 20;
        TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.com_displayer_RoundedBitmapDisplayer);
        roundPixels = a.getInt(R.styleable.com_displayer_RoundedBitmapDisplayer_round_pixel, 10);
        a.recycle();
	}
	
	public void setRoundPixle(int roundPixels) {
		this.roundPixels = roundPixels;
	}
	
	public int getRoundPixle() {
		return roundPixels;
	}
	
	/**
     * @see android.widget.ImageView#onDetachedFromWindow()
     */
    @Override
    protected void onDetachedFromWindow() {
        // This has been detached from Window, so clear the drawable
        setImageDrawable(null);

        super.onDetachedFromWindow();
    }
    
    /**
     * @see android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)
     */
    @Override
    public void setImageDrawable(Drawable drawable) {
        // Keep hold of previous Drawable
        final Drawable previousDrawable = getDrawable();
        
//        if(drawable == null){
//        	super.setImageDrawable(null);
//        	notifyDrawable(previousDrawable, false);
//        	return;
//        }
//        
//        if (drawable instanceof RecyclingBitmapDrawable) {
//        	drawable = new RecyclingBitmapDrawable(getResources(), roundCorners(((RecyclingBitmapDrawable) drawable).getBitmap(), this, roundPixels));
//        }else{
//        	drawable = new RecyclingBitmapDrawable(getResources(), roundCorners(((BitmapDrawable) drawable).getBitmap(), this, roundPixels));
//        }

        // Call super to set new Drawable
        super.setImageDrawable(drawable);

        // Notify new Drawable that it is being displayed
        notifyDrawable(drawable, true);

        // Notify old Drawable so it is no longer being displayed
        notifyDrawable(previousDrawable, false);
    }
    
    /**
     * Notifies the drawable that it's displayed state has changed.
     *
     * @param drawable
     * @param isDisplayed
     */
    private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
        if (drawable instanceof RecyclingBitmapDrawable) {
            // The drawable is a CountingBitmapDrawable, so notify it
            ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
        } else if (drawable instanceof LayerDrawable) {
            // The drawable is a LayerDrawable, so recurse on each layer
            LayerDrawable layerDrawable = (LayerDrawable) drawable;
            for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
                notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
            }
        }
    }
    
    @SuppressLint("DrawAllocation")
	@Override
    protected void onDraw(Canvas canvas) {
    	Drawable drawable = getDrawable();

        if (drawable == null) {
            return;
        }

        if (getWidth() == 0 || getHeight() == 0) {
            return; 
        }
        
        if(drawable instanceof TransitionDrawable){
        	drawable = ((TransitionDrawable) drawable).getDrawable(1);
        }
        
        Bitmap bitmap =  ((BitmapDrawable)drawable).getBitmap() ;
        
        if(bitmap == null)
			return;
        
        Bitmap roundBitmap = roundCorners(bitmap, this, roundPixels);
        
		canvas.drawBitmap(roundBitmap, 0,0, null);
    }

	/**
	 * Process incoming {@linkplain Bitmap} to make rounded corners according to target
	 * {@link com.nostra13.universalimageloader.core.imageaware.ImageViewAware}.<br />
	 * This method <b>doesn't display</b> result bitmap in {@link ImageView}
	 *
	 * @param bitmap      Incoming Bitmap to process
	 * @param imageAware  Target {@link com.nostra13.universalimageloader.core.imageaware.ImageAware ImageAware} to
	 *                    display bitmap in
	 * @param roundPixels Rounded pixels of corner
	 * @param canvas 
	 * @return Result bitmap with rounded corners
	 */
	public static Bitmap roundCorners(Bitmap bitmap, ImageView imageView, int roundPixels) {
		if (imageView == null) {
			return bitmap;
		}
		
		if(bitmap == null)
			return null;

		Bitmap roundBitmap;

		int bw = bitmap.getWidth();
		int bh = bitmap.getHeight();
		int vw = imageView.getWidth();
		int vh = imageView.getHeight();
		if (vw <= 0) vw = bw;
		if (vh <= 0) vh = bh;
<commit_msg>Update RoundedBitmapDisplayer.java<commit_after>package com.displayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.bitmaphandler.R;

public class RoundedBitmapDisplayer extends ImageView {

	private int roundPixels = 10;

	public RoundedBitmapDisplayer(Context context) {
        super(context);
        roundPixels = 10;
    }

    public RoundedBitmapDisplayer(Context context, AttributeSet attrs) {
        super(context, attrs);
        roundPixels = 10;
        TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.com_displayer_RoundedBitmapDisplayer);
        roundPixels = a.getInt(R.styleable.com_displayer_RoundedBitmapDisplayer_round_pixel, 10);
        a.recycle();
    }
    
    public RoundedBitmapDisplayer(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        roundPixels = 20;
        TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.com_displayer_RoundedBitmapDisplayer);
        roundPixels = a.getInt(R.styleable.com_displayer_RoundedBitmapDisplayer_round_pixel, 10);
        a.recycle();
	}
	
	public void setRoundPixle(int roundPixels) {
		this.roundPixels = roundPixels;
	}
	
	public int getRoundPixle() {
		return roundPixels;
	}
	
	/**
     * @see android.widget.ImageView#onDetachedFromWindow()
     */
    @Override
    protected void onDetachedFromWindow() {
        // This has been detached from Window, so clear the drawable
        setImageDrawable(null);

        super.onDetachedFromWindow();
    }
    
    /**
     * @see android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)
     */
    @Override
    public void setImageDrawable(Drawable drawable) {
        // Keep hold of previous Drawable
        final Drawable previousDrawable = getDrawable();
        
//        if(drawable == null){
//        	super.setImageDrawable(null);
//        	notifyDrawable(previousDrawable, false);
//        	return;
//        }
//        
//        if (drawable instanceof RecyclingBitmapDrawable) {
//        	drawable = new RecyclingBitmapDrawable(getResources(), roundCorners(((RecyclingBitmapDrawable) drawable).getBitmap(), this, roundPixels));
//        }else{
//        	drawable = new RecyclingBitmapDrawable(getResources(), roundCorners(((BitmapDrawable) drawable).getBitmap(), this, roundPixels));
//        }

        // Call super to set new Drawable
        super.setImageDrawable(drawable);

        // Notify new Drawable that it is being displayed
        notifyDrawable(drawable, true);

        // Notify old Drawable so it is no longer being displayed
        notifyDrawable(previousDrawable, false);
    }
    
    /**
     * Notifies the drawable that it's displayed state has changed.
     *
     * @param drawable
     * @param isDisplayed
     */
    private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
        if (drawable instanceof RecyclingBitmapDrawable) {
            // The drawable is a CountingBitmapDrawable, so notify it
            ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
        } else if (drawable instanceof LayerDrawable) {
            // The drawable is a LayerDrawable, so recurse on each layer
            LayerDrawable layerDrawable = (LayerDrawable) drawable;
            for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
                notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
            }
        }
    }
    
    @SuppressLint("DrawAllocation")
	@Override
    protected void onDraw(Canvas canvas) {
    	Drawable drawable = getDrawable();

        if (drawable == null) {
            return;
        }

        if (getWidth() == 0 || getHeight() == 0) {
            return; 
        }
        
        if(drawable instanceof TransitionDrawable){
        	drawable = ((TransitionDrawable) drawable).getDrawable(1);
        }
        
        Bitmap bitmap =  ((BitmapDrawable)drawable).getBitmap() ;
        
        if(bitmap == null)
			return;
        
        Bitmap roundBitmap = roundCorners(bitmap, this, roundPixels);
        
		canvas.drawBitmap(roundBitmap, 0,0, null);
    }

	/**
	 * Process incoming {@linkplain Bitmap} to make rounded corners according to target
	 * @param bitmap      Incoming Bitmap to process
	 * @param imageView  Target to display bitmap in
	 * @param roundPixels Rounded pixels of corner
	 * @return Result bitmap with rounded corners
	 */
	public static Bitmap roundCorners(Bitmap bitmap, ImageView imageView, int roundPixels) {
		if (imageView == null) {
			return bitmap;
		}
		
		if(bitmap == null)
			return null;

		Bitmap roundBitmap;

		int bw = bitmap.getWidth();
		int bh = bitmap.getHeight();
		int vw = imageView.getWidth();
		int vh = imageView.getHeight();
		if (vw <= 0) vw = bw;
		if (vh <= 0) vh = bh;

{'fraction_non_alphanumeric': 0.09516968935176871, 'fraction_numerical': 0.003950439935356437, 'mean_word_length': 2.966880341880342, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '969027', 'n_tokens_mistral': 3252, 'n_tokens_neox': 3137, 'n_words': 755}