There's a few threads on the forums about accessing the build in Android resources but i couldn't find any code that would allow me to get a built in Android resource drawable using the resource's name - all posted code required that you already know the resource id.
So after a bit of research i created this method:
The documentation for the android.R.drawable class can be found here: R.drawable | Android Developers
Another thing i've been trying to do recently is simply load an icon on a device with high density display but not have the Android OS automatically upscale the icon to a larger size and leave me with a pixelated poor quality icon.
I don't want the icon upscaled...
A solution is to add the icon to my project's Objects\res\drawable-nodpi - creating that folder if it doesn't exist.
But now how can i access that icon?
A new method derived from Barx's recent post here:
Drawables in the drawable-nodpi folder are NOT rescaled on low or high density devices.
While researching all of this i found that the android.R.string class contains localised versions of commonly used application text such as language versions of 'paste' and 'cancel'.
Another new method:
AndroidResources
Version: 1.6
The String returned by this new method will be in the language that the device has selected in Settings > Language & keyboard settings.
The documentation for the android.R.string class can be found here: R.string | Android Developers.
So i've created the library AndroidResources for everyone to use and if any library writers want to use any of these methods in their libraries then please do!
For some reason the forum would not accept the code snippets so check out the attached AndroidResources.txt file for the complete post!
Martin.
So after a bit of research i created this method:
The documentation for the android.R.drawable class can be found here: R.drawable | Android Developers
Another thing i've been trying to do recently is simply load an icon on a device with high density display but not have the Android OS automatically upscale the icon to a larger size and leave me with a pixelated poor quality icon.
I don't want the icon upscaled...
A solution is to add the icon to my project's Objects\res\drawable-nodpi - creating that folder if it doesn't exist.
But now how can i access that icon?
A new method derived from Barx's recent post here:
Drawables in the drawable-nodpi folder are NOT rescaled on low or high density devices.
While researching all of this i found that the android.R.string class contains localised versions of commonly used application text such as language versions of 'paste' and 'cancel'.
Another new method:
AndroidResources
Version: 1.6
- AndroidResources
Methods:- GetAndroidDrawable (ResourceName As String) As Drawable
Get an android resource drawable by ResourceName.
Returns Null if the Drawable is not found. - GetAndroidDrawableNames As List
Get a List of all available android Drawable resource names. - GetAndroidDrawables (ResourceNames As Map) As Map
Get one or more android resource Drawables.
Pass a Map to this method where each Map key is an android Drawable resource name.
The method will return the same Map object where the Map values are the android resource Drawables defined by the Map keys.
If an android resource Drawable is not found the Map value will not be changed. - GetAndroidString (ResourceName As String) As String
Get an android resource string by ResourceName.
Returns Null if the String is not found. - GetAndroidStringNames As List
Get a List of all available android String resource names. - GetAndroidStrings (ResourceNames As Map) As Map
Get one or more android resource Strings.
Pass a Map to this method where each Map key is an android String resource name.
The method will return the same Map object where the Map values are the android resource Strings defined by the Map keys.
If an android String is not found the Map value will not be changed. - GetApplicationDrawable (ResourceName As String) As Drawable
Get an application resource Drawable by ResourceName.
Returns Null if the Drawable is not found. - GetApplicationDrawables (ResourceNames As Map) As Map
Get one or more application resource Drawables.
Pass a Map to this method where each Map key is an application Drawable resource name.
The method will return the same Map object where the Map values are the application resource Drawables defined by the Map keys.
If an application resource Drawable is not found the Map value will not be changed. - GetApplicationRawResource (ResourceName As String) As InputStreamWrapper
Get an application raw resource as an InputStream.
The InputStream will not be initialized if the raw resource cannot be found. - GetApplicationResourceNames (ResourceType As String) As List
Returns a List of Strings which are the application resource names for the ResourceType.
ResourceType must be one of the android R class nested class names.
ResourceType values such as color, drawable, integer, layout and string are valid.
All nested R class classes are documented here:
http://developer.android.com/reference/android/R.html - GetApplicationString (ResourceName As String) As String
Get an application resource String by ResourceName.
Returns Null if the String is not found. - GetApplicationStrings (ResourceNames As Map) As Map
Get one or more application resource Strings.
Pass a Map to this method where each Map key is an application String resource name.
The method will return the same Map object where the Map values are the application resource Strings defined by the Map keys.
If an application resource String is not found the Map value will not be changed.
- GetAndroidDrawable (ResourceName As String) As Drawable
The String returned by this new method will be in the language that the device has selected in Settings > Language & keyboard settings.
The documentation for the android.R.string class can be found here: R.string | Android Developers.
So i've created the library AndroidResources for everyone to use and if any library writers want to use any of these methods in their libraries then please do!
For some reason the forum would not accept the code snippets so check out the attached AndroidResources.txt file for the complete post!
Martin.
Attachments
Last edited: