The original link: https://github.com/Blankj/AndroidStandardDevelop

Updating Abstract 1 Preface 2 AS specification 3 Naming specification 4 Resource file specification 5 Version-specific specification 6 Third-party library specification 7 Annotation specification 8 Test specification 9 RN specification 10 Some other specifications

In order to facilitate the maintenance of the project and the development of the specification, and promote the efficiency of Code Review among members, we propose the following development specification. If you have better suggestions, please go to GitHub to propose 2 AS specification. Develop with the latest version of the IDE whenever possible; The encoding format is UTF-8. After editing. Java,. XML and other files, be sure to format them (use the AS default template for basic formats). > > Optimize Imports (Settings → Keymap → Optimize Imports) AS common development plug-in can refer to here ~ **AS common development plug-in **

3 Naming code is strictly prohibited to use pinyin and English naming mixed way, not to allow direct use of Chinese way. Correct English spelling and grammar make it easy for readers to understand and avoid ambiguity. Note: Even pure pinyin naming should be avoided. However, international common names such as Alibaba, Taobao, Youku and Hangzhou can be regarded as English.

3.1 Package name Package names are all lowercase, and consecutive words are simply connected without underscores. Use the anti – domain name naming rules, use all lowercase letters. The level-1 package name is a top-level domain name, usually com,edu,gov,net,org, etc. The level-2 package name is the company name, the level-2 package name is based on the application, and the level-4 package name is the module name or layer name. Package name Contained in this package

Com.xx. application name abbreviation activity All activity classes in the user interface

Com.xx. Application Name Abbreviation Fragment All fragment classes on the interface

Com.xx. Application name abbreviation. Base Base shared class

Adapter class used by adapter page (adapter class)

Com.xx. Application name abbreviation. View Custom view class

Com.xx. Application name abbreviation. Util This package contains: public utility method class (util module name)

Vo, Po, dTO This package contains the JavaBean class

Com.xx. application name abbreviation model This package contains: model classes

Com.xx. Application name Abbreviation DB Database operation class

Com.xx. Application name abbreviation. View (or com.xx). Application name abbreviations. Widget) custom View classes, etc

Com.xx. application name Abbreviation Service Service Service

Com.xx. Application name Abbreviation Receiver BroadcastReceiver service

Com.xx. application name abbreviation. Config All configuration related classes

Note: If the project adopts MVP, all interfaces extracted from M, V, and P are placed under the I package of the corresponding module, and all implementations are placed under the IMPL of the corresponding module

3.2 Class Names Class names are written in the UpperCamelCase style. A class name is usually a noun or noun phrase, and an interface name may sometimes be an adjective or adjective phrase. There is no specific rule or well-established convention for naming annotation types. For nouns, use the big hump nomenclature. Avoid abbreviations unless the abbreviations are well-known, such as HTML or URL. If the class name contains abbreviations, capitalize each letter of the abbreviations. Class description for example

The Activity class Activity suffix identifies the welcome page class WelcomeActivity

Adapter Class Adapter the suffix NewDetailAdapter identifies the NewDetailAdapter

Parser Class The suffix identifies the home Parser class HomePosterParser

Thread pool management class: ThreadPoolManager Log tool class: LogUtils (Logger also available) Print tool class: PrinterUtils

The database class identifies the news database with the DBHelper suffix: NewDBHelper

The Service class uses the Service suffix to identify a TimeService

The BroadcastReceiver class uses the suffix “Receiver” to identify the JPushReceiver

The ContentProvider class identifies ShareProvider with the Provider suffix

Custom Shared base classes Starting with the Base BaseActivity BaseFragment

The name of a Test class starts with the name of the class it is testing and ends with Test. For example, HashTest or HashIntegrationTest. Interface: The naming rules are the same as those of classes with the big camel name, and most of them end with able or ible, such as interface Runnable and interface Accessible. Note: If the project uses MVP, all Model, View, and Presenter interfaces are prefixed with I without suffix, and all other interfaces are named in the same way.

3.3 Method Names Method names are written in lowerCamelCase style. Method names are usually verbs or phrasal verbs. Method statement

InitXX () initializes related methods prefixed with init, such as initializing layout initView()

If the isXX() checkXX() method returns a Boolean value, prefix it with is or check

GetXX () a method that returns a value, prefixed by get

SetXX () sets a property value

HandleXX ()/processXX() method of processing data

DisplayXX ()/showXX() Displays the prompt box and the prompt information. Use the prefix display/show to identify the information

UpdateXX () updates data

