Merge branch 'feature/VNQ-6757-keyboard-height' into 'master'

[VNQ-6757] New way to get keyboard height

See merge request qt/qtandroidextensions!85
parents 144f79b5 73a79d15
......@@ -52,6 +52,11 @@ Q_DECL_EXPORT void JNICALL Java_ScreenLayoutHandler_scrollChanged(JNIEnv *, jobj
obj->javaScrollChanged();
}
Q_DECL_EXPORT void JNICALL Java_ScreenLayoutHandler_keyboardHeightChanged(JNIEnv *, jobject, jlong param, jint height)
{
JNI_LINKER_OBJECT(QAndroidScreenLayoutHandler, param, obj)
obj->javaKeyboardHeightChanged(height);
}
static const char * const c_full_class_name_ = "ru/dublgis/androidhelpers/ScreenLayoutHandler";
......@@ -59,6 +64,7 @@ static const JNINativeMethod methods[] = {
{"getActivity", "()Landroid/app/Activity;", reinterpret_cast<void*>(QAndroidQPAPluginGap::getActivityNoThrow)},
{"nativeGlobalLayoutChanged", "(J)V", reinterpret_cast<void*>(Java_ScreenLayoutHandler_globalLayoutChanged)},
{"nativeScrollChanged", "(J)V", reinterpret_cast<void*>(Java_ScreenLayoutHandler_scrollChanged)},
{"nativeKeyboardHeightChanged", "(JI)V", reinterpret_cast<void*>(Java_ScreenLayoutHandler_keyboardHeightChanged)},
};
......@@ -105,3 +111,9 @@ void QAndroidScreenLayoutHandler::javaScrollChanged()
{
emit scrollChanged();
}
void QAndroidScreenLayoutHandler::javaKeyboardHeightChanged(int height)
{
emit keyboardHeightChanged(height);
}
......@@ -71,13 +71,16 @@ signals:
void globalLayoutChanged();
void scrollChanged();
void keyboardHeightChanged(int height);
private:
void javaGlobalLayoutChanged();
void javaScrollChanged();
void javaKeyboardHeightChanged(int height);
private:
Q_DISABLE_COPY(QAndroidScreenLayoutHandler)
friend void JNICALL Java_ScreenLayoutHandler_globalLayoutChanged(JNIEnv *, jobject, jlong param);
friend void JNICALL Java_ScreenLayoutHandler_scrollChanged(JNIEnv *, jobject, jlong param);
friend void JNICALL Java_ScreenLayoutHandler_keyboardHeightChanged(JNIEnv *, jobject, jlong param, jint height);
};
/*
Offscreen Android Views library for Qt
Author:
Timur N. Artikov <t.artikov@gmail.com>
Distrbuted under The BSD License
Copyright (c) 2018, DoubleGIS, LLC.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the DoubleGIS, LLC nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
package ru.dublgis.androidhelpers;
public interface KeyboardHeightObserver
{
void onKeyboardHeightChanged(int height);
}
/*
Offscreen Android Views library for Qt
Author:
Timur N. Artikov <t.artikov@gmail.com>
Distrbuted under The BSD License
Copyright (c) 2018, DoubleGIS, LLC.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the DoubleGIS, LLC nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
package ru.dublgis.androidhelpers;
import android.app.Activity;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager.LayoutParams;
import android.widget.PopupWindow;
/*
The keyboard height provider.
It uses a PopupWindow to calculate the window height when the floating keyboard is opened and closed.
*/
public class KeyboardHeightProvider
extends PopupWindow
implements ViewTreeObserver.OnGlobalLayoutListener
{
public static final String TAG = "Grym/KeyboardHeightProvider";
private KeyboardHeightObserver mObserver;
private View mPopupView;
private Activity mActivity;
public KeyboardHeightProvider(Activity activity, View parentView, KeyboardHeightObserver observer)
{
super(activity);
try
{
mActivity = activity;
mObserver = observer;
mPopupView = new View(activity);
mPopupView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(mPopupView);
setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_RESIZE | LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
setWidth(0);
setHeight(LayoutParams.MATCH_PARENT);
mPopupView.getViewTreeObserver().addOnGlobalLayoutListener(this);
showAtLocation(parentView, Gravity.NO_GRAVITY, 0, 0);
}
catch (final Throwable e)
{
Log.e(TAG, "constructor exception: " + e);
}
}
public void stop()
{
try
{
mPopupView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
dismiss();
}
catch (final Throwable e)
{
Log.e(TAG, "stop exception: " + e);
}
}
@Override
public void onGlobalLayout()
{
try
{
Point screenSize = new Point();
mActivity.getWindowManager().getDefaultDisplay().getSize(screenSize);
Rect rect = new Rect();
mPopupView.getWindowVisibleDisplayFrame(rect);
int keyboardHeight = screenSize.y - rect.bottom;
mObserver.onKeyboardHeightChanged(keyboardHeight);
}
catch (final Throwable e)
{
Log.e(TAG, "onGlobalLayout exception: " + e);
}
}
}
......@@ -42,10 +42,14 @@ import android.view.ViewTreeObserver;
import android.view.Window;
public class ScreenLayoutHandler implements ViewTreeObserver.OnGlobalLayoutListener, ViewTreeObserver.OnScrollChangedListener
public class ScreenLayoutHandler implements
ViewTreeObserver.OnGlobalLayoutListener,
ViewTreeObserver.OnScrollChangedListener,
KeyboardHeightObserver
{
public static final String TAG = "Grym/ScrnLayoutHandler";
private volatile long native_ptr_ = 0;
private KeyboardHeightProvider mKeyboardHeightProvider;
public ScreenLayoutHandler(long native_ptr)
{
......@@ -74,6 +78,10 @@ public class ScreenLayoutHandler implements ViewTreeObserver.OnGlobalLayoutListe
{
view.getViewTreeObserver().addOnGlobalLayoutListener(ScreenLayoutHandler.this);
view.getViewTreeObserver().addOnScrollChangedListener(ScreenLayoutHandler.this);
if (mKeyboardHeightProvider == null)
{
mKeyboardHeightProvider = new KeyboardHeightProvider(getActivity(), view, ScreenLayoutHandler.this);
}
}
catch (Exception e)
{
......@@ -97,6 +105,11 @@ public class ScreenLayoutHandler implements ViewTreeObserver.OnGlobalLayoutListe
{
view.getViewTreeObserver().removeOnGlobalLayoutListener(ScreenLayoutHandler.this);
view.getViewTreeObserver().removeOnScrollChangedListener(ScreenLayoutHandler.this);
if (mKeyboardHeightProvider != null)
{
mKeyboardHeightProvider.stop();
mKeyboardHeightProvider = null;
}
}
catch (Exception e)
{
......@@ -119,6 +132,12 @@ public class ScreenLayoutHandler implements ViewTreeObserver.OnGlobalLayoutListe
nativeScrollChanged(native_ptr_);
}
@Override
public void onKeyboardHeightChanged(int height)
{
nativeKeyboardHeightChanged(native_ptr_, height);
}
private View getDecorView()
{
final Activity context = getActivity();
......@@ -164,4 +183,5 @@ public class ScreenLayoutHandler implements ViewTreeObserver.OnGlobalLayoutListe
public native Activity getActivity();
public native void nativeGlobalLayoutChanged(long nativeptr);
public native void nativeScrollChanged(long nativeptr);
public native void nativeKeyboardHeightChanged(long nativeptr, int height);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment