Skip to content

Commit

Permalink
Dynamic logo
Browse files Browse the repository at this point in the history
  • Loading branch information
RathanakSreang committed Dec 24, 2023
1 parent 5048195 commit edb0881
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.rathanak.khmerroman.keyboard

import android.content.Context
import android.content.res.TypedArray
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.inputmethodservice.InputMethodService
Expand All @@ -12,18 +11,13 @@ import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import android.text.InputType
import android.util.Log
import android.util.SparseArray
import android.view.KeyEvent
import android.view.View
import android.view.Window
import android.view.inputmethod.*
import android.widget.LinearLayout
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.RequiresApi
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.DrawableCompat
import com.rathanak.khmerroman.R
import com.rathanak.khmerroman.data.KeyboardPreferences
import com.rathanak.khmerroman.data.KeyboardPreferences.Companion.KEY_NEEDS_RELOAD
Expand All @@ -36,7 +30,6 @@ import com.rathanak.khmerroman.keyboard.common.PageType.Companion.SHIFT
import com.rathanak.khmerroman.keyboard.common.PageType.Companion.SYMBOL
import com.rathanak.khmerroman.keyboard.common.PageType.Companion.SYMBOL_SHIFT
import com.rathanak.khmerroman.keyboard.common.Styles
import com.rathanak.khmerroman.keyboard.extensions.contains
import com.rathanak.khmerroman.keyboard.keyboardinflater.CustomKeyboard
import com.rathanak.khmerroman.keyboard.smartbar.SmartbarManager
import com.rathanak.khmerroman.keyboard.smartbar.SpellSuggestionManager
Expand Down Expand Up @@ -336,7 +329,6 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener {
renderCurrentLanguage()
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
currentInputConnection.requestCursorUpdates(InputConnection.CURSOR_UPDATE_MONITOR)
super.onStartInput(attribute, restarting)
Expand Down Expand Up @@ -375,7 +367,6 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener {
// update label on Enter key here
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onFinishInput() {
// currentInputConnection.requestCursorUpdates(0)
super.onFinishInput()
Expand All @@ -387,13 +378,13 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener {

override fun onKeyTouchDown() {
isKeyDown = true
smartbarManager.setTypeing(true)
smartbarManager.setTyping(true)
if (enableVibration) vibrate()
}

override fun onKeyTouchUp() {
isKeyDown = false
smartbarManager.setTypeing(false)
smartbarManager.setTyping(false)
}

override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
Expand Down Expand Up @@ -760,7 +751,7 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener {

private fun setPrevWord(word: String) {
previousOne = previousTwo
previousTwo = word.toLowerCase()
previousTwo = word.lowercase()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,31 @@ import com.rathanak.khmerroman.keyboard.common.Styles
import com.rathanak.khmerroman.utils.DownloadData
import com.rathanak.khmerroman.view.KhmerLangApp
import io.realm.Realm
import kotlinx.android.synthetic.main.activity_roman_mapping.*
import kotlinx.android.synthetic.main.smartbar.view.*
import kotlinx.coroutines.*

enum class SPELLCHECKER { NORMAL, TYPING, VALIDATION, NETWORK_ERROR, REACH_LIMIT_ERROR, INVALID_ERROR, OPEN_TOGGLE }

class SmartbarManager(private val r_2_khmer: R2KhmerService, private val spellSuggestionManager: SpellSuggestionManager) {
private var smartbarView: LinearLayout? = null
private var isComposingEnabled: Boolean = false
private var isDarkMood: Boolean = false
var isTyping: Boolean = false
private var isTyping: Boolean = false
var isCorrection: Boolean = true
private var suggestionJob: Job? = null
private var result: List<String> = emptyList()
private var viewState: SPELLCHECKER = SPELLCHECKER.NORMAL
private var isAppLogoOn: Boolean = true

fun createSmartbarView(): LinearLayout {
val smartbarView = View.inflate(r_2_khmer.context, R.layout.smartbar, null) as LinearLayout
this.smartbarView = smartbarView
this.smartbarView!!.btnOpenApp.setOnClickListener {
launchApp()
}
this.smartbarView!!.toggleOption!!.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
buttonView.setBackgroundResource(R.drawable.ic_btn_khmerlang)
toggleBarLayOut(true)
this.smartbarView!!.settingsList.visibility = View.GONE

if (isComposingEnabled) {
r_2_khmer.customInputMethodView?.visibility = View.VISIBLE;
spellSuggestionManager.spellSuggestionView?.visibility = View.GONE
}
} else {
checkButtonOptionsVisibility()
buttonView.setBackgroundResource(R.drawable.ic_btn_khmerlang_off_v2)
toggleBarLayOut(false)
this.smartbarView!!.settingsList.visibility = View.VISIBLE

if (isComposingEnabled) {
r_2_khmer.customInputMethodView?.visibility = View.GONE;
spellSuggestionManager.spellSuggestionView?.visibility = View.VISIBLE
}

}
this.smartbarView!!.btnAppLogo.setOnClickListener {
isAppLogoOn = !isAppLogoOn
handleBtnAppLogoClick()
}
this.smartbarView!!.btnDownloadData.setOnClickListener {
it.visibility = View.GONE
Expand Down Expand Up @@ -196,7 +180,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService, private val spellSu
this.smartbarView!!.hasDataContainer!!.visibility = View.VISIBLE
}

this.smartbarView!!.toggleOption!!.isChecked = show
isAppLogoOn = show
if(isTyping) {
return
}
Expand Down Expand Up @@ -300,6 +284,77 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService, private val spellSu
}
}

fun setTyping(typing: Boolean) {
isTyping = typing
viewState = if(isTyping) {
SPELLCHECKER.TYPING
} else {
SPELLCHECKER.NORMAL
}
updateLogoBtnImage()
}

fun destroy() {
}

private fun handleBtnAppLogoClick() {
// display gif image, typing, request_checking, error_found, no_error
if (isAppLogoOn) {
toggleBarLayOut(true)
this.smartbarView!!.settingsList.visibility = View.GONE
if (isComposingEnabled) {
r_2_khmer.customInputMethodView?.visibility = View.VISIBLE;
spellSuggestionManager.spellSuggestionView?.visibility = View.GONE
}

viewState = SPELLCHECKER.NORMAL
} else {
checkButtonOptionsVisibility()
toggleBarLayOut(false)
this.smartbarView!!.settingsList.visibility = View.VISIBLE

if (isComposingEnabled) {
r_2_khmer.customInputMethodView?.visibility = View.GONE;
spellSuggestionManager.spellSuggestionView?.visibility = View.VISIBLE
}

viewState = SPELLCHECKER.OPEN_TOGGLE
}

updateLogoBtnImage()
}
private fun updateLogoBtnImage() {
var currentIcon = R.drawable.ic_btn_khmerlang
when(viewState) {
SPELLCHECKER.TYPING -> {
currentIcon = R.drawable.btn_base_typing
}
SPELLCHECKER.VALIDATION -> {
currentIcon = R.drawable.btn_base_validation
}
SPELLCHECKER.NETWORK_ERROR -> {
currentIcon = R.drawable.btn_base_network_error
}
SPELLCHECKER.REACH_LIMIT_ERROR -> {
currentIcon = R.drawable.btn_base_react_limit
}
SPELLCHECKER.INVALID_ERROR -> {
currentIcon = R.drawable.btn_base_invalid_token
}
SPELLCHECKER.OPEN_TOGGLE -> {
currentIcon = R.drawable.ic_btn_khmerlang_off_v2
}
else -> {
currentIcon = R.drawable.ic_btn_khmerlang
}
}

Glide.with(r_2_khmer.context)
.load(currentIcon)
.error(R.drawable.ic_btn_khmerlang)
.into(this.smartbarView!!.btnAppLogo)
}

// load spell suggestion data
private suspend fun getSuggestion(prevOne: String, prevTwo: String, composingText: String, isStartSen: Boolean) {
coroutineScope {
Expand All @@ -322,7 +377,6 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService, private val spellSu
}

private suspend fun getSuggestionNext(prevOne: String, prevTwo: String) {

coroutineScope {
var realm: Realm = Realm.getInstance(KhmerLangApp.dbConfig)
try {
Expand All @@ -342,10 +396,6 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService, private val spellSu
}
}

fun setTypeing(typing: Boolean) {
isTyping = typing
}

private val candidateViewOnLongClickListener = View.OnLongClickListener { v ->
true
}
Expand Down Expand Up @@ -404,7 +454,4 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService, private val spellSu
}
}
}

fun destroy() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import java.io.IOException
import java.lang.Thread.sleep
import okhttp3.Response





class DownloadData {
fun downloadKeyboardData(isRemoveCustom: Boolean = false) {
R2KhmerService.jobLoadData = GlobalScope.launch(Dispatchers.Main) {
Expand Down
Loading

0 comments on commit edb0881

Please sign in to comment.