Skip to content

Commit

Permalink
Hide keyboard when the user touches outside the etSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
wilder committed Apr 18, 2017
1 parent b1aea20 commit 8c4f5a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.jakewharton.rxbinding.widget.RxTextView
import com.kobakei.ratethisapp.RateThisApp
import com.wilderpereira.lmgtfygen.App
import com.wilderpereira.lmgtfygen.R
import com.wilderpereira.lmgtfygen.utils.UIUtils
import kotlinx.android.synthetic.main.activity_main.*
import javax.inject.Inject

Expand Down Expand Up @@ -98,6 +99,8 @@ class MainActivity : AppCompatActivity(), MainContract.View {
.subscribe { text -> presenter.updateSearchValue(text.toString(), generatedUrlTv.text)}

RxCompoundButton.checkedChanges(internetExplainerCb).subscribe{ checked -> presenter.includeInternetExplainer(checked) }

RxView.focusChanges(searchEt).subscribe{ hasFocus -> if (!hasFocus) UIUtils.hideKeyboard(this, searchEt) }
}

}
20 changes: 20 additions & 0 deletions app/src/main/java/com/wilderpereira/lmgtfygen/utils/UIUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wilderpereira.lmgtfygen.utils

import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager


/**
* Created by Wilder on 18/04/17.
*/

class UIUtils {
companion object {
fun hideKeyboard(context: Context, view: View) {
val inputMethodManager = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusableInTouchMode="true"
tools:context="com.wilderpereira.lmgtfygen.presentation.MainActivity">

<ImageView
Expand Down

0 comments on commit 8c4f5a1

Please sign in to comment.