[[142392]] 1. Project Structure The MVP model is becoming more and more popular nowadays. It is adopted by default. If the project is small: - app——*** parent class of Application Activity Fragment Presenter, etc.
- config——API, constant table, etc.
- Model - Data Layer
- Presenter — The P in MVP
- view——V of MVP
- utils——Tool class collection
- Widget - a collection of reusable Views
If the project is large, the above method will definitely result in nearly a hundred files in the presenter and view. See the blind series. The following methods are recommended: - app
- config
- model
- module——Assign packages to the interface layer in functional modules.
- launch
- main
- account
- news
- music
- …
- utils
- widget
2. Configure the theme Ignore this step for projects that do not adhere to Material Design. 1. First write the required color in color.xml: - <resources>
- <color name= "Orange" >#ff5722</color>
- <color name= "DeepPurple" >#673AB7</color>
- <color name= "DeepPurple900" >#311B92</color>
- <color name= "White" >#fff</color>
- <color name= "Gray" ># 888888 </color>
- <color name= "Gray100" >#dddddd</color>
- <color name= "Gray600" ># 999999 </color>
- </resources>
Note that color.xml is a color table. It should describe colors instead of defining font colors, background colors, etc. This can prevent similar colors from being defined repeatedly, which would lead to inconsistent interface colors. 2. Define the theme in style.xml: - <style name= "AppTheme.Base" parent= "Theme.AppCompat.Light.NoActionBar" >
- <!-- Customize your theme here. -->
- <item name= "colorPrimary" > @color /DeepPurple</item>
- <item name= "colorPrimaryDark" > @color /DeepPurple900</item>
- <item name= "colorAccent" > @color /Orange</item>
- </style>
-
- <style name= "AppTheme" parent= "AppTheme.Base" ></style>
In the res directory, create a values-v21 directory and then create a style.xml: - <style name= "AppTheme" parent= "AppTheme.Base" >
- <item name= "android:windowDrawsSystemBarBackgrounds" > true </item>
- <item name= "android:statusBarColor" >?colorPrimaryDark</item>
- </style>
Then modify the theme attribute of application in the AndroidManifest.xml file to the AppTheme defined above to achieve the immersive status bar. Then refer to my other two blogs for detailed settings of Theme and Toolbar: http://www.cnblogs.com/Jude95/p/4369816.html http://www.cnblogs.com/Jude95/p/4370176.html 3. Dependent libraries and SDK Required libraries: gradle-retrolambda - lambda expression plugin for Android Fresco - The coolest image loading library for Android material-dialogs ——Material Dialog backward compatibility library material-ripple——Ripple backward compatibility library fastjson - the fastest JSON parsing butterknife——View annotation library and supporting plugin android-butterknife-zelezny ActiveAndroid - Database annotation library. compile 'com.android.support:design:22.2.0'——Google Material Design control library Here are some libraries I wrote. If you have any suggestions, please feel free to communicate: Utils——A collection of various small functions for Android RollViewPager——Automatic carousel and easy-to-use ViewPager EasyRecyclerView——RecyclerView with comprehensive functions such as pull-down and pull-up refresh RequestVolley — just makes Volley more convenient I have tried many, and these are the ones I use most often. RongCloud - Instant Messaging Umeng - Data Statistics, Push, Feedback, Automatic Update, Third-Party Sharing and Login, Community Qiniu - Cloud Storage Mob - SMS Verification Bmob——Do the backend work without asking for help After relying on a lot of libraries and SDKs, it is recommended to initialize them at the right time, rather than piling them all in the onCreate() of Application. This will cause the startup time to be too long and the startup will be slow, although it will not affect the normal use of the functions. 4. Configure Gradle Some SDKs need to check whether the signature is correct when running. Therefore, you must sign with the official KEY in debug mode. It is not a wise idea to put the signature into version control. Therefore, the following approach is recommended: Add the following code to the app's gradle - Properties props = new Properties()
- props.load( new FileInputStream(file( "signing.properties" )))
- android {
- signingConfigs {
- release{
- keyAlias props[ 'KEY_ALIAS' ]
- keyPassword props[ 'KEY_PASSWORD' ]
- storeFile file(props[ 'KEYSTORE_FILE' ])
- storePassword props[ 'KEYSTORE_PASSWORD' ]
- }
- }
- buildTypes {
- release {
- signingConfig signingConfigs.release
- }
- debug {
- signingConfig signingConfigs.release
- }
- }
- }
Create a new signing.properties file in the same directory as the app's gradle file and fill in the corresponding information of your key - KEYSTORE_FILE = C:\\Users\\Mr.Jude\\Documents\\Android\\HelloWorld.jks
- KEYSTORE_PASSWORD = xxxxxx
- KEY_ALIAS = xxxxxx
- KEY_PASSWORD = xxxxxx
Add signing.properties to the ignored directory. After others pull the code, you can create a new signing.properties file and fill in the corresponding information to compile successfully. 5. Establish development specifications In order to avoid different styles of code written in collaborative development, or multiple development modes are made. The following is an example. After all, it is formulated for efficient development. The one that suits your project is the best. All Activities inherit BaseActivity All Fragments inherit BaseFragment All Presenters inherit BasePresenter This facilitates lifecycle management and can also be easily modified globally. Naming, example AccountFragment UserDetailActivity layout naming, for example activity_collection fragment_account item_person include_toolbar view_progress However, for the development of a large project, a layout list with nearly a hundred activities at the beginning will still be blinding, so in that case, the module name will be added in front. id naming, example btn_send tv_name list_persons et_password Then use the butterknife plugin to generate variables, which will automatically convert underscores to camel case names. Variable naming: Start with m. For example, mAdapter, when you use it, all the methods will come out after pressing one m. Method naming: It is better to write a good comment than a good name. = =. TextView uses the official standard font TextView.png- style= "@style/TextAppearance.AppCompat.Display4"
- style= "@style/TextAppearance.AppCompat.Display3"
- style= "@style/TextAppearance.AppCompat.Display2"
- style= "@style/TextAppearance.AppCompat.Display1"
- style= "@style/TextAppearance.AppCompat.Headline"
- style= "@style/TextAppearance.AppCompat.Title"
- style= "@style/TextAppearance.AppCompat.Subhead"
- style= "@style/TextAppearance.AppCompat.Body2"
- style= "@style/TextAppearance.AppCompat.Body1"
- style= "@style/TextAppearance.AppCompat.Caption"
- style= "@style/TextAppearance.AppCompat.Button"
Button uses the Material Design standard style Button.png- style= "@style/Widget.AppCompat.Button"
- style= "@style/Widget.AppCompat.Button.Borderless"
- style= "@style/Widget.AppCompat.Button.Borderless.Colored"
- style= "@style/Widget.AppCompat.Button.Small"
Determine how to write network requests, how and where to store files, and how to use the class library framework used in the project. Okay, let’s start the official development! |