Skip to content

Instantly share code, notes, and snippets.

@trinadhkoya
Created April 14, 2017 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trinadhkoya/e209b897ef8cbe918c8107929c32675e to your computer and use it in GitHub Desktop.
Save trinadhkoya/e209b897ef8cbe918c8107929c32675e to your computer and use it in GitHub Desktop.
Code Structure
activities
Contains all the activities. Classes are all named with Activity at the end. That way, you can immediately know what it is when reading Java code that doesn't have its full package name.
adapters
Contains all the adapters.
authenticator
Contains any class related to signing a user in. I create a local account and having all related classes together is very handy.
analytics
Google Analytics, Facebook Analytics...
data
Contains all classes related to data management such as ContentProvider and SQLiteHelper.
data.migrations
Contains all of my SQLite migrations. I created a class for migrations, read about it here, and put them all in this package.
fragments
Contains all fragments.
helpers
Contains helper classes. A helper class is a place to put code that is used in more than one place. I have a DateHelper for instance. Most of the methods are static.
interfaces
Contains all interfaces.
models
Contains all local models. When syncing from an HTTP API I parse the JSON into these Java objects using Jackson. I also pull Cursor rows into these models as well.
preferences
Contains all classes for custom preferences. When creating the preferences I required a custom PreferenceDialog as well as a custom PreferenceCategory. They live here.
sync
Contains all classes related to syncing. I use a SyncAdapter to pull data from an HTTP API. In addition to the SyncAdapter a SyncService is required, so I created a package.
Layouts
Activity: activity_user_profile.xml
Fragment: fragment_sign_up.xml
Dialog: dialog_change_password.xml
Adapter: item_person.xml
File naming
Activity:SignInActivity,
Fragment:SignInFragment,
Service:ImageUploaderService
Dialog:ChangePasswordDialog
Drawable Files
Asset Type Prefix Example
Action bar ab_ ab_stacked.9.png
Button btn_ btn_send_pressed.9.png
Dialog dialog_ dialog_top.9.png
Divider divider_ divider_horizontal.9.png
Icon ic_ ic_star.png
Menu menu_ menu_submenu_bg.9.png
Notification notification_ notification_bg.9.png
Tabs tab_ tab_pressed.9.png
Icons
Asset Type Prefix Example
Action bar ab_ ab_stacked.9.png
Button btn_ btn_send_pressed.9.png
Dialog dialog_ dialog_top.9.png
Divider divider_ divider_horizontal.9.png
Icon ic_ ic_star.png
Menu menu_ menu_submenu_bg.9.png
Notification notification_ notification_bg.9.png
Tabs tab_ tab_pressed.9.png
SharedPreferences PREF_
Bundle BUNDLE_
Fragment Arguments ARGUMENT_
Intent Extra EXTRA_
Intent Action ACTION_
View Should be always like this
<TextView
android:id="@+id/text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
View Id
Style
Layout width and layout height
Other layout attributes, sorted alphabetically
Remaining attributes, sorted alphabetically
Element Prefix
TextView text_
ImageView image_
Button button_
Menu menu_
Fields definition and naming
Fields should be defined at the top of the file and they should follow the naming rules listed below.
Private, non-static field names start with m.
Private, static field names start with s.
Other fields start with a lower case letter.
Static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment