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:ru.gkpromtech.exhibition.utils.CircleImageView.java

private void sharedConstructor(AttributeSet attrs) {
    if (isInEditMode())
        return;//from   w  ww.  j a v  a 2  s .  c  om

    String widthStr = attrs.getAttributeValue(ANDROID_URI, "layout_width");
    if (widthStr.endsWith("dip")) {
        float width = Float.parseFloat(widthStr.substring(0, widthStr.length() - 3)) / 2.f;
        sharedConstructor(getResources().getColor(R.color.Exhibition_Background), width);
    }
}

From source file:android.support.v7.app.AppCompatViewInflater.java

private View createViewFromTag(Context context, String name, AttributeSet attrs) {
    if (name.equals("view")) {
        name = attrs.getAttributeValue(null, "class");
    }/*ww w .  j a v a 2s .c o m*/

    try {
        mConstructorArgs[0] = context;
        mConstructorArgs[1] = attrs;

        if (-1 == name.indexOf('.')) {
            for (int i = 0; i < sClassPrefixList.length; i++) {
                final View view = createView(context, name, sClassPrefixList[i]);
                if (view != null) {
                    return view;
                }
            }
            return null;
        } else {
            return createView(context, name, null);
        }
    } catch (Exception e) {
        // We do not want to catch these, lets return null and let the actual LayoutInflater
        // try
        return null;
    } finally {
        // Don't retain references on context.
        mConstructorArgs[0] = null;
        mConstructorArgs[1] = null;
    }
}

From source file:android.support.transition.TransitionInflater.java

private Object createCustom(AttributeSet attrs, Class expectedType, String tag) {
    String className = attrs.getAttributeValue(null, "class");

    if (className == null) {
        throw new InflateException(tag + " tag must have a 'class' attribute");
    }/*from   w w w .  j a v  a 2s.c o  m*/

    try {
        synchronized (CONSTRUCTORS) {
            Constructor constructor = CONSTRUCTORS.get(className);
            if (constructor == null) {
                @SuppressWarnings("unchecked")
                Class<?> c = mContext.getClassLoader().loadClass(className).asSubclass(expectedType);
                if (c != null) {
                    constructor = c.getConstructor(CONSTRUCTOR_SIGNATURE);
                    constructor.setAccessible(true);
                    CONSTRUCTORS.put(className, constructor);
                }
            }
            //noinspection ConstantConditions
            return constructor.newInstance(mContext, attrs);
        }
    } catch (Exception e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    }
}

From source file:com.transitionseverywhere.TransitionInflater.java

