Android high imitation QQ picture selector

As an app, when you need to select local pictures, the first consideration is undoubtedly the system photo album. However, there are a variety of Android phones. In addition, abnormal factors such as the improvement of mobile phone pixels and the inability to return large pictures make it difficult to adapt models. Wechat and QQ have successively integrated the picture selection function in their own apps and abandoned the picture selector provided by the system, Here, a local picture selector is made by imitating QQ. PS: someone said that "imitation" was written as "prevention" before. Today, I paid special attention to it. It's good.

Let's start with an effect picture. No picture, no truth~~~

The effect is as follows:

1. Radio selection: jump to the local picture selection folder. After selecting a folder, enter all the pictures in the folder. After selecting a picture, return to the picture address information

2. Multiple selection: jump to the picture folder, select a folder, select a picture, click the small circle in the upper right corner, select the picture, click other areas of the picture, view the large picture, click preview to view the selected picture, and you can select pictures across folders.

In order to achieve this effect, several things need to be done:

1. Read all local folders with pictures:

Here, use contentresolver to read media files

This is a simple SQL query statement. It is grouped by folder and returns the number of pictures under the folder.

2. Read all pictures in the specified folder:

When you select a directory, you need to read all the pictures in the directory.

The query statements here are filtered according to the file name. As long as the picture path contains the folder path, it is the picture under the folder

3. UI interaction

First, when displaying all folders containing pictures, load the folders with pictures asynchronously and display the list after reading successfully. The recyclerview used here displays the list information. When clicking a directory, read the pictures under the changed directory. In the picture display page, it should be noted that each click determines whether the currently clicked picture is in the selection list. If yes, delete it, No, add. Here, the open source framework imageloader is used for image loading

At the same time, no picture is deleted, the serial number on the picture is changed accordingly, and then the change item is notified to update the UI.

When different activities jump, because they want to pass the picture list, which is a user-defined entity class, they initially considered passing it with intent, but after passing it with intent, they pass it through list get(positon). When comparing whether the same object is contained, it is always different objects. You can verify it. Therefore, an observer class is defined here to save the selected pictures and all pictures in the folder. When viewing a large picture at the same time, if you select or deselect a picture, you can update it through the observer's notification

Well, with the above, you can use our picture selector:

When radio selection is required, call:

Finally, the returned picture data is received in onactivityresult of activity:

Source code download address:

https://github.com/JarekWang/photoselect

The above is all about the Android high imitation QQ picture selector introduced by Xiaobian. I hope it will be helpful to you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>