Skip to content

Commit f0b8397

Browse files
committed
added code to show softkeys in the mainActivity and composeActivity
1 parent 39f946b commit f0b8397

3 files changed

Lines changed: 332 additions & 0 deletions

File tree

presentation/src/main/java/com/moez/QKSMS/common/base/QkActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import android.view.WindowManager
2727
import android.widget.TextView
2828
import androidx.appcompat.app.AppCompatActivity
2929
import androidx.appcompat.widget.Toolbar
30+
import com.moez.QKSMS.common.util.KyoceraSoftkeyGuide
3031
import dev.octoshrimpy.quik.R
3132
import dev.octoshrimpy.quik.util.Preferences
3233
import io.reactivex.subjects.BehaviorSubject
@@ -41,6 +42,10 @@ abstract class QkActivity : AppCompatActivity() {
4142
protected val toolbar: Toolbar? get() = findViewById(R.id.toolbar)
4243
protected val toolbarTitle: TextView? get() = findViewById(R.id.toolbarTitle)
4344

45+
// Create an instance for Kyocera soft keys
46+
protected val softkeyGuide: KyoceraSoftkeyGuide? get() = KyoceraSoftkeyGuide.createFor(getWindow())
47+
48+
4449
@SuppressLint("InlinedApi")
4550
override fun onCreate(savedInstanceState: Bundle?) {
4651
super.onCreate(savedInstanceState)

presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import android.view.ContextMenu
4040
import android.view.DragEvent.ACTION_DRAG_ENDED
4141
import android.view.DragEvent.ACTION_DRAG_EXITED
4242
import android.view.DragEvent.ACTION_DROP
43+
import android.view.KeyEvent
4344
import android.view.Menu
4445
import android.view.MenuItem
4546
import android.view.View
@@ -52,6 +53,7 @@ import androidx.core.content.ContextCompat
5253
import androidx.core.view.isVisible
5354
import androidx.lifecycle.ViewModelProvider
5455
import androidx.lifecycle.ViewModelProviders
56+
import androidx.recyclerview.widget.LinearLayoutManager
5557
import com.google.android.flexbox.FlexboxLayoutManager
5658
import com.google.android.material.snackbar.Snackbar
5759
import com.jakewharton.rxbinding2.view.clicks
@@ -164,6 +166,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
164166

165167
private var cameraDestination: Uri? = null
166168

169+
// makes the state global so the functions for kyocera can see
170+
private var currentState: ComposeState? = null
171+
172+
167173
private fun getSeekBarUpdater(): ObservableSubscribeProxy<Long> {
168174
return Observable.interval(500, TimeUnit.MILLISECONDS)
169175
.subscribeOn(Schedulers.single())
@@ -183,6 +189,19 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
183189
showBackButton(true)
184190
viewModel.bindView(this)
185191

192+
193+
// Subscribe to message select for kyocera
194+
messageAdapter.selectionChanges
195+
.autoDisposable(scope())
196+
.subscribe { selectedIds ->
197+
softkeyMode = if (selectedIds.isEmpty())
198+
SoftkeyMode.COMPOSING
199+
else
200+
SoftkeyMode.MESSAGE_SELECTED
201+
updateSoftkeys()
202+
}
203+
204+
186205
binding.contentView.layoutTransition = LayoutTransition().apply {
187206
disableTransitionType(LayoutTransition.CHANGING)
188207
}
@@ -536,6 +555,13 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
536555
binding.speechToTextFrame.y = (binding.contentView.y + (yPercent * binding.contentView.height))
537556
}
538557
}
558+
559+
// Update Kyocera Soft keys
560+
currentState = state
561+
updateSoftkeys()
562+
563+
564+
539565
}
540566

