Git Product home page Git Product logo

androidkeyboardwatcher's People

Contributors

frogermcs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidkeyboardwatcher's Issues

Problem when changing orientation

This problem happen when activity attribut: android:configChanges="orientation" is used in the manifest.
With this attribute set, the activity is not destroyed/recreated when we change orientation.
That mean that KeyboardWatcher is not destroyed/recreated neither.
So the initialValue is now wrong and since the detection of the presence of the keyboard is base on that, onKeyboardClosed() and onKeyboardShown() are thrown wrongly.
So it would be nice to add support for that use case, for example add a resetInitialValue method or something like that.

For now the solution I found is to destroy/recreate the KeyboardWatcher in the onConfigurationChanged method:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (mKeyboardWatcher != null) {
        mKeyboardWatcher.destroy();
        mKeyboardWatcher = new KeyboardWatcher(this);
        mKeyboardWatcher.setListener(this);
    }
}

Not static, leak free

Hello, I like where this is going. I hope these suggestions help you building a robust tool people can use:

1)

Ditch ìnitWith as it does nothing. Have a public KeyboardWatcher(Activity activity) constructor instead. The client activity will hold a reference to an instance. So you can have multiple activities using keyboard watcher at the same time. Activity will create an instance in onCreate and keep it.

2)

Use a more robust way to get the root view. android.R.id.content can change by calling Activity.setContentView(...). Activity.getWindow().getDecorView().getRootView() will not. See http://stackoverflow.com/a/11553582/2444099. Store the reference right after you get the activity in constructor.

3)

Define private final ViewTreeObserver.OnGlobalLayoutListener viewTreeObserverListener = new GlobalLayoutListener(); You can do this because rootView is resolved at the point of execution.

4)

Use weak references for activity, rootView and onKeyboardToggleListener. As soon as the activity is destroyed, you lose the references and prevent leaks.

5)

Rename bindKeyboardWatcher to setListener. Remove unbindKeyboardWatcher because setListener(null).

6)

Consider having addListener and removeListener instead of setListener.

Wrong keyboard height on device rotate

I have found issue in keyboard height calculation after device rotate.
The solution is to calculate keyboard height initialValue - rootViewRef.get().getHeight() in KeyboardWatcher.GlobalLayoutListener:onGlobalLayout() after keyboard has already finished slide from bottom animation.
I need hotfix for my project right now so I used new Handler().postDelayed(() -> {//onGlobalLayout method content//}, 1000); but there should be better solution

when the Activity Fullscreen,it doesn't work

when ths theam of activity like this "android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen",it is not work,i feel that "AndroidBug5497Workaround" will be helpful for this problem,but i failed !

the initialValue is always == rootView.get().getHeight()

if (initialValue == 0) {
initialValue = rootViewRef.get().getHeight();
} else {
if (initialValue > rootViewRef.get().getHeight()) {
if (onKeyboardToggleListenerRef.get() != null) {
if (!hasSentInitialAction || !isKeyboardShown) {
isKeyboardShown = true;
onKeyboardToggleListenerRef.get().onKeyboardShown(initialValue - rootViewRef.get().getHeight());
}
}
} else {
if (!hasSentInitialAction || isKeyboardShown) {
isKeyboardShown = false;
rootViewRef.get().post(new Runnable() {
@OverRide
public void run() {
if (onKeyboardToggleListenerRef.get() != null) {
onKeyboardToggleListenerRef.get().onKeyboardClosed();
}
}
});
}
}
hasSentInitialAction = true;
}

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.