Example usage for android.util AttributeSet getAttributeValue

List of usage examples for android.util AttributeSet getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(String namespace, String name);

Source Link

Document

Returns the value of the specified attribute as a string representation.

Usage

From source file:Main.java

@Nullable
public static String getAttribute(@NonNull Context context, @NonNull AttributeSet attrs, @NonNull String name,
        @Nullable String defaultValue) {
    int resId = attrs.getAttributeResourceValue(ISORON_NAMESPACE, name, 0);
    if (resId != 0)
        return context.getResources().getString(resId);

    String value = attrs.getAttributeValue(ISORON_NAMESPACE, name);
    if (value != null)
        return value;
    else/*from   w  w w .j  a va2 s  . c o m*/
        return defaultValue;
}

From source file:Main.java

public static Boolean getBooleanAttribute(final Context context, final AttributeSet attrs,
        final String namespace, final String name, final Boolean defValue) {
    final int resId = attrs.getAttributeResourceValue(namespace, name, Integer.MIN_VALUE);
    if (resId != Integer.MIN_VALUE) {
        return context.getResources().getBoolean(resId);
    }//from w  ww  .j ava 2 s  .co  m
    String str = attrs.getAttributeValue(namespace, name);
    return str != null ? Boolean.valueOf(str) : defValue;
}

From source file:Main.java

/**
 * Tries to pull the Custom Attribute directly from the TextView.
 *
 * @param context     Activity Context/*from  ww  w  . j a  v a  2 s .c o m*/
 * @param attrs       View Attributes
 * @param attributeId if -1 returns null.
 * @return null if attribute is not defined or added to View
 */
static String pullFontPathFromView(Context context, AttributeSet attrs, int attributeId) {
    if (attributeId == -1)
        return null;

    final String attributeName;
    try {
        attributeName = context.getResources().getResourceEntryName(attributeId);
    } catch (Resources.NotFoundException e) {
        // invalid attribute ID
        return null;
    }

    final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1);
    return stringResourceId > 0 ? context.getString(stringResourceId)
            : attrs.getAttributeValue(null, attributeName);
}

From source file:Main.java

/**
 * Tries to pull the Custom Attribute directly from the TextView.
 *
 * @param context     Activity Context/*from  w ww . j  a  va 2s .c  om*/
 * @param attrs       View Attributes
 * @param attributeId if -1 returns null.
 * @return null if attribute is not defined or added to View
 */
static String pullFontPathFromView(Context context, AttributeSet attrs, int attributeId) {
    if (attributeId == -1 || attrs == null)
        return null;

    final String attributeName;
    try {
        attributeName = context.getResources().getResourceEntryName(attributeId);
    } catch (Resources.NotFoundException e) {
        // invalid attribute ID
        return null;
    }

    final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1);
    return stringResourceId > 0 ? context.getString(stringResourceId)
            : attrs.getAttributeValue(null, attributeName);
}

From source file:Main.java

/**
 * Tries to pull the Custom Attribute directly from the TextView.
 *
 * @param context     Activity Context/*from  w w w .j a va  2  s. c  o  m*/
 * @param attrs       View Attributes
 * @param attributeId if -1 returns null.
 * @return null if attribute is not defined or added to View
 */
static String pullFontPathFromView(Context context, AttributeSet attrs, int[] attributeId) {
    if (attributeId == null || attrs == null)
        return null;

    final String attributeName;
    try {
        attributeName = context.getResources().getResourceEntryName(attributeId[0]);
    } catch (Resources.NotFoundException e) {
        // invalid attribute ID
        return null;
    }

    final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1);
    return stringResourceId > 0 ? context.getString(stringResourceId)
            : attrs.getAttributeValue(null, attributeName);
}

From source file:com.anysoftkeyboard.addons.AddOnsFactory.java

@Nullable
protected static CharSequence getTextFromResourceOrText(Context context, AttributeSet attrs,
        String attributeName) {//from   ww  w.  ja  va 2  s .  c om
    final int stringResId = attrs.getAttributeResourceValue(null, attributeName, AddOn.INVALID_RES_ID);
    if (stringResId != AddOn.INVALID_RES_ID) {
        return context.getResources().getText(stringResId);
    } else {
        return attrs.getAttributeValue(null, attributeName);
    }
}

From source file:com.anysoftkeyboard.dictionaries.ExternalDictionaryFactory.java

