<commit_before>package com.blunderer.materialdesignlibrary.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blunderer.materialdesignlibrary.R;
import com.joooonho.SelectableRoundedImageView;

import carbon.widget.Button;

public class CardView extends android.support.v7.widget.CardView {

    private Context mContext;
    private int mImagePosition;
    private Drawable mImage;
    private String mTitleText;
    private String mDescriptionText;
    private String mNormalButtonText;
    private String mHighlightButtonText;
    private Button mNormalButton;
    private Button mHighlightButton;

    // Listeners
    private OnClickListener mOnNormalButtonClickListener;
    private OnClickListener mOnHighlightButtonClickListener;

    public CardView(Context context) {
        this(context, null);
    }

    public CardView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mContext = context;
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
                R.styleable.MDLCardView, 0, 0);

        try {
            mImagePosition = a.getInt(R.styleable.MDLCardView_mdl_imagePosition, 0);
            mImage = a.getDrawable(R.styleable.MDLCardView_mdl_image);
            mTitleText = a.getString(R.styleable.MDLCardView_mdl_title);
            mDescriptionText = a.getString(R.styleable.MDLCardView_mdl_description);
            mNormalButtonText = a.getString(R.styleable.MDLCardView_mdl_normalButton);
            mHighlightButtonText = a.getString(R.styleable.MDLCardView_mdl_highlightButton);
        } finally {
            a.recycle();
        }

        setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
                getResources().getDisplayMetrics()));
        setPreventCornerOverlap(false);
        setCardBackgroundColor(context.getResources().getColor(R.color.cardview_background));

        inflate();
    }

    public int getImagePosition() {
        return mImagePosition;
    }

    public void setImagePosition(int imagePosition) {
        mImagePosition = imagePosition;

        inflate();
    }

    public Drawable getImage() {
        return mImage;
    }

    public void setImageDrawable(Drawable imageDrawable) {
        mImage = imageDrawable;

        refresh();
    }

    public void setImageResource(int imageResource) {
        mImage = mContext.getResources().getDrawable(imageResource);

        refresh();
    }

    public String getTitle() {
        return mTitleText;
    }

    public void setTitle(String title) {
        mTitleText = title;

        refresh();
    }

    public void setTitleResource(int titleResource) {
        mTitleText = mContext.getString(titleResource);

        refresh();
    }

    public String getDescription() {
        return mDescriptionText;
    }

    public void setDescription(String description) {
        mDescriptionText = description;

        refresh();
    }

    public void setDescriptionResource(int descriptionResource) {
        mDescriptionText = mContext.getString(descriptionResource);

        refresh();
    }

    public Button getNormalButton() {
        return mNormalButton;
    }

    public void setNormalButtonText(String normalButtonText) {
        mNormalButtonText = normalButtonText;

        refresh();
    }

    public Button getHighlightButton() {
        return mHighlightButton;
    }

    public void setHighlightButtonText(String highlightButtonText) {
        mHighlightButtonText = highlightButtonText;

        refresh();
    }

    public OnClickListener getOnNormalButtonClickListener() {
        return mOnNormalButtonClickListener;
    }

    public void setOnNormalButtonClickListener(OnClickListener onNormalButtonClickListener) {
        mOnNormalButtonClickListener = onNormalButtonClickListener;
    }

    public OnClickListener getOnHighlightButtonClickListener() {
        return mOnHighlightButtonClickListener;
    }

    public void setOnHighlightButtonClickListener(OnClickListener onHighlightButtonClickListener) {
        mOnHighlightButtonClickListener = onHighlightButtonClickListener;
    }

    private void inflate() {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (mImagePosition == 1) inflateCardViewImageLeft(inflater);
        else if (mImagePosition == 2) inflateCardViewImageTop(inflater);
        else inflateCardViewNormal(inflater);
    }

    private void refresh() {
        if (mImagePosition == 1) {
            LinearLayout layoutAll = (LinearLayout) getChildAt(0);
            handleImage(layoutAll, 0);

            LinearLayout layout = (LinearLayout) layoutAll.getChildAt(1);
            handleTitle(layout, 0);
            handleDescription(layout, 1);
            handleSpacing(layout, 2);
            handleCardViewNormalAndImageLeftButtons(layout, 3);
        } else if (mImagePosition == 2) {
            LinearLayout layoutAll = (LinearLayout) getChildAt(0);
            RelativeLayout layoutImageTitle = (RelativeLayout) layoutAll.getChildAt(0);
            handleImage(layoutImageTitle, 0);
            handleTitle(layoutImageTitle, 1);

            LinearLayout layout = (LinearLayout) layoutAll.getChildAt(1);
            handleDescription(layout, 0);
            handleCardViewImageTopButtons(layout, 1);
        } else {
            LinearLayout layout = (LinearLayout) getChildAt(0);

            handleTitle(layout, 0);
            handleDescription(layout, 1);
            handleSpacing(layout, 2);
            handleCardViewNormalAndImageLeftButtons(layout, 3);
        }
    }<commit_msg>updated positions variables for cardview<commit_after>package com.blunderer.materialdesignlibrary.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blunderer.materialdesignlibrary.R;
import com.joooonho.SelectableRoundedImageView;

import carbon.widget.Button;

public class CardView extends android.support.v7.widget.CardView {

