Posts categorised "Development"

With Android 5.0, there was a complete revamp of the “Recent Tasks” 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.

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 & Color.

Styling Recent Tasks

Following is a small code-snippet that takes care of the styling for you 🙂


/**
 * Helper class that applies the proper icon, title and background color to recent tasks list.
 */
public class RecentTasksStyler {

    private static Bitmap sIcon = null;

    private RecentTasksStyler() {
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void styleRecentTasksEntry(Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return;
        }

        Resources resources = activity.getResources();
        String label = resources.getString(activity.getApplicationInfo().labelRes);
        int colorPrimary = resources.getColor(R.color.theme_primary);

        if (sIcon == null) {
            // Cache to avoid decoding the same bitmap on every Activity change
            sIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher);
        }

        activity.setTaskDescription(new ActivityManager.TaskDescription(label, sIcon, colorPrimary));
    }
}

Just call this in the onCreate of any activity, and it will apply the default app theme to the Recent Tasks entry.

It's kinda sad that the folks at Facebook cannot find time to add 10 lines of code.

It’s kinda sad that the folks at Facebook cannot find time to add 10 lines of code.

This entry was posted in Development and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

Here’s the first Yahoo! Pipe I came up with. It’s mostly a mashup of all the feeds, Blogs, Twitter, LinkedIn, Flickr, Goodreads, and any other site that came to mind… And it’s pretty big. I could probably write up a decent tutorial, but instead, I guess I’ll just help out if anyone asks (now we all know, that’s not gonna happen!)

Yahoo Pipes

You guys can see it in more detail at my Yahoo! Pipes library

This entry was posted in Development and tagged , , , , , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

C++:

template <class BidirectionalIterator>
bool next_permutation(BidirectionalIterator first,
                      BidirectionalIterator last) {
    if (first == last) return false;
    BidirectionalIterator i = first;
    ++i;
    if (i == last) return false;
    i = last;
    –i;
    for(;;) {
        BidirectionalIterator ii = i–;
        if (*i <*ii) {
            BidirectionalIterator j = last;
            while (!(*i <*–j));
            iter_swap(i, j);
            reverse(ii, last);
            return true;
        }
        if (i == first) {
            reverse(first, last);
            return false;
        }
    }
}

An amazing piece of code! This is the next_permutation() function in the Standard C++ Library, defined in <algorithm>. And the best part… it’s O(n) complexity.

Iterators are a generalization of pointers. That should make it much easier to understand 😀
It checks for the initial conditions of 0 length and 1 character strings, and then iterates through the given string from the last character to find the next largest permutation. 

What I wonder is it’s response when we enter Alphanumeric data, or even Mixed Alphabets (Smalls and Caps). That should break it. 🙂

This entry was posted in Development and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.