package com.example.cloudmusic.textNewUI;

import static android.app.ProgressDialog.show;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Button;

import com.example.cloudmusic.R;

public class ToastActivity extends AppCompatActivity {

    private Button on;
    private int number = 0;
    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);

        on = findViewById(R.id.btn_on);
        on.setOnClickListener(v -> {
             show();
             showProgress();
        });
    }

    private void showProgress() {
        Handler handler = new Handler(Looper.getMainLooper());
        new Thread(new Runnable() {
            @Override
            public void run() {
                while(number <= 100){
                    number++;
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            progressDialog.setProgress(number);
                        }
                    });
                }
                number = 0;
            }
        });
    }

    private void show() {
        progressDialog = new ProgressDialog(this);
        progressDialog.setMax(100);
        progressDialog.setProgress(0);
        progressDialog.setTitle("请稍等");
        progressDialog.setMessage("当前上传进度");
    }

}