How can I tell if the input method picker is open or closed?
Here is a small trick. Please do test it and let us know if it works.
All you have to do is make your activity extend this InputMethodActivity. When you need the user to pick input method, call pickInput(), and onInputMethodPicked() will be called when the user is done.
package mobi.sherif.inputchangecheck;
import android.os.Bundle;
import android.os.Handler;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.inputmethod.InputMethodManager;
public abstract class InputMethodActivity extends FragmentActivity {
protected abstract void onInputMethodPicked();
@Override
protected void onCreate(Bundle savedInstanceState) {
mState = NONE;
super.onCreate(savedInstanceState);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(mState == PICKING) {
mState = CHOSEN;
}
else if(mState == CHOSEN) {
onInputMethodPicked();
}
}
private static final int NONE = 0;
private static final int PICKING = 1;
private static final int CHOSEN = 2;
private int mState;
protected final void pickInput() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showInputMethodPicker();
mState = PICKING;
}
}