SaveXX () saves the data

ResetXX () resets data

ClearXX () clears data

Removex () Removes data or views, such as removeView().

DrawXX () is associated with drawing data or effects, identified with the draw prefix

3.4 Constant Name The constant name is named in CONSTANT_CASE, with all uppercase letters and underscores separating words. So, what exactly is a constant? Each constant is a static final field, but not all static final fields are constants. When deciding whether a field is a constant, consider whether it really feels like one. For example, if the observed state of any of the instances is variable, it will almost certainly not be a constant. It’s generally not enough that you never intend to change an object, it has to really stay the same to show it as a constant. // Constantsstatic final int NUMBER = 5; static final ImmutableListNAMES = ImmutableList.of(“Ed”, “Ann”); static final Joiner COMMA_JOINER = Joiner.on(‘,’); // because Joiner is immutablestatic final SomeMutableType[] EMPTY_ARRAY = {}; enum SomeEnum { ENUM_CONSTANT }// Not constantsstatic String nonFinal = “non-final”; final String nonStatic = “non-static”; static final SetmutableCollection = new HashSet(); static final ImmutableSetmutableElements = ImmutableSet.of(mutable); static final Logger logger = Logger.getLogger(MyClass.getName()); static final String[] nonEmptyArray = {“these”, “can”, “change”};

3.5 Infinitesimal Field Names The infinitesimal field names are modified to the following style based on the lowerCamelCase style: The basic structure is scopeVariableNameType. Non-public, non-static field names start with m. Static field names start with s. Public non-static field names start with P. Public static field (global variable) names start with G. Public class MyClass {int mPackagePrivate; private int mPrivate; protected int mProtected; private static MyClass sSingleton; public int pField; public static int gField; }

Use a one-character prefix to indicate the scope. The one-character prefix must be lowercase, followed by a name composed of one or more ideographic words. In addition, the first letter of each word is capitalized and the other letters are lowercase, which ensures that the variable name can be correctly delimited. Considering that many UI controls are used in Android, to avoid confusion between controls and ordinary member variables and to make them better understood, all member variables used to represent controls are suffixed with control abbreviations (a list of abbreviations is attached at the end of the article). Generally, type suffixes are not added to common variables. If type suffixes are added uniformly, please refer to the abbreviation table at the end of this article. By placing a quantifier at the end, you create more uniform variables that are easier to understand and search for. Note: If ButterKnife is used in your project, do not add the m prefix and name it in the lowerCamelCase style.

For example, use mCustomerStrFirst and mCustomerStrLast instead of mFirstCustomerStr and mLastCustomerStr. Quantifier list Suffixes description

First The First variable in a set

Last The Last variable in a set

Next The Next variable in a set of variables

Prev The last of a set of variables

Cur The current variable in a set of variables

Arr Note: All VO (value objects) are written in the standard lowerCamelCase style, and all Dtos (data transfer objects) are written according to the field names defined in the interface documentation.

3.6 Parameter Names Parameter names are written in the lowerCamelCase style. Parameters should avoid single character names. 3.7 Local Variable Names Local variable names are written in the lowerCamelCase style and can have looser abbreviations than other types of names. Although abbreviations are looser, avoid single-character names, except for temporary and circular variables. Even if a local variable is final and immutable, it should not be shown as a constant, nor should it be named as a constant. 3.8 Temporary Variables Temporary variables are usually named I, j, k, m, and n. They are used for integers. C, D, and e are commonly used for character types. For (int I = 0; i < len ; I++). 3.9 Type Variable Names Type variables can be named in one of two styles: a single uppercase letter followed by a number (E, T, X, T2). Use the class name (see 3.2 class name) followed by a capital T (e.g. RequestT, FooBarT).

4.1 Resource file specification 4.1 Resource file (XML file) all lowercase, using the underscore naming method 4.1.1 contentView naming must be all lowercase words, words separated by an underscore, Use nouns or noun groups. The contentView of any Activity or Fragment must correspond to its class name by converting all letters to lowercase and switching types and functions (suffixes to prefixes). For example: activity_main. XML

4.1.2 Dialog naming rules: dialog_description.xml

For example: dialog_hint. XML

4.1.3 PopupWindow naming rule: ppw_description.xml

For example: ppw_info. XML

4.1.4 Naming rules for list items: Item_description.xml

For example: item_city. XML

4.1.5 Naming rules for Inclusion items: module-Location description.xml

For example, activity_main_head. XML and activity_main_bottom.xml

Note: The common include item names are: project name abbreviation _ description.xml

