Skip to content

Commit

Permalink
add continue input preference
Browse files Browse the repository at this point in the history
+ add back clickable in settings
  • Loading branch information
ranjanistic committed May 28, 2020
1 parent 3c66205 commit b0e6450
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 54 deletions.
63 changes: 33 additions & 30 deletions app/src/main/java/org/ranjanistic/skivvy/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.RoundedBitmapDrawable
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
import kotlinx.coroutines.delay
import org.ranjanistic.skivvy.R.drawable.*
import org.ranjanistic.skivvy.R.string.*
import org.ranjanistic.skivvy.manager.*
Expand All @@ -59,7 +58,6 @@ import java.io.FileOutputStream
import java.util.*
import java.util.concurrent.Executor
import kotlin.collections.ArrayList
import kotlin.properties.Delegates

@ExperimentalStdlibApi
open class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -202,10 +200,8 @@ open class MainActivity : AppCompatActivity() {
greet = findViewById(R.id.greeting)
backfall = findViewById(R.id.backdrop)
packages = skivvy.packageDataManager
audioManager =
applicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
wifiManager =
applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
audioManager = applicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
calculation = CalculationManager(skivvy)
greet.text = getString(app_name)
greet.setCompoundDrawablesWithIntrinsicBounds(dots_in_circle, 0, 0, 0)
Expand Down Expand Up @@ -562,15 +558,24 @@ open class MainActivity : AppCompatActivity() {
}

private fun inGlobalCommands(text: String?): Boolean {
if (!respondToCommand(text!!)) {
if (!directActions(text)) {
if (!computerOps(text)) {
if (!appOptions(text)) {
if (!respondToCommand(text!!)) { //the commands which skivvy can respond promptly and execute directly by itself.
if (!directActions(text)) { //the commands which require intrusion of other services of device, such as calling or SMS functionality.
if (!computerOps(text)) { //the commands which are mathematical in nature, performed directly by Skivvy itself.
if (!appOptions(text)) { //the commands requiring other apps or intents on the device to be opened, leaving Skivvy in the background.
speakOut(getString(recognize_error))
return false
}
} else {
if (skivvy.shouldContinueInput()) //TODO: Requiring permissions should not invoke this.
startVoiceRecIntent(
skivvy.CODE_SPEECH_RECORD,
getString(generic_voice_rec_text)
)
}
}
} else {
if (skivvy.shouldContinueInput())
startVoiceRecIntent(skivvy.CODE_SPEECH_RECORD, getString(generic_voice_rec_text))
}
return true
}
Expand Down Expand Up @@ -1103,10 +1108,8 @@ open class MainActivity : AppCompatActivity() {
private fun settingsCommand(text: String): Boolean {
val setters = arrayOf("set","change","turn","enable","disable")
if(!input.finallySaidLineFromList(text,arrayOf(setters))){
Log.d("noooooooo","not contains")
return false
}else {
Log.d("noooooooo","contains")
when {
text.contains("setup") || text.contains("set up") -> {
startActivity(Intent(context, Setup::class.java))
Expand All @@ -1117,24 +1120,6 @@ open class MainActivity : AppCompatActivity() {
skivvy.setMathsPref(logBase = base.toFloat().toInt())
speakOut("$base is the log base.")
}
text.contains("volume") -> {
volumeOps(text.replace("volume", nothing).trim())
}
text.contains("brightness") -> {
brightnessOps(text.replace("brightness", nothing).trim())
}
text == "mute" -> {
skivvy.setVoicePreference(voiceMute = true)
speakOut("Muted")
}
text == "speak" || text == "unmute" -> {
if (skivvy.getMuteStatus()) {
skivvy.setVoicePreference(voiceMute = false)
speakOut(getString(okay))
} else {
speakOut(getString(voice_output_on))
}
}
text.contains("voice authentication") -> {
return when {
text.contains("enable") && text.contains("disable") -> {
Expand Down Expand Up @@ -1268,6 +1253,24 @@ open class MainActivity : AppCompatActivity() {
val deviceNames = arrayOf("screen", "phone", "device", "system", "yourself")
if (!settingsCommand(text))
when {
text.contains("volume") -> {
volumeOps(text.replace("volume", nothing).trim())
}
text.contains("brightness") -> {
brightnessOps(text.replace("brightness", nothing).trim())
}
text == "mute" -> {
skivvy.setVoicePreference(voiceMute = true)
speakOut("Muted")
}
text == "speak" || text == "unmute" -> {
if (skivvy.getMuteStatus()) {
skivvy.setVoicePreference(voiceMute = false)
speakOut(getString(okay))
} else {
speakOut(getString(voice_output_on))
}
}
text.contains("battery level") || text.contains("battery status") || text.contains("battery") -> {
speakOut("Battery at $batteryLevel%.")
}
Expand Down
93 changes: 75 additions & 18 deletions app/src/main/java/org/ranjanistic/skivvy/Setup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Setup : AppCompatActivity() {
lateinit var handy: Switch
lateinit var onStartup: Switch
lateinit var retryFailure:Switch
lateinit var continueInput: Switch
lateinit var fullScreen: Switch
}

Expand Down Expand Up @@ -104,6 +105,7 @@ class Setup : AppCompatActivity() {
private lateinit var reveal: Animation
private lateinit var slideIn: Animation
private lateinit var slideOut: Animation
private lateinit var back: TextView
private lateinit var settingIcon: ImageView
private lateinit var noteView: TextView

Expand Down Expand Up @@ -174,6 +176,9 @@ class Setup : AppCompatActivity() {
override fun onAnimationRepeat(animation: Animation?) {
}
})
back = findViewById(R.id.goBack)
back.text = getString(R.string.back)
back.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_backarrowskivvy, 0, 0, 0)
settingIcon = findViewById(R.id.settingIcon)
noteView = findViewById(R.id.end_note)
childLayout.scrollView = findViewById(R.id.settingScrollView)
Expand All @@ -191,6 +196,7 @@ class Setup : AppCompatActivity() {
appSetup.handy = findViewById(R.id.handDirectionBtn)
appSetup.onStartup = findViewById(R.id.recordOnStart)
appSetup.retryFailure = findViewById(R.id.retryAfterFailure)
appSetup.continueInput = findViewById(R.id.continueConversation)
appSetup.fullScreen = findViewById(R.id.fullScreenMode)
notify.notifications = findViewById(R.id.showNotification)
notify.battery = findViewById(R.id.batteryStatus)
Expand Down Expand Up @@ -295,6 +301,7 @@ class Setup : AppCompatActivity() {
appSetup.handy,
appSetup.onStartup,
appSetup.retryFailure,
appSetup.continueInput,
appSetup.fullScreen,
notify.notifications,
notify.battery,
Expand All @@ -313,6 +320,7 @@ class Setup : AppCompatActivity() {
skivvy.getLeftHandy(),
skivvy.shouldListenStartup(),
skivvy.shouldRetry(),
skivvy.shouldContinueInput(),
skivvy.shouldFullScreen(),
skivvy.showNotifications(),
skivvy.readBatteryStatus(),
Expand All @@ -329,6 +337,7 @@ class Setup : AppCompatActivity() {
getString(R.string.left_handy),
getString(R.string.listen_on_click),
getString(R.string.retry_fail_on),
getString(R.string.continue_input_on),
getString(R.string.disable_full_screen),
getString(R.string.notifications_on),
getString(R.string.battery_stat_on),
Expand All @@ -345,6 +354,7 @@ class Setup : AppCompatActivity() {
getString(R.string.right_handy),
getString(R.string.listen_on_start),
getString(R.string.retry_fail_off),
getString(R.string.continue_input_off),
getString(R.string.enable_full_screen),
getString(R.string.notifications_off),
getString(R.string.battery_stat_off),
Expand Down Expand Up @@ -621,7 +631,7 @@ class Setup : AppCompatActivity() {
finish()
}
private fun setListeners() {
settingIcon.setOnClickListener {
back.setOnClickListener {
finish()
overridePendingTransition(R.anim.fade_on, R.anim.fade_off)
}
Expand Down Expand Up @@ -817,8 +827,23 @@ class Setup : AppCompatActivity() {
)
speakOut(
when (isChecked) {
true -> getString(R.string.retry_fail_on)
else -> getString(R.string.retry_fail_off)
true -> getString(R.string.ill_retry_on_fail)
else -> getString(R.string.ill_not_retry_on_fail)
}, showSnackbar = true
)
}
appSetup.continueInput.setOnCheckedChangeListener { view, isChecked ->
skivvy.setAppModePref(continueInput = isChecked)
setThumbAttrs(
view as Switch,
isChecked,
getString(R.string.continue_input_on),
getString(R.string.continue_input_off)
)
speakOut(
when (isChecked) {
true -> getString(R.string.ill_continue_listening)
else -> getString(R.string.i_not_continue_listening)
}, showSnackbar = true
)
}
Expand Down Expand Up @@ -849,8 +874,8 @@ class Setup : AppCompatActivity() {
)
speakOut(
when (isChecked) {
true -> getString(R.string.notifications_on)
else -> getString(R.string.notifications_off)
true -> getString(R.string.reading_notifications)
else -> getString(R.string.not_reading_notifications)
}, showSnackbar = true
)
} else {
Expand All @@ -871,8 +896,8 @@ class Setup : AppCompatActivity() {
)
speakOut(
when (isChecked) {
true -> getString(R.string.battery_stat_on)
else -> getString(R.string.battery_stat_off)
true -> getString(R.string.reading_battery_stat)
else -> getString(R.string.not_reading_battery_stat)
}, showSnackbar = true
)
}
Expand Down Expand Up @@ -929,7 +954,11 @@ class Setup : AppCompatActivity() {
true,
onText = getString(R.string.disable_fingerprint)
)
speakOut(getString(R.string.fingerprint_is_on))
speakOut(
getString(R.string.fingerprint_is_on),
showSnackbar = true
)

} else {
if (skivvy.getBiometricStatus()) {
if (skivvy.checkBioMetrics()) {
Expand All @@ -945,7 +974,7 @@ class Setup : AppCompatActivity() {
if (skivvy.getVoiceKeyPhrase() == null) {
speakOut(
getString(R.string.tell_new_secret_phrase),
skivvy.CODE_VOICE_AUTH_INIT
skivvy.CODE_VOICE_AUTH_INIT, showSnackbar = true
)
} else {
skivvy.setSecurityPref(vocalAuthOn = true)
Expand All @@ -955,13 +984,17 @@ class Setup : AppCompatActivity() {
onText = getString(R.string.disable_vocal_authentication)
)
setVisibilityOf(security.deleteVoiceSetup, visible = true)
speakOut(getString(R.string.vocal_auth_enabled))
speakOut(getString(R.string.vocal_auth_enabled), showSnackbar = true)
if (!skivvy.getBiometricStatus()) {
showBiometricRecommendation()
}
}
} else {
speakOut(getString(R.string.vocal_auth_disabled))
speakOut(
getString(R.string.vocal_auth_disabled),
showSnackbar = true,
isPositiveForSnackbar = false
)
defaultVoiceAuthUIState()
}
}
Expand All @@ -988,7 +1021,7 @@ class Setup : AppCompatActivity() {
}
security.deleteVoiceSetup.setOnLongClickListener { view ->
bubbleThis(view)
speakOut(getString(R.string.passphrase_to_be_deleted))
speakOut(getString(R.string.passphrase_to_be_deleted), showSnackbar = true)
true
}
special.permissions.setOnClickListener {
Expand Down Expand Up @@ -1169,15 +1202,28 @@ class Setup : AppCompatActivity() {
defaultVoiceAuthUIState()
if (text != "") {
if (text.length < 5) {
speakOut(getString(R.string.phrase_too_short), skivvy.CODE_VOICE_AUTH_INIT)
speakOut(
getString(R.string.phrase_too_short),
skivvy.CODE_VOICE_AUTH_INIT,
showSnackbar = true,
isPositiveForSnackbar = false
)
} else {
skivvy.setSecurityPref(vocalAuthPhrase = text)
speakOut(getString(R.string.confirm_phrase), skivvy.CODE_VOICE_AUTH_CONFIRM)
speakOut(
getString(R.string.confirm_phrase),
skivvy.CODE_VOICE_AUTH_CONFIRM,
showSnackbar = true
)
}
} else {
skivvy.setSecurityPref(vocalAuthPhrase = null)
defaultVoiceAuthUIState()
speakOut(getString(R.string.no_input))
speakOut(
getString(R.string.no_input),
showSnackbar = true,
isPositiveForSnackbar = false
)
return
}
}
Expand All @@ -1188,7 +1234,10 @@ class Setup : AppCompatActivity() {
security.voiceAuth.isChecked = true
skivvy.setSecurityPref(vocalAuthOn = true)
setVisibilityOf(security.deleteVoiceSetup, visible = true)
speakOut("'${skivvy.getVoiceKeyPhrase()}'" + getString(R.string._is_the_phrase))
speakOut(
"'${skivvy.getVoiceKeyPhrase()}'" + getString(R.string._is_the_phrase),
showSnackbar = true
)
if (!skivvy.getBiometricStatus() && skivvy.checkBioMetrics()) {
showBiometricRecommendation()
}
Expand Down Expand Up @@ -1299,11 +1348,19 @@ class Setup : AppCompatActivity() {
when (code) {
skivvy.CODE_VOICE_AUTH_CONFIRM -> {
skivvy.setSecurityPref(vocalAuthPhrase = null)
speakOut(getString(R.string.secret_phrase_deleted))
speakOut(
getString(R.string.secret_phrase_deleted),
showSnackbar = true,
isPositiveForSnackbar = false
)
defaultVoiceAuthUIState()
}
skivvy.CODE_BIOMETRIC_CONFIRM -> {
speakOut(getString(R.string.fingerprint_off))
speakOut(
getString(R.string.fingerprint_off),
showSnackbar = true,
isPositiveForSnackbar = false
)
skivvy.setSecurityPref(biometricOn = false)
setThumbAttrs(
security.biometrics,
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/ranjanistic/skivvy/Skivvy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Skivvy : Application() {
val PREF_KEY_HANDY = "handSide"
val PREF_KEY_START_TALK = "talkOnStart"
val PREF_KEY_RETRY_INPUT = "retryAfterFailure"
val PREF_KEY_CONTINUE_INPUT = "continueConversation"
val PREF_KEY_FULL_SCREEN = "fullscreen"

val PREF_HEAD_NOTIFICATION = "notifySetup"
Expand Down Expand Up @@ -241,6 +242,7 @@ class Skivvy : Application() {
leftHandy: Boolean? = null,
onStartListen: Boolean? = null,
onFailRetry:Boolean? = null,
continueInput: Boolean? = null,
fullScreen: Boolean? = null,
showNotification: Boolean? = null
) {
Expand All @@ -251,6 +253,7 @@ class Skivvy : Application() {
leftHandy?.let { editor.putBoolean(this.PREF_KEY_HANDY, it).apply() }
onStartListen?.let { editor.putBoolean(this.PREF_KEY_START_TALK, it).apply() }
onFailRetry?.let { editor.putBoolean(this.PREF_KEY_RETRY_INPUT, it).apply() }
continueInput?.let { editor.putBoolean(this.PREF_KEY_CONTINUE_INPUT, it).apply() }
fullScreen?.let { editor.putBoolean(this.PREF_KEY_FULL_SCREEN, it).apply() }
showNotification?.let { editor.putBoolean(this.PREF_KEY_NOTIFY, it).apply() }
}
Expand All @@ -277,6 +280,10 @@ class Skivvy : Application() {
fun shouldRetry():Boolean =
getSharedPreferences(this.PREF_HEAD_APP_SETUP, AppCompatActivity.MODE_PRIVATE)
.getBoolean(this.PREF_KEY_RETRY_INPUT, false)

fun shouldContinueInput(): Boolean =
getSharedPreferences(this.PREF_HEAD_APP_SETUP, AppCompatActivity.MODE_PRIVATE)
.getBoolean(this.PREF_KEY_CONTINUE_INPUT, false)
fun shouldFullScreen(): Boolean =
getSharedPreferences(this.PREF_HEAD_APP_SETUP, AppCompatActivity.MODE_PRIVATE)
.getBoolean(this.PREF_KEY_FULL_SCREEN, false)
Expand Down
Loading

0 comments on commit b0e6450

Please sign in to comment.