Java Code Examples for android.util.TypedValue#TYPE_FRACTION

The following examples show how to use android.util.TypedValue#TYPE_FRACTION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScaleAnimation.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
float resolveScale(float scale, int type, int data, int size, int psize) {
    float targetSize;
    if (type == TypedValue.TYPE_FRACTION) {
        targetSize = TypedValue.complexToFraction(data, size, psize);
    } else if (type == TypedValue.TYPE_DIMENSION) {
        targetSize = TypedValue.complexToDimension(data, mResources.getDisplayMetrics());
    } else {
        return scale;
    }

    if (size == 0) {
        return 1;
    }

    return targetSize/(float)size;
}
 
Example 2
Source File: TypedArray.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves a fractional unit attribute at <var>index</var>.
 *
 * @param index Index of attribute to retrieve.
 * @param base The base value of this fraction.  In other words, a
 *             standard fraction is multiplied by this value.
 * @param pbase The parent base value of this fraction.  In other
 *             words, a parent fraction (nn%p) is multiplied by this
 *             value.
 * @param defValue Value to return if the attribute is not defined or
 *                 not a resource.
 *
 * @return Attribute fractional value multiplied by the appropriate
 *         base value, or defValue if not defined.
 * @throws RuntimeException if the TypedArray has already been recycled.
 * @throws UnsupportedOperationException if the attribute is defined but is
 *         not a fraction.
 */
public float getFraction(@StyleableRes int index, int base, int pbase, float defValue) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }

    final int attrIndex = index;
    index *= STYLE_NUM_ENTRIES;

    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return defValue;
    } else if (type == TypedValue.TYPE_FRACTION) {
        return TypedValue.complexToFraction(data[index + STYLE_DATA], base, pbase);
    } else if (type == TypedValue.TYPE_ATTRIBUTE) {
        final TypedValue value = mValue;
        getValueAt(index, value);
        throw new UnsupportedOperationException(
                "Failed to resolve attribute at index " + attrIndex + ": " + value);
    }

    throw new UnsupportedOperationException("Can't convert value at index " + attrIndex
            + " to fraction: type=0x" + Integer.toHexString(type));
}
 
Example 3
Source File: AXMLPrinter.java    From Android-Applications-Info with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) +
                DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) +
                FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 4
Source File: Keyboard.java    From libcommon with Apache License 2.0 5 votes vote down vote up
static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
	TypedValue value = a.peekValue(index);
	if (value == null) return defValue;
	if (value.type == TypedValue.TYPE_DIMENSION) {
		return a.getDimensionPixelOffset(index, defValue);
	} else if (value.type == TypedValue.TYPE_FRACTION) {
		// Round it to avoid values like 47.9999 from getting truncated
		return Math.round(a.getFraction(index, base, base, defValue));
	}
	return defValue;
}
 
Example 5
Source File: ManifestReader.java    From PluginLoader with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 6
Source File: ResValueFactory.java    From Auto.js-ApkBuilder with Apache License 2.0 5 votes vote down vote up
public ResScalarValue factory(int type, int value, String rawValue) throws IOException {
	switch (type) {
	case TypedValue.TYPE_NULL:
		return new ResReferenceValue(mPackage, 0, null);
	case TypedValue.TYPE_REFERENCE:
		return newReference(value, rawValue);
	case TypedValue.TYPE_ATTRIBUTE:
		return newReference(value, rawValue, true);
	case TypedValue.TYPE_STRING:
		return new ResStringValue(rawValue, value);
	case TypedValue.TYPE_FLOAT:
		return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
	case TypedValue.TYPE_DIMENSION:
		return new ResDimenValue(value, rawValue);
	case TypedValue.TYPE_FRACTION:
		return new ResFractionValue(value, rawValue);
	case TypedValue.TYPE_INT_BOOLEAN:
		return new ResBoolValue(value != 0, value, rawValue);
	case 0x07:
		return newReference(value, rawValue);
	}

	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return new ResColorValue(value, rawValue);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return new ResIntValue(value, rawValue, type);
	}

	throw new IOException("Invalid value type: " + type);
}
 
Example 7
Source File: FakeDialogPhoneWindow.java    From android-apps with MIT License 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width = getMeasuredWidth();
    boolean measure = false;

    widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);

    final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;

    if (tv.type != TypedValue.TYPE_NULL) {
        final int min;
        if (tv.type == TypedValue.TYPE_DIMENSION) {
            min = (int)tv.getDimension(metrics);
        } else if (tv.type == TypedValue.TYPE_FRACTION) {
            min = (int)tv.getFraction(metrics.widthPixels, metrics.widthPixels);
        } else {
            min = 0;
        }

        if (width < min) {
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
            measure = true;
        }
    }

    // TODO: Support height?

    if (measure) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
 
