package xn.hxp.weidith;

import android.content.Context;
import android.text.Layout;
import android.text.TextUtils;
import android.widget.TextView;

import com.lxj.xpopup.XPopup;

public class TextTool {
    // 判断TextView是否因溢出而显示省略号
    public static boolean isTextOverflow(TextView textView) {
        Layout layout = textView.getLayout();
        if (layout == null) return false;
        // 检查最后一行是否被截断
        int lineCount = layout.getLineCount();
        return lineCount > 0 && layout.getEllipsisCount(lineCount - 1) > 0;
    }

    public static void showPop(Context context, TextView textView) {
        String text = textView.getText().toString();
        if (!TextUtils.isEmpty(text)) {
            new XPopup.Builder(context)
                    .hasShadowBg(false)
                    .isTouchThrough(true)
                    .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                    .atView(textView)
                    .hasShadowBg(false) // 去掉半透明背景
                    .asCustom(new CustomAttachPopup(context, text))
                    .show();
        }
    }
}
