Example usage for android.view.inputmethod InputMethodManager getClass

List of usage examples for android.view.inputmethod InputMethodManager getClass

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static void fixInputMethodManagerLeak(Context context) {
    if (context == null) {
        return;/*from  www.j a v a 2  s .  c  o m*/
    }

    try {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm == null) {
            return;
        }

        Field f_mCurRootView = imm.getClass().getDeclaredField("mCurRootView");
        Field f_mServedView = imm.getClass().getDeclaredField("mServedView");
        Field f_mNextServedView = imm.getClass().getDeclaredField("mNextServedView");

        f_mCurRootView.setAccessible(true);
        f_mCurRootView.set(imm, null);

        f_mServedView.setAccessible(true);
        f_mServedView.set(imm, null);

        f_mNextServedView.setAccessible(true);
        f_mNextServedView.set(imm, null);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.qhn.bhne.xhmusic.utils.MyUtils.java

/**
 * InputMethodManager//from   w w w  .j  a va 2  s  .  c o  m
 */
public static void fixInputMethodManagerLeak(Context destContext) {
    if (destContext == null) {
        return;
    }

    InputMethodManager imm = (InputMethodManager) destContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;
    }

    String[] arr = new String[] { "mCurRootView", "mServedView", "mNextServedView" };
    Field f;
    Object obj_get;
    for (String param : arr) {
        try {
            f = imm.getClass().getDeclaredField(param);
            if (!f.isAccessible()) {
                f.setAccessible(true);
            } // author: sodino mail:sodino@qq.com
            obj_get = f.get(imm);
            if (obj_get != null && obj_get instanceof View) {
                View v_get = (View) obj_get;
                if (v_get.getContext() == destContext) { // InputMethodManager?context??
                    f.set(imm, null); // ??path to gc
                } else {
                    // ?????????????,?for
                    /*if (QLog.isColorLevel()) {
                    QLog.d(ReflecterHelper.class.getSimpleName(), QLog.CLR, "fixInputMethodManagerLeak break, context is not suitable, get_context=" + v_get.getContext()+" dest_context=" + destContext);
                    }*/
                    break;
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java

public static void fixInputMethod(Context context) {
    if (context == null)
        return;//from   w w w .jav a 2s .co  m
    InputMethodManager inputMethodManager = null;
    try {
        inputMethodManager = (InputMethodManager) context.getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
    } catch (Throwable th) {
        th.printStackTrace();
    }
    if (inputMethodManager == null)
        return;
    String[] strArr = new String[] { "mCurRootView", "mServedView", "mNextServedView" };
    for (int i = 0; i < 3; i++) {
        try {
            Field declaredField = inputMethodManager.getClass().getDeclaredField(strArr[i]);
            if (declaredField == null)
                continue;
            if (!declaredField.isAccessible()) {
                declaredField.setAccessible(true);
            }
            Object obj = declaredField.get(inputMethodManager);
            if (obj == null || !(obj instanceof View))
                continue;
            View view = (View) obj;
            if (view.getContext() == context) {
                declaredField.set(inputMethodManager, null);
            } else {
                return;
            }
        } catch (Throwable th) {
            CrashReport.postCatchedException(th);
        }
    }
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

private static void showSoftInputUnchecked(View view, InputMethodManager imm, int flags) {
    try {/*from w  w w  .j a va2  s. c  om*/
        Method method = imm.getClass().getMethod("showSoftInputUnchecked", int.class, ResultReceiver.class);
        method.setAccessible(true);
        method.invoke(imm, flags, null);
    } catch (Exception e) {
        //Fallback to public API which hopefully does mostly the same thing
        imm.showSoftInput(view, flags);
    }
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

private static void showSoftInputUnchecked(View view, InputMethodManager imm, int flags) {
    try {//  w ww  .ja  v a 2 s .  c  o m
        Method method = imm.getClass().getMethod("showSoftInputUnchecked", int.class, ResultReceiver.class);
        method.setAccessible(true);
        method.invoke(imm, flags, null);
    } catch (Exception e) {
        // Fallback to public API which hopefully does mostly the same thing
        imm.showSoftInput(view, flags);
    }
}