diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 0000000..2e2f323
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,54 @@
+name: "CodeQL"
+
+on:
+ push:
+ branches: [development, master]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [development]
+ schedule:
+ - cron: '0 12 * * 0'
+
+jobs:
+ analyse:
+ name: Analyse
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ # We must fetch at least the immediate parents so that if this is
+ # a pull request then we can checkout the head.
+ fetch-depth: 2
+
+ # If this run was triggered by a pull request event, then checkout
+ # the head of the pull request instead of the merge commit.
+ - run: git checkout HEAD^2
+ if: ${{ github.event_name == 'pull_request' }}
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ # Override language selection by uncommenting this and choosing your languages
+ # with:
+ # languages: go, javascript, csharp, python, cpp, java
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v1
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 https://git.io/JvXDl
+
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 674414f..41871c2 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -15,6 +15,7 @@
+
diff --git a/README.md b/README.md
index d8630b5..2ccc288 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
[![Last commit](https://img.shields.io/github/last-commit/Crazy-Marvin/Morse.svg?style=flat)](https://github.com/Crazy-Marvin/Morse/commits)
[![Releases](https://img.shields.io/github/downloads/Crazy-Marvin/Morse/total.svg?style=flat)](https://github.com/Crazy-Marvin/Morse/releases)
[![Latest tag](https://img.shields.io/github/tag/Crazy-Marvin/Morse.svg?style=flat)](https://github.com/Crazy-Marvin/Morse/tags)
-[![Issues](https://img.shields.io/github/issues/Crazy-Marvin/MetadataRemover.svg?style=flat)](https://github.com/Crazy-Marvin/Morse/issues)
+[![Issues](https://img.shields.io/github/issues/Crazy-Marvin/Morse.svg?style=flat)](https://github.com/Crazy-Marvin/Morse/issues)
[![Pull requests](https://img.shields.io/github/issues-pr/Crazy-Marvin/Morse.svg?style=flat)](https://github.com/Crazy-Marvin/Morse/pulls)
[![Codacy](https://api.codacy.com/project/badge/Grade/49d72132eca54aa9b68056d3dce5c019)](https://www.codacy.com/app/CrazyMarvin/Morse?utm_source=github.com&utm_medium=referral&utm_content=Crazy-Marvin/Morse&utm_campaign=Badge_Grade)
[![codecov](https://codecov.io/gh/Crazy-Marvin/Morse/branch/master/graph/badge.svg)](https://codecov.io/gh/Crazy-Marvin/Morse)
diff --git a/app/build.gradle b/app/build.gradle
index 01e741a..8be325b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 29
+ compileSdkVersion 30
defaultConfig {
applicationId "rocks.poopjournal.morse"
minSdkVersion 19
- targetSdkVersion 29
- versionCode 5
- versionName "1.5"
+ targetSdkVersion 30
+ versionCode 7
+ versionName "1.6"
}
buildTypes {
@@ -29,7 +29,7 @@ android {
}
dependencies {
- implementation 'androidx.appcompat:appcompat:1.1.0'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
- implementation 'com.google.android.material:material:1.1.0'
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+ implementation 'com.google.android.material:material:1.3.0'
}
diff --git a/app/src/main/java/rocks/poopjournal/morse/LoopMediaPlayer.java b/app/src/main/java/rocks/poopjournal/morse/LoopMediaPlayer.java
new file mode 100644
index 0000000..48f35e0
--- /dev/null
+++ b/app/src/main/java/rocks/poopjournal/morse/LoopMediaPlayer.java
@@ -0,0 +1,60 @@
+package rocks.poopjournal.morse;
+
+import android.content.Context;
+import android.media.MediaPlayer;
+import android.util.Log;
+
+public class LoopMediaPlayer {
+
+ public static final String TAG = LoopMediaPlayer.class.getSimpleName();
+
+ private Context mContext = null;
+ private int mResId = 0;
+ private int mCounter = 1;
+
+ private MediaPlayer mCurrentPlayer = null;
+ private MediaPlayer mNextPlayer = null;
+
+ public static LoopMediaPlayer create(Context context, int resId) {
+ return new LoopMediaPlayer(context, resId);
+ }
+
+ private LoopMediaPlayer(Context context, int resId) {
+ mContext = context;
+ mResId = resId;
+
+ mCurrentPlayer = MediaPlayer.create(mContext, mResId);
+ mCurrentPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+ @Override
+ public void onPrepared(MediaPlayer mediaPlayer) {
+ mCurrentPlayer.start();
+ }
+ });
+
+ createNextMediaPlayer();
+ }
+
+ private void createNextMediaPlayer() {
+ mNextPlayer = MediaPlayer.create(mContext, mResId);
+ mCurrentPlayer.setNextMediaPlayer(mNextPlayer);
+ mCurrentPlayer.setOnCompletionListener(onCompletionListener);
+ }
+
+ private MediaPlayer.OnCompletionListener onCompletionListener = new MediaPlayer.OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer mediaPlayer) {
+ mediaPlayer.release();
+ mCurrentPlayer = mNextPlayer;
+
+ createNextMediaPlayer();
+
+ Log.d(TAG, String.format("Loop #%d", ++mCounter));
+ }
+ };
+
+ public void stopPlayers(){
+ if (mCurrentPlayer.isPlaying()){
+ mCurrentPlayer.stop();
+ }
+ }
+}
diff --git a/app/src/main/java/rocks/poopjournal/morse/MainActivity.java b/app/src/main/java/rocks/poopjournal/morse/MainActivity.java
index 7c9d2e3..0fa7e4f 100644
--- a/app/src/main/java/rocks/poopjournal/morse/MainActivity.java
+++ b/app/src/main/java/rocks/poopjournal/morse/MainActivity.java
@@ -1,6 +1,7 @@
package rocks.poopjournal.morse;
import android.Manifest;
+import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
@@ -9,15 +10,19 @@
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
+import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
import android.hardware.Camera;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Looper;
import android.os.SystemClock;
import android.text.Editable;
import android.text.SpannableStringBuilder;
@@ -27,6 +32,7 @@
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.Log;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@@ -71,6 +77,12 @@ public class MainActivity extends AppCompatActivity implements Camera.AutoFocusC
RelativeLayout space;
RelativeLayout makeInputVisible;
RelativeLayout backspace;
+ RelativeLayout containerTools;
+ RelativeLayout telegraphContainer;
+ RelativeLayout telegraphAudio;
+ RelativeLayout telegraphFlash;
+ RelativeLayout telegraphKey;
+ ImageView telegraphKeyboard,telegraphFlashIV, telegraphAudioIV;
boolean visibilityCheck = false;
ArrayList popularMorse = new ArrayList<>();
HashMap popularMorseConversion = new HashMap<>();
@@ -79,6 +91,9 @@ public class MainActivity extends AppCompatActivity implements Camera.AutoFocusC
DBHelper helper;
ImageView star;
ArrayList arrayList;
+ private int telegraphSelected = 1;
+ MediaPlayer telegraphPlayer = null;
+ long time =0;
ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
@@ -325,6 +340,7 @@ static String morseDecode(String morse) {
return "";
}
+ @SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -345,6 +361,14 @@ protected void onCreate(Bundle savedInstanceState) {
sound = findViewById(R.id.playAudio);
flash = findViewById(R.id.flash);
popularMorseSuggestionContainer = findViewById(R.id.bottom_suggestion_container);
+ telegraphAudio = findViewById(R.id.rl_audio_telegraph);
+ telegraphContainer = findViewById(R.id.morseTelegraphContainer);
+ telegraphFlash = findViewById(R.id.rl_flash_telegraph);
+ telegraphFlashIV = findViewById(R.id.flash_telegraph);
+ telegraphAudioIV = findViewById(R.id.audio_telegraph);
+ telegraphKey = findViewById(R.id.container_dits_dah);
+ telegraphKeyboard = findViewById(R.id.keyboard_telegraph);
+ containerTools = findViewById(R.id.container_tools);
helper = new DBHelper(getApplicationContext());
@@ -364,6 +388,71 @@ protected void onCreate(Bundle savedInstanceState) {
popularMorseConversionText.put("-.-.--.--..", "CQD");
popularMorseConversionText.put(".--.....--.....--....--.----...--.-.---..---.....-", "What hath God wrought");
popularMorseConversionText.put(".-..--...", "rats");
+
+ telegraphKeyboard.setOnClickListener(view -> hideTelegraphKey());
+ fullscreen.setOnClickListener(view -> showTelegraphKey());
+ telegraphFlash.setOnClickListener(v -> setFlashSelectedForTelegraph());
+ telegraphAudio.setOnClickListener(v -> setAudioSelectedForTelegraph());
+ telegraphPlayer= MediaPlayer.create(MainActivity.this,R.raw.beepflac);
+
+ telegraphKey.setOnTouchListener((v, event) -> {
+ if(event.getAction() == MotionEvent.ACTION_DOWN){
+ if (telegraphSelected==1){
+ time = System.currentTimeMillis();
+ telegraphPlayer.start();
+ }
+ else { time = System.currentTimeMillis();
+ camera = Camera.open();
+ turnOn();
+ }
+
+
+ return true;
+ }
+ if(event.getAction() == MotionEvent.ACTION_UP){
+ if (telegraphSelected ==1){
+ if (System.currentTimeMillis()-time>=200){
+ telegraphPlayer.pause();
+ telegraphPlayer.seekTo(0);
+ }
+ else {
+ final Handler handler = new Handler(Looper.getMainLooper());
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ telegraphPlayer.pause();
+ telegraphPlayer.seekTo(0);
+ }
+ }, 100);
+ }
+ }
+ else {
+
+ if (System.currentTimeMillis()-time>=200){
+ turnOff();
+ camera.release();
+ camera = null;
+ }
+ else {
+ final Handler handler = new Handler(Looper.getMainLooper());
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ turnOff();
+ camera.release();
+ camera = null;
+ }
+ }, 100);
+ }
+ }
+
+
+ return true;
+ }
+ return false;
+ });
+
+
flash.setOnClickListener(view -> {
int hasCameraPermission = 0;
@@ -391,6 +480,8 @@ protected void onCreate(Bundle savedInstanceState) {
int currentcounter = 0;
+
+ camera = Camera.open();
for (String s : something) {
if (s.equals(".")) {
turnOn();
@@ -402,7 +493,8 @@ protected void onCreate(Bundle savedInstanceState) {
turnOff();
}
}
-
+ camera.release();
+ camera = null;
}
} else {
if (!TextUtils.isEmpty(input.getText().toString())) {
@@ -419,6 +511,8 @@ protected void onCreate(Bundle savedInstanceState) {
int currentcounter = 0;
+
+ camera = Camera.open();
for (String s : something) {
if (s.equals(".")) {
turnOn();
@@ -430,14 +524,14 @@ protected void onCreate(Bundle savedInstanceState) {
turnOff();
}
}
-
+ camera.release();
+ camera = null;
}
}
});
history.setOnClickListener(view -> startActivity(new Intent(MainActivity.this, PhraseBookActivity.class)));
mic.setOnClickListener(view -> Toast.makeText(getApplicationContext(), "To be implemented in a future release", Toast.LENGTH_SHORT).show());
- fullscreen.setOnClickListener(view -> Toast.makeText(getApplicationContext(), "To be implemented in a future release", Toast.LENGTH_SHORT).show());
settings.setOnClickListener(v -> Toast.makeText(getApplicationContext(), "To be implemented in a future release", Toast.LENGTH_SHORT).show());
container = findViewById(R.id.container);
bottomNavigation = findViewById(R.id.bottomLayout);
@@ -861,8 +955,6 @@ public void onAutoFocus(boolean b, Camera camera) {
}
public void turnOn() {
-
- camera = Camera.open();
try {
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(getFlashOnParameter());
@@ -894,8 +986,6 @@ private String getFlashOnParameter() {
public void turnOff() {
try {
camera.stopPreview();
- camera.release();
- camera = null;
} catch (Exception e) {
// This will happen if the camera fails to turn on.
}
@@ -1017,4 +1107,44 @@ protected void onProgressUpdate(String... text) {
}
+ private void showTelegraphKey(){
+ bottomNavigation.setVisibility(View.GONE);
+ containerTools.setVisibility(View.GONE);
+ telegraphContainer.setVisibility(View.VISIBLE);
+
+ // telegraphAudio.setBackgroundColor(Color.parseColor("#AA7DD3D8"));
+
+ setAudioSelectedForTelegraph();
+ }
+
+ private void hideTelegraphKey(){
+ bottomNavigation.setVisibility(View.VISIBLE);
+ containerTools.setVisibility(View.VISIBLE);
+ telegraphContainer.setVisibility(View.GONE);
+
+ }
+
+ private void setAudioSelectedForTelegraph(){
+ Drawable d = (GradientDrawable)telegraphAudio.getBackground();
+ d.setTint(Color.parseColor("#227DD3D8"));
+
+ Drawable d2 = (GradientDrawable)telegraphFlash.getBackground();
+ d2.setTint(Color.parseColor("#373945"));
+
+ telegraphFlashIV.setColorFilter(Color.parseColor("#9C9CA4"), PorterDuff.Mode.SRC_IN);
+ telegraphAudioIV.setColorFilter(Color.parseColor("#7DD3D8"), android.graphics.PorterDuff.Mode.SRC_IN);
+ telegraphSelected =1;
+ }
+ private void setFlashSelectedForTelegraph(){
+ Log.d("flashselected","yes");
+ Drawable d = (GradientDrawable)telegraphFlash.getBackground();
+ d.setTint(Color.parseColor("#227DD3D8"));
+
+ Drawable d2 = (GradientDrawable)telegraphAudio.getBackground();
+ d2.setTint(Color.parseColor("#373945"));
+
+ telegraphAudioIV.setColorFilter(Color.parseColor("#9C9CA4"), android.graphics.PorterDuff.Mode.SRC_IN);
+ telegraphFlashIV.setColorFilter(Color.parseColor("#7DD3D8"), android.graphics.PorterDuff.Mode.SRC_IN);
+ telegraphSelected =2;
+ }
}
diff --git a/app/src/main/res/drawable/background_telegraph.xml b/app/src/main/res/drawable/background_telegraph.xml
new file mode 100644
index 0000000..f646059
--- /dev/null
+++ b/app/src/main/res/drawable/background_telegraph.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_baseline_keyboard_24.xml b/app/src/main/res/drawable/ic_baseline_keyboard_24.xml
new file mode 100644
index 0000000..533fc15
--- /dev/null
+++ b/app/src/main/res/drawable/ic_baseline_keyboard_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_baseline_wifi_tethering_24.xml b/app/src/main/res/drawable/ic_baseline_wifi_tethering_24.xml
new file mode 100644
index 0000000..3caade1
--- /dev/null
+++ b/app/src/main/res/drawable/ic_baseline_wifi_tethering_24.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 2198a50..6036405 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,6 @@
+ app:tint="@color/colorMorse" />
+ app:tint="@color/colorMorse" />
+ app:tint="@color/colorMorse" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:src="@drawable/ic_baseline_wifi_tethering_24" />