Posts

Showing posts from June, 2015

Android - Apply multiple styles to a view

    Android's styling feature is meant for just one style to be applied to a view. This works just fine in most cases. However, there are times when properties from multiple styles have to be applied to a view. This makes sense only when the desired properties isn't provided in these styles. Ideally, application developers can just have one style extend from another style and get done. However, this is a challenge when one of these styles is a non-public platform style. Forking the platform style into application project is limited and doesn't necessarily work in platforms having different implementations. Besides, its not future proof as the stock AOSP version from Google might change the style implementation in a future release.    In case of non-public platform style, android usually exposes a style attribute to customize the look and feel of it. Applications are supposed to provide a custom style implementation for this style attribute and that is how the plat...

Android - Check for Platform resources in a device

   One of the challenges developing applications for Android is fragmentation. To make things worse, different forks like Amazon's Fire OS and CyanogenMod have significant user base to ignore. These forks despite being different have some similarities with AOSP and in some cases is good enough to run applications without any platform specific change. Anyways, there are times when application developers would want to verify if a platform resource is available in a device running either a CTS compatible version of Android or otherwise.    The hard way of doing this would be extract system files from the device, decompile and find out if a platform resource is available. Fortunately, Android offers a helper API to check for a platform resource.         getResource().getIdentifier("name", "resource_type", "package_name") name is the exact name of the resource. A drawable resource name shouldn't include the extensions like png. resource_type is ...