azimolabs / androidkeyboardwatcher Goto Github PK
View Code? Open in Web Editor NEWSoftware keyboard open/close watcher for Android.
Software keyboard open/close watcher for Android.
Because fullscreen mode doesn't resize,How to solve this.. Anyone got it?
Perfectly working for android lower version than 5.0 . But not on 5.0
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);
}
}
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
.
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 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 !
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.