List of usage examples for android.util AttributeSet getAttributeValue
public String getAttributeValue(int index);
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 ww w.j a v a 2 s .c om return bundle; }
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 w w w . ja v 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 boolean parseApplication(PackageLite packageLite, XmlPullParser xmlPullParser, AttributeSet attributeSet) throws Exception { int i;/*w w w .j a va 2 s . co m*/ 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 parseMetaData(XmlPullParser xmlPullParser, AttributeSet attributeSet, PackageLite mPackageLite) throws XmlPullParserException, IOException { int i = 0;/*ww w .j av a2 s . c o m*/ 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: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 . j a va 2s . c o m super.onInflate(parentActivity, attrs, bundle); }
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 ww w. j a v 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:it.scoppelletti.mobilepower.widget.DateControl.java
/** * Costruttore./*from w ww .j a v 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:me.henrytao.mdcore.core.MdCompat.java
/** * A temporary fix for android.content.res.ColorStateList.inflate *//* ww w. jav a2 s . c o m*/ public static ColorStateList getColorStateList(Context context, int resId) throws IOException, XmlPullParserException { XmlResourceParser parser = context.getResources().getXml(resId); AttributeSet attrs = Xml.asAttributeSet(parser); Resources r = context.getResources(); final int innerDepth = parser.getDepth() + 2; int depth; int type; List<int[]> customStateList = new ArrayList<>(); List<Integer> customColorList = new ArrayList<>(); 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; } // Parse all unrecognized attributes as state specifiers. int j = 0; final int numAttrs = attrs.getAttributeCount(); int color = 0; float alpha = 1.0f; int[] stateSpec = new int[numAttrs]; for (int i = 0; i < numAttrs; i++) { final int stateResId = attrs.getAttributeNameResource(i); switch (stateResId) { case android.R.attr.color: int colorAttrId = attrs.getAttributeResourceValue(i, 0); if (colorAttrId == 0) { String colorAttrValue = attrs.getAttributeValue(i); colorAttrId = Integer.valueOf(colorAttrValue.replace("?", "")); color = getColorFromAttribute(context, colorAttrId); } else { color = ContextCompat.getColor(context, colorAttrId); } break; case android.R.attr.alpha: try { alpha = attrs.getAttributeFloatValue(i, 1.0f); } catch (Exception e) { String alphaAttrValue = attrs.getAttributeValue(i); alpha = getFloatFromAttribute(context, Integer.valueOf(alphaAttrValue.replace("?", ""))); } break; default: stateSpec[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId; } } stateSpec = StateSet.trimStateSet(stateSpec, j); color = modulateColorAlpha(color, alpha); customColorList.add(color); customStateList.add(stateSpec); } int[] colors = new int[customColorList.size()]; int[][] states = new int[customStateList.size()][]; int i = 0; for (int n = states.length; i < n; i++) { colors[i] = customColorList.get(i); states[i] = customStateList.get(i); } return new ColorStateList(states, colors); }
From source file:it.scoppelletti.mobilepower.preference.SeekBarPreference.java
/** * Costruttore./*w ww . j a 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); }