Android Open Source - AlertDialogPro Progress Bar Compat






From Project

Back to project page AlertDialogPro.

License

The source code is released under:

Apache License

If you think the Android project AlertDialogPro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alertdialogpro.material;
/*www.  java  2s  .co  m*/
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;

import com.alertdialogpro.material.drawable.CircularAnimatedDrawable;

public class ProgressBarCompat extends android.widget.ProgressBar {
    private static final int DEFAULT_MATERIAL_BORDER_WIDTH = 4;

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

    public ProgressBarCompat(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.progressBarStyle);
    }

    public ProgressBarCompat(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && isIndeterminate()) {
            final int color = getThemeAttrColor(context, R.attr.colorControlActivated);
            final float borderWidth = TypedValue.applyDimension(
                    TypedValue.COMPLEX_UNIT_DIP,
                    DEFAULT_MATERIAL_BORDER_WIDTH,
                    getResources().getDisplayMetrics()
            );

            if (color != 0) {
                setIndeterminateDrawable(new CircularAnimatedDrawable(color, borderWidth));
            }
        }
    }

    private int getThemeAttrColor(Context context, int attr) {
        if (context == null) {
            return 0;
        }

        TypedValue value = new TypedValue();
        if (context.getTheme().resolveAttribute(attr, value, true)) {
            if (value.type >= TypedValue.TYPE_FIRST_INT
                    && value.type <= TypedValue.TYPE_LAST_INT) {
                return value.data;
            } else if (value.type == TypedValue.TYPE_STRING) {
                return context.getResources().getColor(value.resourceId);
            }
        }

        return 0;
    }

}




Java Source Code List

com.alertdialogpro.AlertDialogPro.java
com.alertdialogpro.ProgressDialogPro.java
com.alertdialogpro.demo.MainActivity.java
com.alertdialogpro.holo.internal.NoTintCheckedTextView.java
com.alertdialogpro.internal.AlertController.java
com.alertdialogpro.internal.DialogTitle.java
com.alertdialogpro.material.ButtonCompat.java
com.alertdialogpro.material.CheckedTextViewCompat.java
com.alertdialogpro.material.ProgressBarCompat.java
com.alertdialogpro.material.drawable.CircularAnimatedDrawable.java