ShadowResources.java revision 9472d8faeb0c6fa20529234e7e2a7ebf967d1f32
133873d2b41a5cd2597b20a4e88eb8942944c0f23Tyler Schultzpackage com.xtremelabs.robolectric.shadows; 2b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 370a3ec81f0bda52d8388facf562a80e2d16ac96fGonçalo Silvaimport android.content.res.AssetManager; 46b77d40267d9b2d4d1b3e206f7d1bdd60a91d8c8Michael Portuesiimport android.content.res.Configuration; 5b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwinimport android.content.res.Resources; 6ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williamsimport android.content.res.TypedArray; 7b01474a3329222965d31068f5c33e59c6e6aa6a4Josh Lauer & Christian Williamsimport android.graphics.BitmapFactory; 8b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwinimport android.graphics.drawable.BitmapDrawable; 9b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwinimport android.graphics.drawable.Drawable; 10ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williamsimport android.util.AttributeSet; 11b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwinimport android.util.DisplayMetrics; 12e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wuimport android.view.Display; 1370a3ec81f0bda52d8388facf562a80e2d16ac96fGonçalo Silvaimport com.xtremelabs.robolectric.Robolectric; 1422c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implementation; 1522c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implements; 16f64d95f87eb9715622e3f77eb0b369d60270054cChristian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.RealObject; 17f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakkerimport com.xtremelabs.robolectric.res.ResourceExtractor; 183f1d4fe696c2f3efe99b8ef39868c064928efb1aTyler Schultzimport com.xtremelabs.robolectric.res.ResourceLoader; 19b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 20e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wuimport java.io.InputStream; 21e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wuimport java.util.Locale; 22e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu 23e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wuimport static com.xtremelabs.robolectric.Robolectric.newInstanceOf; 24e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wuimport static com.xtremelabs.robolectric.Robolectric.shadowOf; 25e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu 2659d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin/** 2759d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin * Shadow of {@code Resources} that simulates the loading of resources 2859d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin * 2959d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin * @see com.xtremelabs.robolectric.RobolectricTestRunner#RobolectricTestRunner(Class, String, String) 3059d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin */ 31b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin@SuppressWarnings({"UnusedDeclaration"}) 32b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin@Implements(Resources.class) 33afe0a89d904a7fe2f5980b9deb26cc3240192459Christian Williamspublic class ShadowResources { 34e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard private float density = 1.0f; 35cc86c1d752c8e2f2e0c45b7083bd290a85061400Chris Van Vranken Configuration configuration = null; 36e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu private DisplayMetrics displayMetrics; 379931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante private Display display; 38e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu 3908d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams static Resources bind(Resources resources, ResourceLoader resourceLoader) { 40a8486da7c7a0b6a10e943c55992f34d9c256456dChristian Williams ShadowResources shadowResources = shadowOf(resources); 4103ce698c2bb5b203761ce51694d2fa104be4a40dTyler Schultz if (shadowResources.resourceLoader != null) throw new RuntimeException("ResourceLoader already set!"); 4203ce698c2bb5b203761ce51694d2fa104be4a40dTyler Schultz shadowResources.resourceLoader = resourceLoader; 4308d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams return resources; 4408d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams } 4508d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams 469931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante @RealObject 479931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante Resources realResources; 4808d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams private ResourceLoader resourceLoader; 4908d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams 50de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 519931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante public int getIdentifier(String name, String defType, String defPackage) { 52f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker Integer index = 0; 539931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 54f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker ResourceExtractor resourceExtractor = resourceLoader.getResourceExtractor(); 559931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 56f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker index = resourceExtractor.getResourceId(defType + "/" + name); 57f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker if (index == null) { 58f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker return 0; 59f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker } 60f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker return index; 61f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker } 629931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 63f320a2d3b8075716daf2a80f5a8f7890086fb609Mark Bakker @Implementation 64b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin public int getColor(int id) throws Resources.NotFoundException { 6525cbf6f16c0fc8e6524935e6fa3d70ec2a92ed25Phil Goodwin & Tyler Schultz return resourceLoader.getColorValue(id); 66b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 679931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 686b77d40267d9b2d4d1b3e206f7d1bdd60a91d8c8Michael Portuesi @Implementation 696b77d40267d9b2d4d1b3e206f7d1bdd60a91d8c8Michael Portuesi public Configuration getConfiguration() { 709931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante if (configuration == null) { 719931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante configuration = new Configuration(); 729931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante configuration.setToDefaults(); 739931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 7485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey if (configuration.locale == null) { 7585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey configuration.locale = Locale.getDefault(); 7685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey } 7740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return configuration; 786b77d40267d9b2d4d1b3e206f7d1bdd60a91d8c8Michael Portuesi } 79b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 80de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 81b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin public String getString(int id) throws Resources.NotFoundException { 8225cbf6f16c0fc8e6524935e6fa3d70ec2a92ed25Phil Goodwin & Tyler Schultz return resourceLoader.getStringValue(id); 83b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 84b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 85de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 86b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin public String getString(int id, Object... formatArgs) throws Resources.NotFoundException { 87b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin String raw = getString(id); 88b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin return String.format(Locale.ENGLISH, raw, formatArgs); 89b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 90b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 91de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 929daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel public String getQuantityString(int id, int quantity, Object... formatArgs) throws Resources.NotFoundException { 939daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel String raw = getQuantityString(id, quantity); 949daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel return String.format(Locale.ENGLISH, raw, formatArgs); 959daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel } 969daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel 979daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel @Implementation 989daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel public String getQuantityString(int id, int quantity) throws Resources.NotFoundException { 999daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel return resourceLoader.getPluralStringValue(id, quantity); 1009daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel } 1019daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel 1029daa83d905eccca3b027ce27e4a77b3f57441a1eJan Berkel @Implementation 103b63be1295e9d42211bd466585850db5897222aa1Macarse public InputStream openRawResource(int id) throws Resources.NotFoundException { 10440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return resourceLoader.getRawValue(id); 105b63be1295e9d42211bd466585850db5897222aa1Macarse } 10640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 107b63be1295e9d42211bd466585850db5897222aa1Macarse @Implementation 108b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin public String[] getStringArray(int id) throws Resources.NotFoundException { 10925cbf6f16c0fc8e6524935e6fa3d70ec2a92ed25Phil Goodwin & Tyler Schultz String[] arrayValue = resourceLoader.getStringArrayValue(id); 110b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin if (arrayValue == null) { 111b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin throw new Resources.NotFoundException(); 112b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 113b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin return arrayValue; 114b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 115b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 116de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 117bd9537bd36434865d4d25ef332bd388d39a51e34Christian Williams & Phil Goodwin public CharSequence[] getTextArray(int id) throws Resources.NotFoundException { 118bd9537bd36434865d4d25ef332bd388d39a51e34Christian Williams & Phil Goodwin return getStringArray(id); 119bd9537bd36434865d4d25ef332bd388d39a51e34Christian Williams & Phil Goodwin } 120bd9537bd36434865d4d25ef332bd388d39a51e34Christian Williams & Phil Goodwin 121bd9537bd36434865d4d25ef332bd388d39a51e34Christian Williams & Phil Goodwin @Implementation 122b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin public CharSequence getText(int id) throws Resources.NotFoundException { 123b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin return getString(id); 124b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 1259472d8faeb0c6fa20529234e7e2a7ebf967d1f32Michael Portuesi 126e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard public void setDensity(float density) { 127e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard this.density = density; 128e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard } 129e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard 1309931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante public void setDisplay(Display display) { 1319931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante this.display = display; 1329931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante displayMetrics = null; 1339931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 1349931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 135de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 136b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin public DisplayMetrics getDisplayMetrics() { 137e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu if (displayMetrics == null) { 1389931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante if (display == null) { 1399931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante display = Robolectric.newInstanceOf(Display.class); 1409931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 1419931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 142e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu displayMetrics = new DisplayMetrics(); 143e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu display.getMetrics(displayMetrics); 144e07511e1e736d9deba522ab8d58ffabcc67d274bRick Kawala & Wei Wu } 145e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard displayMetrics.density = this.density; 146e02d2608f3fa739dd328c6b44a2122b9dfb73bedLowell Kirsh & Ryan Richard return displayMetrics; 147b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 148b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 1499931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante @Implementation 150f1e19869f68b5b04688cc9701c3e2bf73cd35f76Ryan Richard public Drawable getDrawable(int drawableResourceId) throws Resources.NotFoundException { 151fac8bbf7dfc7904540716be8649b2f5a5c9f6d15adriancowham 1529931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante ResourceLoader resLoader = Robolectric.shadowOf(Robolectric.application).getResourceLoader(); 1539931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 1549931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante // Check if this drawable is an XML drawable 1559931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante Drawable xmlDrawable = resLoader.getXmlDrawable(drawableResourceId); 1569931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante if (xmlDrawable != null) { 1579931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante return xmlDrawable; 1589931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 1599931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 1609931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante Drawable animDrawable = resLoader.getAnimDrawable(drawableResourceId); 1619931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante if (animDrawable != null) { 1629931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante return animDrawable; 1639931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 1649931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 1659931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante Drawable colorDrawable = resLoader.getColorDrawable(drawableResourceId); 1669931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante if (colorDrawable != null) { 1679931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante return colorDrawable; 1689931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 1699931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 1709931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante return new BitmapDrawable(BitmapFactory.decodeResource(realResources, drawableResourceId)); 1719931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante } 1729931c0dc82b7213f180aa4570bafdbb57ec563d7Spider Phil Plante 173de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams @Implementation 174fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin public float getDimension(int id) throws Resources.NotFoundException { 175fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin // todo: get this value from the xml resources and scale it by display metrics [xw 20101011] 1769472d8faeb0c6fa20529234e7e2a7ebf967d1f32Michael Portuesi // TODO: The fall-through implementation now gets value from XML resources. resourceLoader.dimensions should be deprecated 17708d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams if (resourceLoader.dimensions.containsKey(id)) { 17808d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams return resourceLoader.dimensions.get(id); 179fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin } 1809472d8faeb0c6fa20529234e7e2a7ebf967d1f32Michael Portuesi 1819472d8faeb0c6fa20529234e7e2a7ebf967d1f32Michael Portuesi return resourceLoader.getDimenValue(id); 182fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin } 183b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 184fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin @Implementation 185fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin public int getDimensionPixelSize(int id) throws Resources.NotFoundException { 186b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin // The int value returned from here is probably going to be handed to TextView.setTextSize(), 187b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin // which takes a float. Avoid int-to-float conversion errors by returning a value generated from this 188b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin // resource ID but which isn't too big (resource values in R.java are all greater than 0x7f000000). 189b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin 190fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin return (int) getDimension(id); 191fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin } 192fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin 193fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin @Implementation 194fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin public int getDimensionPixelOffset(int id) throws Resources.NotFoundException { 195fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin return (int) getDimension(id); 196fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin } 197fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin 198114296321cba71f8133713306049ce3b411e8563Gonçalo Silva @Implementation 19940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams public AssetManager getAssets() { 200a6ff2c2b15018092af3a28697b521d1ca5e789f0Christian Williams & Phil Goodwin return ShadowAssetManager.bind(Robolectric.newInstanceOf(AssetManager.class), resourceLoader); 201114296321cba71f8133713306049ce3b411e8563Gonçalo Silva } 202fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin 203ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams @Implementation 204ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams public final android.content.res.Resources.Theme newTheme() { 205ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams return newInstanceOf(Resources.Theme.class); 206ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams } 207ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams 20859d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin /** 20959d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin * Non-Android accessor that sets the value to be returned by {@link #getDimension(int)} 21059d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin * 21140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams * @param id ID to set the dimension for 21259d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin * @param value value to be returned 2139472d8faeb0c6fa20529234e7e2a7ebf967d1f32Michael Portuesi * @deprecated 21459d9df0f147b94712b36ad44939ebd2afa4cf1b7Phil Goodwin */ 215fba19865a86f986189561f961a27f664eb23ce38Chee Wong & Phil Goodwin public void setDimension(int id, int value) { 21608d5f9aec95a889473eaff1f5d6afefbaa2bd489Christian Williams resourceLoader.dimensions.put(id, value); 217b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin } 218ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams 219ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams @Implements(Resources.Theme.class) 220ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams public static class ShadowTheme { 221ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams @Implementation 222ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams public TypedArray obtainStyledAttributes(int[] attrs) { 223ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams return obtainStyledAttributes(0, attrs); 224ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams } 225ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams 226ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams @Implementation 227ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams public TypedArray obtainStyledAttributes(int resid, int[] attrs) throws android.content.res.Resources.NotFoundException { 228ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams return obtainStyledAttributes(null, attrs, 0, 0); 229ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams } 230ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams 231ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams @Implementation 232ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { 233ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams return newInstanceOf(TypedArray.class); 234ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams } 235ec63d3ad017965dc341bd0ce15f07c65f35b4a90Christian Williams } 236b63effe7b28319e0430f0baa9b8d1b8ddd3ff307Christian Williams & Phil Goodwin} 237