Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Latest commit

 

History

History
56 lines (35 loc) · 3.96 KB

ARTICLES.md

File metadata and controls

56 lines (35 loc) · 3.96 KB

Articles

A list of articles or online answers that have directly contributed to certain portions of the app.

Overriding App "Startup" class

Creating a custom Application class to run methods on app start, such as authentication file checking.

Adding underline to TabLayout

Add a bottom-only line to a TabLayout background by drawing a shape and moving all other sides of the "rectangle" out of the drawing boundaries.

Screen Utility Functions

Several various Screen utility functions for determining current size, orientation, etc.

Access fragments in a TabLayout

Enable accessing specific fragments in a TabLayout (since they are created programmatically) in order to execute their (public) functions.

Access Fragment XML elements from Fragment

In order to use findViewById() from inside a Fragment, a reference to a View is needed (ie. the parent View). This View reference can be found (and stored) inside the constructor, and then used like parentView.findViewById().

Create Snackbar in a Fragment

Snackbars need a view (ie. a context or anchor) to attach to, but fragments will occasionally disappear. In these cases, or other cases where the Snackbar should attach to the "app" as a whole, use a provided id.

View snackbarRoot = getActivity().findViewById(android.R.id.content);

Hide the Soft Keyboard

The Soft Keyboard can be hidden by first checking for the currently focused view and then hiding the keyboard (using the InputMethodManager class).

Access the Android shell

Viewing the app's private files is possible through the use of the Android shell (ADB). Navigate to the project directory and run adb shell in a terminal. Inside the shell, type run-as ca.kendallroth.mileageapp to set the shell permission, the list the directory files (ls files/).

Pass data between Activities

Passing data to a new Activity is as simple as properly using intent.putExtras() when creating the Intent - passing data back from the same Activity is also quite simple. Rather than call startActivity we call startActivityForResult() which will call the class's overriden onActivityResult() method when the Activity returns.

Change AsyncTask return type

The AsyncTask by default (when autogenerated) returns a Boolean; however, a more complex data structure may be required in some cases. It is possible to change the AsyncTask expected result by changing the Generic parameter in ... extends AsynTask<String, Void, [DesiredType]>.

Android App Bar

The App Bar should typically be overridden to provide a custom Toolbar that captures the functionality of the Activity. The following link describes Android's recommended approach:

Android - App Bar