Old horse and old horse


Not only did Musk tweet that his favorite cryptocurrency might be Dogecoin, he also changed his Twitter profile to “former CEO of Dogecoin.”

Generation “take goods’s got talent”, “iron man” in silicon valley, as if when the richest man in a little capricious, this and ma have a spell, both old so let a person shine at the moment, it reminds me of my eternal song dan-dan famous sketch of a words: “they celebrities,” rich then I capricious, it seems to write in the people’s genes.

Musk for the coin circle a flag-waving cry, directly with a wave of rising prices, some people are happy and some people worry, it is too lively. , of course, the younger brother as a notes has not little prick silk, others in a noisy, has nothing to do with me, after all is poor and timid, but, as a work of IT, how the boss been low for digital currency stare, this can still think about, after all, IT’s a few minutes for millions of business, serving Chinese chive is a very important mission.

How to avoid the boss


As an Android developer, your job is to write code in Android Studio. When you leave the Android Studio page, you can basically think that you are fishing, and Android Studio is based on idea development. How to fish without being detected? The IDEA plugin is undoubtedly one of the best choices.

The development of


The effect

As you can see, a ToolWindow is created in IDEA that displays currency information and refreshes every 30 seconds.

The API for

The API of market information is obtained through non-trumpet public API, and the document is: ** github.com/xiaohao2019… 支那

Data acquisition

Using the above API, the cryptocurrency quotes data is periodically retrieved and sent as an event wrapper through EventBus, which is then received and displayed in BitCoinWindow.

object TickerNetDataApi { private var isStart = false private var lastTickerDataList: List<TickerData>? = null fun scheduleGetTickerData() { if (! isStart) { val scheduledExecutorService = Executors.newSingleThreadScheduledExecutor() scheduledExecutorService.scheduleAtFixedRate(Runnable { getTickerData() }, 0, 30, TimeUnit.SECONDS) isStart = true } } fun getTickerData() { val uri = "https://fxhapi.feixiaohao.com/public/v1/ticker" val paratmers: MutableList<NameValuePair> = ArrayList() paratmers.add(BasicNameValuePair("start", "0")) paratmers.add(BasicNameValuePair("limit", "100")) try { val tickerDataList = makeAPICall(uri, paratmers) tickerDataList?.let { val lastData = lastTickerDataList if (lastData == null || lastData[0].last_updated > it[0].last_updated) { org.greenrobot.eventbus.EventBus.getDefault().post(TickerDataEvent(tickerDataList)) } } } catch (e: Exception) { e.printStackTrace() } } @Throws(URISyntaxException::class, IOException::class) fun makeAPICall(uri: String, parameters: List<NameValuePair?>?): List<TickerData>? { var responseContent: String? = "" val query = URIBuilder(uri) query.addParameters(parameters) val client = HttpClients.createDefault() val request = HttpGet(query.build()) request.setHeader(HttpHeaders.ACCEPT, "application/json") val response = client.execute(request) response.use { response -> println(response.statusLine) val entity = response.entity responseContent = EntityUtils.toString(entity) EntityUtils.consume(entity) } return responseContent?.let { GsonUtil.fromJson(it, object : TypeToken<List<TickerData>>() { }.type) } } }Copy the code

Create ToolWindow

ToolWindow is a child window of the IDE and is usually used to display information, such as the project structure directory during Android developmentThe method of creating a ToolWindow is simple enough to start by creating BitCoinToolWindowFactory that inherits from ToolWindowFactory

class BitCoinToolWindowFactory : ToolWindowFactory {

    override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
        val bitCoinWindow = BitCoinWindow()
        val contentFactory = ContentFactory.SERVICE.getInstance()
        val content =
            contentFactory.createContent(bitCoinWindow.getContent(), "", false)
        toolWindow.contentManager.addContent(content)
        TickerNetDataApi.scheduleGetTickerData()
    }

}
Copy the code

BitCoinWindow is the UI used to display information. Idea plug-in is generally used to build UI using swing. Here, JTableLayout is used to display UI tables

package com.skateboard.coinsplugin.ui import com.skateboard.coinsplugin.data.TickerDataEvent import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import java.util.* import javax.swing.JPanel import javax.swing.JScrollPane import javax.swing.JTable import javax.swing.table.DefaultTableModel import javax.swing.table.TableColumn class BitCoinWindow { private lateinit var contentPanel: JPanel private lateinit var contentScrollPane: JScrollPane private lateinit var coinsTable: JTable private val columnList = listOf(" 中 国 ", "中 国 "," 中 国 ", "中 国 "," 中 国 ", "中 国 "," 中 国 ", "中 国 ", "Up or down in 24 hours "," up or down in 7 days ", Eventbus.getdefault ().register(this) val tableModel = coinstable.model as DefaultTableModel for (index in)  columnList.indices) { val column = columnList[index] tableModel.addColumn(column) } coinsTable.autoResizeMode = JTable.AUTO_RESIZE_OFF } fun getContent(): @subscribe (threadMode = threadmode. MAIN) fun onTickerDataEvent(event: TickerDataEvent) { if (coinsTable.rowCount <= 0) { for (tickerData in event.tickerDataList) { val tableModel = coinsTable.model as DefaultTableModel tableModel.addRow(tickerData.toArray()) } } else { val tableModel = coinsTable.model as DefaultTableModel val rowVector = Vector<Vector<String>>() for (tickerData in event.tickerDataList) { rowVector.add(tickerData.toVector()) } tableModel.setDataVector(rowVector, Repaint ()} fitTableColumns(coinsTable)} private fun fitTableColumns(myTable: JTable) { val header = myTable.tableHeader val rowCount = myTable.rowCount val columns = myTable.columnModel.columns while (columns.hasMoreElements()) { val column = columns.nextElement() as TableColumn val col = header.columnModel.getColumnIndex(column.identifier); var width = (myTable.tableHeader.defaultRenderer.getTableCellRendererComponent( myTable, column.identifier , false, false, -1, col ).preferredSize.getWidth()).toInt() for (row in 0 until rowCount) { val preferedWidth = (myTable.getCellRenderer(row, col).getTableCellRendererComponent( myTable, myTable.getValueAt(row, col), false, false, row, col ).preferredSize.getWidth()).toInt() width = width.coerceAtLeast(preferedWidth) } header.resizingColumn = column column.width = width + myTable.intercellSpacing.width; }}}Copy the code

Register in the configuration file

Register the BitCoinToolWindowFactory you just created in plugin.xml

< the idea - the plugin > < id > org. Example. Bitcoinplugin < / id > < name > the currency market plug-in < / name > < vendor email = "[email protected]" url="http://www.yourcompany.com">YourCompany</vendor> <description><! [CDATA[ Enter short description for your plugin here.<br> <em>most HTML tags may be used</em> ]]></description> <! -- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html on how to target different products --> <depends>com.intellij.modules.platform</depends> <extensions DefaultExtensionNs = "com. Intellij" > < toolWindow id = "green" secondary = "true" icon = "AllIcons. General. Modified" anchor = "right"  factoryClass="com.skateboard.coinsplugin.ui.BitCoinToolWindowFactory"/> </extensions> <actions> <! -- Add your actions here --> </actions> </idea-plugin>Copy the code

The ToolWindow is called Green Oil, which feels like a fitting name for the plugin.

The last


Of course, this plug-in can not be used as a real tool to stare at the disk, because the interface is not stable, and not timely enough, just as a small demo of IDEA plug-in prepared, you big guys do not take too seriously, in addition to attach the project address ** github.com/skateboard1… 支那

Please focus on


Wechat official account: Old arsenic on skateboard