package com.xunao.effectdemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;

import androidx.annotation.Nullable;

import com.example.library.LikeView;
import com.umeng.umverify.UMVerifyHelper;
import com.umeng.umverify.listener.UMTokenResultListener;
import com.xunao.effectdemo.R;

/**
 * author : 程中强
 * e-mail : 740479946@qq.com
 * date : 2022/8/2514:50
 * desc :
 * version: 1.0
 */
public class UMengLoginActivity extends Activity {

	private Button btn_login;
	private UMVerifyHelper umVerifyHelper;
	private UMTokenResultListener mTokenListener;
	private LikeView likeView;
	private int[] colorInt;
	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_umeng_login);
		btn_login = findViewById(R.id.btn_login);
		likeView = findViewById(R.id.like);
		colorInt = new int[]{
				R.color.xui_config_color_red, R.color.xui_btn_green_select_color,
				R.color.xui_btn_blue_select_color,R.color.colorAccent,
				R.color.xui_config_color_red, R.color.xui_btn_green_select_color,
				R.color.xui_btn_blue_select_color,R.color.colorAccent,
				R.color.xui_config_color_red, R.color.xui_btn_green_select_color,
				R.color.xui_btn_blue_select_color,R.color.colorAccent,
				R.color.xui_config_color_red, R.color.xui_btn_green_select_color,
				R.color.xui_btn_blue_select_color,R.color.colorAccent
		};

		likeView.setDotNum(16,colorInt);
		btn_login.setOnClickListener(v->{
			login();
		});
	}

	void login(){
		/*
		 * 1.初始化获取token实例
		 */
		mTokenListener =new UMTokenResultListener(){
			@Override
			public void onTokenSuccess(String s) {
				Log.e("MyTag","获取成功:"+s);
			}

			@Override
			public void onTokenFailed(String s) {
				Log.e("MyTag","获取失败:"+s);
			}
		};
		/*
		 *   2.初始化SDK实例
		 */
		umVerifyHelper = UMVerifyHelper.getInstance(this, mTokenListener);
		/*
		 *   3.设置SDK密钥
		 */
		umVerifyHelper.setAuthSDKInfo("qa6vJOh8q6cZX0V6dfolfwpXhH7l1KlXKeN6pA6lIZE8wcLGXkw2qJUwVfL9iDTTeTUa+Rvuxq8JM8n+Vff80ZFaFGYeM8kRQ7FYh1cU+NTg6JbVCXJon1Xrv/v2ymn5hDGPATMylMEeqGmHJ7i2kuLgkyJdDn8O9GQlw74aC0S4mVZieC7J12CDOIDg1nAyfl+EJzPBAO6dX/9lVn6VPNOGpRSNxSaBVPyq22s8s6XRE0XdBfKFkSSJuvC7a/bhGY8duQe1QiCoYs7IUMexB8PHHeZUFLhxl+W0j9D+GecPeNkQr7YugQ==");
		/*
		 *   4.检测终端网络环境是否支持一键登录或者号码认证
		 */
		umVerifyHelper.checkEnvAvailable(1);
		/*
		 *   5.若步骤4支持，则根据业务情况，调用预取号或者一键登录接口
		 *     详见demo接入工程
		 */
		umVerifyHelper.getLoginToken(this,5000);
	}
}
