Example usage for android.util AttributeSet getAttributeIntValue

List of usage examples for android.util AttributeSet getAttributeIntValue

Introduction

In this page you can find the example usage for android.util AttributeSet getAttributeIntValue.

Prototype

public int getAttributeIntValue(int index, int defaultValue);

Source Link

Document

Return the integer value of attribute at 'index'.

Usage

From source file:it.scoppelletti.mobilepower.preference.SeekBarPreference.java

/**
 * Costruttore.//from w w  w  . ja  va  2s.  c om
 * 
 * @param context Contesto.
 * @param attrs   Attributi.
 */
public SeekBarPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    int i, n;
    String name;

    myValueMin = 0;
    myValueMax = 100;
    n = attrs.getAttributeCount();
    for (i = 0; i < n; i++) {
        name = attrs.getAttributeName(i);
        if (SeekBarPreference.ATTR_VALUEMIN.equals(name)) {
            myValueMin = attrs.getAttributeIntValue(i, myValueMin);
        } else if (SeekBarPreference.ATTR_VALUEMAX.equals(name)) {
            myValueMax = attrs.getAttributeIntValue(i, myValueMax);
        } else if (SeekBarPreference.ATTR_PREVIEW.equals(name)) {
            myPreview = attrs.getAttributeValue(i);
        }
    }

    if (myValueMax < 1) {
        myValueMax = 100;
    }

    setDialogLayoutResource(R.layout.seekbarpreference);
}

From source file:com.pavelsikun.seekbarpreference.SeekBarPreference.java

private void init(AttributeSet attrs) {
    setLayoutResource(R.layout.seekbar_preference);

    if (attrs == null) {
        mMinValue = DEFAULT_MIN_VALUE;//from   w ww.j  a  v  a  2s.  c om
        mMaxValue = DEFAULT_MAX_VALUE;
        mInterval = DEFAULT_INTERVAL;
        mMeasurementUnit = DEFAULT_MEASUREMENT_UNIT;
        mValueTextSize = DEFAULT_TEXT_SIZE;
    } else {
        TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.SeekBarPreference);
        try {
            mMinValue = ta.getInt(R.styleable.SeekBarPreference_msbp_minValue, DEFAULT_MIN_VALUE);
            mMaxValue = ta.getInt(R.styleable.SeekBarPreference_msbp_maxValue, DEFAULT_MAX_VALUE);
            mInterval = ta.getInt(R.styleable.SeekBarPreference_msbp_interval, DEFAULT_INTERVAL);

            mDefaultValue = attrs.getAttributeIntValue(android.R.attr.defaultValue, DEFAULT_CURRENT_VALUE);

            mValueTextSize = ta.getDimensionPixelSize(R.styleable.SeekBarPreference_msbp_valueTextSize,
                    (int) (getContext().getResources().getDisplayMetrics().density * DEFAULT_TEXT_SIZE));

            if (mDefaultValue < mMinValue) {
                mDefaultValue = (mMaxValue - mMinValue) / 2;
            }
            mMeasurementUnit = ta.getString(R.styleable.SeekBarPreference_msbp_measurementUnit);
            if (mMeasurementUnit == null) {
                mMeasurementUnit = DEFAULT_MEASUREMENT_UNIT;
            }
        } finally {
            ta.recycle();
        }
    }
}

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

private static ApkLite parseApkLite(String codePath, Resources res, XmlPullParser parser, AttributeSet attrs,
        int flags, Signature[] signatures) throws IOException, XmlPullParserException, PackageParserException {
    final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs, flags);

    int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
    int versionCode = 0;
    int revisionCode = 0;
    boolean coreApp = false;
    boolean multiArch = false;
    boolean extractNativeLibs = true;

    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        final String attr = attrs.getAttributeName(i);
        if (attr.equals("installLocation")) {
            installLocation = attrs.getAttributeIntValue(i, PARSE_DEFAULT_INSTALL_LOCATION);
        } else if (attr.equals("versionCode")) {
            versionCode = attrs.getAttributeIntValue(i, 0);
        } else if (attr.equals("revisionCode")) {
            revisionCode = attrs.getAttributeIntValue(i, 0);
        } else if (attr.equals("coreApp")) {
            coreApp = attrs.getAttributeBooleanValue(i, false);
        }//ww  w  .j  a  v  a 2s  . com
    }

    // Only search the tree when the tag is directly below <manifest>
    int type;
    final int searchDepth = parser.getDepth() + 1;

    final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
            final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags);
            if (verifier != null) {
                verifiers.add(verifier);
            }
        }

        if (parser.getDepth() == searchDepth && "application".equals(parser.getName())) {
            for (int i = 0; i < attrs.getAttributeCount(); ++i) {
                final String attr = attrs.getAttributeName(i);
                if ("multiArch".equals(attr)) {
                    multiArch = attrs.getAttributeBooleanValue(i, false);
                }
                if ("extractNativeLibs".equals(attr)) {
                    extractNativeLibs = attrs.getAttributeBooleanValue(i, true);
                }
            }
        }
    }

    return new ApkLite(codePath, packageSplit.first, packageSplit.second, versionCode, revisionCode,
            installLocation, verifiers, signatures, coreApp, multiArch, extractNativeLibs);
}