Giter Club home page Giter Club logo

inputmethodholder's Introduction

InputMethodHolder

A keyboard listener for Android which by hooking the InputMethodManager. Of course you can also hook the other system services similarly, If you want, create a class, make it a subclass of Hook, and using ServiceManagerHook to hook ServiceManager, learn more from InputMethodManagerHook. If you like this project, ,welcome to fork or star!

Steps:

1.Import InputMethodHodler as a library
2.Call the initialization method, the method will hook InputMethodManager, recommended to call at attachBaseContext:

public class MyApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        InputMethodHolder.init(base);
        super.attachBaseContext(base);
    }
}

3.Register the listener,and unregister when unused:

onInputMethodListener = new OnInputMethodListener() {
    @Override
	public void onShow(boolean result) {
	    Toast.makeText(MainActivity.this, "Show input method! " + result, Toast.LENGTH_SHORT).show();
	}
	@Override
	public void onHide(boolean result) {
	    Toast.makeText(MainActivity.this, "Hide input method! " + result, Toast.LENGTH_SHORT).show();
	}
};
InputMethodHolder.registerListener(onInputMethodListener);
@Override
protected void onDestroy() {
    super.onDestroy();
    InputMethodHolder.unregisterListener(onInputMethodListener);
}

4.Don't forget to release when exiting(avoid memory leaks):

InputMethodHolder.release();

Please read Sample for getting specific use, and if have any problems please submit ISSUE.

Defect

onShow works well in most situations, but onHide can only give callbacks by calling hideSoftInputFromWindows manually. The reason is that system keyboard is hold by another process, and the procedure for using the keyboard by an application is a local process remote call through InputMethodManager, the hook is just that InputMethodManager of the application's process.

public interface OnInputMethodListener {
    void onShow(boolean result);
    void onHide(boolean result);
}

Sample

Contact

[email protected]

License

Copy right 2017. Linmin qiu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

inputmethodholder's People

Contributors

pqpo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.