Example 8
Source File: ResignerLogic.java    From apkReSign with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))
                + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))
                + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT
            && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 9
Source File: GradientDrawableInflateImpl.java    From timecat with Apache License 2.0 5 votes vote down vote up
float getAttrFloatOrFraction(Context context, AttributeSet attrs, int attr, float defaultValue, float base, float pbase) {
    TypedArray a = DrawableUtils.obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr});
    TypedValue tv = a.peekValue(0);
    float v = defaultValue;
    if (tv != null) {
        boolean isFraction = tv.type == TypedValue.TYPE_FRACTION;
        v = isFraction ? tv.getFraction(base, pbase) : tv.getFloat();
    }
    a.recycle();
    return v;
}
 
Example 10
Source File: GradientDrawableInflateImpl.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
float getAttrFloatOrFraction(Context context, AttributeSet attrs, int attr, float defaultValue, float base, float pbase) {
    TypedArray a = DrawableUtils.obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr});
    TypedValue tv = a.peekValue(0);
    float v = defaultValue;
    if (tv != null) {
        boolean isFraction = tv.type == TypedValue.TYPE_FRACTION;
        v = isFraction ? tv.getFraction(base, pbase) : tv.getFloat();
    }
    a.recycle();
    return v;
}
 
Example 11
Source File: Rotate3dAnimation.java    From pe-protector-moe with GNU General Public License v3.0 5 votes vote down vote up
Description parseValue(TypedValue value) {
    Description d = new Description();
    if (value == null) {
        d.type = ABSOLUTE;
        d.value = 0;
    } else {
        if (value.type == TypedValue.TYPE_FRACTION) {
            d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) ==
                    TypedValue.COMPLEX_UNIT_FRACTION_PARENT ?
                    RELATIVE_TO_PARENT : RELATIVE_TO_SELF;
            d.value = TypedValue.complexToFloat(value.data);
            return d;
        } else if (value.type == TypedValue.TYPE_FLOAT) {
            d.type = ABSOLUTE;
            d.value = value.getFloat();
            return d;
        } else if (value.type >= TypedValue.TYPE_FIRST_INT &&
                value.type <= TypedValue.TYPE_LAST_INT) {
            d.type = ABSOLUTE;
            d.value = value.data;
            return d;
        }
    }

    d.type = ABSOLUTE;
    d.value = 0.0f;

    return d;
}
 
Example 12
Source File: ManifestReader.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    if (type == 0x07) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 13
Source File: AndroidXmlConvertor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
	int type = parser.getAttributeValueType(index);
	int data = parser.getAttributeValueData(index);

	if (type == TypedValue.TYPE_STRING) {
		return parser.getAttributeValue(index);
	}
	if (type == TypedValue.TYPE_ATTRIBUTE) {
		return String.format("?%s%08X", getPackage(data), data);
	}
	if (type == TypedValue.TYPE_REFERENCE) {
		return String.format("@%s%08X", getPackage(data), data);
	}
	if (type == TypedValue.TYPE_FLOAT) {
		return String.valueOf(Float.intBitsToFloat(data));
	}
	if (type == TypedValue.TYPE_INT_HEX) {
		return String.format("0x%08X", data);
	}
	if (type == TypedValue.TYPE_INT_BOOLEAN) {
		return data == 0 ? "false" : "true";
	}
	if (type == TypedValue.TYPE_DIMENSION) {
		return Float.toString(complexToFloat(data)) +
			DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type == TypedValue.TYPE_FRACTION) {
		return Float.toString(complexToFloat(data)) +
			FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return String.format("#%08X", data);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return String.valueOf(data);
	}
	return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 14
Source File: XmlManifestReader.java    From AndroidPlugin with MIT License 5 votes vote down vote up
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))
                + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))
                + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT
            && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 15
