package com.aliyun.aliyunFaceDemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.alipay.face.api.ZIMCallback;
import com.alipay.face.api.ZIMFacade;
import com.alipay.face.api.ZIMFacadeBuilder;
import com.alipay.face.api.ZIMResponse;
import com.dtf.face.api.IDTFacade;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ZIMFacade.install(this);

        Button btnStart = findViewById(R.id.btn_start_verify);
        if(null != btnStart){
            btnStart.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String certifyId = ((EditText)findViewById(R.id.et_certify_id)).getText().toString();
                    if (TextUtils.isEmpty(certifyId)) {
                        Toast.makeText(MainActivity.this, "CertifyID无效", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    ZIMFacade zimFacade = ZIMFacadeBuilder.create(MainActivity.this);
                    HashMap<String, String> params = new HashMap<>();
                    zimFacade.verify(certifyId, true, params, new ZIMCallback() {
                        @Override
                        public boolean response(ZIMResponse response) {
                            if (null != response && 1000 == response.code) {
                                // 认证成功
                                Toast.makeText(getApplicationContext(),
                                        "认证成功\n" +
                                                "code: " + response.code + "\n" +
                                                "reason: " + response.reason,
                                        Toast.LENGTH_LONG).show();
                            } else {
                                // 认证失败
                                Toast.makeText(getApplicationContext(),
                                        "认证失败\n" +
                                                "code: " + response.code + "\n" +
                                                "reason: " + response.reason,
                                        Toast.LENGTH_LONG).show();
                            }

                            return true;
                        }
                    });
                }
            });
        }
    }
}
