From afdb83f84844094b86ad60e1bee18996d26cd5d9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 6 Jul 2018 19:15:53 +0300 Subject: [PATCH] add match parent continue button if keyboard visible --- OsmAnd-telegram/res/layout/login_dialog.xml | 2 ++ .../osmand/telegram/ui/LoginDialogFragment.kt | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/OsmAnd-telegram/res/layout/login_dialog.xml b/OsmAnd-telegram/res/layout/login_dialog.xml index f931571b73..9ecec70ff7 100644 --- a/OsmAnd-telegram/res/layout/login_dialog.xml +++ b/OsmAnd-telegram/res/layout/login_dialog.xml @@ -376,6 +376,8 @@ android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:layout_marginBottom="@dimen/dialog_button_bottom_padding" + android:layout_marginLeft="@dimen/content_padding_half" + android:layout_marginRight="@dimen/content_padding_half" android:text="@string/shared_string_continue" /> diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt index 42402e0e30..dd13f1dedf 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt @@ -16,6 +16,7 @@ import net.osmand.telegram.R import net.osmand.telegram.utils.AndroidUtils import studio.carbonylgroup.textfieldboxes.ExtendedEditText import android.content.Intent +import android.graphics.Rect import android.net.Uri import android.support.v4.content.ContextCompat import android.view.* @@ -37,10 +38,13 @@ class LoginDialogFragment : DialogFragment() { private const val SHOW_PROGRESS_PARAM_KEY = "show_progress_param" private const val SHOW_WELCOME_DIALOG_PARAM_KEY = "show_welcome_dialog_param" private const val TELEGRAM_PACKAGE = "org.telegram.messenger" + private const val SOFT_KEYBOARD_MIN_DETECTION_SIZE = 0.15 var welcomeDialogShown = false private set + private var softKeyboardShown: Boolean = false + fun showWelcomeDialog(fragmentManager: FragmentManager) { welcomeDialogShown = true showDialog(fragmentManager, welcomeDialog = true) @@ -134,9 +138,37 @@ class LoginDialogFragment : DialogFragment() { } buildDialog(view) + view.viewTreeObserver.addOnGlobalLayoutListener { + val r = Rect() + view.getWindowVisibleDisplayFrame(r) + val screenHeight = view.rootView.height + val keypadHeight = screenHeight - r.bottom + val softKeyboardVisible = keypadHeight > screenHeight * SOFT_KEYBOARD_MIN_DETECTION_SIZE + if (!softKeyboardShown && softKeyboardVisible) { + softKeyboardShown = softKeyboardVisible + setContinueButtonSize(true) + } else if (softKeyboardShown && !softKeyboardVisible) { + setContinueButtonSize(false) + } + softKeyboardShown = softKeyboardVisible + } return view } + private fun setContinueButtonSize(isWide: Boolean) { + val params = continueButton.layoutParams + if (params is ViewGroup.MarginLayoutParams) { + if (isWide) { + params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, AndroidUtils.dpToPx(context!!, 16F)) + params.width = ViewGroup.LayoutParams.MATCH_PARENT + } else { + params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, AndroidUtils.dpToPx(context!!, 40F)) + params.width = ViewGroup.LayoutParams.WRAP_CONTENT + } + continueButton.requestLayout() + } + } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return object : Dialog(requireActivity(), theme) { override fun onBackPressed() {