Source File: Rotate3dAnimation.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
Description parseValue(TypedValue value) {
    Description d = new Description();
    if (value == null) {
        d.type = ABSOLUTE;
        d.value = 0;
    } else {
        if (value.type == TypedValue.TYPE_FRACTION) {
            d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) ==
                    TypedValue.COMPLEX_UNIT_FRACTION_PARENT ?
                    RELATIVE_TO_PARENT : RELATIVE_TO_SELF;
            d.value = TypedValue.complexToFloat(value.data);
            return d;
        } else if (value.type == TypedValue.TYPE_FLOAT) {
            d.type = ABSOLUTE;
            d.value = value.getFloat();
            return d;
        } else if (value.type >= TypedValue.TYPE_FIRST_INT &&
                value.type <= TypedValue.TYPE_LAST_INT) {
            d.type = ABSOLUTE;
            d.value = value.data;
            return d;
        }
    }

    d.type = ABSOLUTE;
    d.value = 0.0f;

    return d;
}
 
Example 16
Source File: Animation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Size descriptions can appear inthree forms:
 * <ol>
 * <li>An absolute size. This is represented by a number.</li>
 * <li>A size relative to the size of the object being animated. This
 * is represented by a number followed by "%".</li> *
 * <li>A size relative to the size of the parent of object being
 * animated. This is represented by a number followed by "%p".</li>
 * </ol>
 * @param value The typed value to parse
 * @return The parsed version of the description
 */
static Description parseValue(TypedValue value) {
    Description d = new Description();
    if (value == null) {
        d.type = ABSOLUTE;
        d.value = 0;
    } else {
        if (value.type == TypedValue.TYPE_FRACTION) {
            d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) ==
                    TypedValue.COMPLEX_UNIT_FRACTION_PARENT ?
                            RELATIVE_TO_PARENT : RELATIVE_TO_SELF;
            d.value = TypedValue.complexToFloat(value.data);
            return d;
        } else if (value.type == TypedValue.TYPE_FLOAT) {
            d.type = ABSOLUTE;
            d.value = value.getFloat();
            return d;
        } else if (value.type >= TypedValue.TYPE_FIRST_INT &&
                value.type <= TypedValue.TYPE_LAST_INT) {
            d.type = ABSOLUTE;
            d.value = value.data;
            return d;
        }
    }

    d.type = ABSOLUTE;
    d.value = 0.0f;

    return d;
}
 
Example 17
Source File: ResourceUtils.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isFractionValue(final TypedValue v) {
    return v.type == TypedValue.TYPE_FRACTION;
}
 
Example 18
Source File: LinearProgressDrawable.java    From material with Apache License 2.0 4 votes vote down vote up
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinearProgressDrawable, defStyleAttr, defStyleRes);
	int resId;
	
	progressPercent(a.getFloat(R.styleable.LinearProgressDrawable_pv_progress, 0));	
	secondaryProgressPercent(a.getFloat(R.styleable.LinearProgressDrawable_pv_secondaryProgress, 0));
	
	TypedValue value = a.peekValue(R.styleable.LinearProgressDrawable_lpd_maxLineWidth);
	if(value == null)
		maxLineWidth(0.75f);
	else if(value.type == TypedValue.TYPE_FRACTION)
		maxLineWidth(a.getFraction(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 1, 1, 0.75f));
	else 
		maxLineWidth(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 0));
	
	value = a.peekValue(R.styleable.LinearProgressDrawable_lpd_minLineWidth);
	if(value == null)
		minLineWidth(0.25f);
	else if(value.type == TypedValue.TYPE_FRACTION)
		minLineWidth(a.getFraction(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 1, 1, 0.25f));
	else 
		minLineWidth(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 0));
	
	strokeSize(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_strokeSize, ThemeUtil.dpToPx(context, 4)));
	verticalAlign(a.getInteger(R.styleable.LinearProgressDrawable_lpd_verticalAlign, LinearProgressDrawable.ALIGN_BOTTOM));
	strokeColors(a.getColor(R.styleable.LinearProgressDrawable_lpd_strokeColor, ThemeUtil.colorPrimary(context, 0xFF000000)));
	if((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_strokeColors, 0)) != 0){
		TypedArray ta = context.getResources().obtainTypedArray(resId);				        	
		int[] colors = new int[ta.length()];
		for(int j = 0; j < ta.length(); j++)
		    colors[j] = ta.getColor(j, 0);				        	
		ta.recycle();
		strokeColors(colors);
	}
	strokeSecondaryColor(a.getColor(R.styleable.LinearProgressDrawable_lpd_strokeSecondaryColor, 0));
	reverse(a.getBoolean(R.styleable.LinearProgressDrawable_lpd_reverse, false));
	travelDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_travelDuration, context.getResources().getInteger(android.R.integer.config_longAnimTime)));
	transformDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_transformDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	keepDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_keepDuration, context.getResources().getInteger(android.R.integer.config_shortAnimTime)));
	if((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_transformInterpolator, 0)) != 0)
		transformInterpolator(AnimationUtils.loadInterpolator(context, resId));
	progressMode(a.getInteger(R.styleable.LinearProgressDrawable_pv_progressMode, ProgressView.MODE_INDETERMINATE));
	inAnimDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_inAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	outAnimDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_outAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	
	a.recycle();				
}
 
