Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search sessions or speakers by voice-search #776

Merged
merged 9 commits into from
Feb 16, 2020
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"
Copy link
Collaborator

@jmatsu-bot jmatsu-bot Feb 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Attribute usesCleartextTraffic is only used in API level 23 and higher (current min is 21)

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/1pm-47edcdP3BYp59_cImgrvXiEOWYTxtXYUUb8CpeE8/viewform"
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>