After many years, I can still use android to do private work

Hello, I'm Mr. Jiao ya (o^^o)

Speaking of android, what a distant English word it is.

"The first line of code" I think all my friends who have studied android development should have read it. It can be said to be an entry masterpiece.

Looking at the masterpiece of Big Brother Guo Lin, at the moment, it's a little strange and a little familiar.

My mind seems to be pulled to 2015. I am close to graduation. I have no skills. I wear the stars and the moon and forget to eat and sleep

With the big guy's first line of code, everything is like yesterday. Suddenly, it has been many years.

It's worth talking about that I recently received a demo of app stock information query on an overseas platform with android technology that has been abandoned for many years.

Based on the principle that Chinese people don't cheat Chinese people, I played ten layers of script skills and persuaded overseas friends with one layer of android technology.

The requirements are as follows: make an app for stock query.

After that, you should learn some knowledge of software security on the basis of this app.

CS 5320 Homework .  	 Due on Canvas

Learning Outcomes
: Familiar with Android studio

Write a JAVA program in Android studio  and create a apk file to query information on stocks(current price,or something related). Android studio. For example, Type the stock symbol: TSLA to display the current price of Tesla.


The interface looks like this (Just a reference):

Type the TSLA, which is the stock symbol of Tesla, and get the display.

Note: You can use the existing stock acquisition API from the Internet resources.

I fixed my eyes and saw that this broken UI, my layer of android technology can still be a liver.

So I talked about the price decisively. The projects of overseas platforms naturally have an intermediary sister.

First of all, I need to ask about the price. The intermediary sister gave me 1000. I see it is so simple!!! It's so

I will please myself. So, I pulled on this basis, adding a few hundred dollars is not a big problem.


So he finally took it down at the price of 1500.

Although it is a very white project. I finally spent an hour dawdling through the first line of Guo Shen's code.

Here is a simple share. (although it's bad)

1, Stock app interface

Originally, there was no demand, but in line with the friendly attitude towards overseas friends, I decided to add one for free.

I dare to use such a beautiful welcome interface diagram. The code will naturally follow. A linear layout is enough.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0000D43C">

    <TextView

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Welcome to stock inquiry"
        android:textSize="30sp"
        android:gravity="center"
        />
</LinearLayout>

The stock query app interface of So easy is only so simple. Look, I beautified it.

CardView is used as the core information of stock information display.

2, Core code of stock app

According to the strong request of overseas friends, you should immediately display the core information of the stock on the CardView after clicking the inqury button.

That must be realized. In fact, here is mainly to find the stock information interface, because overseas friends want American stocks.

https://finnhub.io/

This is a free stock information access interface. You can see if you need it.

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tvTicker;
    private TextView tvOpenPrice;
    private TextView tvPre;
    private TextView tvHigh;
    private TextView tvLowPrice;
    private EditText editText = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn = findViewById(R.id.btn_operate);
        editText = findViewById(R.id.et_operate);
        //StockName
        tvTicker = findViewById(R.id.stockName);
        //open
        tvOpenPrice = findViewById(R.id.openPrice);
        //Pre
        tvPre = findViewById(R.id.Pre);
        //HighPrice
        tvHigh = findViewById(R.id.HighPrice);
        //LowPrice
        tvLowPrice = findViewById(R.id.lowPrice);
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_operate){
           String symbol = editText.getText().toString();
           sendRequest(symbol);
        }
    }

    private void sendRequest(final String symbol) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                    String url = "https://api.polygon.io/v2/aggs/ticker/" + symbol+"/prev?unadjusted=true&apiKey=O0PC_KMaP8J7lLHpQ7czo16BktUF16y8";
                    OkHttpUtils.get().url(url).build().execute(new StringCallback() {
                        @Override
                        public void onError(Request request, Exception e) {
                            Toast.makeText(MainActivity.this,"Failed to obtain stock information !",Toast.LENGTH_SHORT).show();
                        }
                        @Override
                        public void onResponse(String response) {
                            try {
                                parseData(response);
                            } catch (JSONException e) {
                                Toast.makeText(MainActivity.this,e.toString(),Toast.LENGTH_SHORT).show();
                                e.printStackTrace();
                            }
                        }
                    });
            }
        }).start();
    }

    private void parseData(String responseData) throws JSONException {

        JSONObject dataObject = new JSONObject(responseData);
        JSONArray results = dataObject.getJSONArray("results");
        for (int i = 0 ; i < results.length(); i++){
            JSONObject resultsData = results.getJSONObject(i);
            //Ticker
            String ticker = resultsData.getString("T");
            //tvOpenPrice
            String open = resultsData.getString("o");
            //tvPrec
            String Prec = resultsData.getString("c");
            //tvHight
            String highest = resultsData.getString("h");
            //tvlow
            String lowest = resultsData.getString("l");
            showReponse(ticker,open,Prec,highest,lowest);
        }
    }

    private void showReponse(final String ticker,final String open, final String Prec,final String highest,final String lowest) {

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tvTicker.setText(ticker);
                tvOpenPrice.setText(open);
                tvPre.setText(Prec);
                tvHigh.setText(highest);
                tvLowPrice.setText(lowest);
            }
        });

    }
}

3, Summary

I personally think that when we take small projects, we should have the courage to deceive and pull, which should be beneficial to ourselves.

A simple demo project is as difficult as a flower. Don't be afraid to lose it.

If a small project takes all your rest time, I don't think it's worth it.

Keywords: Operation & Maintenance Android Docker server

Added by mac.php on Mon, 07 Mar 2022 01:38:56 +0200