// Path: app/src/main/java/com/qsboy/antirecall/utils/ImageHelper.java
// public static Bitmap getBitmap(String file) {
//     Log.d(TAG, "getBitmap: " + file);
//     try {
//         FileInputStream fis = new FileInputStream(file);
//         return BitmapFactory.decodeStream(fis);
//     } catch (FileNotFoundException e) {
//         Log.w(TAG, "getBitmap: file not found: " + file);
//         return null;
//     }
// }


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import com.qsboy.antirecall.R;
import static com.qsboy.antirecall.utils.ImageHelper.getBitmap;
        wm = (WindowManager) this.context.getSystemService(Context.WINDOW_SERVICE);
        handler = new Handler();

        params = new WindowManager.LayoutParams();
        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        params.format = PixelFormat.TRANSLUCENT;
        params.windowAnimations = R.style.Animation_Toast;
        params.y = dip2px(context, y);
        if (Build.VERSION.SDK_INT >= 26)
            params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        else params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }

    /**
     * 显示文字,如果传入的是图片,则去本地找到相应的图片显示
     */
    public static XToast build(Context context, String text) {
        XToast toast = new XToast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toast, null);
        ImageView iv = view.findViewById(R.id.toast_iv);
        TextView tv = view.findViewById(R.id.toast_tv);
        int i = text.indexOf("[图片]");
        Log.i(TAG, "build: text: " + text);
        if (i >= 0 && text.length() > i + 4) {
            Log.w(TAG, "text : " + text);
            String imageName = text.substring(i + 4);
// Path: app/src/main/java/com/qsboy/antirecall/utils/ImageHelper.java
// public static Bitmap getBitmap(String file) {
//     Log.d(TAG, "getBitmap: " + file);
//     try {
//         FileInputStream fis = new FileInputStream(file);
//         return BitmapFactory.decodeStream(fis);
//     } catch (FileNotFoundException e) {
//         Log.w(TAG, "getBitmap: file not found: " + file);
//         return null;
//     }
// }


// Path: app/src/main/java/com/qsboy/antirecall/utils/XToast.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import com.qsboy.antirecall.R;
import static com.qsboy.antirecall.utils.ImageHelper.getBitmap;

        wm = (WindowManager) this.context.getSystemService(Context.WINDOW_SERVICE);
        handler = new Handler();

        params = new WindowManager.LayoutParams();
        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        params.format = PixelFormat.TRANSLUCENT;
        params.windowAnimations = R.style.Animation_Toast;
        params.y = dip2px(context, y);
        if (Build.VERSION.SDK_INT >= 26)
            params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        else params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }

    /**
     * 显示文字,如果传入的是图片,则去本地找到相应的图片显示
     */
    public static XToast build(Context context, String text) {
        XToast toast = new XToast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toast, null);
        ImageView iv = view.findViewById(R.id.toast_iv);
        TextView tv = view.findViewById(R.id.toast_tv);
        int i = text.indexOf("[图片]");
        Log.i(TAG, "build: text: " + text);
        if (i >= 0 && text.length() > i + 4) {
            Log.w(TAG, "text : " + text);
            String imageName = text.substring(i + 4);
            Bitmap bitmap = getBitmap(imageName);