cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anchann <>
Subject [GitHub] cordova-plugins pull request: CB-6289 Keyboard plugin on Android
Date Wed, 14 Oct 2015 05:02:52 GMT
Github user anchann commented on the pull request:
    I just ended up implementing this by adopting the ionic version of the keyboard plugin
(which seems to be the inspiration for this PR as well). Was going to try to contribute back,
but seeing as there's already a PR for this feature, not going to. Still, I feel that my implementation
is ever so slightly cleaner, as it does not assume any keyboard size threshold, so pasting
it below in case the author wants to adopt.
    public class Keyboard extends CordovaPlugin {
    	public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    		super.initialize(cordova, webView);
    		final CordovaWebView appView = webView;
    		final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(;
    		OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
    			double heightRatioWithKeyboard = 0;
    			double heightRatioWithoutKeyboard = 0;
    			Set<Double> heightRatios = new HashSet<Double>();
    			double lastHeightRatio = 0;
    			public void onGlobalLayout() {
    				Rect r = new Rect();
    				//r will be populated with the coordinates of your view that area still visible.
    				int currTotalHeight = rootView.getRootView().getHeight();
    				int currUsableHeight = (r.bottom -;
    				double currHeightRatio = ((double)currUsableHeight) / currTotalHeight;
    				if (!heightRatios.contains(currHeightRatio)) {
    					heightRatioWithKeyboard = Collections.min(heightRatios);
    					heightRatioWithoutKeyboard = Collections.max(heightRatios);
    				if (heightRatios.size() >= 2 && currHeightRatio != lastHeightRatio) {
    					if (currHeightRatio == heightRatioWithoutKeyboard) {
    					else if (currHeightRatio == heightRatioWithKeyboard) {
    				lastHeightRatio = currHeightRatio;
    		// fire once to get the initial ratio
    	// the rest is unchanged

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message