Example usage for android.util TypedValue TYPE_REFERENCE

List of usage examples for android.util TypedValue TYPE_REFERENCE

Introduction

In this page you can find the example usage for android.util TypedValue TYPE_REFERENCE.

Prototype

int TYPE_REFERENCE

To view the source code for android.util TypedValue TYPE_REFERENCE.

Click Source Link

Document

The data field holds a resource identifier.

Usage

From source file:android.support.wear.widget.CircularProgressLayout.java

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

    mProgressDrawable = new CircularProgressDrawable(context);
    mProgressDrawable.setProgressRotation(DEFAULT_ROTATION);
    mProgressDrawable.setStrokeCap(Paint.Cap.BUTT);
    setBackground(mProgressDrawable);/*  w w w  . ja va 2  s  .c  o m*/

    // If a child view is added, make it center aligned so it fits in the progress drawable.
    setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
        @Override
        public void onChildViewAdded(View parent, View child) {
            // Ensure that child view is aligned in center
            LayoutParams params = (LayoutParams) child.getLayoutParams();
            params.gravity = Gravity.CENTER;
            child.setLayoutParams(params);
        }

        @Override
        public void onChildViewRemoved(View parent, View child) {

        }
    });

    mController = new CircularProgressLayoutController(this);

    Resources r = context.getResources();
    TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout);

    if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE
            || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) {
        int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors,
                R.array.circular_progress_layout_color_scheme_colors);
        setColorSchemeColors(getColorListFromResources(r, arrayResId));
    } else {
        setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK));
    }

    setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth,
            r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width)));

    setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor,
            ContextCompat.getColor(context, R.color.circular_progress_layout_background_color)));

    setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false));

    a.recycle();
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static int getColorFromAttribute(Context context, int attr, int def) {
    final TypedValue outValue = new TypedValue();
    if (!context.getTheme().resolveAttribute(attr, outValue, true))
        return def;
    if (outValue.type == TypedValue.TYPE_REFERENCE)
        return context.getResources().getColor(attr);
    return outValue.data;
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static int getColorFromAttribute(Context context, int themeId, int attr, int def) {
    final TypedValue outValue = new TypedValue();
    final Resources.Theme theme = context.getResources().newTheme();
    theme.applyStyle(themeId, true);/*from w w  w .ja  v a 2  s . c  o  m*/
    if (!theme.resolveAttribute(attr, outValue, true))
        return def;
    if (outValue.type == TypedValue.TYPE_REFERENCE)
        return context.getResources().getColor(attr);
    return outValue.data;
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static int getThemeForegroundColor(final Context context, int themeRes) {
    @SuppressWarnings("ConstantConditions")
    final TypedValue value = new TypedValue();
    final Resources.Theme theme;
    if (themeRes != 0) {
        theme = context.getResources().newTheme();
        theme.applyStyle(themeRes, false);
    } else {/*from  w w w.  j  a  v  a  2 s  .  c  om*/
        theme = context.getTheme();
    }
    if (!theme.resolveAttribute(android.R.attr.colorForeground, value, true)) {
        return 0;
    }
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        // windowBackground is a color
        return value.data;
    } else if (value.type == TypedValue.TYPE_REFERENCE) {
        return theme.getResources().getColor(value.resourceId);
    }
    return 0;
}