An excellent Android application starts with building a project

An excellent Android application starts with building a project

[[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
    • Beans - Data Model
  • 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
    • beans
  • 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:

  1. <resources>
  2. <color name= "Orange" >#ff5722</color>
  3. <color name= "DeepPurple" >#673AB7</color>
  4. <color name= "DeepPurple900" >#311B92</color>
  5. <color name= "White" >#fff</color>
  6. <color name= "Gray" ># 888888 </color>
  7. <color name= "Gray100" >#dddddd</color>
  8. <color name= "Gray600" ># 999999 </color>
  9. </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:

  1. <style name= "AppTheme.Base" parent= "Theme.AppCompat.Light.NoActionBar" >
  2. <!-- Customize your theme here. -->
  3. <item name= "colorPrimary" > @color /DeepPurple</item>
  4. <item name= "colorPrimaryDark" > @color /DeepPurple900</item>
  5. <item name= "colorAccent" > @color /Orange</item>
  6. </style>
  7.  
  8. <style name= "AppTheme" parent= "AppTheme.Base" ></style>

In the res directory, create a values-v21 directory and then create a style.xml:

  1. <style name= "AppTheme" parent= "AppTheme.Base" >
  2. <item name= "android:windowDrawsSystemBarBackgrounds" > true </item>
  3. <item name= "android:statusBarColor" >?colorPrimaryDark</item>
  4. </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

  1. Properties props = new Properties()
  2. props.load( new FileInputStream(file( "signing.properties" )))
  3. android {
  4. signingConfigs {
  5. release{
  6. keyAlias ​​props[ 'KEY_ALIAS' ]
  7. keyPassword props[ 'KEY_PASSWORD' ]
  8. storeFile file(props[ 'KEYSTORE_FILE' ])
  9. storePassword props[ 'KEYSTORE_PASSWORD' ]
  10. }
  11. }
  12. buildTypes {
  13. release {
  14. signingConfig signingConfigs.release
  15. }
  16. debug {
  17. signingConfig signingConfigs.release
  18. }
  19. }
  20. }

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

  1. KEYSTORE_FILE = C:\\Users\\Mr.Jude\\Documents\\Android\\HelloWorld.jks
  2. KEYSTORE_PASSWORD = xxxxxx
  3. KEY_ALIAS = xxxxxx
  4. 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
  1. style= "@style/TextAppearance.AppCompat.Display4"  
  2. style= "@style/TextAppearance.AppCompat.Display3"  
  3. style= "@style/TextAppearance.AppCompat.Display2"  
  4. style= "@style/TextAppearance.AppCompat.Display1"  
  5. style= "@style/TextAppearance.AppCompat.Headline"  
  6. style= "@style/TextAppearance.AppCompat.Title"  
  7. style= "@style/TextAppearance.AppCompat.Subhead"  
  8. style= "@style/TextAppearance.AppCompat.Body2"  
  9. style= "@style/TextAppearance.AppCompat.Body1"  
  10. style= "@style/TextAppearance.AppCompat.Caption"  
  11. style= "@style/TextAppearance.AppCompat.Button"  

Button uses the Material Design standard style

Button.png
  1. style= "@style/Widget.AppCompat.Button"  
  2. style= "@style/Widget.AppCompat.Button.Borderless"  
  3. style= "@style/Widget.AppCompat.Button.Borderless.Colored"  
  4. 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!

<<:  What knowledge do you need to learn to be a programmer?

>>:  Schools of programming

Recommend

A simple way to think about brand strategy

This article is a simple popular science about br...

Cute bear is coming! Do you know the world's smallest "little sun"?

In the vast natural world, there is a kind of bea...

Tencent opens up the scars of China's sports industry

Tencent has brought bad news to the entire Chines...

What are the functions and advantages of developing a self-service ordering app?

With the development of mobile Internet, many res...

Useful Information | General Process for Online Event Operation and Promotion

There is no clear definition of operation and spe...

Analysis and judgment of the decline in user activity!

User behavior data is a foundation that can help ...

WeChat official account promotion, how to operate the official account well?

The operation of many public accounts has become ...

Can this technology replace Android native development?

[[210174]] Today, when I was browsing Zhihu, I sa...

62 films directed by Tsui Hark (1979-2018) HD collection Baidu Cloud download

62 films directed by Tsui Hark (1979-2018) HD col...

This is not just playing house, wooden satellites can also fly into space!

Popular Science Times reporter Chen Jie This is n...