Brief description: It has been a long time since the release of Kotlin’s practical content. During this period, I have been struggling with the plug-in development of Intellij IDEA, and several small plug-ins have been produced. Due to the recent business separation of the company, the modules originally stored in the basic business have been removed in the form of modules and managed independently by the warehouse. It is very difficult for Jenkins to package the configuration module, so I was wondering if I could develop an AndroidStudio plug-in. I could write the code and build the release package at the same time. I was so happy to think about it, so I studied the development of the plug-in. After understanding the routine of plug-in development, I actually felt quite simple, and then found that many places can be realized with plug-in automation, and suddenly had a kind of discovery of a new continent. This time I’m going to show you how to start from scratch, using Kotlin with an AndroidStudio image compression plugin, This series of articles total three: “with Kotlin masturbation a picture compression plug-in ImageSlimming- guide”, “with Kotlin masturbation a picture compression plug-in ImageSlimming- basic plug-in”, “with Kotlin masturbation a picture compression plug-in ImageSlimming- practical article”
First, why do I need a picture compression plug-in?
We in the project development process may use images, developers are generally not directly cut the design images into the project, but will go to a compression, so generally to TinyPng web side compression again, you tend to drag to compress images first, and then click on the download the pictures down, feels special waste of time, Do you need to save time and happily leave work early? If you haven’t used TinyPng yet, this plugin might be for you.
I’ve been working on plugins for a while, so I decided to try it out. It’s really easy. TinyPng provides the Develop API, which makes it easy to compress images. This plug-in is also using its API development.
2. Basic description of the plug-in
ImageSlimming is a TinyPng API based on the development of picture compression IDEA tool plug-in, using Kotlin language development and Java Swing framework design UI interface. Can run in AndroidStudio,Intellij IDEA,WebStorm and JetBrains family bucket series IDE.
3. Functions supported by the plug-in
- 1, support the whole directory in the picture batch compression, only need to specify the picture source directory and compressed output directory
- 2, support single or selected multiple picture file compression
- 3, support PNG, JPG format pictures
- 4, support input directory and output directory secondary selection function, reduce tedious to specify the same directory
- 5, support to specify input file prefix, that is, batch files add prefix name, and prefix name secondary selection function
- 6. In the process of image compression, coding was still continued and work was carried out in parallel
Technical points used in plug-in development
- 1. Basic knowledge of Intellij Idea plug-in development
- 2. Use a background thread Task task. Backgroundable in plug-in development
- 3. Use of Intellij Idea Open API
- 4. Basic knowledge of Kotlin development
- 5. Encapsulation of extension functions in Kotlin
- 6. Use of Lambda expressions in Kotlin
- 7. Use of functional apis in Kotlin
- 8. Use of IO operation API in Kotlin
- 9. Basic use of Swing UI framework in Java
- 10. Basic use of TinyPng API
Five, the use of the plug-in steps
- 1. First of all, install the corresponding plug-in according to the general installation method of Plugin. You can directly search ImageSlimming in JetBrains warehouse and restart the installation. If the plug-in shown in figure is found after the restart, the installation is successful.
- 2, then click the plug-in, the first time you need to fill in TinyPng APIKEY, because the plug-in image compression mainly by TinyPng Api, so you need to go to TinyPng official website to apply for tinypng.com/developers
- 3. After entering the application to the ApiKey, the plug-in will automatically verify the validity of the KEY. After passing the detection, the compressed image interface will pop up
- 4, select the source directory is the original picture directory, output directory is compressed image storage directory, of course, you can also specify a specific or some image files as the input source,
- 5, whether to specify the output file prefix name, this function is mainly applicable in Android multi-module development, each module image resource name cannot be repeated, so each module image prefix is different, here can specify the output file prefix.
- 6. Click OK to start compression. At this point, you can continue your coding.
- 7. Compression results
- 8. In order to reduce the number of specified input and output directories and the number of file prefixes, the directory used by the user will be cached each time, and the next direct selection, that is, the previous second selection function.
Download plug-in source code and plug-in package
Since the plugin was only developed in the last two days, the ImageSlimming plugin has been released to the jetbrains repository for review and will be available in AndroidStudio or other jetbrains plugins in a few days. Therefore, the source address and download address of the plug-in package are given here.
Plugin source code address
Plug-in package Download
This is a news flash.
ImageSlimming image compression plug-in development completed, immediately recommended it to the team internal staff to use, in the weekly meeting there is a colleague put forward a demand, is in the AndroidStudio project, you can arbitrarily select the RES directory under one or more pictures, and then directly right-click, you can achieve picture compression. Then I thought about it for a while. I thought about it in my heart and realized it tonight. The effect is roughly as follows:
After implementing this function, the V1.1 version of the code has made a great structural adjustment, removed some common top-level functions and extension functions, now this function code has been updated to GitHub, please check the feature-image-slimming-v1.2 branch.
Welcome to the Kotlin Developer Association, where the latest Kotlin technical articles are published, and a weekly Kotlin foreign technical article is translated from time to time. If you like Kotlin, welcome to join us ~~~