Sunday, January 25, 2015

Google Chrome Update to Version 40 Breaks the Power User Shortcuts on Google Search Results Page To Open in Background Tab

Like any developer I also do "Google Driven Development", where I quickly search for the problem I am stuck on using Google, browse the result, zero down on causes and find a solution. To quicken the process, shortcuts on Google Search results are very handy and heavily used.

I will describe you these shortcuts if you are not aware of them. On Google Search Results page you can press TAB once to jump on the result. The first result is going to show a small blue triangle next to the search result title, you can browse the results using UP/DOWN arrow keys. To open a result in Background tab, just press Command + Enter. The process is demonstrate using a YouTube video down here.

Then suddenly one morning I was not able to do the search using these shortcuts. As it happened, Google Chrome updated itself to new version 40 last night. So the culprit looks like the new version which was not tested for this hidden/unaware but extremely useful and popular feature. I just can't live without this since it is like part of my behavior now, and if it doesn't work it leaves me very very irritated. I raised a ticket for this particular bug, but if any of you had an experience with Google product service, you are not going to bet much on them. Rather I thought of going back to version 39 which was working fine for me.

But this downgrade, or reverse upgrade is not possible through Chrome, you have to install it separately. And Google official website is not going to give you an older version of Chrome but the latest version of it. I was going to head over to but thought of doing a search first. As it happens a few good people at have the archived versions for Google Chrome. I went ahead and reverse upgraded myself with version 39.

But then again next day, Chrome smartly upgraded itself to version 40. So this time I tried to find ways to disable the smart ass automatic update at least till the bug is fixed in v40. The official documentation details a few steps to disable automatic upgrades but those didn't work for me. I checked the process that were used to do the upgrade and that took me to the file /Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/ksadmin . For now I have renamed ksadmin to ksadmin.bak and the automatic upgrades have been disabled. Hope Google fixes these serious issues on Chrome and don't have to use these roundabout ways of doing things.

Wednesday, January 7, 2015

Downloading a File in an Unreliable/Flaky Connection

Many of us find ourselves stuck in a place where we have a very unreliable/flaky connection and need to download a file urgently. Most likely you don't have an external download manager (those were popular in age of IE 6), and using a browser to download restarts the download from beginning every time. With a lot of luck you hope the download is successful this time. I went through the same when I spent my New Year holidays with family in a not so connected to internet part of India.

Obviously, one such solution that props to mind is using curl with "-C" continue the download flag. So using curl your command is going to look like

curl -L -O http://xyz.url

and when the download has failed, switch over to command

curl -L -O -C - http://xyz.url

But this have another problem. You have to constantly monitor the download and launch the command as soon as it craps. Curl helps you by returning an error exit value if the download was not successful and otherwise. Wish there was a command to relaunch it based on the exit flag. Since there is none, ruby can come to your rescue. We can write a small ruby script to do just that. The ruby script looks like

ruby -e "while(\!system(\"curl -L -O -C - http://xyz.url\")); end"

Hope this helps. Happy New Year !

Monday, September 22, 2014

[Updated] Seagate External HDD NTFS Driver for Mac

This is a simplified post detailing how to go about using Seagate External HDD on Mac.

  1. The Seagate External HDD by default formatted as NTFS. Mac has flaky support to read and write to NTFS. Sometimes you will be able to write, otherwise it will open the HDD in read-only mode. In worst circumstances it will not even detect your HDD. Don't Panic.
  2. If you are able to read your Seagate HDD in read-only mode, check for driver inside Vendor folder and hope along with all the goodies you have the NTFS Driver. Don't confuse goodies with driver. After installing all the relevant apps inside Vendor, restart your Mac and hope everything works flawlessly. If you are still facing issues continue following the instructions.
  3. If the above solution didn't work for your or if you are not even able to detect your HDD, download the Paragon NTFS Driver for Mac from the Seagate website using this link. Accept the EULA, and download the dmg driver file. Install and restart your Mac, check you are able to detect your HDD and read/write without any issues.
These are the only tricks up my sleeve, if it still didn't work for you, hard luck :(. If this post was helpful, kindly '+1' this and leave a comment :).

Android Continuous Long Click Listener

This is about implementing a UI Pattern very common for mobile applications. You have a button which increments the value if you do a simple click on a button. If you long press instead of click, it increments the value in chunks rather than single units. These behaviours can be implemented using standard Android library event listeners like View.OnClickListener and View.OnLongClickListener.

For my app, I was looking for implementation where you keep the button pressed and it continuously keeps updating the value in chunks. Sadly, View.OnLongClickListener doesn't have any such support, so I decided to make a custom listener for this behaviour. You can view the final implementation here -

Some notes on the implementation of this listener -
  1. To support continuous long click listener, I am attaching 2 listeners to the view object. View.OnLongClickListener and View.OnTouchListener
  2. View.OnLongClickListener kicks in when it first detects a long click by user. After executing the default behaviour, it adds a delayed message to a Handler to execute the same code. This way, after a stipulated time the same code kicks in and increments the value again and thus simulating the required behaviour for continuous long click.
  3. View.OnTouchListener is used to detect a MotionEvent.ACTION_UP event, where the user disengages from the screen. On detecting it, any pending messages in the Handler are cleared thus finishing the event.
  4. As an add-on, I stimulate a haptic feedback every time the code is run to give user feedback about the long click action being kicked in.
