Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SplashShadowResources.java
Go to the documentation of this file.
1package io.flutter.embedding.android;
2
3import static org.robolectric.util.reflector.Reflector.reflector;
4
5import android.content.res.Resources;
6import android.graphics.Color;
7import android.graphics.drawable.ColorDrawable;
8import android.graphics.drawable.Drawable;
9import androidx.annotation.Nullable;
10import org.robolectric.annotation.Implementation;
11import org.robolectric.annotation.Implements;
12import org.robolectric.annotation.RealObject;
13import org.robolectric.shadows.ShadowResources;
14import org.robolectric.util.reflector.Direct;
15import org.robolectric.util.reflector.ForType;
16
17@SuppressWarnings("deprecation")
18// getDrawableInt
19@Implements(Resources.class)
20public class SplashShadowResources extends ShadowResources {
21 @RealObject private Resources resources;
22
23 public static final int SPLASH_DRAWABLE_ID = 191919;
24 public static final int THEMED_SPLASH_DRAWABLE_ID = 212121;
25
26 @ForType(Resources.class)
28 @Direct
29 Drawable getDrawable(int id, Resources.Theme theme);
30
31 @Direct
32 Drawable getDrawable(int id);
33 }
34
35 @Implementation
36 protected Drawable getDrawable(int id) {
37 if (id == SPLASH_DRAWABLE_ID) {
38 return new ColorDrawable(Color.BLUE);
39 }
40 return reflector(Resources.class, resources).getDrawable(id);
41 }
42
43 @Implementation
44 protected Drawable getDrawable(int id, @Nullable Resources.Theme theme) {
45 if (id == THEMED_SPLASH_DRAWABLE_ID) {
46 // We pretend the drawable contains theme references. It can't be parsed without the app
47 // theme.
48 if (theme == null) {
49 throw new Resources.NotFoundException(
50 "Cannot parse drawable due to missing theme references.");
51 }
52 return new ColorDrawable(Color.GRAY);
53 }
54 return reflector(Resources.class, resources).getDrawable(id, theme);
55 }
56}
Drawable getDrawable(int id, @Nullable Resources.Theme theme)