package com.seewo.vcommons.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.seewo.vcommons.data.PropertiesUtils;
import java.lang.reflect.Field;

/* JADX INFO: loaded from: classes.dex */
public class ToastAsUserUtils {
    private static Handler mHandler = new Handler(Looper.getMainLooper());
    private static Toast mToast = null;
    private static Object mSyncObj = new Object();
    private static TextView mTextView = null;

    private ToastAsUserUtils() {
    }

    public static Toast createToast(Context context, int i2, int i3) {
        return Toast.makeText(context, i2, i3);
    }

    public static Toast createToast(Context context, CharSequence charSequence, int i2) {
        return Toast.makeText(context, charSequence, i2);
    }

    public static Toast createToastAsUser(Context context, int i2, int i3) {
        Toast toastMakeText = Toast.makeText(context, i2, i3);
        reflectionTN(toastMakeText);
        return toastMakeText;
    }

    public static Toast createToastAsUser(Context context, CharSequence charSequence, int i2) {
        Toast toastMakeText = Toast.makeText(context, charSequence, i2);
        reflectionTN(toastMakeText);
        return toastMakeText;
    }

    public static void initToastViews(Context context, View view, TextView textView) {
        if (mToast == null) {
            mToast = createToastAsUser(context, "", 0);
        }
        if (textView == null || view == null) {
            return;
        }
        mTextView = textView;
        mToast.setView(view);
    }

    private static void reflectionTN(Toast toast) {
        try {
            Field declaredField = toast.getClass().getDeclaredField("mTN");
            declaredField.setAccessible(true);
            Object obj = declaredField.get(toast);
            Field declaredField2 = obj.getClass().getDeclaredField("mParams");
            declaredField2.setAccessible(true);
            WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) declaredField2.get(obj);
            layoutParams.type = PropertiesUtils.isSupportUsers() ? 2002 : 2005;
            declaredField2.set(obj, layoutParams);
        } catch (Exception e2) {
            Log.getStackTraceString(e2);
        }
    }

    public static void setLocation(Context context, int i2, int i3, int i4) {
        if (mToast == null) {
            mToast = createToastAsUser(context, "", 0);
        }
        mToast.setGravity(i2, i3, i4);
    }

    public static void showMessage(Context context, int i2) {
        showMessage(context, i2, 0);
    }

    public static void showMessage(Context context, int i2, int i3) {
        showMessage(context, context.getString(i2), i3);
    }

    public static void showMessage(Context context, String str) {
        showMessage(context, str, 0);
    }

    public static void showMessage(final Context context, final String str, final int i2) {
        new Thread(new Runnable() { // from class: com.seewo.vcommons.utils.ToastAsUserUtils.1
            @Override // java.lang.Runnable
            public void run() {
                ToastAsUserUtils.mHandler.post(new Runnable() { // from class: com.seewo.vcommons.utils.ToastAsUserUtils.1.1
                    @Override // java.lang.Runnable
                    public void run() {
                        synchronized (ToastAsUserUtils.mSyncObj) {
                            if (ToastAsUserUtils.mToast != null) {
                                if (ToastAsUserUtils.mTextView != null) {
                                    ToastAsUserUtils.mTextView.setText(str);
                                } else {
                                    ToastAsUserUtils.mToast.setText(str);
                                }
                                ToastAsUserUtils.mToast.setDuration(i2);
                            } else {
                                AnonymousClass1 anonymousClass1 = AnonymousClass1.this;
                                Toast unused = ToastAsUserUtils.mToast = ToastAsUserUtils.createToastAsUser(context, str, i2);
                            }
                            ToastAsUserUtils.mToast.show();
                        }
                    }
                });
            }
        }).start();
    }
}
