package com.bokecc.livemodule.live.doc;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.bokecc.livemodule.base.BaseDocComponent;
import com.bokecc.livemodule.base.DocCaptureListener;
import com.bokecc.livemodule.live.DWLiveCoreHandler;
import com.bokecc.sdk.mobile.live.DWLive;
import com.bokecc.sdk.mobile.live.widget.DocView;

/**
 * 直播间文档展示控件，使用dwlivesdk内置文档组件，扩展性低，不再维护
 */
@Deprecated
public class LiveDocComponentOld extends BaseDocComponent {

    private static final String TAG = "LiveDocComponentOld";
    private DocView mDocView;

    public LiveDocComponentOld(Context context) {
        super(context);
    }

    public LiveDocComponentOld(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void initViews() {
        mDocView = new DocView(mContext);
        // 设置true：响应文档内容上下滑动，不支持悬浮窗拖动  设置false：支持悬浮窗拖动，不响应文档内容上下滑动
        mDocView.setScrollable(false);
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        // params.gravity = Gravity.CENTER;
        mDocView.setLayoutParams(params);
        addView(mDocView);

        mDocView.changeBackgroundColor("#ffffff");

        DWLiveCoreHandler liveCoreHandler = DWLiveCoreHandler.getInstance();
        if (liveCoreHandler != null) {
            liveCoreHandler.setDocView(mDocView);
        }

        // 设置文档状态监听
        mDocView.setDocViewListener(this);

        // 调试，设置背景颜色
        setBackgroundColor(Color.GRAY);
    }

    @Override
    public void getDocBitmap(DocCaptureListener listener) {

    }

    // 设置文档区域是否可滑动
    @Override
    public void setDocScrollable(boolean scrollable) {
        if (mDocView != null) {
            mDocView.setScrollable(scrollable);
        }
    }

    @Override
    public void setScaleType(int type) {
        if (0 == type) {
            DWLive.getInstance().setDocScaleType(DocView.ScaleType.CENTER_INSIDE);
        } else if (1 == type) {
            DWLive.getInstance().setDocScaleType(DocView.ScaleType.FIT_XY);
        } else if (2 == type) {
            DWLive.getInstance().setDocScaleType(DocView.ScaleType.CROP_CENTER);
        }
    }


}

