hide the keyboard at pressing on a date or timepicker

This commit is contained in:
tibbi 2016-12-09 18:57:21 +01:00
parent 1ba39edc37
commit 2105ec3c33
2 changed files with 7 additions and 0 deletions

View File

@ -158,6 +158,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
} }
fun endCheckboxChecked(isChecked: Boolean) { fun endCheckboxChecked(isChecked: Boolean) {
hideKeyboard()
event_end_date.beVisibleIf(isChecked) event_end_date.beVisibleIf(isChecked)
event_end_time.beVisibleIf(isChecked) event_end_time.beVisibleIf(isChecked)
} }
@ -305,20 +306,24 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
} }
fun setupStartDate() { fun setupStartDate() {
hideKeyboard()
DatePickerDialog(this, mDialogTheme, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1, DatePickerDialog(this, mDialogTheme, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1,
mEventStartDateTime.dayOfMonth).show() mEventStartDateTime.dayOfMonth).show()
} }
fun setupStartTime() { fun setupStartTime() {
hideKeyboard()
TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, true).show() TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, true).show()
} }
fun setupEndDate() { fun setupEndDate() {
hideKeyboard()
DatePickerDialog(this, mDialogTheme, endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1, DatePickerDialog(this, mDialogTheme, endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1,
mEventEndDateTime.dayOfMonth).show() mEventEndDateTime.dayOfMonth).show()
} }
fun setupEndTime() { fun setupEndTime() {
hideKeyboard()
TimePickerDialog(this, mDialogTheme, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, true).show() TimePickerDialog(this, mDialogTheme, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, true).show()
} }

View File

@ -3,12 +3,14 @@ package com.simplemobiletools.calendar.extensions
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.view.View import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.EditText import android.widget.EditText
fun Activity.hideKeyboard() { fun Activity.hideKeyboard() {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow((currentFocus ?: View(this)).windowToken, 0) inputMethodManager.hideSoftInputFromWindow((currentFocus ?: View(this)).windowToken, 0)
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
} }
fun Activity.showKeyboard(et: EditText) { fun Activity.showKeyboard(et: EditText) {