-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconventions.txt
More file actions
59 lines (42 loc) · 2.3 KB
/
conventions.txt
File metadata and controls
59 lines (42 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Coding Conventions
- Activities
* All XML activity layouts should begin with "activity_", i.e. activity_details
- Widgets/Layouts
* Prefix the layout name with a description of what type of layout it is, i.e.
row_shout_details
* // TODO: We should have a standard naming convention for widget ids. There are
multiple ways of doing this, and I don't really have a preference of which one.
For example, you could have an EditText widget id by edit_text_username, or
just username. Android doesn't favor either of the two.
- Menus/ActionBar
* No two activities should use the same menu XML file.
* Menu XML files should be named the same name as the activity they are used for.
* If an activity has two different menus, append the state that chooses the menu
at the end of the file name, i.e. activity_details_state1, activity_details_state2
* The ID of each menu item should begin with menu_ and be followed by the description
of the item
- Themes and Styles
* All styles should go in styles.xml and themes shoud go in themes.xml
* All style and theme names should be title case
- Strings
* All string resources should begin with a descriptive identifier of their function,
i.e. label_username, desc_avatar, title_activity_shout.
* It's usually a good idea to split string files into multiple files based on context.
For example, strings_activity_details.xml will contain all strings used only in the
DetailsActivity. strings.xml will contain strings that are used globally or that do
not fit anywhere else.
* For menu item labels, the prefix should be menu_
- Drawables
* Provide a drawable for each screen resolution.
* Prefix all icon names with ic_, i.e. ic_launcher
* Prefix all menu/ActionBar icon names with ic_menu_, i.e. ic_menu_save
- Miscellaneous
* Prefer match_parent over fill_parent. Fill_parent is deprecated.
* If it is OK for a method or variable to be unused (i.e. TAG variables for logging),
then add the annotation @SuppressWarnings("unused") to the method/variable.
- Tips
* Pay attention to lint warnings. They're helpful
* Use Eclipse's auto format tool (SHIFT+CTRL+F), especially with XML files
- Spacing
* Use tabs for indentation in code, spaces for alignment. Using spaces in text files,
such as these is usually a good idea as well.