JavaScript – detect support for background-size: cover

Most of the other solutions worked generally, but gave false negatives (e.g., IE9 does support it, but most test would indicate it did not). Here’s what seems to work so far, for me:

If you just use the second test (in the if block), old IE will report true – the first test is […]

Android – Accordion Widget

I’ve published a new Android widget, for API’s later than 3 (although we could swap out the animator to support older versions if necessary). The widget manages the layout and display state of arbitrary Views so is completely customizable. As always, it’s available on github.

PHP – RegexRouter

PHP Routing class that translates any valid PCRE into a closure, in 14 lines of wholesome goodness For the impatient:

Android – draw single or separate borders on Views

Just subclass the View type you’re using, and override on Draw with a quick call to canvas.drawLine. Remember to call super.onDraw first, so that the text or image or standard contents is rendered beneath your border. Also, ViewGroups will need to have setWillNotDraw( false );

Android – dynamic Fragment not filling parent

If, during onCreateView, you’re using the ‘new’ operator to instantiate a View instance (rather than inflating from XML, and/or using the attachToRoot parameter), your fragment’s View will be given default layout parameters of WRAP_CONTENT. If your content is smaller than the screen, this can look odd. Since you’re not directly adding the view to the […]

Android – event dispatching with LocalBroadcastReceiver

If your background is with ECMA languages (JavaScript, ActionScript), passing data around the Android environment can get a little confusing. Fortunately, there’s a class that makes things a little more familiar – LocalBroadcastReceiver. Strangely, this is only available in the support library, but that’s pretty much a requirement for most apps, and is in fact […]

Android – custom addView behavior

In many widgets, one particular ViewGroup should contain all the “content”, while other Views might serve as containers, controllers, navigation elements, or decoration. For example, for short, scrolling ListView-like widgets, it can be easier to wrap a LinearLayout in a ScrollView, rather than worrying about adapters and header views… This technique allows you to create […]

Create a Virtual Host on Windows

While you can often stick a project in a subdirectory of your htdocs and access from localhost/project, that can be inconvenient (e.g., assume leading slashes from absolute-from-root pathing, like /path/to/file.ext). It’s simple enough to create a virtual host like http://project.local or 1. Open httpd-vhosts.conf (usually in your Apache install directory, under conf/extra… note that […]

Install Android App (.apk) from PC

Connect your phone via USB, then from your android-sdks/platform-tools directory (on windows, usually c:/users//android-sdks/platform-tools), use the adb install command: [code] adb install "C:/path/to/your/File.apk" [/code] That’s it. Assuming File.apk exists at the path provided, you’ll see it listed in your Applications list and be able to use it immediately.

JavaScript – move head of array

Function to move the head of an array by x positions – elements are moved to the end of the array, with order preserved. Dirty: