package com.key.vibekeyboard.utils;

import android.content.Context;
import android.provider.Settings;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;

import com.key.vibekeyboard.MyApplication;

import java.util.List;

public class InputMethodUtils {
    private static final InputMethodManager methodManager =
            (InputMethodManager) MyApplication.instance.getSystemService(Context.INPUT_METHOD_SERVICE);

    public static boolean isInputMethodEnabled() {
        List<InputMethodInfo> enabledInputMethods = methodManager.getEnabledInputMethodList();
        for (InputMethodInfo inputMethodInfo : enabledInputMethods) {
            if (inputMethodInfo.getId().startsWith(MyApplication.instance.getPackageName())) {
                return true;
            }
        }
        return false;
    }

    public static boolean isCurrentInputMethodActive() {
        String currentInputMethod = Settings.Secure.getString(MyApplication.instance.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
        return currentInputMethod != null && currentInputMethod.startsWith(MyApplication.instance.getPackageName());
    }
}

