<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package es.voghdev.progressbuttonview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

public class ProgressButtonView extends FrameLayout {
    public static final int NO_DRAWABLE = -1;
    public static final int NO_COLOR = -1;
    public static final float DEFAULT_SIZE = 14f;

    Button button;
    ProgressBar progressBar;

    int textColor;
    boolean hideButtonOnClick = false;
    boolean loading = false;
    String buttonText = "";

    public ProgressButtonView(Context context) {
        super(context);
        initViews();
        style(button, context, null, -1);
    }

    public ProgressButtonView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews();
        style(button, context, attrs, -1);
    }

    public ProgressButtonView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initViews();
        style(button, context, attrs, defStyle);
    }

    private void initViews() {
        View v = inflate(getContext(), getLayoutId(), this);
        bindViewListeners(v);
    }

    protected void bindViewListeners(View v) {
        button = (Button) v.findViewById(R.id.progress_button_btn);
        progressBar = (ProgressBar) v.findViewById(R.id.progress_button_progressBar);
    }

    protected int getLayoutId() {
        return R.layout.view_progress_button;
    }

    public void setOnClickListener(OnClickListener l) {
        button.setOnClickListener(l);
    }

    public void setOnLongClickListener(OnLongClickListener l) {
        button.setOnLongClickListener(l);
    }

    public void setText(String text) {
        button.setText(text);
    }

    public void setText(int resId) {
        setText(getContext().getString(resId));
    }

    public void setTextColor(int color) {
        button.setTextColor(color);
    }

    public void setTextSize(float textSize) {
        button.setTextSize(textSize);
    }

    public void setEnabled(boolean enabled) {
        button.setEnabled(enabled);
    }

    public void setBackground(Drawable background) {
        if (Build.VERSION.SDK_INT >= 16 && button != null) {
            button.setBackground(background);
        } else if (Build.VERSION.SDK_INT < 16 && button != null) {
            button.setBackgroundDrawable(background);
        }<commit_msg>1st approach to #5 for API 21+<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package es.voghdev.progressbuttonview;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

public class ProgressButtonView extends FrameLayout {
    public static final int NO_DRAWABLE = -1;
    public static final int NO_COLOR = -1;
    public static final float DEFAULT_SIZE = 14f;

    Button button;
    ProgressBar progressBar;

    int textColor;
    boolean hideButtonOnClick = false;
    boolean loading = false;
    String buttonText = "";

    public ProgressButtonView(Context context) {
        super(context);
        initViews();
        style(button, context, null, -1);
    }

    public ProgressButtonView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews();
        style(button, context, attrs, -1);
    }

    public ProgressButtonView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initViews();
        style(button, context, attrs, defStyle);
    }

    private void initViews() {
        View v = inflate(getContext(), getLayoutId(), this);
        bindViewListeners(v);
    }

    protected void bindViewListeners(View v) {
        button = (Button) v.findViewById(R.id.progress_button_btn);
        progressBar = (ProgressBar) v.findViewById(R.id.progress_button_progressBar);
    }

    protected int getLayoutId() {
        return R.layout.view_progress_button;
    }

    public void setOnClickListener(OnClickListener l) {
        button.setOnClickListener(l);
    }

    public void setOnLongClickListener(OnLongClickListener l) {
        button.setOnLongClickListener(l);
    }

    public void setText(String text) {
        button.setText(text);
    }

    public void setText(int resId) {
        setText(getContext().getString(resId));
    }

    public void setTextColor(int color) {
        button.setTextColor(color);
    }

    public void setTextSize(float textSize) {
        button.setTextSize(textSize);
    }

    public void setEnabled(boolean enabled) {
        button.setEnabled(enabled);
    }

    @SuppressWarnings("NewApi")
    public void setIndeterminateTintMode(PorterDuff.Mode tintMode) {
        progressBar.setIndeterminateTintMode(tintMode);
    }

    @SuppressWarnings("NewApi")
    public void setIndeterminateDrawableTiled(Drawable d) {
        progressBar.setIndeterminateDrawableTiled(d);
    }

    public void setIndeterminateDrawable(Drawable d) {
        progressBar.setIndeterminateDrawable(d);
    }

    @SuppressWarnings("NewApi")
    public void setIndeterminateTintList(ColorStateList tint) {
        progressBar.setIndeterminateTintList(tint);
    }

    public void setBackground(Drawable background) {
        if (Build.VERSION.SDK_INT >= 16 && button != null) {
            button.setBackground(background);
        } else if (Build.VERSION.SDK_INT < 16 && button != null) {
            button.setBackgroundDrawable(background);
        }
{'fraction_non_alphanumeric': 0.09192733233164868, 'fraction_numerical': 0.005736921185630378, 'mean_word_length': 3.322314049586777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1377731', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1989, 'n_words': 549}