@Override
protected DictionaryAddOnAndBuilder createConcreteAddOn(Context askContext, Context context, String prefId,
        int nameId, String description, boolean isHidden, int sortIndex, AttributeSet attrs) {

    final String language = attrs.getAttributeValue(null, XML_LANGUAGE_ATTRIBUTE);
    final String assets = attrs.getAttributeValue(null, XML_ASSETS_ATTRIBUTE);
    final int dictionaryResourceId = attrs.getAttributeResourceValue(null, XML_RESOURCE_ATTRIBUTE,
            AddOn.INVALID_RES_ID);// w  w w .java 2 s  .  c o m
    final int autoTextResId = attrs.getAttributeResourceValue(null, XML_AUTO_TEXT_RESOURCE_ATTRIBUTE,
            AddOn.INVALID_RES_ID);
    final int initialSuggestionsId = attrs.getAttributeResourceValue(null,
            XML_INITIAL_SUGGESTIONS_ARRAY_RESOURCE_ATTRIBUTE, AddOn.INVALID_RES_ID);
    //asserting
    if (TextUtils.isEmpty(prefId) || (language == null) || (nameId == AddOn.INVALID_RES_ID)
            || ((assets == null) && (dictionaryResourceId == AddOn.INVALID_RES_ID))) {
        Logger.e(TAG,
                "External dictionary does not include all mandatory details! Will not create dictionary.");
        return null;
    } else {
        final DictionaryAddOnAndBuilder creator;
        if (dictionaryResourceId == AddOn.INVALID_RES_ID)
            creator = new DictionaryAddOnAndBuilder(askContext, context, prefId, nameId, description, isHidden,
                    sortIndex, language, assets, initialSuggestionsId);
        else
            creator = new DictionaryAddOnAndBuilder(askContext, context, prefId, nameId, description, isHidden,
                    sortIndex, language, dictionaryResourceId, autoTextResId, initialSuggestionsId);

        return creator;
    }
}

From source file:com.example.leapfrog.userbasedictionary.dictionary.ExternalDictionaryFactory.java

@Override
protected DictionaryAddOnAndBuilder createConcreteAddOn(Context askContext, Context context, String prefId,
        int nameId, String description, int sortIndex, AttributeSet attrs) {

    final String language = attrs.getAttributeValue(null, XML_LANGUAGE_ATTRIBUTE);
    final String assets = attrs.getAttributeValue(null, XML_ASSETS_ATTRIBUTE);
    final int dictionaryResourceId = attrs.getAttributeResourceValue(null, XML_RESOURCE_ATTRIBUTE,
            AddOn.INVALID_RES_ID);//from w  w w  .  j  ava2 s.  com
    final int autoTextResId = attrs.getAttributeResourceValue(null, XML_AUTO_TEXT_RESOURCE_ATTRIBUTE,
            AddOn.INVALID_RES_ID);
    final int initialSuggestionsId = attrs.getAttributeResourceValue(null,
            XML_INITIAL_SUGGESTIONS_ARRAY_RESOURCE_ATTRIBUTE, AddOn.INVALID_RES_ID);
    //asserting
    if (TextUtils.isEmpty(prefId) || (language == null) || (nameId == AddOn.INVALID_RES_ID)
            || ((assets == null) && (dictionaryResourceId == AddOn.INVALID_RES_ID))) {
        Log.e(TAG, "External dictionary does not include all mandatory details! Will not create dictionary.");
        return null;
    } else {
        final DictionaryAddOnAndBuilder creator;
        if (dictionaryResourceId == AddOn.INVALID_RES_ID) {
            creator = new DictionaryAddOnAndBuilder(askContext, context, prefId, nameId, description, sortIndex,
                    language, assets, initialSuggestionsId);
        } else {
            creator = new DictionaryAddOnAndBuilder(askContext, context, prefId, nameId, description, sortIndex,
                    language, dictionaryResourceId, autoTextResId, initialSuggestionsId);
        }
        return creator;
    }
}

From source file:com.quran.labs.androidquran.ui.preference.SeekBarPreference.java

public SeekBarPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;/* w w  w . j  a  v a2  s.c om*/
    mSuffix = attrs.getAttributeValue(ANDROID_NS, "text");
    mDefault = attrs.getAttributeIntValue(ANDROID_NS, "defaultValue", Constants.DEFAULT_TEXT_SIZE);
    mMax = attrs.getAttributeIntValue(ANDROID_NS, "max", 100);
    setLayoutResource(R.layout.seekbar_pref);
    mTintColor = ContextCompat.getColor(context, R.color.accent_color);
}

From source file:com.quinsoft.zeidon.android.ZeidonTableLayout.java

public ZeidonTableLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    viewDelegate.loadConfig(this, attrs);
    rowLayoutName = attrs.getAttributeValue(ZeidonAndroidViewDelegate.ZEIDON_NS, "row_layout_name");
    headerLayoutName = attrs.getAttributeValue(ZeidonAndroidViewDelegate.ZEIDON_NS, "header_layout_name");
    hasHeaders = !StringUtils.isBlank(headerLayoutName);
}