private Object createCustom(AttributeSet attrs, Class expectedType, String tag) {
    String className = attrs.getAttributeValue(null, "class");

    if (className == null) {
        throw new InflateException(tag + " tag must have a 'class' attribute");
    }/*www .  j a  v a  2s.  co m*/

    try {
        synchronized (sConstructors) {
            Constructor constructor = sConstructors.get(className);
            if (constructor == null) {
                Class c = mContext.getClassLoader().loadClass(className).asSubclass(expectedType);
                if (c != null) {
                    constructor = c.getConstructor(sConstructorSignature);
                    if (!constructor.isAccessible()) {
                        constructor.setAccessible(true);
                    }
                    sConstructors.put(className, constructor);
                }
            }

            return constructor.newInstance(mContext, attrs);
        }
    } catch (InstantiationException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (ClassNotFoundException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (InvocationTargetException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (NoSuchMethodException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (IllegalAccessException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    }
}

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

/**
 * Load attribute values common to most/all Zeidon views.
 *
 * @param androidView/*from   www  . jav  a 2  s . co  m*/
 * @param attrs
 */
public void loadConfig(android.view.View androidView, AttributeSet attrs) {
    this.androidView = androidView;
    viewName = attrs.getAttributeValue(ZEIDON_NS, "view_name");
    entityName = attrs.getAttributeValue(ZEIDON_NS, "entity_name");
    attributeName = attrs.getAttributeValue(ZEIDON_NS, "attribute_name");
    contextName = attrs.getAttributeValue(ZEIDON_NS, "context_name");
    nullRepresentation = attrs.getAttributeValue(ZEIDON_NS, "null_representation");
}

From source file:com.gmail.walles.johan.headsetharry.settings.PermissionsPreference.java

public PermissionsPreference(Context context, AttributeSet attributeSet) {
    super(context, attributeSet);
    activity = (Activity) context;/*from  w w w.  j a v  a 2 s .  c o m*/

    if (ALLOWED_KEYS.indexOf(getKey().intern()) == -1) {
        throw new IllegalArgumentException("Key must be listed in PermissionsPreference.ALLOWED_KEYS");
    }

    String permissionsAttribute = attributeSet.getAttributeValue(
            "http://schemas.android.com/apk/lib/com.gmail.walles.johan.headsetharry", "permissions");
    if (permissionsAttribute == null) {
        throw new IllegalArgumentException(
                "Must be set but wasn't: 'permissions' of namespace 'http://schemas.android.com/apk/lib/com.gmail.walles.johan.headsetharry'");
    }
    permissions = parsePermissions(permissionsAttribute);
    if (permissions.length == 0) {
        throw new IllegalArgumentException(
                "Must contain at least one permission but didn't: 'permissions' of namespace 'http://schemas.android.com/apk/lib/com.gmail.walles.johan.headsetharry'");
    }

    // Preferences change listener registered in {@link #onAttachedToActivity}
}

From source file:com.anysoftkeyboard.keyboards.KeyboardFactory.java

@Override
protected KeyboardAddOnAndBuilder createConcreteAddOn(Context askContext, Context context, String prefId,
        int nameId, String description, boolean isHidden, int sortIndex, AttributeSet attrs) {
    final int layoutResId = attrs.getAttributeResourceValue(null, XML_LAYOUT_RES_ID_ATTRIBUTE,
            AddOn.INVALID_RES_ID);// w ww. j  a  va2s .c  o  m
    final int landscapeLayoutResId = attrs.getAttributeResourceValue(null,
            XML_LANDSCAPE_LAYOUT_RES_ID_ATTRIBUTE, AddOn.INVALID_RES_ID);
    final int iconResId = attrs.getAttributeResourceValue(null, XML_ICON_RES_ID_ATTRIBUTE,
            R.drawable.sym_keyboard_notification_icon);
    final String defaultDictionary = attrs.getAttributeValue(null, XML_DICTIONARY_NAME_ATTRIBUTE);
    final String additionalIsLetterExceptions = attrs.getAttributeValue(null,
            XML_ADDITIONAL_IS_LETTER_EXCEPTIONS_ATTRIBUTE);
    String sentenceSeparators = attrs.getAttributeValue(null, XML_SENTENCE_SEPARATOR_CHARACTERS_ATTRIBUTE);
    if (TextUtils.isEmpty(sentenceSeparators))
        sentenceSeparators = DEFAULT_SENTENCE_SEPARATORS;
    final int physicalTranslationResId = attrs.getAttributeResourceValue(null,
            XML_PHYSICAL_TRANSLATION_RES_ID_ATTRIBUTE, AddOn.INVALID_RES_ID);
    // A keyboard is enabled by default if it is the first one (index==1)
    final boolean keyboardDefault = attrs.getAttributeBooleanValue(null, XML_DEFAULT_ATTRIBUTE, sortIndex == 1);

    // asserting
    if ((prefId == null) || (nameId == AddOn.INVALID_RES_ID) || (layoutResId == AddOn.INVALID_RES_ID)) {
        Logger.e(TAG, "External Keyboard does not include all mandatory details! Will not create keyboard.");
        return null;
    } else {
        if (BuildConfig.DEBUG) {
            Logger.d(TAG,
                    "External keyboard details: prefId:" + prefId + " nameId:" + nameId + " resId:"
                            + layoutResId + " landscapeResId:" + landscapeLayoutResId + " iconResId:"
                            + iconResId + " defaultDictionary:" + defaultDictionary);
        }
        return new KeyboardAddOnAndBuilder(askContext, context, prefId, nameId, layoutResId,
                landscapeLayoutResId, defaultDictionary, iconResId, physicalTranslationResId,
                additionalIsLetterExceptions, sentenceSeparators, description, isHidden, sortIndex,
                keyboardDefault);
    }
}

From source file:com.ttxgps.zoom.GestureImageView.java

public GestureImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    String scaleType = attrs.getAttributeValue(GLOBAL_NS, "scaleType");

    if (scaleType == null || scaleType.trim().length() == 0) {
        setScaleType(ScaleType.CENTER_INSIDE);
    }/*from w ww  .j  a v a  2s . c  om*/

    setMinScale(attrs.getAttributeFloatValue(LOCAL_NS, "min-scale", minScale));
    setMaxScale(attrs.getAttributeFloatValue(LOCAL_NS, "max-scale", maxScale));
    setStrict(attrs.getAttributeBooleanValue(LOCAL_NS, "strict", strict));
    setRecycle(attrs.getAttributeBooleanValue(LOCAL_NS, "recycle", recycle));
    zoom = attrs.getAttributeBooleanValue(LOCAL_NS, "zoom", zoom);
    initImage(false);
}

From source file:com.chuhan.privatecalc.fragment.os.FragmentActivity.java

/**
 * Add support for inflating the &lt;fragment> tag.
 *//*from  w w w  . j  a  va  2s.  c o m*/
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
    if (!"fragment".equals(name)) {
        return super.onCreateView(name, context, attrs);
    }

    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a = context.obtainStyledAttributes(attrs, FragmentTag.Fragment);
    if (fname == null) {
        fname = a.getString(FragmentTag.Fragment_name);
    }
    int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
    String tag = a.getString(FragmentTag.Fragment_tag);
    a.recycle();

    View parent = null; // NOTE: no way to get parent pre-Honeycomb.
    int containerId = parent != null ? parent.getId() : 0;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
    }

    // If we restored from a previous state, we may already have
    // instantiated this fragment from the state and should use
    // that instance instead of making a new one.
    Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = mFragments.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = mFragments.findFragmentById(containerId);
    }

    if (FragmentManagerImpl.DEBUG)
        Log.v(TAG,
                "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment);
    if (fragment == null) {
        fragment = Fragment.instantiate(this, fname);
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = mFragments;
        fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        mFragments.addFragment(fragment, true);

    } else if (fragment.mInLayout) {
        // A fragment already exists and it is not one we restored from
        // previous state.
        throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x"
                + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x"
                + Integer.toHexString(containerId) + " with another fragment for " + fname);
    } else {
        // This fragment was retained from a previous instance; get it
        // going now.
        fragment.mInLayout = true;
        // If this fragment is newly instantiated (either right now, or
        // from last saved state), then give it the attributes to
        // initialize itself.
        if (!fragment.mRetaining) {
            fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        }
        mFragments.moveToState(fragment);
    }

    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}

