Android

The first software stack we started with is Android. It's been a long journey since the days of Android Eclair. We've seen how the ecosystem has grown from an operating system designed to only work on phones to tablets and other form factors.

Over the years there have been a number of guidelines published. Some suggested prefixing every private variable with an m (never understood how this improves readability).

Here are a few guidelines and practices we follow:

Project Structure

All new projects should start with the gradle build system. Please use the latest Android studio to create a new project.

Class files

All class files should be written in UpperCamelCase. Class files that extend system classes should have use the system class name as a suffix.

Preferred

public class WednesdayActivity extends Activity {}

Not Preferred

public class Wednesday extends Activity {}

Resource Files

All resources files are written in snake_case

  • Drawable

Please follow these naming conventions for drawables:

Asset Type

Prefix

Example

Icon

ic_

ic_wednesday.png

Button

btn_

btn_wednesday.png

Dialog

dialog_

dialog_wednesday.png

Menu

menu_

menu_wednesday.png

Notification

notification_

notification_wednesday.png

Tabs

tab_

tab_wednesday.png

  • Layout

Please follow these naming convention for layout files:

System Class

Class Name

Example

Activity

WednesdayActivity

activity_wednesday.xml

Fragment

WednesdayFragment

fragment_wednesday.xml

Dialog

WednesdayDialog

diaglog_wednesday.xml

Adapter Item

-NA-

item_wednesday.xml

Partial

-NA-

partial_wednesday.xml

For the last two the suffix wednesday would be replaced by a name that is more apt to your use case.

  • Selector States

State

Suffix

Example

Pressed

_pressed

btn_wednesday_pressed.png

Focussed

_focussed

btn_wednesday_focussed.png

Selected

_selected

btn_wednesday_selected.png

Checked

_checked

btn_wednesday_checked.png

Disabled

_disabled

btn_wednesday_disabled.png

  • Menu

Considering all menu resources are in the menu folder. Don't suffix these with the _menu string.

For example the menu for the WednesdayActivity should be named activity_wednesday.xml

  • Values

We prefer to follow the default android naming convention. Resource files like strings, values are always named in plural.

XML Style Guidelines

  • While defining parameters of a view please follow this order:

    • id

    • Style

    • All other parameters

Preferred

<TextView
android:id:"@+id/text_view_wednesday"
android:style="@+style/StyleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

Not Preferred

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id:"@+id/text_view_wednesday"
android:style="@+style/StyleTextView" />
  • Prefix all id 's with a string that declares the name of the View.

Preferred

android:id="@+id/text_view_wednesday"

Not Preferred

android:id="@+id/wednesday_text"
  • Please define all styles using upper camel case syntax.

Preferred

android:style="@+style/WednesdayText"

Not Preferred

android:style="@+style/wednesday_text"

Nomenclature (Java)

We follow the same Java Style Guide that google prescribes. You can find it here: https://google.github.io/styleguide/javaguide.html

Nomenclature (Kotlin)

We follow the Kotlin Style guide that is endorsed by google. You can find it here: https://developer.android.com/kotlin/style-guide

Best Practices

We like to follow the reactive principle where our application logic reacts to change either from a user generated event or a change in the underlying data.

Google has done an amazing job of describing the best practices to ensure your app is testable, reusable and robust. Please head here to know more: https://developer.android.com/jetpack/docs/guide

We use the following libraries in our applications:

Please ensure you write espresso and unit tests for the features you build.