Example usage for android.util AttributeSet getAttributeCount

List of usage examples for android.util AttributeSet getAttributeCount

Introduction

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

Prototype

public int getAttributeCount();

Source Link

Document

Returns the number of attributes available in the set.

Usage

From source file:it.scoppelletti.mobilepower.widget.DateControl.java

/**
 * Costruttore./*from w  ww. j av a  2 s  . c o m*/
 * 
 * @param ctx   Contesto.
 * @param attrs Attributi.
 */
public DateControl(Context ctx, AttributeSet attrs) {
    super(ctx, attrs);

    int i, n;
    String name;

    myIsEmptyAllowed = true;
    myIsResetEnabled = false;

    n = attrs.getAttributeCount();
    for (i = 0; i < n; i++) {
        name = attrs.getAttributeName(i);
        if (DateControl.STATE_DIALOGTAG.equals(name)) {
            myDialogTag = attrs.getAttributeValue(i);
        } else if (DateControl.STATE_ISEMPTYALLOWED.equals(name)) {
            myIsEmptyAllowed = attrs.getAttributeBooleanValue(i, myIsEmptyAllowed);
        } else if (DateControl.STATE_ISRESETENABLED.equals(name)) {
            myIsResetEnabled = attrs.getAttributeBooleanValue(i, myIsResetEnabled);
        }
    }

    init(ctx);
}

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

/**
 * Costruttore.//w  ww  .  ja v  a2  s.co m
 * 
 * @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.nttec.everychan.ui.theme.CustomThemeHelper.java

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    int mappingCount = 0;
    if (attrs != null) {
        for (int i = 0, size = attrs.getAttributeCount(); i < size; ++i) {
            String value = attrs.getAttributeValue(i);
            if (!value.startsWith("?"))
                continue;
            int attrId = resources.getIdentifier(value.substring(1), null, null); //Integer.parseInt(value.substring(1));
            if (attrId == 0) {
                Logger.e(TAG, "couldn't get id for attribute: " + value);
                continue;
            }/*from  w  w w  .  j  av a2  s  .  c o  m*/
            int index = customAttrs.indexOfKey(attrId);
            if (index >= 0) {
                mappingKeys[mappingCount] = attrs.getAttributeNameResource(i);
                mappingValues[mappingCount] = customAttrs.valueAt(index);
                ++mappingCount;
            }
        }
    }

    if (mappingCount == 0 && textColorPrimaryOverridden == textColorPrimaryOriginal)
        return null;

    View view = instantiate(name, context, attrs);
    if (view == null)
        return null;

    boolean shouldOverrideTextColor = textColorPrimaryOverridden != textColorPrimaryOriginal
            && view instanceof TextView;
    for (int i = 0; i < mappingCount; ++i) {
        switch (mappingKeys[i]) {
        case android.R.attr.background:
            view.setBackgroundColor(mappingValues[i]);
            break;
        case android.R.attr.textColor:
            if (view instanceof TextView) {
                ((TextView) view).setTextColor(mappingValues[i]);
                shouldOverrideTextColor = false;
            } else {
                Logger.e(TAG, "couldn't apply attribute 'textColor' on class " + name
                        + " (not instance of TextView)");
            }
            break;
        case android.R.attr.divider:
            if (view instanceof ListView) {
                ListView listView = (ListView) view;
                int dividerHeight = listView.getDividerHeight();
                listView.setDivider(new ColorDrawable(mappingValues[i]));
                listView.setDividerHeight(dividerHeight);
            } else {
                Logger.e(TAG,
                        "couldn't apply attribute 'divider' on class " + name + " (not instance of ListView)");
            }
            break;
        default:
            String attrResName = null;
            try {
                attrResName = resources.getResourceName(mappingKeys[i]);
            } catch (Exception e) {
                attrResName = Integer.toString(mappingKeys[i]);
            }
            Logger.e(TAG, "couldn't apply attribure '" + attrResName + "' on class " + name);
        }
    }

    if (shouldOverrideTextColor) {
        TextView tv = (TextView) view;
        if (tv.getCurrentTextColor() == textColorPrimaryOriginal) {
            tv.setTextColor(textColorPrimaryOverridden);
        }
    }

    return view;
}

From source file:android.support.v7.content.res.AppCompatColorStateListInflater.java

/**
 * Fill in this object based on the contents of an XML "selector" element.
 *//*from  ww w  .j av a  2s.c o m*/
private static ColorStateList inflate(@NonNull Resources r, @NonNull XmlPullParser parser,
        @NonNull AttributeSet attrs, @Nullable Resources.Theme theme)
        throws XmlPullParserException, IOException {
    final int innerDepth = parser.getDepth() + 1;
    int depth;
    int type;
    int defaultColor = DEFAULT_COLOR;

    int[][] stateSpecList = new int[20][];
    int[] colorList = new int[stateSpecList.length];
    int listSize = 0;

    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) {
            continue;
        }

        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.ColorStateListItem);
        final int baseColor = a.getColor(R.styleable.ColorStateListItem_android_color, Color.MAGENTA);

        float alphaMod = 1.0f;
        if (a.hasValue(R.styleable.ColorStateListItem_android_alpha)) {
            alphaMod = a.getFloat(R.styleable.ColorStateListItem_android_alpha, alphaMod);
        } else if (a.hasValue(R.styleable.ColorStateListItem_alpha)) {
            alphaMod = a.getFloat(R.styleable.ColorStateListItem_alpha, alphaMod);
        }

        a.recycle();

        // Parse all unrecognized attributes as state specifiers.
        int j = 0;
        final int numAttrs = attrs.getAttributeCount();
        int[] stateSpec = new int[numAttrs];
        for (int i = 0; i < numAttrs; i++) {
            final int stateResId = attrs.getAttributeNameResource(i);
            if (stateResId != android.R.attr.color && stateResId != android.R.attr.alpha
                    && stateResId != R.attr.alpha) {
                // Unrecognized attribute, add to state set
                stateSpec[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
            }
        }
        stateSpec = StateSet.trimStateSet(stateSpec, j);

        // Apply alpha modulation. If we couldn't resolve the color or
        // alpha yet, the default values leave us enough information to
        // modulate again during applyTheme().
        final int color = modulateColorAlpha(baseColor, alphaMod);
        if (listSize == 0 || stateSpec.length == 0) {
            defaultColor = color;
        }

        colorList = GrowingArrayUtils.append(colorList, listSize, color);
        stateSpecList = GrowingArrayUtils.append(stateSpecList, listSize, stateSpec);
        listSize++;
    }

    int[] colors = new int[listSize];
    int[][] stateSpecs = new int[listSize][];
    System.arraycopy(colorList, 0, colors, 0, listSize);
    System.arraycopy(stateSpecList, 0, stateSpecs, 0, listSize);

    return new ColorStateList(stateSpecs, colors);
}

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);
        }/*from  w ww .ja  v  a 2  s. c o  m*/
    }

    // 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);
}