Posts

Android - UnsupportedOperationException: Cant convert to color: type=0x2

 You are most likely trying to reference a styleable attribute of reference type in a drawable resource and it bailed out with an UnsupportedOperationException.    <shape android:shape="rectangle">         <solid android:color="?attr/item_background" />     </shape> Sadly this is the case with pre-lollipop android versions. There isn't any way to reference attributes in a drawable resource. This works just fine in Lollipop though and is tracked here . The only other alternative is to have a hard coded color specific drawable resource for older platform versions. /drawable/red_rectangle.xml    <shape android:shape="rectangle">         <solid android:color="@android:color/red" />     </shape> /drawable/orange_rectangle.xml    <shape android:shape="rectangle">         <solid android:color="@android:color/orang...

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

Android - Tinting RippleDrawables

     Android starting from Lollipop provided ability to tint UI elements for better user feedback. Pressing and holding a button starts a tint animation which is stopped as soon as the user lets go of the button. This is done by handling the touch event and using appropriate drawable resources to redraw the button. Besides, the tint animation is pivoted at the touch coordinates known as a hot spot. Lollipop by default supports tint animations for all applications and the SDK offers API to customize the color. This would be needed for applications which have a custom color for the UI elements and the platform's tint color doesn't necessarily work with the app custom color. Besides, new versions of support library even offers compat versions to apply tint colors.    DrawableCompat offers a setTintList API to apply tint colors based on various states of the drawable resource. This is usually applicable for stateful drawables ( Drawable.isStateful ).   ...

Android - Could not read input channel file descriptors from parcel

     This is one crazy runtime failure that doesn't really give any straight forward hint to application developers. The stack trace is usually related to android's internal classes with the top of the frame failing in InputChannel. java.lang.RuntimeException: Could not read input channel file descriptors from parcel.        at android.view.InputChannel.nativeReadFromParcel(InputChannel.java)        at android.view.InputChannel.readFromParcel(InputChannel.java:148)        at android.view.InputChannel$1.createFromParcel(InputChannel.java:39)        at android.view.InputChannel$1.createFromParcel(InputChannel.java:36)        at com.android.internal.view.InputBindResult.<init>(InputBindResult.java:62)        at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:102)        at com.android.int...

Android - Marshmallow Now on Tap

Image
   One of the fascinating features of Marshmallow was Now on Tap. It crawls through the screen content and displays relevant information.     The trigger event is to long press the home button for few seconds. This kind of suggests that some kind of intent is being fired and is being handled by a background application launching the relevant UI. However, an intent design can be hijacked by third party applications and might be confusing for users expecting Now on Tap. In fact, firefox managed to trap the launch intent for Google Now cards in earlier versions of Android. Based on the logs, this seems to be some kind of platform level core changes and surprisingly is coupled with speech and audio inputs. It looks like the touch event is being routed as audio inputs. This feature was either designed with speech input as a trigger event or speech input is further down the line. MicrophoneInputStream: mic_starting com.google.android.apps.gsa.speech.audio.y@4799...

Android - Marshmallow WifiInfo's getMacAddress()

Image
     Android Marshmallow changed the behavior for WifiInfo's getMacAddress() due to privacy concerns. The API wasn't removed or deprecated instead was just updated to return a default address 02:00:00:00:00:00. The intention is to block access to device's hardware identifier using WiFi and Bluetooth APIs. In addition, any background wifi or bluetooth scan is shown as being generated by random mac address starting from Android 6.0. This doesn't let tracking softwares like the ones used in coffee shops, malls do what they used to do, study customer behavior without their knowledge, just because they had their wifi or bluetooth turned on by default. This is similar to what Apple did to iOS8. In Android 6.0, there are still few apps like Settings which continue to have access to the mac address. This is accessed via Settings > About Phone > Status or via Settings > WiFi > Advanced.      Is there any other hidden API that might return the...