Skip to content

Commit

Permalink
few minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danbrough committed Jan 25, 2019
1 parent b157b8c commit 92001c2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 117 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'

}
38 changes: 22 additions & 16 deletions app/src/main/java/danbroid/searchviewdemo/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity.*
import java.util.*

private val log by lazy {
org.slf4j.LoggerFactory.getLogger(BaseActivity::class.java)
}

abstract class BaseActivity : AppCompatActivity() {

Expand Down Expand Up @@ -57,21 +54,20 @@ abstract class BaseActivity : AppCompatActivity() {
}


fun addButton(title: CharSequence, onClick: () -> Unit) =
content_container.addView(

Button(this).apply {
text = title
fun addButton(title: CharSequence, onClick: () -> Unit): View =
Button(this).apply {
text = title

layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)

setOnClickListener {
onClick()
}
}
)
setOnClickListener {
onClick()
}
}.also {
content_container.addView(it)
}


fun addNote(text: String) {
Expand Down Expand Up @@ -118,6 +114,12 @@ abstract class BaseActivity : AppCompatActivity() {
closeSearchView()
}

/**
* toolbar.collapseActionView() is enough to close any expanded action view
* while content_container.requestFocus() moves the focus elsewhere so that
* no parts of the action bar become highlighted when the search view is closed
*
*/
protected fun closeSearchView() {
log.debug("closeSearchView()")
toolbar.collapseActionView()
Expand Down Expand Up @@ -160,3 +162,7 @@ abstract class BaseActivity : AppCompatActivity() {
return true
}
}

private val log =
org.slf4j.LoggerFactory.getLogger(BaseActivity::class.java)

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import android.widget.Toast
import androidx.appcompat.widget.SearchView
import danbroid.searchviewdemo.BaseActivity

private val log by lazy {
org.slf4j.LoggerFactory.getLogger(DarkDropDownActivity::class.java)
}

class DarkDropDownActivity : BaseActivity() {

Expand All @@ -30,7 +27,7 @@ class DarkDropDownActivity : BaseActivity() {

suggestions.saveRecentQuery(
suggestion,
"Love this one (DarkDropDownActivity)"
"(DarkDropDownActivity)"
)
}

Expand All @@ -41,37 +38,32 @@ class DarkDropDownActivity : BaseActivity() {

override fun configureSearchMenu(menuItem: MenuItem) {

val searchView = object : SearchView(themedContext) {

override fun dispatchKeyEventPreIme(event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_BACK &&
event.action == KeyEvent.ACTION_UP) {
log.trace("triggering action view collapse..")
onActionViewCollapsed()
clearFocus()
}
return super.dispatchKeyEventPreIme(event)
}
//Creating the search view with the themedContext to create a dark search view

}.apply {
SearchView(themedContext).apply {
setIconifiedByDefault(true)
setSearchableInfo(searchManager.getSearchableInfo(componentName))
}
isSubmitButtonEnabled = true

setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
log.trace("onQueryTextSubmit() $query")
return false
}

searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
log.trace("onQueryTextSubmit() $query")
return false
}
override fun onQueryTextChange(newText: String): Boolean {
isSubmitButtonEnabled = newText.length > 2
return false
}

override fun onQueryTextChange(query: String): Boolean {
log.trace("onQueryTextChange() $query")
return false
}
})
})
}.also {
menuItem.actionView = it
}

menuItem.actionView = searchView
}


}

private val log =
org.slf4j.LoggerFactory.getLogger(DarkDropDownActivity::class.java)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,28 @@ class LightDropDownActivity : BaseActivity() {
override fun configureSearchMenu(menuItem: MenuItem) {

//Note that we are using the activity as the context rather than the themedContext
val searchView = object : SearchView(this) {

/* override fun dispatchKeyEventPreIme(event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_BACK &&
event.action == KeyEvent.ACTION_UP) {
log.trace("triggering action view collapse..")
onActionViewCollapsed()
clearFocus()
}
return super.dispatchKeyEventPreIme(event)
}*/

}.apply {
SearchView(this).apply {
setIconifiedByDefault(true)
setSearchableInfo(searchManager.getSearchableInfo(componentName))
isSubmitButtonEnabled = true
}


searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
log.trace("onQueryTextSubmit() $query")
return false
}

override fun onQueryTextChange(newText: String): Boolean {
searchView.isSubmitButtonEnabled = newText.length > 2
return false
}
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
log.trace("onQueryTextSubmit() $query")
return false
}

})
override fun onQueryTextChange(newText: String): Boolean {
isSubmitButtonEnabled = newText.length > 2
return false
}

})
}.also {
menuItem.actionView = it
}

menuItem.actionView = searchView
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class SearchDialogActivity : BaseActivity() {
else -> super.onOptionsItemSelected(item)
}

override fun onSearchRequested(): Boolean {
log.trace("onSearchRequested()")
return super.onSearchRequested()
}

override fun startSearch(initialQuery: String?, selectInitialQuery: Boolean, appSearchData: Bundle?, globalSearch: Boolean) {
log.trace("startSearch() initalQuery: $initialQuery selectInitialQuery: $selectInitialQuery appSearchData: $appSearchData globalSearch: $globalSearch")
super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch)
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/layout/activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@

</com.google.android.material.appbar.AppBarLayout>

<com.arlib.floatingsearchview.FloatingSearchView
android:id="@+id/floating_search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:floatingSearch_leftActionMode="showHamburger"
android:fitsSystemWindows="true"
android:visibility="gone" />

<LinearLayout
android:focusable="true"
Expand Down
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.11'
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Expand Down

0 comments on commit 92001c2

Please sign in to comment.