Skip input selection

Skip input selection, default to user keyboard selection (Voice/Draw/Keyboard).

Tested for Voice, keyboard, and draw.
This commit is contained in:
Hafiz 2023-05-12 08:22:05 -04:00
parent 9e0bbcd501
commit cfa6d1907a
3 changed files with 12 additions and 58 deletions

View file

@ -21,14 +21,6 @@ class InputActivity : BaseActivity<ActivityInputBinding, InputViewModel>() {
override fun onCreate(savedInstanceState: Bundle?) {
binding = ActivityInputBinding.inflate(layoutInflater)
super.onCreate(savedInstanceState)
binding.titleView.text = viewModel.title
binding.speechInput.setOnClickListener {
showSpeechInput()
}
binding.keyboardInput.setOnClickListener {
showKeyboard()
}
binding.editText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE) {
@ -38,6 +30,8 @@ class InputActivity : BaseActivity<ActivityInputBinding, InputViewModel>() {
}
false
}
showKeyboard()
}
private fun returnInput(inputString: String?) {
@ -48,28 +42,15 @@ class InputActivity : BaseActivity<ActivityInputBinding, InputViewModel>() {
}
private fun showKeyboard() {
binding.editText.hint = binding.titleView.text
binding.editText.setText(viewModel.existingInput)
binding.editText.requestFocus()
binding.editText.postDelayed(100) {
val imm: InputMethodManager =
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(binding.editText, InputMethodManager.SHOW_FORCED)
binding.editText.post {
binding.editText.setText(viewModel.existingInput)
binding.editText.requestFocus()
binding.editText.postDelayed(250) {
val imm: InputMethodManager =
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(binding.editText, InputMethodManager.SHOW_FORCED)
}
}
}
private val speechInputResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
val spokenText: String? = it.data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.firstOrNull()
returnInput(spokenText)
}
}
private fun showSpeechInput() {
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
putExtra(RecognizerIntent.EXTRA_PROMPT, binding.titleView.text)
}
speechInputResult.launch(intent)
}
}

View file

@ -9,42 +9,15 @@
android:layout_gravity="center"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/title_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
style="@style/Text.SubHeader1"
android:textColor="@color/watch_white"
android:layout_marginBottom="@dimen/spacing_large"/>
<LinearLayout
android:id="@+id/picker_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/speech_input"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_microphone"
android:tint="@color/watch_black"
android:scaleType="center"
android:background="@drawable/circle"
android:backgroundTint="@color/watch_purple_100"
android:layout_marginEnd="16dp"/>
<ImageView
android:id="@+id/keyboard_input"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_keyboard"
android:tint="@color/watch_black"
android:scaleType="center"
android:background="@drawable/circle"
android:backgroundTint="@color/watch_purple_100"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
android:visibility="visible">
<EditText
android:id="@+id/edit_text"
android:layout_width="wrap_content"

View file

@ -25,7 +25,7 @@
<string name="start_new_day">Start new day</string>
<string name="check_off_yesterday">Check off any you did yesterday:</string>
<string name="task_type">Task Type</string>
<string name="task_title_hint">Task title…</string>
<string name="task_title_hint">Enter Task Title</string>
<string name="save">Save</string>
<string name="sync_data">Sync Data</string>
<string name="hide_task_rewards">Hide task rewards</string>