A LiveData class that has null
value.
Home / android / common
Absent live data
Barcode scanner using Google Vision
The implementation of the Google Vision api is not that hard, but there are a few fixes you’ll need to make your app production ready. Most importantly: the default implementation does not support autofocus which makes it very hard to scan a barcode.
Read more…Camera2 implementation in an extendable Fragment
If you’re going to add a custom camera to your app, use these snippets to do it right. This recipe uses the Camera2 APIs, and hides all the weird code required for setting up a viewfinder and taking pictures.
Read more…Custom TestRunner
Adds several features over the regular AndroidJUnitRunner:
Read more…Double trigger livedata transformation
A replacement for the mediator LiveData for triggering LiveData transformations.
Read more…Encrypted shared prefs
A class that is using the “normal” shared preferences for any device with an sdk < M and the EncryptedSharedPreferences
for M and above.
FragmentActivity
This recipe is outdated! We’ll keep it for now, because it might be useful when maintaining old apps, but the
new prefered way is to use a FragmentContainerView
instead.
Get the SHA of a keystore
Gets the MD5, SHA1 and SHA256 of a keystore. You’ll need this for many signin solutions, such as Google SignIn, Facebook, Twitter, etc.
Read more…Getting the user's location
All the methods below need the location permission:
Read more…HtmlCompat for Android Nougat and up
Tiny snippet for reducing compatibility clutter.
Read more…Lock an app using the phone's default lock screen
The snippets below can lock access to the app whenever the user leaves the app and comes back, with an optional timeout.
Read more…Monitor permission status
Use LiveData to determine the status of any permission (in the sample code below: the location permission). If the user grants the permission at any point, then we will get notified.
Read more…Open settings activity
Start the App Settings Activity so that the user can change settings related to the application, such as permissions.
Read more…Pagination
A very complete recipe that implements a RecyclerView that pulls in paginated data, using Retrofit, LiveData. It includes example models, adapter, viewholders, and a viewholder for displaying the network state in case of an error.
Read more…Room type converters
Common type converters for the Room library.
Read more…Showing notifications
Simple snippet for showing a notification. Tweak where needed.
Read more…Simple date formatting cheatsheet
It’s date formatting string time! This is the table you need for all simple date formatting in Java/Kotlin.
Read more…Soft keyboard event listener
Detect when the keyboard is visible and when not.
Read more…Take a picture using the default camera
Add a file file_paths.xml
to the resources directory res/xml/
in order to grant access to the correct folders:
Turn timestamps into "time ago" strings
This recipe creates a “time ago” string from any timestamp, often used to display how long ago a comment was posted or a notification was received.
We’re creating an extension method, so any Long
timestamp can be converted like so: 12313131.timeAgo(arr)
where arr
is a list of labels.
This list can be retrieved from a string-array
in the strings.xml
to make it localizable.
Using the clipboard
Copying and pasting from and to the system clipboard. Assuming text and/or html content.
Read more…Vibration and haptic feedback
For haptic feedback on button touches:
Read more…