The code for the above sample can be found on github here ->

The gist of listener implementation is below ->

Thursday, September 18, 2014

Enabling Developer Options in Xiaomi Redmi and Mi3 for Android Development and USB Debugging

I hope many of us in India were able to grab the Xiaomi Mi3 or Redmi throught the flash sale on Flipkart. If you haven't, I would highly recommend to get this value for money phone.

Anyways, for me, the primary purpose of buying this phone was to use it for Android App development. To my surprise, I couldn't find the USB Debugging option in the Settings. I was utterly confused and so I did the obvious - Googled it.

It turns out, the Developer Options are hidden by default in the MIUI - the custom UI that comes installed on Xiaomi phones. And to show these hidden options is like finding an easter egg.

To enable the developer options follow the steps as below -
  1. Open Settings -> General Settings -> About Phone (Screenshot 1)
  2. Tap on the item "Android version" (Screenshot 2). As you tap on it, you will see a toast message saying "x more clicks from Developer Options"
  3. As you keep tapping, finally you will see a toast message confirming "You are now a developer" (Screenshot 3)
  4. Thats it. To confirm the Developer options are enabled, go back to General Settings and find Developer options under System settings group (Screenshot 4)
This phone have host of Developer options ranging from the basic of keeping phone awake to doing some basic profiling. I haven't checked out all of them yet, but hope to do so soon. Happy coding.

Screenshot #1 Screenshot #2 Screenshot #3 Screenshot #4

Wednesday, August 27, 2014

Android Instructions Overlay - Showing a Screen Pointing To Hidden Navigation Features on First Launch

The demo code for this can be found @anagri/AndroidInstructionsOverlay.

With the advent of mobile apps, the standard patterns of UX are rapidly evolving. Each major release of Android or iOS brings with it some new and innovative UI features that is now the preferred way of interaction discarding the old one. Earlier, there were hardware buttons which are now replaced with onscreen buttons, menus are now replaced by the rich features of ActionBar and gestures open up a plethora of novel UX patterns everyday.

With so many UX patterns, it is very hard to convey to users on the first launch of app of the patterns you have used in your app. For some cases this problem can be solved by the Instructions Overlay screen. In this blog post I will take you through implementing one such simple application that uses this help pattern.

The Instructions Overlay is achieved by having an image that points to the main navigation features of the app, including gestures and setting this image to invisible by default. When the app is launched for first time, this image is displayed with a translucent background pointing to the actual widgets on the screen along with a concise instruction of using that widget. Also this is noted down in the preference/local datastore, so that this screen does not appear next time the app is launched. We also need to set a click listener so that if image is clicked or touched, it goes away. Optionally we can have a menu item which makes this instruction overlay image visible again for reference.

But with the screen size fragmentation, it is difficult to have a single image that displays the instructions. To overcome this issue, draw9patch tool is used to mark the areas that can be expanded if this image is being displayed on higher screen sizes. Just make sure the original image follows the aspect ratio of 4:3 which is the most common screen aspect ratio for Android devices.

This is how the instructions overlay looks on emulators running Galaxy Nexus S with screen resolution of 720x1280 and Nexus One with screen resolution 480x800.

Galaxy Nexus 720x1280 px Nexus One 480x800 px

Tuesday, August 26, 2014

Looping ViewPager - Small hack to make ViewPager loop through screens

For my Android app, I am using ViewPager to get a cool animation navigating by swiping cards left and right. The supporting Android class FragmentStatePagerAdapter does all the heavy lifting but also restricts few features.

For example, I was looking for a looping ViewPager, where on first swiping back from first page takes you to last page, as well on swiping forward on last page takes you back again to the first page and this loop continues.

I checked on stackoverflow for any clean solutions, but I was not satisfied with the hacks detailed over there. I did some brainstorming and started working on my own design.

So, I decided instead of having "n" pages in my ViewPager, I will have "n+2", that is additional 2 pages. I have 2 variables here, position - a zero index based variable specifying page number in ViewPager and contentIndex - an index of string array I am displaying as ViewPager cards. These additional 2 pages would be the first page at position 0 which would display the content at the last index of array, and the last page at position n+1 which would display the content at index 0. Thus for content at index 0 and n are being displayed by 2 pages.

Then I listen for OnPageChange events. For these 2 special pages, as soon as I land on them, instead of displaying these pages, I switch the page to go to the original page that was already displaying it at its proper position. I navigate to it without any animation.

For e.g. if I come to position 0 which displays the last content of array, instead of being at position 0, I switch it to position n which was displaying the same content. The switch is instantaneous, although if you watch closely, you will notice a sort of jerk that happens. Similarly I switch to page at position 1 as soon as I land on page at position n+1.

A project with complete implementation of above hack can be found on Github @anagri/ViewPagerLoop

The screenshots from the above app looks like -

The core logic in code is ->

If you found this helpful or have any suggestions, kindly leave a comment.