Search in sources :

Example 1 with ResourceName

use of org.robolectric.res.android.ResTable.ResourceName in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourcePackageName.

@Implementation
protected String getResourcePackageName(int resid) {
    CppAssetManager cppAssetManager = assetManagerForJavaObject();
    ResourceName name = new ResourceName();
    if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
        return null;
    }
    return name.packageName.trim();
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResourceName(org.robolectric.res.android.ResTable.ResourceName) Implementation(org.robolectric.annotation.Implementation)

Example 2 with ResourceName

use of org.robolectric.res.android.ResTable.ResourceName in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourceEntryName.

@Implementation
protected String getResourceEntryName(int resid) {
    CppAssetManager cppAssetManager = assetManagerForJavaObject();
    ResourceName name = new ResourceName();
    if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
        return null;
    }
    return name.name;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResourceName(org.robolectric.res.android.ResTable.ResourceName) Implementation(org.robolectric.annotation.Implementation)

Example 3 with ResourceName

use of org.robolectric.res.android.ResTable.ResourceName in project robolectric by robolectric.

the class ResTableTheme method applyStyle.

public int applyStyle(int resID, boolean force) {
    AppliedStyle newAppliedStyle = new AppliedStyle(resID, force);
    if (styleDebug) {
        System.out.println("Apply " + newAppliedStyle + " to " + this);
    }
    styles.add(newAppliedStyle);
    final Ref<bag_entry[]> bag = new Ref<>(null);
    final Ref<Integer> bagTypeSpecFlags = new Ref<>(0);
    mTable.lock();
    final int N = mTable.getBagLocked(resID, bag, bagTypeSpecFlags);
    if (kDebugTableNoisy) {
        ALOGV("Applying style 0x%08x to theme %s, count=%d", resID, this, N);
    }
    if (N < 0) {
        mTable.unlock();
        return N;
    }
    mTypeSpecFlags.set(mTypeSpecFlags.get() | bagTypeSpecFlags.get());
    int curPackage = 0xffffffff;
    int curPackageIndex = 0;
    package_info curPI = null;
    int curType = 0xffffffff;
    int numEntries = 0;
    theme_entry[] curEntries = null;
    final int end = N;
    int bagIndex = 0;
    while (bagIndex < end) {
        bag_entry bag_entry = bag.get()[bagIndex];
        final int attrRes = bag_entry.map.name.ident;
        final int p = Res_GETPACKAGE(attrRes);
        final int t = Res_GETTYPE(attrRes);
        final int e = Res_GETENTRY(attrRes);
        if (curPackage != p) {
            final int pidx = mTable.getResourcePackageIndex(attrRes);
            if (pidx < 0) {
                ALOGE("Style contains key with bad package: 0x%08x\n", attrRes);
                bagIndex++;
                continue;
            }
            curPackage = p;
            curPackageIndex = pidx;
            curPI = mPackages[pidx];
            if (curPI == null) {
                curPI = new package_info();
                mPackages[pidx] = curPI;
            }
            curType = 0xffffffff;
        }
        if (curType != t) {
            if (t > Res_MAXTYPE) {
                ALOGE("Style contains key with bad type: 0x%08x\n", attrRes);
                bagIndex++;
                continue;
            }
            curType = t;
            curEntries = curPI.types[t] != null ? curPI.types[t].entries : null;
            if (curEntries == null) {
                final PackageGroup grp = mTable.mPackageGroups.get(curPackageIndex);
                final List<Type> typeList = getOrDefault(grp.types, t, Collections.emptyList());
                int cnt = typeList.isEmpty() ? 0 : typeList.get(0).entryCount;
                curEntries = new theme_entry[cnt];
                // memset(curEntries, Res_value::TYPE_NULL, buff_size);
                curPI.types[t] = new type_info();
                curPI.types[t].numEntries = cnt;
                curPI.types[t].entries = curEntries;
            }
            numEntries = curPI.types[t].numEntries;
        }
        if (e >= numEntries) {
            ALOGE("Style contains key with bad entry: 0x%08x\n", attrRes);
            bagIndex++;
            continue;
        }
        if (curEntries[e] == null) {
            curEntries[e] = new theme_entry();
        }
        theme_entry curEntry = curEntries[e];
        if (styleDebug) {
            ResourceName outName = new ResourceName();
            mTable.getResourceName(attrRes, true, outName);
            System.out.println("  " + outName + "(" + attrRes + ")" + " := " + bag_entry.map.value);
        }
        if (kDebugTableNoisy) {
            ALOGV("Attr 0x%08x: type=0x%x, data=0x%08x; curType=0x%x", attrRes, bag.get()[bagIndex].map.value.dataType, bag.get()[bagIndex].map.value.data, curEntry.value.dataType);
        }
        if (force || (curEntry.value.dataType == TYPE_NULL && curEntry.value.data != Res_value.DATA_NULL_EMPTY)) {
            curEntry.stringBlock = bag_entry.stringBlock;
            curEntry.typeSpecFlags |= bagTypeSpecFlags.get();
            curEntry.value = new Res_value(bag_entry.map.value);
        }
        bagIndex++;
    }
    mTable.unlock();
    if (kDebugTableTheme) {
        ALOGI("Applying style 0x%08x (force=%s)  theme %s...\n", resID, force, this);
        dumpToLog();
    }
    return NO_ERROR;
}
Also used : Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResourceName(org.robolectric.res.android.ResTable.ResourceName) PackageGroup(org.robolectric.res.android.ResTable.PackageGroup) Type(org.robolectric.res.android.ResTable.Type) ResTable.bag_entry(org.robolectric.res.android.ResTable.bag_entry)

