diff --git a/app/build.gradle b/app/build.gradle index 4286e810..3676ac02 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0043c09e..6a937b86 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,9 +7,7 @@ - - @@ -26,7 +24,10 @@ android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/AppTheme"> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - + - - + - - + - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/simplemobiletools/flashlight/MorseFlashActivity.kt b/app/src/main/java/com/simplemobiletools/flashlight/MorseFlashActivity.kt new file mode 100644 index 00000000..87e8fe65 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/flashlight/MorseFlashActivity.kt @@ -0,0 +1,148 @@ +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) + + var _u = 200L + val MSG = arrayListOf(_u) + val editText_UserInput = findViewById(R.id.editText_UserInput) + val morseAlphabet = mapOf( + '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 "--..", + '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 "--..", + '1' to ".----", + '2' to "..---", + '3' to "...--", + '4' to "....-", + '5' to ".....", + '6' to "-....", + '7' to "--...", + '8' to "---..", + '9' to "----.", + '0' to "-----" + ) + + var resultMorseCode = " " + + val cameraManager = getSystemService(CAMERA_SERVICE) as CameraManager + val cameraId = cameraManager.cameraIdList[0] + + + btn_morseFlash.setOnClickListener{ + val text_user = editText_UserInput.text + + System.out.println("Saisie Utilisateur ====> "+ text_user) + + resultMorseCode = text_user.map { if (it == ' ') "/" else morseAlphabet[it] }.joinToString(" ") + textView_translation.setText(resultMorseCode) + + 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) + Thread.sleep(_u*7) + } + else if (resultMorseCode[i]==' '){ + cameraManager.setTorchMode(cameraId, false) + System.out.println("flash OFF") + if(resultMorseCode[i+1]!='/' && resultMorseCode[i-1]!='/'){ + Thread.sleep(_u*3) + MSG.add(_u*3) + }} + + else if (resultMorseCode[i]=='-'){ + cameraManager.setTorchMode(cameraId, true) + System.out.println("flash ON") + MSG.add(_u*3) + Thread.sleep(_u*3) + cameraManager.setTorchMode(cameraId, false) + System.out.println("flash Off") + if(i+1 " + MSG) + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt index 06594e5e..27006344 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt index 1313ed1c..2a57dd87 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt @@ -7,8 +7,10 @@ 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 @@ -16,6 +18,7 @@ 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 @@ -65,6 +68,10 @@ class MainActivity : SimpleActivity() { toggleStroboscope(true) } + morse_btn.setOnClickListener { + startActivity(Intent(applicationContext, MorseFlashActivity::class.java)) + } + stroboscope_btn.setOnClickListener { toggleStroboscope(false) } diff --git a/app/src/main/res/drawable/ic_morse_vector.xml b/app/src/main/res/drawable/ic_morse_vector.xml new file mode 100644 index 00000000..052742e9 --- /dev/null +++ b/app/src/main/res/drawable/ic_morse_vector.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1547162d..ebc79eba 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -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" /> + + + + + + + + + + + + + + + + + + + +