You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: project_and_code_guidelines.md
+37-37Lines changed: 37 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,15 +65,15 @@ Layout files should match the name of the Android components that they are inten
65
65
| AdapterView item | --- |`item_person.xml`|
66
66
| Partial layout | --- |`partial_stats_bar.xml`|
67
67
68
-
A slighly different case is when we are creating a layout that is going to be inflated by an `Adapter`, e.g to populate a `ListView`. In this case, the name of the layout should start with `item_`
68
+
A slightly different case is when we are creating a layout that is going to be inflated by an `Adapter`, e.g to populate a `ListView`. In this case, the name of the layout should start with `item_`.
69
69
70
-
Note that there are cases where these rules will not be possible to apply. For example, when creating layout files that are intended to be part of other layouts. In this case you should use the prefix `partial_`
70
+
Note that there are cases where these rules will not be possible to apply. For example, when creating layout files that are intended to be part of other layouts. In this case you should use the prefix `partial_`.
71
71
72
72
#### 1.2.1.3 Menu files
73
73
74
-
Similar to layout files, menu files should match the name of the component. For example, if we are defining a menu file that is going to be use in the `UserActivity`, then the name of the file should be `activity_user.xml`
74
+
Similar to layout files, menu files should match the name of the component. For example, if we are defining a menu file that is going to be used in the `UserActivity`, then the name of the file should be `activity_user.xml`
75
75
76
-
A good practise is to not include the word `menu` as part of the name because these files are already located in directory called menu.
76
+
A good practice is to not include the word `menu` as part of the name because these files are already located in the `menu` directory.
77
77
78
78
#### 1.2.1.4 Values files
79
79
@@ -164,15 +164,15 @@ public class MyClass {
164
164
165
165
### 2.2.4 Use spaces for indentation
166
166
167
-
Use __4 space__idents for blocks:
167
+
Use __4 space__indents for blocks:
168
168
169
169
```java
170
170
if (x ==1) {
171
171
x++;
172
172
}
173
173
```
174
174
175
-
Use __8 space__idents for line wraps:
175
+
Use __8 space__indents for line wraps:
176
176
177
177
```java
178
178
Instrument i =
@@ -222,13 +222,13 @@ According to the Android code style guide, the standard practices for some of th
222
222
223
223
*`@SuppressWarnings`: The @SuppressWarnings annotation should only be used under circumstances where it is impossible to eliminate a warning. If a warning passes this "impossible to eliminate" test, the @SuppressWarnings annotation must be used, so as to ensure that all warnings reflect actual problems in the code.
224
224
225
-
More information about annotations guidelines can be found [here](http://source.android.com/source/code-style.html#use-standard-java-annotations).
225
+
More information about annotation guidelines can be found [here](http://source.android.com/source/code-style.html#use-standard-java-annotations).
226
226
227
227
#### 2.2.6.2 Annotations style
228
228
229
229
__Classes, Methods and Constructors__
230
230
231
-
When annotations are applied to a class, method or constructor they are listed after the documentation block and should appear as __one annotation per line__ .
231
+
When annotations are applied to a class, method, or constructor, they are listed after the documentation block and should appear as __one annotation per line__ .
232
232
233
233
```java
234
234
/* This is the documentation block about the class */
@@ -264,14 +264,14 @@ The ordering of import statements is:
264
264
265
265
To exactly match the IDE settings, the imports should be:
266
266
267
-
*Alphabetical within each grouping, with capital letters before lower case letters (e.g. Z before a).
267
+
*Alphabetically ordered within each grouping, with capital letters before lower case letters (e.g. Z before a).
268
268
* There should be a blank line between each major grouping (android, com, junit, net, org, java, javax).
269
269
270
270
More info [here](https://source.android.com/source/code-style.html#limit-variable-scope)
271
271
272
272
### 2.2.9 Logging guidelines
273
273
274
-
Use the logging methods provided by the `Log` class to print out error messages or other information that may be useful for developers to identifiy issues:
274
+
Use the logging methods provided by the `Log` class to print out error messages or other information that may be useful for developers to identify issues:
275
275
276
276
*`Log.v(String tag, String msg)` (verbose)
277
277
*`Log.d(String tag, String msg)` (debug)
@@ -290,8 +290,8 @@ public class MyClass {
290
290
}
291
291
}
292
292
```
293
-
294
-
VERBOSE and DEBUG logs __must__ be disable on relase builds. It is also recommendable to disable INFORMATION, WARNING and ERROR logs but you may want to keep them enable if you think they may be useful to identify issues on release builds. If you decide to leave them enable, you have to make sure that they are not leaking private information such as email addresses, user ids, etc.
293
+
294
+
VERBOSE and DEBUG logs __must__ be disabled on release builds. It is also recommended to disable INFORMATION, WARNING and ERROR logs but you may want to keep them enabled if you think they may be useful to identify issues on release builds. If you decide to leave them enabled, you have to make sure that they are not leaking private information such as email addresses, user ids, etc.
295
295
296
296
To only show logs on debug builds:
297
297
@@ -339,7 +339,7 @@ public class MainActivity extends Activity {
339
339
}
340
340
```
341
341
342
-
If your class is extending and__Android component__ such as an Activity or a Fragment, it is a good practise to order the override methods so that they __match the component's lifecycle__. For example, if you have an Activity that implements `onCreate()`, `onDestroy()`, `onPause()` and `onResume()`, then the correct order is:
342
+
If your class is extending an__Android component__ such as an Activity or a Fragment, it is a good practice to order the override methods so that they __match the component's lifecycle__. For example, if you have an Activity that implements `onCreate()`, `onDestroy()`, `onPause()` and `onResume()`, then the correct order is:
343
343
344
344
```java
345
345
publicclassMainActivityextendsActivity {
@@ -355,7 +355,7 @@ public class MainActivity extends Activity {
355
355
publicvoidonPause() {}
356
356
357
357
@Override
358
-
publicvoidonDestory() {}
358
+
publicvoidonDestroy() {}
359
359
360
360
}
361
361
```
@@ -369,18 +369,18 @@ The opposite case are __callback__ interfaces that should always be the __last__
369
369
Examples:
370
370
371
371
```java
372
-
// Context always go first
372
+
// Context always goes first
373
373
publicUser loadUser(Context context, int userId);
374
374
375
375
// Callbacks always go last
376
376
publicvoid loadUserAsync(Context context, int userId, UserCallback callback);
377
377
```
378
378
379
-
### 2.2.13 String constants, naming and values
379
+
### 2.2.13 String constants, naming, and values
380
380
381
-
Many elements of the Android SDK such as `SharedPreferences`, `Bundle` or `Intent` use a key-value pair approach so it's very likely that even for a small app you end up having to write a lot of String constants.
381
+
Many elements of the Android SDK such as `SharedPreferences`, `Bundle`, or `Intent` use a key-value pair approach so it's very likely that even for a small app you end up having to write a lot of String constants.
382
382
383
-
When using one of these components, you __must__ define the keys as a `static final` fields and they should be prefixed as indicaded below.
383
+
When using one of these components, you __must__ define the keys as a `static final` fields and they should be prefixed as indicated below.
384
384
385
385
| Element | Field Name Prefix |
386
386
| ----------------- | ----------------- |
@@ -390,7 +390,7 @@ When using one of these components, you __must__ define the keys as a `static fi
390
390
| Intent Extra |`EXTRA_`|
391
391
| Intent Action |`ACTION_`|
392
392
393
-
Note that the arguments of a Fragment - `Fragment.getArguments()` - are also a Bundle. However, because this is a quite common use of Bundles, we define a different prefix for them.
393
+
Note that the arguments of a Fragment - `Fragment.getArguments()` - are also a Bundle. However, because this is a quite common use of Bundles, we define a different prefix for them.
394
394
395
395
Example:
396
396
@@ -407,11 +407,11 @@ static final String ACTION_OPEN_USER = "com.myapp.action.ACTION_OPEN_USER";
407
407
408
408
### 2.2.14 Arguments in Fragments and Activities
409
409
410
-
When data is passed into an `Activity `or `Fragment` via `Intents` or a `Bundles`, the keys for the different values __must__ follow the rules described in the section above.
410
+
When data is passed into an `Activity `or `Fragment` via an `Intent` or a `Bundle`, the keys for the different values __must__ follow the rules described in the section above.
411
411
412
-
When an `Activity` or `Fragment`expect arguments, it should provide a `static public` method that facilitates the creation of the `Fragment` or `Intent`.
412
+
When an `Activity` or `Fragment`expects arguments, it should provide a `public static` method that facilitates the creation of the relevant `Intent` or `Fragment`.
413
413
414
-
In the case of Activities the method is usually called `getStartIntent()`
414
+
In the case of Activities the method is usually called `getStartIntent()`:
415
415
416
416
```java
417
417
publicstaticIntent getStartIntent(Context context, User user) {
@@ -421,7 +421,7 @@ public static Intent getStartIntent(Context context, User user) {
421
421
}
422
422
```
423
423
424
-
For Fragments it's named `newInstance()` and it handles the creation of the Fragment with the right arguments.
424
+
For Fragments it is named `newInstance()` and handles the creation of the Fragment with the right arguments:
425
425
426
426
```java
427
427
publicstaticUserFragment newInstance(User user) {
@@ -433,18 +433,18 @@ public static UserFragment newInstance(User user) {
433
433
}
434
434
```
435
435
436
-
__Note 1__: these methods should go at the top of the class before `onCreate()`
436
+
__Note 1__: These methods should go at the top of the class before `onCreate()`.
437
437
438
-
__Note 2__: if we provide the methods described above, the keys for extras and arguments should be `private` because there is not need for them to be exposed outside the class.
438
+
__Note 2__: If we provide the methods described above, the keys for extras and arguments should be `private` because there is not need for them to be exposed outside the class.
439
439
440
440
### 2.2.15 Line length limit
441
441
442
442
Code lines should not exceed __100 characters__. If the line is longer than this limit there are usually two options to reduce its length:
443
443
444
-
* Extract a local variable or method (Preferable).
444
+
* Extract a local variable or method (preferable).
445
445
* Apply line-wrapping to divide a single line into multiple ones.
446
446
447
-
There are two __exceptions__ where is possible to have lines longer than 100:
447
+
There are two __exceptions__ where it is possible to have lines longer than 100:
448
448
449
449
* Lines that are not possible to split, e.g. long URLs in comments.
An exception to the break at operators rule is the assignment operator `=`, where the line break should happen __after__ the operator.
467
+
An exception to the `break at operators` rule is the assignment operator `=`, where the line break should happen __after__ the operator.
468
468
469
469
```java
470
470
int longName =
@@ -487,7 +487,7 @@ Picasso.with(context)
487
487
488
488
__Long parameters case__
489
489
490
-
When a method has many parameters or its parameters are very long we should break the line after every comma `,`
490
+
When a method has many parameters or its parameters are very long, we should break the line after every comma `,`
491
491
492
492
```java
493
493
loadPicture(context, "http://ribot.co.uk/images/sexyjoe.jpg", mImageViewProfilePicture, clickListener, "Title of the picture");
@@ -527,7 +527,7 @@ public Observable<Location> syncLocations() {
527
527
528
528
### 2.3.1 Use self closing tags
529
529
530
-
When an XML element doesn't have any content, you __must__ use self closing tags.
530
+
When an XML element doesn\'t have any contents, you __must__ use self closing tags.
531
531
532
532
This is good:
533
533
@@ -541,7 +541,7 @@ This is good:
541
541
This is __bad__ :
542
542
543
543
```xml
544
-
<!-- Don't do this! -->
544
+
<!-- Don\'t do this! -->
545
545
<TextView
546
546
android:id="@+id/text_view_profile"
547
547
android:layout_width="wrap_content"
@@ -552,7 +552,7 @@ This is __bad__ :
552
552
553
553
### 2.3.2 Resources naming
554
554
555
-
Resource IDs and names are written in __lowercase_underscore__
555
+
Resource IDs and names are written in __lowercase_underscore__.
556
556
557
557
#### 2.3.2.1 ID naming
558
558
@@ -587,7 +587,7 @@ Menu example:
587
587
588
588
#### 2.3.2.2 Strings
589
589
590
-
String names start with a prefix that indentifies the section they belong to. For example `registration_email_hint` or `registration_name_hint`. If a string __doesn't belong__ to any section then you should follow the rules below:
590
+
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 you should follow the rules below:
591
591
592
592
593
593
| Prefix | Description |
@@ -617,22 +617,22 @@ As a general rule you should try to group similar attributes together. A good wa
617
617
618
618
### 2.4.1 Unit tests
619
619
620
-
Test classes should match the name of the class that the tests are targeting, followed by `Test`. For example, if we create a test class that contains tests for the `DatabaseHelper`, we should name it `DatabaseHelperTest`.
620
+
Test classes should match the name of the class the tests are targeting, followed by `Test`. For example, if we create a test class that contains tests for the `DatabaseHelper`, we should name it `DatabaseHelperTest`.
621
621
622
-
Test methods are annotated with `@Test` and should generally start with the name of the method that is being tested, followed by a precondition and/or expected behaviour.
622
+
Test methods are annotated with `@Test` and should generally start with the name of the method that is being tested, followed by a precondition and/or expected behaviour.
Precondition and/or expected behaviour may not always be required if the test is clear enough without them.
628
628
629
-
Sometimes a class may contain a large amount of methods, that at the same time require several tests for each method. In this case, it's recommendable to split up the test class into multiple ones. For example, if the `DataManager` contains a lot of methods we may want to divide it into `DataManagerSignInTest`, `DataManagerLoadUsersTest`, etc. Generally you will be able to see what tests belong together because they have common [test fixtures](https://en.wikipedia.org/wiki/Test_fixture).
629
+
Sometimes a class may contain a large amount of methods, that at the same time require several tests for each method. In this case, it\'s recommendable to split up the test class into multiple ones. For example, if the `DataManager` contains a lot of methods we may want to divide it into `DataManagerSignInTest`, `DataManagerLoadUsersTest`, etc. Generally you will be able to see what tests belong together because they have common [test fixtures](https://en.wikipedia.org/wiki/Test_fixture).
630
630
631
631
### 2.4.2 Espresso tests
632
632
633
633
Every Espresso test class usually targets an Activity, therefore the name should match the name of the targeted Activity followed by `Test`, e.g. `SignInActivityTest`
634
634
635
-
When using the Espresso API is a common practise to place chained methods in new lines.
635
+
When using the Espresso API it is a common practice to place chained methods in new lines.
0 commit comments