<commit_before>package pl.polidea.androidflip3d;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;

/**
 * Views that can be swapped on click in 3D animation mode.
 * 
 */
public class Flip3DView extends FrameLayout {

    private class OnClickListener implements View.OnClickListener {
        @Override
        public void onClick(final View view) {
            if (isFirstView) {
                applyRotation(0, -90);
                isFirstView = false;
            } else {
                applyRotation(0, 90);
                isFirstView = true;
            }
        }
    }

    private View viewFront;
    private View viewBack;

    private boolean isFirstView = true;

    public Flip3DView(final Context context, final AttributeSet attrs,
            final int defStyle) {
        super(context, attrs, defStyle);
        initializeViews();
        parseAttributes(context, attrs);
    }

    public Flip3DView(final Context context, final AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public Flip3DView(final Context context) {
        super(context);
        initializeViews();
    }

    private void parseAttributes(final Context context, final AttributeSet attrs) {
        final TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.Flip3DView);
        try {
            final Drawable front = a
                    .getDrawable(R.styleable.Flip3DView_src_front);
            if (front != null) {
                setImageFrontDrawable(front);
            }
            final Drawable back = a
                    .getDrawable(R.styleable.Flip3DView_src_back);
            if (back != null) {
                setImageBackDrawable(back);
            }
        } finally {
            a.recycle();
        }
    }

    private final void setImageParameters(final ImageView imageView,
            final Drawable drawable) {
        LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        if (drawable instanceof ColorDrawable) {
            layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT, Gravity.CENTER);
        }
        imageView.setLayoutParams(layoutParams);
        imageView.setImageDrawable(drawable);
    }

    /**
     * Sets front view on the control.
     * 
     * @param viewFront
     *            front view
     */
    public final void setViewFront(final View viewFront) {
        if (this.viewFront != null) {
            this.removeView(this.viewFront);
        }
        this.viewFront = viewFront;
        this.addView(viewFront);
    }

    /**
     * Sets back view on the control.
     * 
     * @param viewBack
     *            back view
     */
    public final void setViewBack(final View viewBack) {
        if (this.viewBack != null) {
            this.removeView(this.viewBack);
        }
        this.viewBack = viewBack;
        this.addView(viewBack);
    }

    /**
     * Sets image drawable for front.
     * 
     * @param drawable
     *            drawable for front.
     */
    public void setImageFrontDrawable(final Drawable drawable) {
        final ImageView imageViewFront = new ImageView(getContext());
        setImageParameters(imageViewFront, drawable);
        setViewFront(imageViewFront);
    }

    /**
     * Sets image drawable for back.
     * 
     * @param drawable
     *            drawable for back.
     */
    public void setImageBackDrawable(final Drawable drawable) {
        final ImageView imageViewBack = new ImageView(getContext());
        setImageParameters(imageViewBack, drawable);
        setViewBack(imageViewBack);<commit_msg>Another round of PMD/checkstyle fixes<commit_after>package pl.polidea.androidflip3d;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;

/**
 * Views that can be swapped on click in 3D animation mode.
 * 
 */
public class Flip3DView extends FrameLayout {

    private class OnClickListener implements View.OnClickListener {
        @Override
        public void onClick(final View view) {
            if (isFirstView) {
                applyRotation(0, -90);
                isFirstView = false;
            } else {
                applyRotation(0, 90);
                isFirstView = true;
            }
        }
    }

    private View viewFront;
    private View viewBack;

    private boolean isFirstView = true;

    public Flip3DView(final Context context, final AttributeSet attrs,
            final int defStyle) {
        super(context, attrs, defStyle);
        initializeViews();
        parseAttributes(context, attrs);
    }

    public Flip3DView(final Context context, final AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public Flip3DView(final Context context) {
        super(context);
        initializeViews();
    }

    private void parseAttributes(final Context context, final AttributeSet attrs) {
        final TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.Flip3DView);
        try {
            final Drawable front = a
                    .getDrawable(R.styleable.Flip3DView_src_front);
            if (front != null) {
                setImageFrontDrawable(front);
            }
            final Drawable back = a
                    .getDrawable(R.styleable.Flip3DView_src_back);
            if (back != null) {
                setImageBackDrawable(back);
            }
        } finally {
            a.recycle();
        }
    }

    private void setImageParameters(final ImageView imageView,
            final Drawable drawable) {
        LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        if (drawable instanceof ColorDrawable) {
            layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT, Gravity.CENTER);
        }
        imageView.setLayoutParams(layoutParams);
        imageView.setImageDrawable(drawable);
    }

    /**
     * Sets front view on the control.
     * 
     * @param viewFront
     *            front view
     */
    public final void setViewFront(final View viewFront) {
        if (this.viewFront != null) {
            this.removeView(this.viewFront);
        }
        this.viewFront = viewFront;
        this.addView(viewFront);
    }

    /**
     * Sets back view on the control.
     * 
     * @param viewBack
     *            back view
     */
    public final void setViewBack(final View viewBack) {
        if (this.viewBack != null) {
            this.removeView(this.viewBack);
        }
        this.viewBack = viewBack;
        this.addView(viewBack);
    }

    /**
     * Sets image drawable for front.
     * 
     * @param drawable
     *            drawable for front.
     */
    public final void setImageFrontDrawable(final Drawable drawable) {
        final ImageView imageViewFront = new ImageView(getContext());
        setImageParameters(imageViewFront, drawable);
        setViewFront(imageViewFront);
    }

    /**
     * Sets image drawable for back.
     * 
     * @param drawable
     *            drawable for back.
     */
    public final void setImageBackDrawable(final Drawable drawable) {
        final ImageView imageViewBack = new ImageView(getContext());
        setImageParameters(imageViewBack, drawable);
        setViewBack(imageViewBack);
{'fraction_non_alphanumeric': 0.08196520460671404, 'fraction_numerical': 0.0039206076941926, 'mean_word_length': 2.11208539839878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5002437', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2169, 'n_words': 516}