541567
override fun clearSelection() = messageAdapter.clearSelection()
@@ -802,4 +828,156 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
802828
override fun focusMessage() {
803829
binding.message.requestFocus()
804830
}
831+
832+
833+
834+
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
835+
836+
// if ((currentState?.selectedMessages ?: 0) >= 1) {
837+
// makeToast("gaming", Toast.LENGTH_LONG)
838+
// }
839+
val s = currentState ?: return false
840+
val lm = binding.messageList.layoutManager as LinearLayoutManager
841+
842+
when (softkeyMode){
843+
SoftkeyMode.COMPOSING -> {
844+
when (keyCode){
845+
KeyEvent.KEYCODE_F1 -> {
846+
// Show Submenu
847+
val options = arrayOf(
848+
"Attach a contact",
849+
"Schedule message",
850+
"Attach any file",
851+
"Record an audio message",
852+
"Take a photo"
853+
)
854+
AlertDialog.Builder(this)
855+
.setItems(options) { _, which ->
856+
when (which) {
857+
0 -> binding.contact.performClick()
858+
859+
// 0 -> binding.gallery.performClick()
860+
1 -> binding.schedule.performClick()
861+
2 -> binding.attachAFileIcon.performClick()
862+
3 -> binding.recordAudioMsg.performClick()
863+
4 -> binding.camera.performClick()
864+
}
865+
}
866+
.show()
867+
// binding.attach.performClick()
868+
869+
// if(!binding.attach.hasFocus())
870+
// binding.attach.requestFocus()
871+
// else
872+
// binding.message.requestFocus()
873+
return true
874+
}
875+
KeyEvent.KEYCODE_F2 -> {
876+
// Send Text
877+
if(currentState?.canSend == true)
878+
binding.send.performClick()
879+
return true
880+
}
881+
KeyEvent.KEYCODE_F3 -> {
882+
// Show info
883+
// Page down (jump by N items)
884+
val current = lm.findLastVisibleItemPosition()
885+
binding.messageList.scrollToPosition(minOf(current + 5, messageAdapter.itemCount - 1))
886+
return true
887+
}
888+
KeyEvent.KEYCODE_F4 -> {
889+
// cancel selection
890+
val current = lm.findFirstVisibleItemPosition()
891+
binding.messageList.scrollToPosition(maxOf(current - 5, 0))
892+
return true
893+
}
894+
}
895+
}
896+
897+
898+
// When A message[s] is selected
899+
SoftkeyMode.MESSAGE_SELECTED -> when (keyCode) {
900+
// KeyEvent.KEYCODE_DPAD_CENTER -> {
901+
// return true
902+
// }
903+
KeyEvent.KEYCODE_F1 -> {
904+
// makeToast("Details: "+s.canSend, Toast.LENGTH_SHORT)
905+
// messageAdapter.reactionClicks.
906+
// optionsItemIntent.onNext(R.id.info)
907+
return true
908+
}
909+
KeyEvent.KEYCODE_F2 -> {
910+
// makeToast("delete", Toast.LENGTH_SHORT)
911+
optionsItemIntent.onNext(R.id.details)
912+
return true
913+
}
914+
KeyEvent.KEYCODE_F3 -> {
915+
// Show info
916+
makeToast("Copied", Toast.LENGTH_SHORT)
917+
optionsItemIntent.onNext(R.id.copy)
918+
// binding.message.requestFocus()
919+
return true
920+
}
921+
KeyEvent.KEYCODE_F4 -> {
922+
// cancel selection
923+
// makeToast("more", Toast.LENGTH_SHORT)
924+
optionsItemIntent.onNext(R.id.delete)
925+
return true
926+
}
927+
}
928+
929+
}
930+
return super.onKeyDown(keyCode, event)
931+
}
932+
933+
934+
935+
/**
936+
* Kyocera soft keys testing
937+
*/
938+
private enum class SoftkeyMode {
939+
COMPOSING, // default, typing a message
940+
MESSAGE_SELECTED // one or more bubbles selected
941+
}
942+
943+
private var softkeyMode = SoftkeyMode.COMPOSING
944+
945+
private fun updateSoftkeys() {
946+
947+
val s = currentState ?: return
948+
949+
when (softkeyMode) {
950+
951+
SoftkeyMode.COMPOSING -> {
952+
softkeyGuide?.apply {
953+
setText(1, "Submenu")
954+
setText(2, "Send")
955+
setText(3, "")
956+
setText(4, "")
957+
setEnabled(0, true)
958+
setEnabled(2, s.canSend)
959+
setEnabled(3, true)
960+
setEnabled(4, true)
961+
}
962+
}
963+
964+
SoftkeyMode.MESSAGE_SELECTED -> {
965+
softkeyGuide?.apply {
966+
setText(1, "Info")
967+
setText(2, "Details")
968+
setText(3, "Copy")
969+
setText(4, "Delete")
970+
setEnabled(1, true)
971+
setEnabled(2, (s.selectedMessages ?: 0) == 1)
972+
setEnabled(3, true)
973+
setEnabled(4, true)
974+
}
975+
}
976+
}
977+
// Update the Kyocera's keys
978+
softkeyGuide?.invalidate()
979+
980+
}
981+
982+
805983
}

0 commit comments

Comments
 (0)