-
Notifications
You must be signed in to change notification settings - Fork 0
2. Android Coding Convention
κΈ°λ³Έμ μΌλ‘ 곡μλ¬ΈμμΈ Kotlin Coding Conventionsκ³Ό Kotlin style guideλ₯Ό μ€μνλ€.
μλλ‘μ΄λ μ€νλμ€μ Optimize imports
κΈ°λ₯κ³Ό Reformat Code
κΈ°λ₯μ μ΄μ©νλ€.
-
Optimize imports
(Ctrl+Alt+O)
: μ¬μ©νμ§ μλ Classλ₯Ό importνκ³ μλ κ²½μ° μ κ±°ν΄μ€λ€. -
Reformat Code
(Ctrl+Alt+L)
: μ½λμ Kotlin Style Guideλ₯Ό μ μ©νμ¬ Codeλ₯Ό Reformatνλ€.
View μ΄λ¦μ Pascal Caseλ₯Ό μΆμ½νμ¬ Snake Caseλ‘ λ³νν κ²μ Prefixλ‘ μ¬μ©νλ€.
<WHAT>_<DESCRIPTION>
View | Prefix |
---|---|
TextView | tv_ |
ImageView | iv_ |
EditText | et |
Button, ImageButton | btn_ |
Toolbar | tb_ |
ConstraintLayout | cl_ |
LinearLayout | ll_ |
BottomNavigationView | bnv_ |
.. | .. |
@+id/tv_login
@+id/et_password
@+id/btn_login
Layoutμ xml νμΌμ μ΄λ¦μ .kt .javaμ Pascal Caseλ₯Ό Snake Caseλ‘ λ³ννμ¬ μ¬μ©νλ€.
<WHAT>_<WHERE>
View | Prefix |
---|---|
Activity | activity_ |
Fragment | fragment_ |
Dialog | dialog_ |
CustomView | view_ |
Item | item_ |
SignInActivity.kt -> activity_sign_in.xml
SignUpFragment.kt -> fragment_sign_up.xml
CustomCalendarView.kt -> view_custom_calendar.xml
item_user.xml
<WHAT_DESCRIPTION>
Drawable | Prefix |
---|---|
Icon | ic_ |
Image | img_ |
Background | bg_ |
Shape | <shape>_<color>_<radius>_<value> |
ic_error.xml
img_default_user.xml
bg_main.xml
rectangle_yellow_radius_20.xml
menu_
Colorμ μ΄λ¦μ Camel Caseλ₯Ό μ΄μ©ν΄ μμ±νλ, μ¬μ΄νΈλ₯Ό μ°Έκ³ ν΄ Colorλ₯Ό μ§κ΄μ μΌλ‘ μ°μν μ μλ μ΄λ¦μ μ¬μ©νλ€.
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="cornflowerBlue">#6195ED</color>
String μμ± μ μ£Όμμ ν΅ν΄ Stringμ΄ μ¬μ©λλ κ³³μ λͺ μνλ€.
<WHERE/WHAT>_<DESCRIPTION>
<!--Main Menu-->
<string name="menu_daily">ν루μ κΈ°λ‘</string>
<string name="menu_remind">νκ° λ° νκ³ </string>
<string name="menu_my">My</string>
<!--Toolbar Title-->
<string name="title_search">κ²μ</string>
<string name="title_settings">νκ²½μ€μ </string>
<!--Dialog Message-->
<string name="msg_login">λ‘κ·ΈμΈνμκ² μ΅λκΉ?</string>
<string name="msg_login_failed">λ‘κ·ΈμΈμ μ€ν¨νμ΅λλ€.</string>
<string name="msg_password_error">λΉλ°λ²νΈκ° μ¬λ°λ₯΄μ§ μμ΅λλ€.</string>
Viewμ Pascal Caseμ Styleμ λν μ€λͺ μ μ‘°ν©νμ¬ Style λͺ μ μ§μ νλ€.
<WHAT><Description>Style
<style name="LoginEditTextStyle"/>
<style name="MainDialogStyle"/>
ν΄λμ€ νμΌ μ΄λ¦μ UpperCamelCase(νμ€μΉΌ μΌμ΄μ€(PascalCase))λ‘ μμ±νλ€.
<DESCRIPTION><WHAT>
Prefixλ ν΄λΉ ν΄λμ€μ κ΄λ ¨μ±μ΄ λμ κ²μΌλ‘ μμλ‘ μμ±νλ€.
MainActivity
UserViewModel
WriteFragment
λ©μλ μ΄λ¦μ lowerCamelCaseλ‘ μμ±νλ€.
"λμ¬"λ‘ μμνλ "λμ¬κ΅¬" ννλ₯Ό μ¬μ©νλ, λμ¬ μνλ§μ μ¬μ©νλ€.
μμ£Ό μ¬μ©νλ λμ¬λ μ©λ²μ λ§κ² μ¬μ©νλ€.
Word | Description |
---|---|
show | Invisibleν κ²μ Visibleνκ² λ°κΎΈλ λμ |
check | μ΄λ€ κ²μ νμΈν ν boolean λλ κ°μΌλ‘ λ°ννλ λμ |
is | μ΄λ€ κ²μΈμ§ νμΈν ν booleanμΌλ‘ λ°ννλ λμ |
has | μ΄λ€κ²μκ°μ§κ³ μλ νμΈ ν booleanμΌλ‘ λ°ννλ λμ |
showList
updateContacts
λ³μ μ΄λ¦ λν λ§μ°¬κ°μ§λ‘ lowerCamelCaseλ‘ μμ±νλ€.
isEnd
viewPagerAdapter