• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import android.content.res.AssetManager;
4 import java.util.Collection;
5 import java.util.List;
6 import org.robolectric.RuntimeEnvironment;
7 import org.robolectric.res.FsFile;
8 import org.robolectric.res.android.AssetPath;
9 import org.robolectric.res.android.CppAssetManager;
10 import org.robolectric.res.android.ResTable;
11 import org.robolectric.res.android.String8;
12 import org.robolectric.shadow.api.Shadow;
13 
14 abstract public class ShadowAssetManager {
15 
16   public static class Picker extends ResourceModeShadowPicker<ShadowAssetManager> {
17 
Picker()18     public Picker() {
19       super(ShadowLegacyAssetManager.class,
20               ShadowArscAssetManager.class,
21               ShadowArscAssetManager9.class
22               // BEGIN-INTERNAL
23               ,ShadowArscAssetManager10.class
24               // END-INTERNAL
25       );
26     }
27   }
28 
29   /**
30    * @deprecated Avoid use.
31    */
32   @Deprecated
useLegacy()33   public static boolean useLegacy() {
34     return RuntimeEnvironment.useLegacyResources();
35   }
36 
37   /**
38    * @deprecated Avoid use.
39    */
40   @Deprecated
legacyShadowOf(AssetManager assetManager)41   static ShadowLegacyAssetManager legacyShadowOf(AssetManager assetManager) {
42     return (ShadowLegacyAssetManager) Shadow.extract(assetManager);
43   }
44 
getAllAssetDirs()45   abstract Collection<FsFile> getAllAssetDirs();
46 
47   public abstract static class ArscBase extends ShadowAssetManager {
48     private ResTable compileTimeResTable;
49 
50     /**
51      * @deprecated Avoid use.
52      */
53     @Deprecated
getCompileTimeResTable()54     synchronized public ResTable getCompileTimeResTable() {
55       if (compileTimeResTable == null) {
56         CppAssetManager compileTimeCppAssetManager = new CppAssetManager();
57         for (AssetPath assetPath : getAssetPaths()) {
58           if (assetPath.isSystem) {
59             compileTimeCppAssetManager.addDefaultAssets(
60                 RuntimeEnvironment.compileTimeSystemResourcesFile.getPath());
61           } else {
62             compileTimeCppAssetManager.addAssetPath(new String8(assetPath.file.getPath()), null, false);
63           }
64         }
65         compileTimeResTable = compileTimeCppAssetManager.getResources();
66       }
67 
68       return compileTimeResTable;
69     }
70 
getAssetPaths()71     abstract List<AssetPath> getAssetPaths();
72   }
73 }
74