Android Tips Round-Up, Part 5

Here's the final round-up of Android tips I've been posting.

I've officially run out of things to post. If I ever come across something new I'll post it but it won't be daily anymore. It's been fun everyone!

More: Part 1 | Part 2 | Part 3 | Part 4 | Part 5

ViewDragHelper - Dragging Views is a complex problem and this class helps a lot. If you want an example, DrawerLayout uses it for swiping. Flavient Laurent also wrote an excellent article about it.

PopupWindow - Used all around Android without you even realizing it (action bars, autocomplete, edittext errors), this class is the primary method for creating floating content.

ActionBar.getThemedContext() - ActionBar theming is surprisingly complex (and can be different from the theming of the rest of the Activity). This gets you a Context so if you create your own Views they will be properly themed.

ThumbnailUtils - Helps create thumbnails; in general I'd just use whatever image library was already in place (e.g. Picasso or Volley), but it can also create video thumbnails!

Context.getExternalFilesDir() - While you do have permission to write anywhere on the SD card if you ask for it, it's much more polite to write your data in the correct designated folder. That way it gets cleaned up and users get a common experience. Additionally, as of Kit Kat you can write to this folder without permission, and each user has their own external files dir.

SparseArray - A more efficient version of Map<Integer, Object>. Be sure to check out sister classes SparseBooleanArray, SparseIntArray and SparseLongArray as well.

[PackageManager.setComponentEnabledSetting()](https://developer.android.com/reference/android/content/pm/PackageManager.html#setComponentEnabledSetting(android.content.ComponentName, int, int)) - Lets you enable/disable components in your app's manifest. What's nice here is being able to shut off unnecessary functionality - for example, a BroadcastReceiver that is unnecessary due to the current app configuration.

SQLiteDatabase.yieldIfContendedSafely() - Lets you temporarily stop a db transaction so you don't tie up too much of the system.

Environment.getExternalStoragePublicDirectory() - Again, users like a consistent experience with their SD card; using this method will grab the correct directory for placing typed files (music, pictures, etc.) on their drive.

View.generateViewId() - Every once in a while I've wanted to dynamically generate view IDs. The problem is ensuring you aren't clobbering existing IDs (or other generated ones).

ActivityManager.clearApplicationUserData() - A reset button for your app. Perhaps the easiest way to log out a user, ever.

Context.createConfigurationContext() - Customize your configuration context. Common problem I've run into: forcing part of an app to render in a particular locale (not that I normally condone this sort of behavior, but you never know). This would make it a lot easier to do so.

ActivityOptions - Nice custom animations when moving between Activities. ActivityOptionsCompat is good for backwards compatible functionality.

AdapterViewFlipper.fyiWillBeAdvancedByHostKThx() - Because it's funny and for no other reason. There are other amusing tidbits in AOSP (like GRAVITY_DEATH_STAR_I) but unlike those this one is actually useful.

ViewParent.requestDisallowInterceptTouchEvent() - The Android touch event system defaults handle what you want most of the time, but sometimes you need this method to wrest event control from parents. (By the way, if you want to know about the touch system, this talk is amazing.)