To add a custom typeface to your app, the preferred way is to use Downloadable Fonts. To support legacy devices, use Pixplicity Letterpress.
Read more…All snippets tagged with java
Page 2 of 3FontUtil - several styling options for text
Simple alert dialog fragment
A simple wrap of an AlertDialog
into a Fragment
.
Checks if a TextView is ellipsized.
Note that this doesn’t just check if the TextView
has ellipsizing enabled, it actually checks if the size of the TextView is too short for the full text to appear.
Shared element transitions
On shared views, set android:transitionName="@string/transition_detail"
in both first and second activity. Then launch the second activity like this:
Circular reveal animation
These are the three steps to show the Material Design circular animation when launching an Activity. Make sure to only use this animation when it makes sense - it is meant to make it clear to the user that a button results in the screen being opened.
Read more…Play a sound using the MediaPlayer
Important: make mMediaPlayer
a field, because otherwise the garbage collector will clean up the mediaplayer while the sound is still playing, causing it to be cut off!
Reading and writing files from/to private storage
Reading and writing files from/to private storage. Using a Context you can access the methods
Read more…Simple deeplinking
These are instructions to support and test simple deeplinking, without Firebase or the Navigation Components.
Read more…Rotate a bitmap according to the file's EXIF data
Loads a bitmap from a file, and applies the rotation that is specified in the EXIF data of the file.
Read more…Check if current connection is WiFi
Note: requires android.Manifest.permission.ACCESS_NETWORK_STATE
in the manifest.
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:
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…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…Custom TestRunner
Adds several features over the regular AndroidJUnitRunner:
Read more…