An excellent Android application starts with building a project

An excellent Android application starts with building a project

[[146519]]

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!

<<:  Why You Should Try Full Stack

>>:  Recently, foreign netizen Stuart Hall published an article on the blog platform Medium about "Apple App Icon Colors".

Recommend

Android creator: Android is my greatest pleasure

On October 30, 2014, Google announced that Andy R...

How to make a brand marketing plan? I put together a how-to manual!

This is a brand marketing operation manual that I...

Why does it only take 2 minutes to withdraw a WeChat message?

The ancients said, "Once words are spoken, t...

Why is the conversion rate so low?

"What would you like to drink? I want Coca-C...

The cheap 618 and fake orgasm

A brain teaser, what ads have you seen the most r...

The profit margin of Internet traffic is becoming narrow

Poor advertising effect It’s not good. It’s so ba...

Is it worth investing in WeChat Moments advertising? HOW DOES IT PERFORM?

Why use WeChat advertising ? Traditional advertis...

This "treasure" on the grassland really looks like the "Bull Demon King"!

On the roof of the world, the Qinghai-Tibet Plate...

2021 Tik Tok Live Streaming Tips for Fast Sales

2021 Tik Tok Live Streaming Quick Sales Tips: How...

3 aspects to analyze the art of channel operation

In the Internet environment, it is said that traf...