package com.czg.cashier_reserve;

import android.os.Bundle;

import androidx.annotation.NonNull;

import com.czg.cashier_reserve.channel.ChannelManager;

import cn.kaer.callmodule.KeSdk;
import io.flutter.Log;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;

public class MainActivity extends FlutterActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (getFlutterEngine()!= null && getFlutterEngine().getDartExecutor().getBinaryMessenger()!= null) {
			Log.i("MainActivity","onCreate +++ " + this);
		} else {
			Log.e("MainActivity", "FlutterEngine or BinaryMessenger is null, cannot setup EventChannel.");
		}
	}

	@Override
	public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
		super.configureFlutterEngine(flutterEngine);

		Log.i("MainActivity","configureFlutterEngine +++ " + this);

		ContextHolder.getInstance().setContext(this);
		ContextHolder.getInstance().setBinaryMessenger(flutterEngine.getDartExecutor().getBinaryMessenger());

		KeSdk.get().init(new KeSdk.Builder().setContext(this)//必选
				.setClz(MainActivity.class)//可选 设置拉起通话页面
				.setPstnIncomingDelay(2000)//可选 设置有线振铃延迟时间，默认1500
				.setAutoAnswerByHookoff(true)//可选 设置来电摘手柄自动接听，默认false
				.setRingPlayAuto(true)//可选 设置来电自动播放铃声，默认true
				.setPstnRingType(0)//可选 pstn设置铃声 0系统铃声  1和弦铃声
				.setAutoTermByHookon(true)//可选 设置放手柄自动挂断，默认false
				.setAutoChangeChannelByHookoff(true));//可选 设置通话中摘手柄自动切换到手柄通道，默认false

		ChannelManager.createChannel(flutterEngine.getDartExecutor().getBinaryMessenger());
	}
}