Example 4 with ResourceName

use of org.robolectric.res.android.ResTable.ResourceName in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourceBagValues.

public static Map<String, Integer> getResourceBagValues(int ident, ResTable res) {
    // Now lock down the resource object and start pulling stuff from it.
    res.lock();
    HashMap<String, Integer> map;
    try {
        final Ref<bag_entry[]> entryRef = new Ref<>(null);
        final Ref<Integer> typeSpecFlags = new Ref<>(0);
        int entryCount = res.getBagLocked(ident, entryRef, typeSpecFlags);
        map = new HashMap<>();
        bag_entry[] bag_entries = entryRef.get();
        for (int i = 0; i < entryCount; i++) {
            bag_entry entry = bag_entries[i];
            ResourceName resourceName = new ResourceName();
            if (res.getResourceName(entry.map.name.ident, true, resourceName)) {
                map.put(resourceName.name, entry.map.value.data);
            }
        }
    } finally {
        res.unlock();
    }
    return map;
}
Also used : Ref(org.robolectric.res.android.Ref) ResourceName(org.robolectric.res.android.ResTable.ResourceName) ResTable.bag_entry(org.robolectric.res.android.ResTable.bag_entry)

Example 5 with ResourceName

use of org.robolectric.res.android.ResTable.ResourceName in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourceTypeName.

@Implementation
protected String getResourceTypeName(int resid) {
    CppAssetManager cppAssetManager = assetManagerForJavaObject();
    ResourceName name = new ResourceName();
    if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
        return null;
    }
    return name.type;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResourceName(org.robolectric.res.android.ResTable.ResourceName) Implementation(org.robolectric.annotation.Implementation)

Aggregations

ResourceName (org.robolectric.res.android.ResTable.ResourceName)6 Implementation (org.robolectric.annotation.Implementation)4 CppAssetManager (org.robolectric.res.android.CppAssetManager)4 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)2 Ref (org.robolectric.res.android.Ref)1 PackageGroup (org.robolectric.res.android.ResTable.PackageGroup)1 Type (org.robolectric.res.android.ResTable.Type)1 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)1