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
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,7 +153,7 @@ public class MyClass {
153
153
}
154
154
```
155
155
156
-
### 2.2.3 Treat acronyms as words
156
+
### 2.2.2 Treat acronyms as words
157
157
158
158
| Good | Bad |
159
159
| -------------- | -------------- |
@@ -162,7 +162,7 @@ public class MyClass {
162
162
|`String url`|`String URL`|
163
163
|`long id`|`long ID`|
164
164
165
-
### 2.2.4 Use spaces for indentation
165
+
### 2.2.3 Use spaces for indentation
166
166
167
167
Use __4 space__ indents for blocks:
168
168
@@ -179,7 +179,7 @@ Instrument i =
179
179
someLongExpression(that, wouldNotFit, on, one, line);
180
180
```
181
181
182
-
### 2.2.5 Use standard brace style
182
+
### 2.2.4 Use standard brace style
183
183
184
184
Braces go on the same line as the code before them.
185
185
@@ -212,9 +212,9 @@ if (condition)
212
212
body(); // bad!
213
213
```
214
214
215
-
### 2.2.6 Annotations
215
+
### 2.2.5 Annotations
216
216
217
-
#### 2.2.6.1 Annotations practices
217
+
#### 2.2.5.1 Annotations practices
218
218
219
219
According to the Android code style guide, the standard practices for some of the predefined annotations in Java are:
220
220
@@ -224,7 +224,7 @@ According to the Android code style guide, the standard practices for some of th
224
224
225
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
-
#### 2.2.6.2 Annotations style
227
+
#### 2.2.5.2 Annotations style
228
228
229
229
__Classes, Methods and Constructors__
230
230
@@ -245,13 +245,13 @@ Annotations applying to fields should be listed __on the same line__, unless the
245
245
@Nullable@MockDataManager mDataManager;
246
246
```
247
247
248
-
### 2.2.7 Limit variable scope
248
+
### 2.2.6 Limit variable scope
249
249
250
250
_The scope of local variables should be kept to a minimum (Effective Java Item 29). By doing so, you increase the readability and maintainability of your code and reduce the likelihood of error. Each variable should be declared in the innermost block that encloses all uses of the variable._
251
251
252
252
_Local variables should be declared at the point they are first used. Nearly every local variable declaration should contain an initializer. If you don't yet have enough information to initialize a variable sensibly, you should postpone the declaration until you do._ - ([Android code style guidelines](https://source.android.com/source/code-style.html#limit-variable-scope))
253
253
254
-
### 2.2.8 Order import statements
254
+
### 2.2.7 Order import statements
255
255
256
256
If you are using an IDE such as Android Studio, you don't have to worry about this because your IDE is already obeying these rules. If not, have a look below.
257
257
@@ -269,7 +269,7 @@ To exactly match the IDE settings, the imports should be:
269
269
270
270
More info [here](https://source.android.com/source/code-style.html#limit-variable-scope)
271
271
272
-
### 2.2.9 Logging guidelines
272
+
### 2.2.8 Logging guidelines
273
273
274
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
@@ -299,7 +299,7 @@ To only show logs on debug builds:
299
299
if (BuildConfig.DEBUG) Log.d(TAG, "The value of x is "+ x);
300
300
```
301
301
302
-
### 2.2.10 Class member ordering
302
+
### 2.2.9 Class member ordering
303
303
304
304
There is no single correct solution for this but using a __logical__ and __consistent__ order will improve code learnability and readability. It is recommendable to use the following order:
305
305
@@ -362,7 +362,7 @@ public class MainActivity extends Activity {
362
362
}
363
363
```
364
364
365
-
### 2.2.11 Parameter ordering in methods
365
+
### 2.2.10 Parameter ordering in methods
366
366
367
367
When programming for Android, it is quite common to define methods that take a `Context`. If you are writing a method like this, then the __Context__ must be the __first__ parameter.
368
368
@@ -378,7 +378,7 @@ public User loadUser(Context context, int userId);
378
378
publicvoid loadUserAsync(Context context, int userId, UserCallback callback);
379
379
```
380
380
381
-
### 2.2.13 String constants, naming, and values
381
+
### 2.2.11 String constants, naming, and values
382
382
383
383
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.
384
384
@@ -407,7 +407,7 @@ static final String EXTRA_SURNAME = "com.myapp.extras.EXTRA_SURNAME";
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.
413
413
@@ -439,7 +439,7 @@ __Note 1__: These methods should go at the top of the class before `onCreate()`.
439
439
440
440
__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.
441
441
442
-
### 2.2.15 Line length limit
442
+
### 2.2.13 Line length limit
443
443
444
444
Code lines should not exceed __100 characters__. If the line is longer than this limit there are usually two options to reduce its length:
445
445
@@ -451,7 +451,7 @@ There are two __exceptions__ where it is possible to have lines longer than 100:
451
451
* Lines that are not possible to split, e.g. long URLs in comments.
452
452
*`package` and `import` statements.
453
453
454
-
#### 2.2.15.1 Line-wrapping strategies
454
+
#### 2.2.13.1 Line-wrapping strategies
455
455
456
456
There isn't an exact formula that explains how to line-wrap and quite often different solutions are valid. However there are a few rules that can be applied to common cases.
457
457
@@ -503,7 +503,7 @@ loadPicture(context,
503
503
"Title of the picture");
504
504
```
505
505
506
-
### 2.2.16 RxJava chains styling
506
+
### 2.2.14 RxJava chains styling
507
507
508
508
Rx chains of operators require line-wrapping. Every operator must go in a new line and the line should be broken before the `.`
0 commit comments