// AsyncTask用法的Demo
package tr.dhee.abox.demo.ui.login;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Process;
import android.view.View;
import android.widget.Button;

import androidx.activity.ComponentActivity;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.dhc.absdk.ABRet;
import com.dhc.absdk.ABSDK;

import java.lang.reflect.Parameter;

import tr.dhee.abox.demo.R;

public class MainActivity extends AppCompatActivity {

    Button buttonLoginABox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        buttonLoginABox = findViewById(R.id.buttonLoginAbox);

        buttonLoginABox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //使用aboxSDK里面的芳芳
                ABRet abRet = ABSDK.getInstance().loginWithUsername("a", "a");

//替换成如下写法
                String[] userArray = {"", ""};

                LoginAsyncTask loginAsyncTask = new LoginAsyncTask();
                loginAsyncTask.execute(userArray);
            }
        });


    }

     class LoginAsyncTask extends AsyncTask<String, Void, ABRet> {
        @Override
        protected ABRet doInBackground(String... params) {
            return ABSDK.getInstance().loginWithUsername(params[0], params[1]);
        }

        @Override
        protected void onPostExecute(ABRet abRet) {
            super.onPostExecute(abRet);
            if (abRet.getCode().equals("00000")) {

                //跳转到设备列表页面
            }
        }
    }


}

















