Posts

Showing posts from July, 2018

Android - negative x and y in onTouchEvent

    Android's handling of touch event recommends to use getX() and getY() when trying to determine the coordinates with respect to the actual view that is being touched. This makes sense for most use cases and developers might expect positive values starting from 0,0 to width-1,height-1.    However, there are cases when getX() and getY() would return negative values and values greater than the actual view dimensions. The reason is due to padding added to the view. Padding unlike margin is internal to the view. Clicking on the padded space before the start of the view dimensions would result in a negative values. The best solution is just to check for the touch coordinates to be within the view boundary and then handle appropriately.

Android - Chrome browser tabs as separate tasks in Recent Apps Overview

    Chrome browser for Lollipop and above introduced a nice feature to show tabs as separate tasks in Recent Apps Overview. Users can turn off this feature via settings. For some reason, this was only supported from Lollipop and not for older versions of Android. This is most likely due to SDK APIs introduced in API level 21, ActivityManager.AppTask . This is meant for applications wanting to manage tasks in recent apps overview. Applications can determine how and when activities appear in the overview screen. Chrome browser is most likely using these APIs restricting the feature to Lollipop and above.    Besides, Chrome also has the ability to resume the last used task when users launch the browser via launcher's shortcut. In a typical android application, android's launcher shortcut would always fire a specific intent resolving to the main activity of the application. In case of Chrome, this action is mapped to launch the last used tab and not the first tab. How...