From source file:com.tencent.tws.assistant.support.v4.app.TwsFragmentActivity.java

/**
 * Add support for inflating the &lt;fragment> tag.
 *//*from ww w . j  a v  a2s .  co  m*/
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
    if (!"fragment".equals(name)) {
        return super.onCreateView(name, context, attrs);
    }

    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a = context.obtainStyledAttributes(attrs, FragmentTag.Fragment);
    if (fname == null) {
        fname = a.getString(FragmentTag.Fragment_name);
    }
    int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
    String tag = a.getString(FragmentTag.Fragment_tag);
    a.recycle();

    if (!Fragment.isSupportFragmentClass(this, fname)) {
        // Invalid support lib fragment; let the device's framework handle it.
        // This will allow android.app.Fragments to do the right thing.
        return super.onCreateView(name, context, attrs);
    }

    View parent = null; // NOTE: no way to get parent pre-Honeycomb.
    int containerId = parent != null ? parent.getId() : 0;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
    }

    // If we restored from a previous state, we may already have
    // instantiated this fragment from the state and should use
    // that instance instead of making a new one.
    Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = mFragments.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = mFragments.findFragmentById(containerId);
    }

    if (FragmentManagerImpl.DEBUG)
        Log.v(TAG,
                "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment);
    if (fragment == null) {
        fragment = Fragment.instantiate(this, fname);
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = mFragments;
        fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        mFragments.addFragment(fragment, true);

    } else if (fragment.mInLayout) {
        // A fragment already exists and it is not one we restored from
        // previous state.
        throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x"
                + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x"
                + Integer.toHexString(containerId) + " with another fragment for " + fname);
    } else {
        // This fragment was retained from a previous instance; get it
        // going now.
        fragment.mInLayout = true;
        // If this fragment is newly instantiated (either right now, or
        // from last saved state), then give it the attributes to
        // initialize itself.
        if (!fragment.mRetaining) {
            fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        }
        mFragments.moveToState(fragment);
    }

    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}