github

AzimoLabs / AndroidKeyboardWatcher

  • пятница, 25 марта 2016 г. в 02:14:42
https://github.com/AzimoLabs/AndroidKeyboardWatcher

Java
Software keyboard open/close watcher for Android.



AndroidKeyboardWatcher

Software keyboard open/close watcher for Android.

Android SDK doesn't provide direct way to track open/close events from software keyboard. This small library does it for you.

AndroidKeyboardWatcher

Usage

Make sure that you use adjustResize windowSoftInputMode in your Acitivty configuration in AndroidManifest.xml:

<activity
    android:name=".MainActivity"
    android:windowSoftInputMode="adjustResize" />

Bind KeyboardWatcher in your Activity.onCreate() method. To prevent memory leaks make sure to unbind it in onDestroy() method.

public class MainActivity extends Activity implements KeyboardWatcher.OnKeyboardToggleListener {
    private KeyboardWatcher keyboardWatcher;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //...
        keyboardWatcher = KeyboardWatcher.initWith(this).bindKeyboardWatcher(this);
    }

    @Override
    protected void onDestroy() {
        keyboardWatcher.unbindKeyboardWatcher();
        super.onDestroy();
    }

    @Override
    public void onKeyboardShown(int keyboardSize) {

    }

    @Override
    public void onKeyboardClosed() {

    }
}

Download

Java code

If you don't want to add another dependency to your project, just copy KeyboardWatcher.java to your source directory.

Library dependency

dependencies {
  compile 'com.azimolabs.keyboardwatcher:keyboardwatcher:0.1.2'
}

If you have issues with downloading it from jCenter repository please add temporary those lines to your root gradle file:

allprojects {
    repositories {
        jcenter()
        maven{ //This will get KeyboardWatcher from local bintray Maven repository
            url 'https://dl.bintray.com/azimolabs/maven'
        }
    }
}

License

Copyright (C) 2016 Azimo

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.