Example usage for android.util AttributeSet getAttributeName

List of usage examples for android.util AttributeSet getAttributeName

Introduction

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

Prototype

public String getAttributeName(int index);

Source Link

Document

Returns the name of the specified attribute.

Usage

From source file:Main.java

public static Bundle fromXml(XmlPullParser parser) {
    Bundle bundle = new Bundle();
    AttributeSet attr = Xml.asAttributeSet(parser);
    for (int i = 0; i < attr.getAttributeCount(); i++) {
        bundle.putString(attr.getAttributeName(i), attr.getAttributeValue(i));
    }/*from   w w  w.j  av a  2 s  . co  m*/
    return bundle;
}

From source file:Main.java

/**
 * Applies stirng to View by Reflection/*  w ww .j  a va2 s  .c o m*/
 *
 * @param context      Context
 * @param view         View to apply to.
 * @param attrs        Attributes of Layout
 */
public static void applyResourceStringToView(Context context, View view, AttributeSet attrs) {
    if (attrs != null) {
        Resources res = context.getResources();
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            int resId = attrs.getAttributeResourceValue(i, 0);
            if (resId > 0) {
                String resType = res.getResourceTypeName(resId);
                if (resType.equals("string")) {
                    String attrName = attrs.getAttributeName(i);
                    try {
                        Method method = view.getClass().getMethod("set" + capitalize(attrName),
                                CharSequence.class);
                        method.setAccessible(true);
                        method.invoke(view, res.getString(resId));
                    } catch (NoSuchMethodException e) {
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
}

From source file:com.openAtlas.bundleInfo.maker.PackageLite.java

private static boolean parseApplication(PackageLite packageLite, XmlPullParser xmlPullParser,
        AttributeSet attributeSet) throws Exception {
    int i;/*from w w w  .  j  a v a 2 s  .  c om*/
    String str = packageLite.packageName;
    for (i = 0; i < attributeSet.getAttributeCount(); i++) {
        String attributeName = attributeSet.getAttributeName(i);
        if (attributeName.equals("name")) {
            packageLite.applicationClassName = buildClassName(str, attributeSet.getAttributeValue(i));
        } else if (attributeName.equals("icon")) {
            packageLite.applicationIcon = attributeSet.getAttributeResourceValue(i, 0);
        } else if (attributeName.equals("label")) {
            packageLite.applicationLabel = attributeSet.getAttributeResourceValue(i, 0);
        } else if (attributeName.equals("description")) {
            packageLite.applicationDescription = attributeSet.getAttributeResourceValue(i, 0);
        }
    }

    final int innerDepth = xmlPullParser.getDepth();

    int type;
    while ((type = xmlPullParser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || xmlPullParser.getDepth() > innerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = xmlPullParser.getName();
        if (tagName.equals("activity")) {

            parseComponentData(packageLite, xmlPullParser, attributeSet, false, Component.ACTIVITY);

        } else if (tagName.equals("receiver")) {

            parseComponentData(packageLite, xmlPullParser, attributeSet, true, Component.RECEIVER);

        } else if (tagName.equals("service")) {

            parseComponentData(packageLite, xmlPullParser, attributeSet, true, Component.SERVISE);

        } else if (tagName.equals("provider")) {

            parseComponentData(packageLite, xmlPullParser, attributeSet, false, Component.PROVIDER);

        } else if (tagName.equals("activity-alias")) {
        } else if (xmlPullParser.getName().equals("meta-data")) {

            parseMetaData(xmlPullParser, attributeSet, packageLite);

        } else if (tagName.equals("uses-library")) {
        } else if (tagName.equals("uses-package")) {
        } else {
        }
    }

    return true;
}

From source file:com.openAtlas.bundleInfo.maker.PackageLite.java

private static void parseComponentData(PackageLite packageLite, XmlPullParser xmlPullParser,
        AttributeSet attributeSet, boolean isDisable, Component mComponent) throws XmlPullParserException {

    String pkgName = packageLite.packageName;
    for (int index = 0; index < attributeSet.getAttributeCount(); index++) {
        if (attributeSet.getAttributeName(index).equals("name")) {
            String mComponentName = attributeSet.getAttributeValue(index);
            if (mComponentName.startsWith(".")) {
                mComponentName = pkgName.concat(mComponentName);
            }//from  www  . j av  a 2  s. co  m
            switch (mComponent) {
            case PROVIDER:
                packageLite.providers.add(mComponentName);
                break;

            case ACTIVITY:
                packageLite.activitys.add(mComponentName);
                break;
            case SERVISE:
                packageLite.services.add(mComponentName);
                break;
            case RECEIVER:
                packageLite.receivers.add(mComponentName);
                break;
            default:
                break;
            }

            if (isDisable && !(TextUtils.equals(mComponentName,
                    XMLDISABLECOMPONENT_SSO_ALIPAY_AUTHENTICATION_SERVICE)
                    && TextUtils.equals(mComponentName, XMLDISABLECOMPONENT_SSO_AUTHENTICATION_SERVICE))) {
                packageLite.disableComponents.add(mComponentName);
            }

        }
    }

}

From source file:com.openAtlas.bundleInfo.maker.PackageLite.java

private static void parseMetaData(XmlPullParser xmlPullParser, AttributeSet attributeSet,
        PackageLite mPackageLite) throws XmlPullParserException, IOException {
    int i = 0;//w w  w.j a  v  a  2  s  .  c  om

    String mTagValue = null;
    String mTagName = null;
    int i2 = 0;
    while (i < attributeSet.getAttributeCount()) {
        String attributeName = attributeSet.getAttributeName(i);
        if (attributeName.equals("name")) {
            mTagName = attributeSet.getAttributeValue(i);
            i2++;
        } else if (attributeName.equals("value")) {
            mTagValue = attributeSet.getAttributeValue(i);
            i2++;
        }
        if (i2 >= 2) {
            break;
        }
        i++;
    }
    if (!(mTagName == null || mTagValue == null)) {
        if (mTagName.equals("dependency")) {
            String[] dependencys = mTagValue.split(",");
            for (String string : dependencys) {
                mPackageLite.dependency.add(string);
            }
            //   System.out.println("PackageLite.parseMetaData()"+mTagValue);
        }
        //bundle.putString(str2, str);
    }
    //return bundle;
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int findAttributeResourceValue(AttributeSet attrs, String name, int defaultValue) {
    for (int i = 0, j = attrs.getAttributeCount(); i < j; i++) {
        if (attrs.getAttributeName(i).equals(name))
            return attrs.getAttributeResourceValue(i, defaultValue);
    }//  w  w  w  . j  av  a  2 s  . com
    return defaultValue;
}

From source file:dev.ronlemire.data.ListViewFragment.java

@Override
public void onInflate(Activity parentActivity, AttributeSet attrs, Bundle bundle) {
    Log.v(ListViewFragment.TAG, "in ListViewFragment onInflate. AttributeSet contains:");
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        Log.v(ListViewFragment.TAG, "    " + attrs.getAttributeName(i) + " = " + attrs.getAttributeValue(i));
    }/* w  w  w.  jav  a2  s. c  o  m*/
    super.onInflate(parentActivity, attrs, bundle);
}

From source file:com.app.bolayam.view.APTabPageIndicator.java

private void initCustomStyleAttribute(AttributeSet attrs) {
    String style = "style";
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        if (style.equals(attrs.getAttributeName(i))) {
            mCustomStyleAttribute = attrs.getAttributeResourceValue(i, -1);
            break;
        }/*ww  w .  j  a  v a 2  s.  c om*/
    }
}

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

/**
 * Costruttore.//  w  w w  .  jav  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.//from  ww w  .  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);
}