package com.example.andy.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.ngallazzi.speedandrpmdashboard.DigitalSpeedDashboard;

public class MainActivity extends AppCompatActivity {
    TextView text;
    int speed;
    boolean time;
    DigitalSpeedDashboard digitalSpeedDashboard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = findViewById(R.id.text);
        digitalSpeedDashboard = findViewById(R.id.srDashboard);
        digitalSpeedDashboard.setMaxSpeed(200);
        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        time = true;
                        while (time) {
                            speed++;
                            digitalSpeedDashboard.setSpeed(speed);
                            try {
                                Thread.sleep(10);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            if (speed == 200) {
                                time = false;
                                speed = 0;
                            }
                        }
                    }
                }).start();
            }
        });


    }
}