Example 19
Source File: LinearProgressDrawable.java    From MDPreference with Apache License 2.0 4 votes vote down vote up
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinearProgressDrawable, defStyleAttr, defStyleRes);
	int resId;
	
	progressPercent(a.getFloat(R.styleable.LinearProgressDrawable_pv_progress, 0));	
	secondaryProgressPercent(a.getFloat(R.styleable.LinearProgressDrawable_pv_secondaryProgress, 0));
	
	TypedValue value = a.peekValue(R.styleable.LinearProgressDrawable_lpd_maxLineWidth);
	if(value == null)
		maxLineWidth(0.75f);
	else if(value.type == TypedValue.TYPE_FRACTION)
		maxLineWidth(a.getFraction(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 1, 1, 0.75f));
	else 
		maxLineWidth(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 0));
	
	value = a.peekValue(R.styleable.LinearProgressDrawable_lpd_minLineWidth);
	if(value == null)
		minLineWidth(0.25f);
	else if(value.type == TypedValue.TYPE_FRACTION)
		minLineWidth(a.getFraction(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 1, 1, 0.25f));
	else 
		minLineWidth(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 0));
	
	strokeSize(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_strokeSize, ThemeUtil.dpToPx(context, 4)));
	verticalAlign(a.getInteger(R.styleable.LinearProgressDrawable_lpd_verticalAlign, LinearProgressDrawable.ALIGN_BOTTOM));
	strokeColors(a.getColor(R.styleable.LinearProgressDrawable_lpd_strokeColor, ThemeUtil.colorPrimary(context, 0xFF000000)));
	if((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_strokeColors, 0)) != 0){
		TypedArray ta = context.getResources().obtainTypedArray(resId);				        	
		int[] colors = new int[ta.length()];
		for(int j = 0; j < ta.length(); j++)
		    colors[j] = ta.getColor(j, 0);				        	
		ta.recycle();
		strokeColors(colors);
	}
	strokeSecondaryColor(a.getColor(R.styleable.LinearProgressDrawable_lpd_strokeSecondaryColor, 0));
	reverse(a.getBoolean(R.styleable.LinearProgressDrawable_lpd_reverse, false));
	travelDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_travelDuration, context.getResources().getInteger(android.R.integer.config_longAnimTime)));
	transformDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_transformDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	keepDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_keepDuration, context.getResources().getInteger(android.R.integer.config_shortAnimTime)));
	if((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_transformInterpolator, 0)) != 0)
		transformInterpolator(AnimationUtils.loadInterpolator(context, resId));
	progressMode(a.getInteger(R.styleable.LinearProgressDrawable_pv_progressMode, ProgressView.MODE_INDETERMINATE));
	inAnimDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_inAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	outAnimDuration(a.getInteger(R.styleable.LinearProgressDrawable_lpd_outAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	
	a.recycle();				
}
 
Example 20
Source File: Resources.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieve a fractional unit for a particular resource ID.
 * 
 * @param id The desired resource identifier, as generated by the aapt
 *           tool. This integer encodes the package, type, and resource
 *           entry. The value 0 is an invalid identifier.
 * @param base The base value of this fraction.  In other words, a 
 *             standard fraction is multiplied by this value.
 * @param pbase The parent base value of this fraction.  In other 
 *             words, a parent fraction (nn%p) is multiplied by this
 *             value.
 * 
 * @return Attribute fractional value multiplied by the appropriate 
 * base value.
 *  
 * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
 */
public float getFraction(@FractionRes int id, int base, int pbase) {
    final TypedValue value = obtainTempTypedValue();
    try {
        mResourcesImpl.getValue(id, value, true);
        if (value.type == TypedValue.TYPE_FRACTION) {
            return TypedValue.complexToFraction(value.data, base, pbase);
        }
        throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id)
                + " type #0x" + Integer.toHexString(value.type) + " is not valid");
    } finally {
        releaseTempTypedValue(value);
    }
}