Android – CloneView

To visually clone another view. This does not make a functional copy of the view – no hit areas or other behavior or state is cloned. This is a simple View instance that draws the pixels of the source View and positions them appropriately.

Android – Use callbacks to handle Exceptions

Just a simple alternative to specific try/catch blocks.

Usage…

Android – Use lambda or function reference for BroadcastReceiver

E.g.,

Android – Simulate application resource reclamation

In android, when resources are low, the device may kill an application (usually in the background) to re-allocate those resources to the app the user is interacting with at the moment. This is a different process than force-stopping or killing the application, both of which are easy to simulate with ADB commands:

The above […]

Android – Replacement for Gradle “The TaskInternal.execute() method has been deprecated”

So lot’s of people use “dynamic” tasks in gradle, like so:

Which is now deprecated: The TaskInternal.execute() method has been deprecated and is scheduled to be removed in Gradle 5.0. There are better ways to re-use task logic, see https://docs.gradle.org/4.4/userguide/custom_tasks.html#sec:reusing_task_logic. We found ourselves in this position with the com.eriwen JS and CSS minification plugins.  The […]

Android – match_parent won’t always match parent

Here’s a simple example:

(You may want to throw that whole block in a ScrollView for more obvious results) So what you have above is pretty straightforward. You have a container with wrap_content for height. It has 2 children, one is at a fixed height of 10000dp, and the other is set to match_parent. […]

Android – Throttle and Debounce

Throttle: one submission every {interval}, won’t start a new task until elapsed time has passed. Debounce: one submission every {interval}, will cancel all pending tasks to schedule a new one. Both are instantiated with and the only public API is attempt(Runnable), where Runnable is the task to be queued. In practical terms:

In the […]

JavaScript – get absolute position from top or left of document (x, y)

This should probably not be as complicated as it is, but obviously: JavaScript. Anyway, there are 2 basic approaches. You may see offsetTop and offsetLeft used in examples in blogs and on stack. This is great in a garden path setup, but only gives the distance between the element and it’s nearest “offsetParent” (which is […]

Android – layout available space

This is one of the most common questions around Android layout, and one that’s not at all intuitive or well documented. Let’s take the most simple use case: you have a thumbnail that’s 75dp on the right, and you want a TextView to take up the rest of the space. Of course, you could satisfy […]

Android – Application object as Server (instances instead of singletons)

Singletons have drawbacks. This is an old argument and I won’t get into it, but if you find static classes or Singletons are serving large portions of your app, here’s an alternative approach I’ve found success with. This is in directly violation of DI and I understand there are valid arguments against it, but at […]