Search in sources :

Example 46 with HiddenApi

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

the class ShadowArscAssetManager method loadThemeAttributeValue.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected static int loadThemeAttributeValue(long themeHandle, int ident, TypedValue outValue, boolean resolve) {
    ResTableTheme theme = Preconditions.checkNotNull(Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeHandle));
    ResTable res = theme.getResTable();
    final Ref<Res_value> value = new Ref<>(null);
    // XXX value could be different in different configs!
    final Ref<Integer> typeSpecFlags = new Ref<>(0);
    int block = theme.GetAttribute(ident, value, typeSpecFlags);
    final Ref<Integer> ref = new Ref<>(0);
    if (resolve) {
        block = res.resolveReference(value, block, ref, typeSpecFlags);
        if (kThrowOnBadId) {
            if (block == BAD_INDEX) {
                throw new IllegalStateException("Bad resource!");
            }
        }
    }
    return block >= 0 ? copyValue(outValue, res, value.get(), ref.get(), block, typeSpecFlags.get(), null) : block;
}
Also used : Ref(org.robolectric.res.android.Ref) ResTableTheme(org.robolectric.res.android.ResTableTheme) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 47 with HiddenApi

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

the class ShadowArscAssetManager method newTheme.

@HiddenApi
@Implementation
protected final Number newTheme() {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return RuntimeEnvironment.castNativePtr(0);
    }
    ResTableTheme theme = new ResTableTheme(am.getResources());
    return RuntimeEnvironment.castNativePtr(Registries.NATIVE_THEME_REGISTRY.register(theme));
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) CppAssetManager(org.robolectric.res.android.CppAssetManager) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 48 with HiddenApi

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

the class ShadowLegacyAssetManager method setConfiguration.

@HiddenApi
@Implementation(minSdk = VERSION_CODES.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 majorVersion) {
    // AssetManager* am = assetManagerForJavaObject(env, clazz);
    ResTable_config config = new ResTable_config();
    // Constants duplicated from Java class android.content.res.Configuration.
    final int kScreenLayoutRoundMask = 0x300;
    final 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 = colorMode; // todo
    config.sdkVersion = majorVersion;
    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);
    if (locale != null) {
        config.setBcp47Locale(locale);
    }
    // am->setConfiguration(config, locale8);
    this.config = config;
}
Also used : ResTable_config(org.robolectric.res.android.ResTable_config) SuppressLint(android.annotation.SuppressLint) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 49 with HiddenApi

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

the class ShadowLegacyAssetManager method getArrayIntResource.

@HiddenApi
@Implementation(maxSdk = O_MR1)
public int[] getArrayIntResource(int resId) {
    TypedResource value = getAndResolve(resId, config, true);
    if (value == null)
        return null;
    List<TypedResource> items = getConverter(value).getItems(value);
    int[] ints = new int[items.size()];
    for (int i = 0; i < items.size(); i++) {
        TypedResource typedResource = resolve(items.get(i), config, resId);
        ints[i] = getConverter(typedResource).asInt(typedResource);
    }
    return ints;
}
Also used : TypedResource(org.robolectric.res.TypedResource) FileTypedResource(org.robolectric.res.FileTypedResource) SuppressLint(android.annotation.SuppressLint) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 50 with HiddenApi

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

the class ShadowLegacyAssetManager method applyThemeStyle.

@HiddenApi
@Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1)
public static void applyThemeStyle(long themePtr, int styleRes, boolean force) {
    NativeTheme nativeTheme = getNativeTheme(themePtr);
    Style style = nativeTheme.getShadowAssetManager().resolveStyle(styleRes, null);
    nativeTheme.themeStyleSet.apply(style, force);
}
Also used : EmptyStyle(org.robolectric.res.EmptyStyle) Style(org.robolectric.res.Style) 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