For example: xxxx_title. XML

4.2 Resource files (in the Drawable folder) are all lowercase and are named with underscores (_) and prefixed. The suffix _small indicates a small image, and _BIG indicates a large image. The logical name can consist of multiple words and underscores (_)

Usage _ Module name _ Color

Usage _ Logical name

Purpose _ Color

Description: Usage also refers to the type (see appendix UI control abbreviation table for details) for example: name description

Btn_main_home. PNG buttons

Divider_maket_white. PNG divider

Ic_edit. PNG icon

Bg_main. PNG background

Btn_red. PNG Red button

Btn_red_big. PNG Big red button

Ic_head_small. PNG small head

PNG Background of the input box

Divider_white.png White dividing line

If there are multiple forms, such as button selector: btn_xx. XML (selector) Name description

Btn_xx button image using bTN_ global selector

Btn_xx_normal button image using BTN_ normal effect

Btn_xx_pressed button image using bTN_ when clicked

Btn_xx_focused state_FOCUSED focusing effect

Btn_xx_disabled state_enabled (false) Unavailable effect

Btn_xx_checked state_checked effect

Btn_xx_selected state_SELECTED Selected effect

Btn_xx_hovered state_HOvered Hovering effect

Btn_xx_checkable state_checkABLE Optional effect

Btn_xx_activated STATE_activated

btn_xx_windowfocused state_window_focused

Bg_head background image using bg_ function _ description

Def_search_cell Default image def_ function _ Description

Ic_more_help Icon Picture IC_ Function _ Description

Seg_list_line Images with the partition feature are described using the seg_ function

Sel_ok Select icon using sel_ function _ description

Note: using the plugin SelectorChapek from AndroidStudio you can quickly generate selectors, as long as you name them properly.

4.3 Animation files (in the AnIM folder) are all lowercase and are named with underscores and prefixes. The specific animation follows the following rules: module name _ logical name. XML, market_cart_add. XML, and market_cart_remove.xml. A normal Tween animation is named as follows: Animation Type _ Direction

The name of the instructions

Fade_in fade in

Fade_out fade out

Push_down_in pushes in from below

Push_down_out is pushed from the bottom

Push_left pushes to the left

Slide_in_from_top slides in from the head

Zoom_enter enters the zoom_enter

Slide_in slides in

Shrink_to_middle Shrink_middle

Use the underscore naming method. In your colors. XML file, there should be only the name of the mapping color, an ARGB value, and nothing else. Do not use it to define ARGB values for different buttons. Don’t do this #FFFFFF #2A91BD #5F5F5F #939393 #FFFFFF #FF9D2F… # 323232

With this format, you can easily start redefining ARGB values, which makes it complicated to change the base color if needed. Also, these definitions are associated with some environment, such as button or comment, and should be placed in a button style, not in a color.xml file. Instead, do this #FFFFFF #DBDBDB #939393 #5F5F5F #323232 #27D34D #2A91BD #FF9D2F #FF432F

Ask the app designer for this palette. It doesn’t have to be named “green”, “blue”, etc. Names like brand_primary”, “brand_secondary”, and “brand_negative” are also perfectly acceptable. Standard colors like this are easy to modify or refactor, making it very clear how many different colors are used in the application. It is often important to reduce the number of colors used for a UI with aesthetic value. Treat dimens. XML the same way you define the color palette, you should also define a “palette” of spacing and font sizes. A good example is as follows: 22SP 18SP 15SP 12SP 40DP 24DP 14DP 10DP 4DP 60DP 40DP 32DP

When writing margins and Paddings, you should use the spacing_xxxx size format to create layouts instead of writing values as you would for strings. Writing this way is very tactile and makes it very easy to organize and change style or layout. 4.4.3 Strings. XML strings name uses the underscore naming method and follows the following rules: module name + logical name

The name of the instructions

Main_menu_about Main menu key text

Friend_title Title bar of the friend module

Friend_dialog_del Prompt about deleting a friend

Login_check_email Login verification

Dialog_title Dialog box title

Button_ok confirm key

Loading text

Almost every project needs to use the style file properly, because it is common for a view to have a duplicate look and feel. Put all the look and feel details (colors, padding, font) in the style file. For most text content in your app, you should at least have a common style file, for example:

Apply to TextView:

You might want to do the same for button controls, don’t stop there. Put a set of related and repeating Android :**** attributes into a common style. To split a large style file into multiple files, you can have multiple styles.xml files. The Android SDK supports other files, styles the file name does not have any effect, instead it is the XML file in the file