This is a common section for Java and Kotlin android projects. Please refer to Java guideline and Kotlin guideline for more details.
Before usage of any third party library you have to check its license. Refer to open source licenses guide.
The project should follow standard Android project guidelines however in short:
root/
└─ app/
└─ gradle/
└─ lib/
└─ miscFiles.txt
The root structure should follow clean architecture approach with separation of layers.
app
├─ di
│ ├─ payments
│ └─ operation
├─ presentation
│ ├─ view
│ │ ├─ payments
│ │ │ ├─ PaymentsView
│ │ │ └─ PaymentsFragment
│ │ └─ operations
│ │ ├─ OperationsView
│ │ └─ OperationsFragment
│ └─ presenter
│ ├─ payments
│ │ └─ PaymantsPresenter
│ └─ operations
│ └─ OperationsPresenter
├─ domain (business logic)
│ ├─ payments
│ │ ├─ PaymentsInteractor
│ │ ├─ PaymentsInteractorImpl
│ │ └─ CurrencyHandler (helper class for PaymentsInteractor)
│ └─ operations
│ ├─ OperationsInteractor
│ ├─ rubs
│ │ ├─ OperationsInteractorRubs
│ │ └─ RubsManager (helper class for OperationsInteractorRubs)
│ └─ currency
│ ├─ OperationsInteractorCurr
│ └─ CurrencyManager (helper class for OperationsInteractorCurr)
├─ repositories
│ ├─ payments
│ │ ├─ PaymentsRepository
│ │ └─ PaymentsRepositoryImpl
│ └─ operations
│ ├─ OperationsRepository
│ └─ OperationsRepositoryImpl
├─ data
│ ├─ network
│ └─ db
└─ models (dto descriptions)
├─ payments
│ ├─ PaymentsModel
└─ operations
├─ presentation
│ └─ OperationUIModel
├─ domain
│ ├─ OperationsRubModel
│ └─ OperationCurrModel
└─ data
├─ OperationsRubNetworkModel
└─ OperationCurrNetworkModel
Structure above is not mandatory, for example you could combine layers by features.
├─ presentation
│ ├─ payments
│ │ ├─ PaymentsView
│ │ ├─ PaymentsFragment
│ │ └─ PaymantsPresenter
│ └─ operations
│ ├─ OperationsView
│ ├─ OperationsFragment
│ └─ OperationsPresenter
You can refer to SkyLocker project as example.
Class names should be written in UpperCamelCase.
For classes that extend an Android component, the name of the class should end with the name of the component; for example:
SignInActivity
SignInFragment
ImageUploaderService
ChangePasswordDialog
Resources file names are written in lowercase_underscore. e.g.
ic_launcher
background_default
Icons should follow the naming scheme seen in Material Icons which
follows the format ic_<Name>_<Color>_<Size>
; the exception being launcher images which should be named ic_launcher
.
For example:
ic_link_black_24dp.xml
ic_user_white_48dp.xml
Assuming a selector state requires an image instead of an embedded shape, each images should be
named based on the main selector (button_order
in the example) with the states as a suffix. e.g.
State | Suffix | Example |
---|---|---|
Normal | _normal |
button_order_normal.9.png |
Pressed | _pressed |
button_order_pressed.9.png |
Focused | _focused |
button_order_focused.9.png |
Disabled | _disabled |
button_order_disabled.9.png |
Selected | _selected |
button_order_selected.9.png |
Layout file names should be prefixed with the section the source code will be used by with prefixing the Android component name. e.g.
Component | Class Name | Layout Name |
---|---|---|
Activity | LoginActivity |
activity_login.xml |
Fragment | SignUpFragment |
fragment_sign_up.xml |
Dialog | ChangePasswordDialog |
dialog_change_password.xml |
AdapterView item | PersonViewHolder |
adapter_view_person.xml |
Menu file names should match the parent layout naming, they should not include menu
as they are already
separated by the R.menu.*
reference. e.g.
Parent Layout | Menu Name |
---|---|
user_profile.xml |
user_profile |
person.xml |
person |
Similarly to Java and Kotlin rules, indentation should be 4 characters.
When possible self closing tags should be used. e.g.
<TextView
android:id="@+id/profileTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Not
<TextView
android:id="@+id/profileTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
Resources should follow lowercase_underscore naming, the exception being Ids, Styles and Themes (described below)
IDs should have a suffix indicating the element or category type in LowerCamelCase. e.g.
Element | Suffix |
---|---|
TextView |
someTextView |
ImageView |
anImageView |
Button |
helpButton |
Menu Item |
loginMenuItem |
Action Mode Menu |
artistActionMenu |
Context Menu |
personContextMenu |
String names start with a prefix that identifies the section they belong to. For example registration_email_hint
or registration_name_hint
. If a string doesn't belong to any section then a simple name should be used. e.g.
Name | Value |
---|---|
done |
Done |
general_network_error |
There was an unknown network error |
Unlike the rest of resources, style names are written in UpperCamelCase.
Attributes should follow the auto ordering that Android Studio enforces; in general this is
id
style
andtheme
layout_width
,layout_height
, andlayout_weight
- Other attributes sorted alphabetically
- Non-
android
namespace items (e.g.app
) sorted alphabetically tools
namespace items sorted alphabetically
Explore our expertise in Native Mobile Development and iOS Development.
If you need professional assistance with your mobile or web project, feel free to contact our team