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

Play Icon When in a Command Mode #251

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/java/be/scri/helpers/MyKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ class MyKeyboard {
R.drawable.ic_arrow_right_vector
EditorInfo.IME_ACTION_SEND ->
R.drawable.ic_send_vector
MyCustomActions.IME_ACTION_COMMAND ->
R.drawable.play_button
else ->
R.drawable.ic_enter_vector
}
Expand Down Expand Up @@ -463,4 +465,8 @@ class MyKeyboard {
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
a.recycle()
}

object MyCustomActions {
const val IME_ACTION_COMMAND = 0x00000008
}
}
18 changes: 16 additions & 2 deletions app/src/main/java/be/scri/services/SimpleKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ abstract class SimpleKeyboardIME(
var isAutoSuggestEnabled: Boolean = false
var lastWord: String? = null
var autosuggestEmojis: MutableList<String>? = null
private var currentEnterKeyType: Int? = null
// abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding

protected var currentState: ScribeState = ScribeState.IDLE
Expand All @@ -87,6 +88,15 @@ abstract class SimpleKeyboardIME(
DISPLAY_INFORMATION,
}

private fun updateKeyboardMode(isCommandMode: Boolean = false) {
if (isCommandMode) {
enterKeyType = MyKeyboard.MyCustomActions.IME_ACTION_COMMAND
} else {
enterKeyType = currentEnterKeyType!!
}
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
}

fun getIsAccentCharacter(): Boolean {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_Swedish", false)
Expand Down Expand Up @@ -151,7 +161,6 @@ abstract class SimpleKeyboardIME(
updateButtonVisibility(isAutoSuggestEnabled)
updateButtonText(isAutoSuggestEnabled, autosuggestEmojis)
}

ScribeState.SELECT_COMMAND -> setupSelectCommandView()
else -> switchToToolBar()
}
Expand Down Expand Up @@ -184,6 +193,7 @@ abstract class SimpleKeyboardIME(
updateUI()
}
setInputView(keyboardHolder)
updateKeyboardMode(false)
}

private fun setupIdleView() {
Expand Down Expand Up @@ -247,17 +257,20 @@ abstract class SimpleKeyboardIME(
updateUI()
}
binding.translateBtn.setOnClickListener {
currentState = ScribeState.TRANSLATE
Log.i("MY-TAG", "TRANSLATE STATE")
updateKeyboardMode(true)
currentState = ScribeState.TRANSLATE
updateUI()
}
binding.conjugateBtn.setOnClickListener {
Log.i("MY-TAG", "CONJUGATE STATE")
updateKeyboardMode(true)
currentState = ScribeState.CONJUGATE
updateUI()
}
binding.pluralBtn.setOnClickListener {
Log.i("MY-TAG", "PLURAL STATE")
updateKeyboardMode(true)
currentState = ScribeState.PLURAL
updateUI()
}
Expand Down Expand Up @@ -391,6 +404,7 @@ abstract class SimpleKeyboardIME(

inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS
enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION)
currentEnterKeyType = enterKeyType
val inputConnection = currentInputConnection
hasTextBeforeCursor = inputConnection?.getTextBeforeCursor(1, 0)?.isNotEmpty() == true

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/play_button.xml
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:pathData="M2.883,-0.023C3.195,-0.023 3.508,-0.023 3.82,-0.023C4.293,0.094 4.746,0.273 5.18,0.516C10.617,3.641 16.055,6.766 21.492,9.891C22.098,10.262 22.512,10.785 22.734,11.461C22.895,12.18 22.738,12.82 22.266,13.383C22.035,13.645 21.777,13.871 21.492,14.063C15.883,17.305 10.258,20.523 4.617,23.719C4.348,23.813 4.082,23.898 3.82,23.977C3.508,23.977 3.195,23.977 2.883,23.977C1.938,23.684 1.383,23.043 1.219,22.055C1.164,18.695 1.141,15.336 1.148,11.977C1.141,8.617 1.164,5.258 1.219,1.898C1.383,0.91 1.938,0.27 2.883,-0.023ZM2.883,-0.023"
android:fillColor="#FFFFFFFF"/>
</vector>
Loading