{"id":257,"date":"2015-01-27T11:42:03","date_gmt":"2015-01-27T11:42:03","guid":{"rendered":"http:\/\/ratneshneema.com\/tech\/?p=257"},"modified":"2015-12-26T08:37:33","modified_gmt":"2015-12-26T08:37:33","slug":"style-your-app-preview-in-the-recent-tasks","status":"publish","type":"post","link":"http:\/\/ratneshneema.com\/tech\/development\/style-your-app-preview-in-the-recent-tasks\/","title":{"rendered":"Style your App Preview in the Recent Tasks"},"content":{"rendered":"<p>With Android 5.0, there was a complete revamp of the &#8220;Recent Tasks&#8221; implementation on Android. The changes impact the way we think of <em>tasks<\/em>, as well as how they are presented in the Overview Screen. I may get into the logical, and implementation level changes at a later date, but first we tackle the visual changes.<\/p>\n<p>To keep the UI in line with the colorful, fun, approach of the rest of the OS, an API was introduced to give developers some manner of control over the presentation of their tasks in the Overview Screen. The entry has three components: Label, Icon &amp; Color.<\/p>\n<p><a href=\"https:\/\/ratneshneema.com\/tech\/wp-content\/uploads\/2015\/05\/Styling-Recent-Tasks.png\"><img src=\"https:\/\/ratneshneema.com\/tech\/wp-content\/uploads\/2015\/05\/Styling-Recent-Tasks.png\" alt=\"Styling Recent Tasks\" width=\"720\" class=\"content-width wp-image-278\" \/><\/a><\/p>\n<p>Following is a small code-snippet that takes care of the styling for you \ud83d\ude42<\/p>\n<pre><code>\r\n\/**\r\n * Helper class that applies the proper icon, title and background color to recent tasks list.\r\n *\/\r\npublic class RecentTasksStyler {\r\n\r\n    private static Bitmap sIcon = null;\r\n\r\n    private RecentTasksStyler() {\r\n    }\r\n\r\n    @TargetApi(Build.VERSION_CODES.LOLLIPOP)\r\n    public static void styleRecentTasksEntry(Activity activity) {\r\n        if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.LOLLIPOP) {\r\n            return;\r\n        }\r\n\r\n        Resources resources = activity.getResources();\r\n        String label = resources.getString(activity.getApplicationInfo().labelRes);\r\n        int colorPrimary = resources.getColor(R.color.theme_primary);\r\n\r\n        if (sIcon == null) {\r\n            \/\/ Cache to avoid decoding the same bitmap on every Activity change\r\n            sIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher);\r\n        }\r\n\r\n        activity.setTaskDescription(new ActivityManager.TaskDescription(label, sIcon, colorPrimary));\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<p>Just call this in the onCreate of any activity, and it will apply the default app theme to the Recent Tasks entry. <\/p>\n<div id=\"attachment_274\" style=\"width: 1090px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/ratneshneema.com\/tech\/wp-content\/uploads\/2016\/04\/Styled-Recent-Tasks.png\"><img aria-describedby=\"caption-attachment-274\" class=\"content-width wp-image-274\" src=\"https:\/\/ratneshneema.com\/tech\/wp-content\/uploads\/2016\/04\/Styled-Recent-Tasks.png\" alt=\"It's kinda sad that the folks at Facebook cannot find time to add 10 lines of code.\" width=\"720\" \/><\/a><p id=\"caption-attachment-274\" class=\"wp-caption-text\">It&#8217;s kinda sad that the folks at Facebook cannot find time to add 10 lines of code.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>With Android 5.0, there was a complete revamp of the &#8220;Recent Tasks&#8221; implementation on Android. The changes impact the way we think of tasks, as well as how they are presented in the Overview Screen. I may get into the logical, and implementation level changes at a later date, but first we tackle the visual changes.<\/p>\n<p>To keep the UI in line with the colorful, fun, approach of the rest of the OS, an API was introduced to give developers some [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[69],"tags":[24,46],"_links":{"self":[{"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/posts\/257"}],"collection":[{"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":12,"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":283,"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/posts\/257\/revisions\/283"}],"wp:attachment":[{"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ratneshneema.com\/tech\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}