add match parent continue button if keyboard visible
This commit is contained in:
parent
ccdec89cdb
commit
afdb83f848
2 changed files with 34 additions and 0 deletions
|
@ -376,6 +376,8 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|center_horizontal"
|
android:layout_gravity="bottom|center_horizontal"
|
||||||
android:layout_marginBottom="@dimen/dialog_button_bottom_padding"
|
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" />
|
android:text="@string/shared_string_continue" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -16,6 +16,7 @@ import net.osmand.telegram.R
|
||||||
import net.osmand.telegram.utils.AndroidUtils
|
import net.osmand.telegram.utils.AndroidUtils
|
||||||
import studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
import studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.graphics.Rect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
@ -37,10 +38,13 @@ class LoginDialogFragment : DialogFragment() {
|
||||||
private const val SHOW_PROGRESS_PARAM_KEY = "show_progress_param"
|
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 SHOW_WELCOME_DIALOG_PARAM_KEY = "show_welcome_dialog_param"
|
||||||
private const val TELEGRAM_PACKAGE = "org.telegram.messenger"
|
private const val TELEGRAM_PACKAGE = "org.telegram.messenger"
|
||||||
|
private const val SOFT_KEYBOARD_MIN_DETECTION_SIZE = 0.15
|
||||||
|
|
||||||
var welcomeDialogShown = false
|
var welcomeDialogShown = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
private var softKeyboardShown: Boolean = false
|
||||||
|
|
||||||
fun showWelcomeDialog(fragmentManager: FragmentManager) {
|
fun showWelcomeDialog(fragmentManager: FragmentManager) {
|
||||||
welcomeDialogShown = true
|
welcomeDialogShown = true
|
||||||
showDialog(fragmentManager, welcomeDialog = true)
|
showDialog(fragmentManager, welcomeDialog = true)
|
||||||
|
@ -134,9 +138,37 @@ class LoginDialogFragment : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildDialog(view)
|
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
|
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 {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
return object : Dialog(requireActivity(), theme) {
|
return object : Dialog(requireActivity(), theme) {
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
|
Loading…
Reference in a new issue