Android TypedValue - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TypedValue class.

This code example shows how to use the following methods:getDimension, getFraction
        if (!fixedWidth && widthMode == AT_MOST) {
            final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;
            if (tv != null && 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;
                } 
            } 
        } 
        if (!fixedHeight && heightMode == AT_MOST) {
            final TypedValue tv = isPortrait ? mMinHeightMinor : mMinHeightMajor;
7
CodeRank
This code example shows how to use the following methods:applyDimension
@RunWith(TestRunners.WithDefaults.class) 
public class TypedValueTest { 
 
    @Test 
    public void testApplyDimensionIsWired() throws Exception { 
        DisplayMetrics metrics = new DisplayMetrics();
        metrics.density = 0.5f;
        float convertedValue = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, metrics);
        assertThat(convertedValue).isEqualTo(50f);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
 * @see R.attr#gdActionBarItemColorAlt 
 * @author Cyril Mottier 
 */ 
public class ActionBarDrawable extends BitmapDrawable {
 
    private static final TypedValue sTypedValue = new TypedValue();
 
    private ColorFilter mNormalCf;
    private ColorFilter mAltCf;
 
    /** 
     * Create a new ActionBarDrawable 
     *  
     * @param res The Resources from which the given icon is retrieved 
     * @param resId The icon's resource ID 
     * @deprecated Use {@link ActionBarDrawable#ActionBarDrawable(Context, int)} 
     *             as it looks for the default alternative/normal colors in the 
     *             theme. 
     */ 
    @Deprecated 
7
CodeRank
This code example shows how to use the following methods:resolveAttribute
This code example shows how to use the following methods:coerceToString
                    + attrs.getPositionDescription());
        } 
        TypedValue v = sa.peekValue(R.styleable.Extra_android_value);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                outBundle.putCharSequence(name, cs);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                outBundle.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT
                    && v.type <= TypedValue.TYPE_LAST_INT) {
                outBundle.putInt(name, v.data);
            } else if (v.type == TypedValue.TYPE_FLOAT) {
                outBundle.putFloat(name, v.getFloat());
            } else { 
                sa.recycle();
                throw new XmlPullParserException("<" + tagName
                        + "> only supports string, integer, float, color, and boolean at " 
                        + attrs.getPositionDescription());
            } 
7
CodeRank
This code example shows how to use the following methods:getDimension, getFraction
        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? 
 
7
CodeRank
This code example shows how to use the following methods:resolveAttribute
 
    protected Drawable getActionBarBackground(Context context) {
        int[] android_styleable_ActionBar = {android.R.attr.background};
 
        // Need to get resource id of style pointed to from actionBarStyle 
        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);
        // Now get action bar style values... 
        TypedArray abStyle = context.getTheme().obtainStyledAttributes(outValue.resourceId,
                android_styleable_ActionBar);
        try { 
            // background is the first attr in the array above so it's index is 0. 
            return abStyle.getDrawable(0);
        } finally { 
            abStyle.recycle();
        } 
    } 
 
    protected int getActionBarSize(Context context) {
        int[] attrs = {android.R.attr.actionBarSize};
7
CodeRank
This code example shows how to use the following methods:resolveAttribute
This code example shows how to use the following methods:complexToDimension, getMetrics
This code example shows how to use the following methods:
public final class ResourceHelper { 
 
  private final static Pattern sFloatPattern = Pattern.compile("(-?[0-9]+(?:\\.[0-9]+)?)(.*)");
  private final static float[] sFloatOut = new float[1];
 
  private final static TypedValue mValue = new TypedValue();
 
  /** 
   * Returns the color value represented by the given string value 
   * @param value the color value 
   * @return the color as an int 
   * @throw NumberFormatException if the conversion failed. 
   */ 
  public static int getColor(String value) {
    if (value != null) {
      if (value.startsWith("#") == false) {
        throw new NumberFormatException(
            String.format("Color value '%s' must start with #", value));
      } 
 
6
CodeRank

Related Android TypedValue Questions & Answers:

See Code Examples for Android TypedValue Methods: