Search in sources :

Example 1 with SkinAttr

use of cn.feng.skin.manager.entity.SkinAttr in project Android-Skin-Loader by fengjundev.

the class SkinInflaterFactory method parseSkinAttr.

/**
 * Collect skin able tag such as background , textColor and so on
 *
 * @param context
 * @param attrs
 * @param view
 */
private void parseSkinAttr(Context context, AttributeSet attrs, View view) {
    List<SkinAttr> viewAttrs = new ArrayList<SkinAttr>();
    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        String attrName = attrs.getAttributeName(i);
        String attrValue = attrs.getAttributeValue(i);
        if (!AttrFactory.isSupportedAttr(attrName)) {
            continue;
        }
        if (attrValue.startsWith("@")) {
            try {
                int id = Integer.parseInt(attrValue.substring(1));
                String entryName = context.getResources().getResourceEntryName(id);
                String typeName = context.getResources().getResourceTypeName(id);
                SkinAttr mSkinAttr = AttrFactory.get(attrName, id, entryName, typeName);
                if (mSkinAttr != null) {
                    viewAttrs.add(mSkinAttr);
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (NotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    if (!ListUtils.isEmpty(viewAttrs)) {
        SkinItem skinItem = new SkinItem();
        skinItem.view = view;
        skinItem.attrs = viewAttrs;
        mSkinItems.add(skinItem);
        if (SkinManager.getInstance().isExternalSkin()) {
            skinItem.apply();
        }
    }
}
Also used : SkinAttr(cn.feng.skin.manager.entity.SkinAttr) ArrayList(java.util.ArrayList) NotFoundException(android.content.res.Resources.NotFoundException) SkinItem(cn.feng.skin.manager.entity.SkinItem)

Example 2 with SkinAttr

use of cn.feng.skin.manager.entity.SkinAttr in project Android-Skin-Loader by fengjundev.

the class SkinInflaterFactory method dynamicAddSkinEnableView.

public void dynamicAddSkinEnableView(Context context, View view, List<DynamicAttr> pDAttrs) {
    List<SkinAttr> viewAttrs = new ArrayList<SkinAttr>();
    SkinItem skinItem = new SkinItem();
    skinItem.view = view;
    for (DynamicAttr dAttr : pDAttrs) {
        int id = dAttr.refResId;
        String entryName = context.getResources().getResourceEntryName(id);
        String typeName = context.getResources().getResourceTypeName(id);
        SkinAttr mSkinAttr = AttrFactory.get(dAttr.attrName, id, entryName, typeName);
        viewAttrs.add(mSkinAttr);
    }
    skinItem.attrs = viewAttrs;
    addSkinView(skinItem);
}
Also used : DynamicAttr(cn.feng.skin.manager.entity.DynamicAttr) SkinAttr(cn.feng.skin.manager.entity.SkinAttr) ArrayList(java.util.ArrayList) SkinItem(cn.feng.skin.manager.entity.SkinItem)

Example 3 with SkinAttr

use of cn.feng.skin.manager.entity.SkinAttr in project Android-Skin-Loader by fengjundev.

the class SkinInflaterFactory method dynamicAddSkinEnableView.

public void dynamicAddSkinEnableView(Context context, View view, String attrName, int attrValueResId) {
    int id = attrValueResId;
    String entryName = context.getResources().getResourceEntryName(id);
    String typeName = context.getResources().getResourceTypeName(id);
    SkinAttr mSkinAttr = AttrFactory.get(attrName, id, entryName, typeName);
    SkinItem skinItem = new SkinItem();
    skinItem.view = view;
    List<SkinAttr> viewAttrs = new ArrayList<SkinAttr>();
    viewAttrs.add(mSkinAttr);
    skinItem.attrs = viewAttrs;
    addSkinView(skinItem);
}
Also used : SkinAttr(cn.feng.skin.manager.entity.SkinAttr) ArrayList(java.util.ArrayList) SkinItem(cn.feng.skin.manager.entity.SkinItem)

Aggregations

SkinAttr (cn.feng.skin.manager.entity.SkinAttr)3 SkinItem (cn.feng.skin.manager.entity.SkinItem)3 ArrayList (java.util.ArrayList)3 NotFoundException (android.content.res.Resources.NotFoundException)1 DynamicAttr (cn.feng.skin.manager.entity.DynamicAttr)1