Skip to content

Commit

Permalink
Merge pull request #776 from imsaku/feature/voice-search
Browse files Browse the repository at this point in the history
Search sessions or speakers by voice-search
  • Loading branch information
takahirom authored Feb 16, 2020
2 parents 0b90f7d + eb532fe commit 8c1b6d7
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
6 changes: 5 additions & 1 deletion android-base/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
android:supportsRtl="false"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.DroidKaigi.DayNight">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
<nav-graph android:value="@navigation/navigation" />
</activity>
<receiver android:name=".session.broadcastreceiver.NotificationBroadcastReceiver" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ class MainActivity : AppCompatActivity(), HasAndroidInjector {
}
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
setIntent(intent)
}

companion object {
const val ENTIRE_SURVEY =
"https://docs.google.com/forms/d/e/1FAIpQLSfQHIwT0lf-20tx5xgUFSm7PPy_EjD5lI8SHuxV3DHN4D9pkA/viewform" // ktlint-disable max-line-length
Expand Down
7 changes: 7 additions & 0 deletions android-base/src/main/res/xml/searchable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:hint="@string/query_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">

</searchable>
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package io.github.droidkaigi.confsched2020.session.ui

import android.app.Activity
import android.app.SearchManager
import android.content.Intent
import android.os.Bundle
import android.speech.RecognizerIntent
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.SearchView
import androidx.core.content.getSystemService
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -65,6 +69,8 @@ class SearchSessionsFragment : Fragment(R.layout.fragment_search_sessions), Inje
@Inject
lateinit var sectionHeaderItemFactory: SectionHeaderItem.Factory

private var menu: Menu? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
Expand Down Expand Up @@ -148,22 +154,51 @@ class SearchSessionsFragment : Fragment(R.layout.fragment_search_sessions), Inje
}
}

override fun onResume() {
super.onResume()
val activity = requireActivity()
val intent = activity.intent
if (intent.action == Intent.ACTION_SEARCH &&
intent.hasExtra(RecognizerIntent.EXTRA_RESULTS)
) {
val query: String = requireNotNull(intent.getStringExtra(SearchManager.QUERY))
val searchView: SearchView? =
menu?.findItem(R.id.search_view)?.actionView as SearchView?
searchView?.setQuery(query, true)
}
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_search_sessions, menu)
this.menu = menu
val searchView = menu.findItem(R.id.search_view).actionView as SearchView
val context = requireContext()
context.getSystemService<SearchManager>()?.let { searchManager ->
searchView.setSearchableInfo(
searchManager.getSearchableInfo(requireActivity().componentName)
)
}
(searchView.findViewById(AppcompatRId.search_button) as ImageView).setColorFilter(
AppCompatResources.getColorStateList(
requireContext(),
context,
R.color.search_icon
).defaultColor
)
(searchView.findViewById(AppcompatRId.search_close_btn) as ImageView).setColorFilter(
AppCompatResources.getColorStateList(
requireContext(),
context,
R.color.search_close_icon
).defaultColor
)
val searchVoiceButton = searchView.findViewById(AppcompatRId.search_voice_btn) as ImageView
searchVoiceButton.setImageResource(R.drawable.ic_keyboard_voice_24px)
searchVoiceButton.setColorFilter(
AppCompatResources.getColorStateList(
context,
R.color.search_voice_icon
).defaultColor
)
searchView.isIconified = false
searchView.clearFocus()
val searchResult = searchSessionsViewModel.uiModel.requireValue().searchResult
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" />
</selector>
4 changes: 4 additions & 0 deletions feature/session/src/main/res/color/search_voice_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorPrimary" />
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,15c1.66,0 2.99,-1.34 2.99,-3L15,6c0,-1.66 -1.34,-3 -3,-3S9,4.34 9,6v6c0,1.66 1.34,3 3,3zM10.8,5.9c0,-0.66 0.54,-1.2 1.2,-1.2s1.2,0.54 1.2,1.2l-0.01,6.2c0,0.66 -0.53,1.2 -1.19,1.2s-1.2,-0.54 -1.2,-1.2L10.8,5.9zM17.3,12c0,3 -2.54,5.1 -5.3,5.1S6.7,15 6.7,12L5,12c0,3.41 2.72,6.23 6,6.72L11,22h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z"/>
</vector>

0 comments on commit 8c1b6d7

Please sign in to comment.