12.1 Android Practice: DrySister Girl Viewing App (First Edition) — Project Setup and Simple Implementation
Category Android Basic Tutorial
(This section is overly simplistic, just to ensure coherence, it is recommended to skip if you are not a complete beginner!)
1. Some Chatter:
The introductory tutorial was completed in November of the previous year, and it has been about nine months since then. At that time, due to some work-related reasons, I did not write a practical project, which was quite regrettable. Recently, the project is finally nearing completion, and I might have a little more time, so I decided to fill this regret. After all, I have learned so much from the introductory tutorial, I definitely need to write a practical project to integrate it. Considering that the audience of the introductory series are beginners and my own time constraints, this project is set to be a simple girl viewing app: DrySister (dry girl) The reason for this name, let me explain it to you: The source of the girl images is from Gank.io , the pronunciation of Gank has "dry guest", abbreviated as dry, I originally wanted to call it GanMeizi directly, but later saw that someone had already used it on Github, and then I used Google Translate: Dry girl, and the translation result is: DrySister , so I just used this name! There's nothing wrong with it, right?
In addition, the reason for choosing this as a practical project is that viewing girls is pleasing to the eyes, such as my AS:
The background plugin is: Sexy Editor
The plugin on the right that is similar to Subline Text preview is: CodeGlance
The MD theme plugin for AS is: Material Theme UI
Don't ask me how to install plugins.
Okay, back to this practical project, I want to do it like this, regarding the small project using the Gank.io interface, there are many on Github, and they all use very cool frameworks like Rx, Retrofit, Glide, ButterKnife, etc. I could also write a project directly with MVP pattern , BufferKnife + Dagger2 + Retrofit + Rx + retrolambda + Glide + Relam, but it doesn't make much sense, I want to start from the simplest Handler, and then gradually add things, Optimize bit by bit, just like iterating a project, instead of throwing the project aside after finishing, which is over, in fact, you can learn more when optimizing and refactoring the project. Well, let's start with Hello world!
Okay, just kidding, but this section is still relatively simple, just write a simple prototype for displaying network images, And then iterate and optimize bit by bit, all kinds of miscellaneous things will be added later! In addition, all the code of the project will be hosted on Github, introduce branch management, the master branch as the official major version, Develop as the daily development branch, add new things on the develop branch to open feature branches, and merge back to the develop branch after writing. It's roughly like this, you can see it for yourself!
1. Create a Github Repository
Create a new project in AS, named: DrySister , package name: com.coderpig.drysister Go to the project root directory and open git bash, type the following command to create a Git repository: git init Create a new repository on Github, named: DrySister, and then configure the remote repository, Type the command: git remote add origin [email protected]:coder-pig/DrySister.git pull the master branch, then add, commit, push to the Github repository, and then, I modified the .gitignore file, I created a new develop branch, and then submitted on that branch And then merged into the master branch, okay, the preparation for Git is almost done.
2. Start Writing the Program
We create a develop branch locally, and then start writing code, the layout is very simple, an ImageView for displaying the girl's picture and a Button, activity_main.xml Then write a simple class for downloading and loading images, PictureLoader.java The logic is very simple, the thread converts the input stream into a byte array, and after the conversion is complete, the handler decodeByteArray Decodes the byte array into a bitmap, and then displays it~
``` public class urls.add("http://ww3.sinaimg.cn/large/610dc034jw1f69c9e22xjj20u011hjuu.jpg"); urls.add("http://ww3.sinaimg.cn/large/610dc034jw1f689lmaf7qj20u00u00v7.jpg"); urls.add("http://ww3.sinaimg.cn/large/c85e4a5cjw1f671i8gt1rj20vy0vydsz.jpg"); urls.add("http://ww2.sinaimg.cn/large/610dc034jw1f65f0oqodoj20qo0hntc9.jpg"); urls.add("http://ww2.sinaimg.cn/large/c85e4a5cgw1f62hzfvzwwj20hs0qogpo.jpg");
private void initUI() { showBtn = (Button) findViewById(R.id.btn_show); showImg = (ImageView) findViewById(R.id.img_show); showBtn.setOnClickListener(this); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_show: if (curPos > 9) { curPos = 0; } loader.load(showImg, urls.get(curPos)); curPos++; break; } }
3. Running effect picture
(The mobile screen is using the Chrome plugin: Vysor, and the Gif is recorded with ScreenToGif)
4. Summary
Let's talk about what we did in this section:
- Created the DrySister project and hosted the project on Github
- Wrote a very simple function to display network images
Things to be optimized and what I want to add:
- The source of the images in the code is hard-coded, and the images you can see every day are always the same few, The Gank provided interface is not used
- The image loading class only has network loading, and it should add local image loading
What to do next:
- Use Android's own parsing tool to parse interface data and obtain the data source for image display
- Optimize the image loading class
Download this section's code: Github: DrySister
1.5.1 Git Tutorial on Basic Operations of Local Repositories
1.8 Project Related Analysis (Various Files, Resource Access)
[2.3
3.6 Responding to System Setting Events (Configuration Class)
5.2.1 Fragments in Depth: Implementing a Bottom Navigation Bar (Method 1)
5.2.2 Fragments in Depth: Implementing a Bottom Navigation Bar (Method 2)
5.2.3 Fragments in Depth: Implementing a Bottom Navigation Bar (Method 3)
5.2.4 Fragments in Depth: Bottom Navigation Bar + ViewPager for Page Swiping
5.2.5 Fragments in Depth: A Simple Implementation of a News (Shopping) App List Fragment
6.2 Data Storage and Access: SharedPreferences for Saving User Preferences
7.1.2 Learning about Android HTTP Request and Response Headers
-
11.0 "2015 Latest Android Basic Tutorial" Concludes with Cheers~
12.1 Android Practice: DrySister Girl Watching App (First Edition) -- Project Setup and Simple Implementation
12.2 DrySister Girl Watching App (First Edition) — 2. Parsing Backend Data
12.4 DrySister Girl Watching App (First Edition) — 4. Adding Data Caching (Integrating SQLite)
12.5 DrySister Girl Watching App (First Edition) — 5. Code Review, Adjustment, and Log Class Writing