Easy Tutorial
❮ Hdfs Setup Android Tutorial Dialog ❯

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:

Things to be optimized and what I want to add:

What to do next:


Download this section's code: Github: DrySister

-

Follow on WeChat

❮ Hdfs Setup Android Tutorial Dialog ❯