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

add of morse code entry in the flashlight #192

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:8bcb4d3851'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.4.0'
}
399 changes: 187 additions & 212 deletions app/src/main/AndroidManifest.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
package com.simplemobiletools.flashlight

import android.hardware.camera2.CameraManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.EditText
import kotlinx.android.synthetic.main.activity_morse_flash.*

class MorseFlashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_morse_flash)

/*
bsae19 marked this conversation as resolved.
Show resolved Hide resolved
u = 200L
DEFAULT LENGTH DASH = u * 3 ---> delai 3 pour un -
DEFAULT DELAY LETTERS = u * 3 ---> delai 3 entre les lettres
DEFAULT DELAY WORDS = u * 7 ---> delai entre les mots

u = .(point) après u = pause u*3= pause entre les lettre après u*3 = - (tiret)

. . . - - - . . .
SOS = arrayListOf(u, u, u, u, u, u * 3, u * 3, u, u * 3, u, u * 3, u * 3, u, u, u, u, u, u * 7)
p p ! p p ! p p pause entre les mots
V V
pause entre les lettres pause entre les lettres


pl = pause entre les lettres
pm = pause entre les mots
. p . p . pl - p - p - pl . p . p . pm
MSG FLASH ====> [200, 200, 200, 200, 200, 600, 600, 200, 600, 200, 600, 600, 200, 200, 200, 200, 200, 1400]
*/

var _u = 200L // DEFAULT LENGTH ONE UNIT MILLISECONDS
val MSG = arrayListOf(_u) // Futur message flashing morse code

val editText_UserInput = findViewById<EditText>(R.id.editText_UserInput)

// for morse translator . and -
val morseAlphabet = mapOf(
// letters lowercase
'a' to ".-",
'b' to "-...",
'c' to "-.-.",
'd' to "-..",
'e' to ".",
'f' to "..-.",
'g' to "--.",
'h' to "....",
'i' to "..",
'j' to ".---",
'k' to "-.-",
'l' to ".-..",
'm' to "--",
'n' to "-.",
'o' to "---",
'p' to ".--.",
'q' to "--.-",
'r' to ".-.",
's' to "...",
't' to "-",
'u' to "..-",
'v' to "...-",
'w' to ".--",
'x' to "-..-",
'y' to "-.--",
'z' to "--..",
// letters uppercase
'A' to ".-",
'B' to "-...",
'C' to "-.-.",
'D' to "-..",
'E' to ".",
'F' to "..-.",
'G' to "--.",
'H' to "....",
'I' to "..",
'J' to ".---",
'K' to "-.-",
'L' to ".-..",
'M' to "--",
'N' to "-.",
'O' to "---",
'P' to ".--.",
'Q' to "--.-",
'R' to ".-.",
'S' to "...",
'T' to "-",
'U' to "..-",
'V' to "...-",
'W' to ".--",
'X' to "-..-",
'Y' to "-.--",
'Z' to "--..",
// numbers
'1' to ".----",
'2' to "..---",
'3' to "...--",
'4' to "....-",
'5' to ".....",
'6' to "-....",
'7' to "--...",
'8' to "---..",
'9' to "----.",
'0' to "-----"
)

var resultMorseCode = " " // futur result of translation

val cameraManager = getSystemService(CAMERA_SERVICE) as CameraManager
val cameraId = cameraManager.cameraIdList[0]


