From 0b030331f1b8c17d67f28e7ae1a2fec35adc3ad9 Mon Sep 17 00:00:00 2001 From: Lukasz Kozakiewicz Date: Mon, 9 Apr 2018 18:04:41 +0200 Subject: [PATCH] =?UTF-8?q?Android:=20=20=20ensure=20=E2=80=9Chide=20nativ?= =?UTF-8?q?e=20keyboard=20message=E2=80=9D=20is=20sent=20only=20after=20th?= =?UTF-8?q?e=20keyboard=20was=20actually=20shown.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native/java/JuceAppActivity.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/modules/juce_core/native/java/JuceAppActivity.java b/modules/juce_core/native/java/JuceAppActivity.java index b649ef5a76..63ede84ffa 100644 --- a/modules/juce_core/native/java/JuceAppActivity.java +++ b/modules/juce_core/native/java/JuceAppActivity.java @@ -808,20 +808,38 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$ } private class TreeObserver implements ViewTreeObserver.OnGlobalLayoutListener - { + { + TreeObserver() + { + keyboardShown = false; + } + @Override public void onGlobalLayout() { Rect r = new Rect(); + + ViewGroup parentView = (ViewGroup) getParent(); + + if (parentView == null) + return; - view.getWindowVisibleDisplayFrame(r); + parentView.getWindowVisibleDisplayFrame (r); - int diff = view.getHeight() - (r.bottom - r.top); + int diff = parentView.getHeight() - (r.bottom - r.top); // Arbitrary threshold, surely keyboard would take more than 20 pix. - if (diff < 20) - handleKeyboardHidden (view.host); - }; + if (diff < 20 && keyboardShown) + { + keyboardShown = false; + handleKeyboardHidden (view.host); + } + + if (! keyboardShown && diff > 20) + keyboardShown = true; + }; + + private boolean keyboardShown; }; private ComponentPeerView view;