Example usage for android.util TypedValue TYPE_LAST_INT

List of usage examples for android.util TypedValue TYPE_LAST_INT

Introduction

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

Prototype

int TYPE_LAST_INT

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

Click Source Link

Document

Identifies the end of plain integer values.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
private static int getColor(Context context, int id, int defaultValue) {
    if (value == null) {
        value = new TypedValue();
    }/*from   ww  w. ja  va  2 s  .  c  o  m*/

    try {
        Resources.Theme theme = context.getTheme();
        if (theme != null && theme.resolveAttribute(id, 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);
            }
        }
    } catch (Exception ignored) {
    }
    return defaultValue;
}

From source file:net.yanzm.actionbarprogress.ThemeUtils.java

public static int getThemeAttrColor(@NonNull Context context, int attr) {
    TypedValue typedValue = new TypedValue();
    if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
        if (typedValue.type >= TypedValue.TYPE_FIRST_INT && typedValue.type <= TypedValue.TYPE_LAST_INT) {
            return typedValue.data;
        } else if (typedValue.type == TypedValue.TYPE_STRING) {
            return ContextCompat.getColor(context, typedValue.resourceId);
        }/*from   w ww. ja v a2s  . co  m*/
    }
    return 0;
}

From source file:eu.power_switch.gui.ThemeHelper.java

/**
 * Get Color from Theme attribute/*from w  w w . j a  va  2  s  . c o m*/
 *
 * @param context Activity context
 * @param attr    Attribute ressource ID
 * @return Color as Int
 */
@ColorInt
public static int getThemeAttrColor(Context context, @AttrRes int attr) {
    TypedValue typedValue = new TypedValue();
    if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
        if (typedValue.type >= TypedValue.TYPE_FIRST_INT && typedValue.type <= TypedValue.TYPE_LAST_INT) {
            return typedValue.data;
        } else if (typedValue.type == TypedValue.TYPE_STRING) {
            return ContextCompat.getColor(context, typedValue.resourceId);
        }
    }

    return 0;
}

From source file:org.opensilk.common.ui.util.ThemeUtils.java

public static int getThemeAttrColor(Context context, int attr) {
    synchronized (sTypedValue) {
        if (context.getTheme().resolveAttribute(attr, sTypedValue, true)) {
            if (sTypedValue.type >= TypedValue.TYPE_FIRST_INT && sTypedValue.type <= TypedValue.TYPE_LAST_INT) {
                return sTypedValue.data;
            } else if (sTypedValue.type == TypedValue.TYPE_STRING) {
                return ContextCompat.getColor(context, sTypedValue.resourceId);
            }/*from w w w .  j  ava  2s.  c o  m*/
        }
    }
    return 0;
}

From source file:com.weihuoya.bboo._G.java

public static int getThemeColor(int id, int defaultValue) {
    TypedValue value = new TypedValue();
    try {//from  ww w . j av a 2s. com
        Context context = getContext();
        Resources.Theme theme = context.getTheme();
        if (theme != null && theme.resolveAttribute(id, 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) {
                ContextCompat.getColor(context, value.resourceId);
            }
        }
    } catch (Exception e) {
        _G.log(e.toString());
    }
    return defaultValue;
}

From source file:lewa.support.v7.internal.widget.TintManager.java

int getThemeAttrColor(int attr) {
    if (mContext.getTheme().resolveAttribute(attr, mTypedValue, true)) {
        if (mTypedValue.type >= TypedValue.TYPE_FIRST_INT && mTypedValue.type <= TypedValue.TYPE_LAST_INT) {
            return mTypedValue.data;
        } else if (mTypedValue.type == TypedValue.TYPE_STRING) {
            return mResources.getColor(mTypedValue.resourceId);
        }//from   ww  w  . j av  a2s .  com
    }
    return 0;
}

From source file:android.content.pm.PackageParser.java

private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesPermission);

    // Note: don't allow this value to be a reference to a resource
    // that may change.
    String name = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestUsesPermission_name);

    int maxSdkVersion = 0;
    TypedValue val = sa.peekValue(com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion);
    if (val != null) {
        if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) {
            maxSdkVersion = val.data;
        }//from  w ww  .j a  v a 2 s . c o  m
    }

    sa.recycle();

    if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.RESOURCES_SDK_INT)) {
        if (name != null) {
            int index = pkg.requestedPermissions.indexOf(name);
            if (index == -1) {
                pkg.requestedPermissions.add(name.intern());
            } else {
                Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " + name
                        + " in package: " + pkg.packageName + " at: " + parser.getPositionDescription());
            }
        }
    }

    XmlUtils.skipCurrentTag(parser);
    return true;
}

From source file:android.content.pm.PackageParser.java

private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data,
        String[] outError) throws XmlPullParserException, IOException {

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData);

    if (data == null) {
        data = new Bundle();
    }/* w  w  w  .  ja v  a  2  s. co  m*/

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name,
            0);
    if (name == null) {
        outError[0] = "<meta-data> requires an android:name attribute";
        sa.recycle();
        return null;
    }

    name = name.intern();

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource);
    if (v != null && v.resourceId != 0) {
        //Slog.i(TAG, "Meta data ref " + name + ": " + v);
        data.putInt(name, v.resourceId);
    } else {
        v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value);
        //Slog.i(TAG, "Meta data " + name + ": " + v);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                data.putString(name, cs != null ? cs.toString().intern() : null);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                data.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) {
                data.putInt(name, v.data);
            } else if (v.type == TypedValue.TYPE_FLOAT) {
                data.putFloat(name, v.getFloat());
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG,
                            "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
                                    + parser.getName() + " at " + mArchiveSourcePath + " "
                                    + parser.getPositionDescription());
                } else {
                    outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
                    data = null;
                }
            }
        } else {
            outError[0] = "<meta-data> requires an android:value or android:resource attribute";
            data = null;
        }
    }

    sa.recycle();

    XmlUtils.skipCurrentTag(parser);

    return data;
}