    // Positions
    public final static int POSITION_NONE = 0;
    public final static int POSITION_LEFT = 1;
    public final static int POSITION_TOP = 2;

    // Variables
    private Context mContext;
    private int mImagePosition;
    private Drawable mImage;
    private String mTitleText;
    private String mDescriptionText;
    private String mNormalButtonText;
    private String mHighlightButtonText;
    private Button mNormalButton;
    private Button mHighlightButton;

    // Listeners
    private OnClickListener mOnNormalButtonClickListener;
    private OnClickListener mOnHighlightButtonClickListener;

    public CardView(Context context) {
        this(context, null);
    }

    public CardView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mContext = context;
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
                R.styleable.MDLCardView, 0, 0);

        try {
            mImagePosition = a.getInt(R.styleable.MDLCardView_mdl_imagePosition, 0);
            mImage = a.getDrawable(R.styleable.MDLCardView_mdl_image);
            mTitleText = a.getString(R.styleable.MDLCardView_mdl_title);
            mDescriptionText = a.getString(R.styleable.MDLCardView_mdl_description);
            mNormalButtonText = a.getString(R.styleable.MDLCardView_mdl_normalButton);
            mHighlightButtonText = a.getString(R.styleable.MDLCardView_mdl_highlightButton);
        } finally {
            a.recycle();
        }

        setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
                getResources().getDisplayMetrics()));
        setPreventCornerOverlap(false);
        setCardBackgroundColor(context.getResources().getColor(R.color.cardview_background));

        inflate();
    }

    public int getImagePosition() {
        return mImagePosition;
    }

    public void setImagePosition(int imagePosition) {
        mImagePosition = imagePosition;

        inflate();
    }

    public Drawable getImage() {
        return mImage;
    }

    public void setImageDrawable(Drawable imageDrawable) {
        mImage = imageDrawable;

        refresh();
    }

    public void setImageResource(int imageResource) {
        mImage = mContext.getResources().getDrawable(imageResource);

        refresh();
    }

    public String getTitle() {
        return mTitleText;
    }

    public void setTitle(String title) {
        mTitleText = title;

        refresh();
    }

    public void setTitleResource(int titleResource) {
        mTitleText = mContext.getString(titleResource);

        refresh();
    }

    public String getDescription() {
        return mDescriptionText;
    }

    public void setDescription(String description) {
        mDescriptionText = description;

        refresh();
    }

    public void setDescriptionResource(int descriptionResource) {
        mDescriptionText = mContext.getString(descriptionResource);

        refresh();
    }

    public Button getNormalButton() {
        return mNormalButton;
    }

    public void setNormalButtonText(String normalButtonText) {
        mNormalButtonText = normalButtonText;

        refresh();
    }

    public Button getHighlightButton() {
        return mHighlightButton;
    }

    public void setHighlightButtonText(String highlightButtonText) {
        mHighlightButtonText = highlightButtonText;

        refresh();
    }

    public OnClickListener getOnNormalButtonClickListener() {
        return mOnNormalButtonClickListener;
    }

    public void setOnNormalButtonClickListener(OnClickListener onNormalButtonClickListener) {
        mOnNormalButtonClickListener = onNormalButtonClickListener;
    }

    public OnClickListener getOnHighlightButtonClickListener() {
        return mOnHighlightButtonClickListener;
    }

    public void setOnHighlightButtonClickListener(OnClickListener onHighlightButtonClickListener) {
        mOnHighlightButtonClickListener = onHighlightButtonClickListener;
    }

    private void inflate() {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (mImagePosition == POSITION_LEFT) inflateCardViewImageLeft(inflater);
        else if (mImagePosition == POSITION_TOP) inflateCardViewImageTop(inflater);
        else inflateCardViewNormal(inflater);
    }

    private void refresh() {
        if (mImagePosition == POSITION_LEFT) {
            LinearLayout layoutAll = (LinearLayout) getChildAt(0);
            handleImage(layoutAll, 0);

            LinearLayout layout = (LinearLayout) layoutAll.getChildAt(1);
            handleTitle(layout, 0);
            handleDescription(layout, 1);
            handleSpacing(layout, 2);
            handleCardViewNormalAndImageLeftButtons(layout, 3);
        } else if (mImagePosition == POSITION_TOP) {
            LinearLayout layoutAll = (LinearLayout) getChildAt(0);
            RelativeLayout layoutImageTitle = (RelativeLayout) layoutAll.getChildAt(0);
            handleImage(layoutImageTitle, 0);
            handleTitle(layoutImageTitle, 1);

            LinearLayout layout = (LinearLayout) layoutAll.getChildAt(1);
            handleDescription(layout, 0);
            handleCardViewImageTopButtons(layout, 1);
        } else {
            LinearLayout layout = (LinearLayout) getChildAt(0);

            handleTitle(layout, 0);
            handleDescription(layout, 1);
            handleSpacing(layout, 2);
            handleCardViewNormalAndImageLeftButtons(layout, 3);
        }
    }
{'fraction_non_alphanumeric': 0.07754836611933019, 'fraction_numerical': 0.00447081775321086, 'mean_word_length': 3.0510372077708263, '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': '3875450', 'n_tokens_mistral': 3316, 'n_tokens_neox': 3124, 'n_words': 642}