Several short snippets for File I/O in generic Java.
Read more…All snippets tagged with java
Page 1 of 3File I/O operations
Check and observe the availability of the Play Store.
Useful for checking if a watch face is running on a watch that is being used with an iPhone.
Read more…Grant special permissions to a WebView
Accessing the camera or location in a WebView is not possible without granting the WebView
permission. Make sure your app has permissions already through the conventional method before calling this snippet:
Complete example of using a WebView
Fragment with a WebView
and fall-back UI in case there’s no active data connection.
Wrapping a RecyclerView to the height of its content.
This LayoutManager
functions as a wrap_content
of sorts for the height of a RecyclerView
.
A View that shows a vertical, dotted line
This is a custom view to draw dotted, vertical lines.
Read more…Progress bar masked by text
This custom view shows a progress bar in the foreground of a TextView. Check the Pixplicity Authenticator app for an example.
Read more…Pie chart-like progress bar
This custom view shows a clock-like circular countdown, and can be used as a timer or as a ProgressBar
. To use as a timer, create your own handler (or similar) to update the progress automatically.
Using <ul> in TextViews
Adds very basic support for using bulleted lists in TextViews
.
Underline text in a view
There’s no textStyle
to add underline to a TextView
or Button
. Use the following to add it programmatically instead:
Getting the screen size in pixels
Start by getting a reference to the WindowManager
. When in an Activity
, you can use getWindowManager()
, otherwise, use:
Bottom-to-top chat-style reversed RecyclerView
To turn a RecycerView
upside-down, and add elements from the bottom like a chat window, use this:
RecyclerView with CursorAdapter and reordering
This is a combination of a CursorAdapter
fit for RecyclerViews
, and several helpers to support drag-and-drop and swipe-to-dismiss.
Using a RecyclerView
This is the bare minimum boilerplate for quickly creating a RecyclerView.
Read more…Using a theme to show a splash or placeholder while activity loads
Rule: never ever implement a splash screen using a separate activity. Splash screens should be used to show something while the app loads, and is not a way to delay app launch just to show a logo.
Read more…