btn_morseFlash.setOnClickListener{
val text_user = editText_UserInput.text //get text of input

System.out.println("Saisie Utilisateur ====> "+ text_user)

resultMorseCode = text_user.map { if (it == ' ') "/" else morseAlphabet[it] }.joinToString(" ")
textView_translation.setText(resultMorseCode) // set the result of translation on TextView

System.out.println("Traduction MORSE ====> "+ resultMorseCode)

MSG.clear()

System.out.println("MSG vide ====> " + MSG)

for (i in resultMorseCode.indices) {
if (resultMorseCode[i] == '/'){
cameraManager.setTorchMode(cameraId, false)
System.out.println("flash OFF")
MSG.add(_u*7) // DEFAULT DELAY WORDS = u * 7 // flash OFF
Thread.sleep(_u*7)
}
else if (resultMorseCode[i]==' '){
cameraManager.setTorchMode(cameraId, false)
System.out.println("flash OFF")
if(resultMorseCode[i+1]!='/' && resultMorseCode[i-1]!='/'){// flash OFF
Thread.sleep(_u*3)
MSG.add(_u*3) // DEFAULT DELAY LETTERS = u * 3
}}

else if (resultMorseCode[i]=='-'){
cameraManager.setTorchMode(cameraId, true) // flash ON
System.out.println("flash ON")
MSG.add(_u*3) // DEFAULT LENGTH DASH = u * 3
Thread.sleep(_u*3)
cameraManager.setTorchMode(cameraId, false)
System.out.println("flash Off")
if(i+1<resultMorseCode.length){
if(resultMorseCode[i+1]!=' '){ // flash OFF
Thread.sleep(_u)
MSG.add(_u)
}}}

else if (resultMorseCode[i]=='.'){
cameraManager.setTorchMode(cameraId, true) // flash ON
System.out.println("flash ON")
MSG.add(_u)
Thread.sleep(_u)
cameraManager.setTorchMode(cameraId, false)
System.out.println("flash OFF")
if(i+1<resultMorseCode.length){
if(resultMorseCode[i+1]!=' '){
Thread.sleep(_u)
MSG.add(_u) // DEFAULT DELAY light off in a letter = u * 3
}}}
}
MSG.removeLast()
MSG.add(_u*7)
System.out.println("MESSAGE FLASH ====> " + MSG)
}
}
}

//Je pense que c'est correct , mais reste à etre améliorer le flash marche sur mon téléphone
//on supprimera les commentaires par la suite
//I think it's correct , but still have to be improved the flash works correctly on my phone
//comments will be deleted later.

/* OUTPUT CONSOLE ==> FOR SOS MESSAGE
I/System.out: Saisie Utilisateur ====> sos
I/System.out: Traduction MORSE ====> ... --- ...
I/System.out: MSG vide ====> []
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: MESSAGE FLASH ====> [200, 200, 200, 200, 200, 600, 600, 200, 600, 200, 600, 600, 200, 200, 200, 200, 200, 1400]


Je pense que c'est correct , mais reste à etre améliorer le flash marche sur mon téléphone
I think it's correct , but still have to be improved the flash works correctly on my phone

*/

