<span id="Label3"></p><p><p>The code style file for square is imported directly into the Project. (google is not imported because square offers both Java and Android two sets of unified style, Google only provides a set)</p></p><p><p>Square Code Styles</p></p><p><p>Goolge Code Styles</p></p><p><p></p></p><p><p>After importing, there are many benefits, such as annotation normalization, import specification, method ordering, Unified auto-break (pc screen is wider, recommended number of break characters set to 120[file->setting–>code Style, right Margin Columns ]) and other</p></p><p><p>In addition, the code can be formatted automatically when the encoding is saved or submitted, and the extra blank lines, extra indentation, Invalid annotations and other irregular writing are Deleted.</p></p><p><p></p></p><p><p>Suggest reading the Google Java Style Chinese translation article:</p></p><p><p></p></p><p><p></p></p><p><p></p></p><strong><strong>Android Basic Specification</strong></strong><p><p></p></p><p><p>In development, following good coding practices not only improves the readability of the code, reduces the likelihood of errors, but also reduces the cost of communication with other developers and makes it easier for others to maintain and Collaborate. This article briefly summarizes some of the code specifications in Android development for developers to refer To.</p></p>Basic requirements <ul> <ul> <li>In addition to comments, the code does not appear in Chinese</li> <li>Each class is written with the necessary comments, description of the class, author, contact</li> <li>Method plus the necessary explanatory notes to facilitate later maintenance</li> </ul> </ul>Package Management <ol> <ol> <li>Base: A package that holds the underlying class with a <code class="highlighter-rouge">Base</code> prefix such as <code class="highlighter-rouge">BaseActivity</code> ;</li> <li>Activity: a package that stores activity, each activity is named with activity endings, for example <code class="highlighter-rouge">MainActivity</code> ;</li> <li>Fragment: a package that stores fragment, each fragment named with fragment end, for example <code class="highlighter-rouge">ChatFragment</code> ;</li> <li>Receiver: the packet that holds receiver;</li> <li>Service: the package that stores the service;</li> <li>Adapter: a package that stores adapter, each adapter named with adapter end, for example <code class="highlighter-rouge">EventItemAdapter</code> ;</li> <li>Common: store Some common constants, such as backend interface, <code class="highlighter-rouge">SharedPreferenceKey</code> and <code class="highlighter-rouge">IntentExtra</code> so on;</li> <li>Utils: A package that stores a tool class, such as a common tool class: <code class="highlighter-rouge">LogUtils</code> <code class="highlighter-rouge">DateUtils</code> ;</li> <li>Entity: A package that holds a class of entities;</li> <li>Widget: A package that stores custom view;</li> </ol> </ol><p><p>The above are some common packages, but not limited to this, depending on the specific circumstances of the Project.</p></p>Named<p><p><strong>Big Hump naming (uppercamelcase): The first letter of each word is Capitalized.</strong></p></p><p><p><strong>Small hump naming (lowercamelcase): in addition to the first word, the first letter of each word is Capitalized.</strong></p></p><p><p><strong>The basic principles of naming:</strong></p></p> <ul> <ul> <li>Use a uniform naming convention whenever possible;</li> <li>Do not use Hanyu pinyin;</li> <li>In addition to the common abbreviations in english, use abbreviations sparingly;</li> </ul> </ul>1. Package naming <ul> <ul> <li>Lowercase letters, See package management above;</li> <li>Consecutive words are connected directly, not using underscores;</li> </ul> </ul>2. Java class naming <ul> <ul> <li>Big Hump named <code class="highlighter-rouge">UserListAdapter</code> ;</li> <li>In addition to the usual abbreviated words, do not use abbreviations, each letter of the abbreviated word is capitalized <code class="highlighter-rouge">RequesURLList</code> ;</li> <li>The public tool class suggests a <code class="highlighter-rouge">Utils</code> <code class="highlighter-rouge">Manager</code> suffix, such as <code class="highlighter-rouge">LogUtils</code> ;</li> <li>Interface naming follows the above principles, <code class="highlighter-rouge">able</code> or <code class="highlighter-rouge">ible</code> suffix;</li> </ul> </ul>3. variable naming <ul> <ul> <li> member variable name <ul> <li> Small Hump name; </li> <li> does not recommend the use of Google's front plus m encoding style (if using the team using m, uniform use); </li> </ul> </li> <li> constant Name ul> </li> <li> Word each letter is uppercase; </li> <li> The underline connection between words; </li> </ul> <li> control variable name <ul> <li> Small hump naming; </li> <li> recommended use of <cod e class="highlighter-rouge"> control abbreviation + logical name format, For example <code class="highlighter-rouge">tvposttitle </code> , <code class="highlighter-rouge">etusername </code>; </cod></li> <li> name of the corresponding Control's ID <code class="highlighter-rouge"> control abbreviation _ Logical name </code>, the words are lowercase and underlined, for example: <code class="highlighter-rouge">tv_post_title </code>, <code class="highlighter-rouge">et_user_name </code>; </li> <li> Common control abbreviations are as Follows: </li> </ul> </li> </ul> <table class="confluenceTable tablesorter"> <tbody> <tr> <td class="confluencetd">linearlayout </td> <td class="confluencetd">ll </td> </tr> <tr> <td class="co nfluencetd ">relativelayout </td> <td class=" confluencetd ">rl </td> </tr> <tr> <td class=" confluencetd ">textview </td> <td class="confluencetd">tv </td> </tr> <tr> <td class="confluencetd">edittext </td> <td class="confluencetd">et </td> </tr> <tr> <td class="confluencetd">button </td> <td class="confluencetd">btn </td> </tr> <tr> <td class="confluencetd">imageview </td> <td class="confluencetd">iv </td> </tr> <tr> <td class="confluencetd">checkbox </td> <td class="confluencetd">chb </td> </tr> <tr> <td class="confluencetd">listview </td> <td class="confluencetd">lv </td> </tr> <tr> <td class="confluencetd">gridview </td> <td class="confluencetd">gv </td> </tr> <tr> <td class="confluencetd">radiobutton </td> <td class="confluencetd">rb </td> </tr> </tbody> <thead> <tr class="sortableHeader"> <th class="confluenceTh sortableHeader" data-column="0">Control</th> <th class="confluenceTh sortableHeader" data-column="1">Abbreviations</th> </tr> </thead> <thead></thead> </table>4. Method naming <ul> <ul> <li>Small Hump named;</li> <li>Getter and Setter methods, the recommended use of automatic generation, writing is also very convenient. Note that the variable Getter method of type bool is written in <code class="highlighter-rouge">isTrue</code> this way;</li> <li>The method name should ensure the principle of knowing the meaning of the name, try not <code class="highlighter-rouge">or</code> to use or <code class="highlighter-rouge">and</code> , follow the "do one thing" principle;</li> </ul> </ul>5. Layout file naming <ul> <ul> <li>activity, fragment layout filename is prefixed with the corresponding category name, the logical name is followed by an underscore connection, for example, <code class="highlighter-rouge">activity_home</code> <code class="highlighter-rouge">fragment_chat_list</code> to facilitate the search;</li> <li>The item layout file of the ListView and GridView suggests a <code class="highlighter-rouge">list_item</code> <code class="highlighter-rouge">gird_item</code> prefix, plus a corresponding logical name, such <code class="highlighter-rouge">list_item_post</code> as <code class="highlighter-rouge">grid_item_photo</code> ;</li> <li>The dialog layout file <code class="highlighter-rouge">dialog</code> is prefixed with the logical name followed by an underscore connection, for example <code class="highlighter-rouge">dialog_warnning</code> ;</li> <li>The containing item layout is named to <code class="highlighter-rouge">include</code> begin with, plus the corresponding logical name, such as<code class="highlighter-rouge">include_foot</code></li> <li>The ID of the control is named see Control variable name;</li> </ul> </ul>6. Resource Naming <ul> <ul> <li>The icon resource <code class="highlighter-rouge">ic</code> is prefixed with, For example <code class="highlighter-rouge">ic_chat</code> , a chat icon;</li> <li>The background image is <code class="highlighter-rouge">bg</code> prefixed with, For example <code class="highlighter-rouge">bg_login</code> , the background image of the login page;</li> <li>Button picture to <code class="highlighter-rouge">btn</code> prefix, For example <code class="highlighter-rouge">btn_login </code> , refers to the picture of the login button, but there is only one state, the need to add the state can be added later, for example <code class="highlighter-rouge">btn_login_pressed</code> , the login button to press the picture;</li> <li>When using the shape and selector files as backgrounds or buttons, the name refers to the above description;</li> </ul> </ul>Resources<p><p>This article refers to the following:</p></p> <ul> <ul> <li>Best Practices for Android code specification</li> <li>Android Development Code</li> </ul> </ul><p><p></p></p><p><p>Java&android Code Specification</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service