Search in sources :

Example 31 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowAssetManager method getResourceTextArray.

@HiddenApi
@Implementation
public CharSequence[] getResourceTextArray(int resId) {
    TypedResource value = getAndResolve(resId, RuntimeEnvironment.getQualifiers(), true);
    if (value == null)
        return null;
    TypedResource[] items = getConverter(value).getItems(value);
    CharSequence[] charSequences = new CharSequence[items.length];
    for (int i = 0; i < items.length; i++) {
        TypedResource typedResource = resolve(items[i], RuntimeEnvironment.getQualifiers(), resId);
        charSequences[i] = getConverter(typedResource).asCharSequence(typedResource);
    }
    return charSequences;
}
Also used : FileTypedResource(org.robolectric.res.FileTypedResource) TypedResource(org.robolectric.res.TypedResource) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 32 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowAssetManager method getThemeValue.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) {
    ResName resName = resourceTable.getResName(ident);
    ThemeStyleSet themeStyleSet = getNativeTheme(themePtr).themeStyleSet;
    AttributeResource attrValue = themeStyleSet.getAttrValue(resName);
    while (attrValue != null && attrValue.isStyleReference()) {
        ResName attrResName = attrValue.getStyleReference();
        if (attrValue.resName.equals(attrResName)) {
            Logger.info("huh... circular reference for %s?", attrResName.getFullyQualifiedName());
            return false;
        }
        attrValue = themeStyleSet.getAttrValue(attrResName);
    }
    if (attrValue != null) {
        convertAndFill(attrValue, outValue, RuntimeEnvironment.getQualifiers(), resolveRefs);
        return true;
    }
    return false;
}
Also used : AttributeResource(org.robolectric.res.AttributeResource) ThemeStyleSet(org.robolectric.res.ThemeStyleSet) ResName(org.robolectric.res.ResName) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 33 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourceIdentifier.

@HiddenApi
@Implementation
public int getResourceIdentifier(String name, String defType, String defPackage) {
    if (Strings.isNullOrEmpty(name)) {
        return 0;
    }
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    int ident = am.getResources().identifierForName(name, defType, defPackage);
    return ident;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 34 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowArscAssetManager method setConfiguration.

@HiddenApi
@Implementation(minSdk = O)
public void setConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int colorMode, int sdkVersion) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return;
    }
    ResTable_config config = new ResTable_config();
    // memset(&config, 0, sizeof(config));
    // const char* locale8 = locale != NULL ? env->GetStringUTFChars(locale, NULL) : NULL;
    // Constants duplicated from Java class android.content.res.Configuration.
    int kScreenLayoutRoundMask = 0x300;
    int kScreenLayoutRoundShift = 8;
    config.mcc = mcc;
    config.mnc = mnc;
    config.orientation = orientation;
    config.touchscreen = touchscreen;
    config.density = density;
    config.keyboard = keyboard;
    config.inputFlags = keyboardHidden;
    config.navigation = navigation;
    config.screenWidth = screenWidth;
    config.screenHeight = screenHeight;
    config.smallestScreenWidthDp = smallestScreenWidthDp;
    config.screenWidthDp = screenWidthDp;
    config.screenHeightDp = screenHeightDp;
    config.screenLayout = screenLayout;
    config.uiMode = uiMode;
    config.colorMode = (byte) colorMode;
    config.sdkVersion = sdkVersion;
    config.minorVersion = 0;
    // In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer
    // in C++. We must extract the round qualifier out of the Java screenLayout and put it
    // into screenLayout2.
    config.screenLayout2 = (byte) ((screenLayout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift);
    am.setConfiguration(config, locale);
// if (locale != null) env->ReleaseStringUTFChars(locale, locale8);
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 35 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowArscAssetManager method openAssetFd.

@HiddenApi
@Implementation
protected ParcelFileDescriptor openAssetFd(String fileName, long[] outOffsets) throws IOException {
    CppAssetManager am = assetManagerForJavaObject();
    ALOGV("openAssetFd in %s", am);
    String fileName8 = fileName;
    if (fileName8 == null) {
        return null;
    }
    Asset a = am.open(fileName8, Asset.AccessMode.ACCESS_RANDOM);
    if (a == null) {
        throw new FileNotFoundException(fileName8);
    }
    return returnParcelFileDescriptor(a, outOffsets);
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) FileNotFoundException(java.io.FileNotFoundException) Asset(org.robolectric.res.android.Asset) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

HiddenApi (org.robolectric.annotation.HiddenApi)61 Implementation (org.robolectric.annotation.Implementation)61 CppAssetManager (org.robolectric.res.android.CppAssetManager)18 Ref (org.robolectric.res.android.Ref)9 ResTable (org.robolectric.res.android.ResTable)9 FileTypedResource (org.robolectric.res.FileTypedResource)8 Asset (org.robolectric.res.android.Asset)8 TypedResource (org.robolectric.res.TypedResource)6 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)6 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 ResTableTheme (org.robolectric.res.android.ResTableTheme)5 SuppressLint (android.annotation.SuppressLint)4 ResName (org.robolectric.res.ResName)4 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)4 ResTable_config (org.robolectric.res.android.ResTable_config)4 IOException (java.io.IOException)3 AttributedOpEntry (android.app.AppOpsManager.AttributedOpEntry)2 OpEntry (android.app.AppOpsManager.OpEntry)2 PackageOps (android.app.AppOpsManager.PackageOps)2