/* OUTPUT CONSOLE FOR MESSAGE ==> test sos (same TEST SOS)

I/System.out: Saisie Utilisateur ====> test sos
I/System.out: Traduction MORSE ====> - . ... - / ... --- ...
I/System.out: MSG vide ====> []
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: flash ON
I/System.out: flash OFF
I/System.out: MESSAGE FLASH ====> [600, 600, 200, 600, 200, 200, 200, 200, 200, 600, 600, 600, 600, 200, 200, 200, 200, 200, 600, 600, 200, 600, 200, 600, 600, 200, 200, 200, 200, 200, 1400]

*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simplemobiletools.flashlight.activities

import android.content.pm.ActivityInfo
import android.graphics.drawable.ColorDrawable
import android.hardware.camera2.CameraManager
import android.os.Bundle
import android.view.WindowManager
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import android.content.pm.ShortcutInfo
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import com.google.android.material.snackbar.Snackbar
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LICENSE_EVENT_BUS
import com.simplemobiletools.commons.helpers.PERMISSION_CAMERA
import com.simplemobiletools.commons.helpers.isNougatMR1Plus
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.flashlight.BuildConfig
import com.simplemobiletools.flashlight.MorseFlashActivity
import com.simplemobiletools.flashlight.R
import com.simplemobiletools.flashlight.extensions.config
import com.simplemobiletools.flashlight.helpers.CameraTorchListener
Expand Down Expand Up @@ -65,6 +68,10 @@ class MainActivity : SimpleActivity() {
toggleStroboscope(true)
}

morse_btn.setOnClickListener {
startActivity(Intent(applicationContext, MorseFlashActivity::class.java))
}

stroboscope_btn.setOnClickListener {
toggleStroboscope(false)
}
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/res/drawable/ic_morse_vector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"

android:width="192dp"
android:height="192dp"
android:viewportWidth="512"
android:viewportHeight="512"
>
<path
android:pathData="M417.13,0H94.87C51.44,0 16.11,35.33 16.11,78.76V347.25c0,43.43 35.33,78.76 78.76,78.76h53.38l94.45,81.07c7.65,6.57 18.94,6.56 26.59,0l94.45,-81.07h53.38c43.43,0 78.76,-35.33 78.76,-78.76V78.76C495.89,35.33 460.56,0 417.13,0zM256,464.68l-45.06,-38.68h90.12L256,464.68zM455.06,347.25c0,20.91 -17.01,37.93 -37.93,37.93c-11.97,0 -303.03,0 -322.27,0c-20.91,0 -37.93,-17.01 -37.93,-37.93V78.76C56.94,57.84 73.96,40.83 94.87,40.83h322.27c20.91,0 37.93,17.01 37.93,37.93V347.25z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M391.11,105.44H256c-11.27,0 -20.42,9.14 -20.42,20.42s9.14,20.42 20.42,20.42h135.12c11.27,0 20.42,-9.14 20.42,-20.42C411.53,114.58 402.39,105.44 391.11,105.44z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M118.88,146.17c1.42,0.14 2.59,0.15 4.01,0c10.67,-1.11 18.4,-9.98 18.4,-20.31c0,-10.27 -7.66,-19.19 -18.4,-20.32c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32C100.47,136 108.09,145.07 118.88,146.17z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M256.01,279.73H120.89c-11.27,0 -20.42,9.14 -20.42,20.42s9.14,20.42 20.42,20.42h135.12c11.27,0 20.42,-9.14 20.42,-20.42S267.28,279.73 256.01,279.73z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M186.45,146.17c1.42,0.14 2.59,0.15 4.01,0c10.67,-1.11 18.4,-9.98 18.4,-20.31c0,-10.27 -7.66,-19.19 -18.4,-20.32c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32C168.03,136 175.66,145.07 186.45,146.17z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M118.88,233.31c1.42,0.14 2.59,0.15 4.01,0c10.67,-1.11 18.4,-9.98 18.4,-20.31c0,-10.27 -7.66,-19.19 -18.4,-20.32c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32C100.47,223.14 108.09,232.22 118.88,233.31z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M258.02,233.31c10.67,-1.11 18.4,-9.98 18.4,-20.31c0,-10.27 -7.66,-19.19 -18.4,-20.32c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32c0,10.13 7.63,19.21 18.41,20.31C255.43,233.46 256.59,233.46 258.02,233.31z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M393.13,192.69c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32c0,10.13 7.63,19.21 18.41,20.31c1.42,0.14 2.59,0.15 4.01,0c10.67,-1.11 18.4,-9.98 18.4,-20.31C411.53,202.74 403.87,193.81 393.13,192.69z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M393.13,279.83c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32c0,10.13 7.63,19.21 18.41,20.31c1.42,0.14 2.59,0.15 4.01,0c10.67,-1.11 18.4,-9.98 18.4,-20.31C411.53,289.88 403.87,280.96 393.13,279.83z"
android:fillColor="#FFFFFFFF"/>
<path
android:pathData="M326.06,279.83c-1.33,-0.14 -2.68,-0.14 -4.01,0c-10.8,1.11 -18.41,10.18 -18.41,20.32c0,10.13 7.63,19.21 18.41,20.31c1.42,0.14 2.59,0.15 4.01,0c10.67,-1.11 18.4,-9.98 18.4,-20.31C344.46,289.88 336.81,280.96 326.06,279.83z"
android:fillColor="#FFFFFFFF"/>
</vector>
17 changes: 16 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,23 @@
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/stroboscope_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_bias="0.379"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bright_display_btn" />

<ImageView
android:id="@+id/morse_btn"
android:layout_width="@dimen/smaller_button_size"
android:layout_height="@dimen/smaller_button_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.25"
app:layout_constraintStart_toEndOf="@+id/sos_btn"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.628"
app:srcCompat="@drawable/ic_morse_vector" />


<ImageView
android:id="@+id/stroboscope_btn"
android:layout_width="@dimen/smaller_button_size"
Expand All @@ -83,6 +96,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sos_btn" />



<com.simplemobiletools.commons.views.MySeekBar
android:id="@+id/stroboscope_bar"
android:layout_width="@dimen/seekbar_width"
Expand Down
Loading