Skip to content

Commit

Permalink
Merge pull request #20 from Crazy-Marvin/rc-1.3
Browse files Browse the repository at this point in the history
Release candidate 1.3
  • Loading branch information
CrazyMarvin authored Nov 5, 2019
2 parents 55cc1e2 + 400d7d7 commit 4359d36
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 17 deletions.
Binary file modified app/debug/app-debug.apk
Binary file not shown.
73 changes: 70 additions & 3 deletions app/src/main/java/rocks/poopjournal/morse/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.graphics.Typeface;
import android.hardware.Camera;
import android.media.AudioManager;
import android.media.MediaPlayer;
Expand All @@ -18,14 +19,22 @@
import android.os.Handler;
import android.os.PowerManager;
import android.os.SystemClock;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
Expand All @@ -50,6 +59,7 @@ public class MainActivity extends AppCompatActivity implements Camera.AutoFocusC
TextView buttonTwo;
RelativeLayout switchImageContainer;
EditTextTouch input;
RelativeLayout popularMorseSuggestionContainer;
TextView output;
ImageView copy;
ImageView sound;
Expand Down Expand Up @@ -88,6 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
copy = findViewById(R.id.copyText);
sound = findViewById(R.id.playAudio);
flash = findViewById(R.id.flash);
popularMorseSuggestionContainer = findViewById(R.id.bottom_suggestion_container);

popularMorse.add("...---...");
popularMorse.add("-.-.--.--..");
Expand Down Expand Up @@ -507,7 +518,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
else {
if (popularMorse.contains(input.getText().toString())){
final Dialog confirm = DialogsUtil.showVerificationDialog(MainActivity.this);
/* final Dialog confirm = DialogsUtil.showVerificationDialog(MainActivity.this);
TextView original, converted, discard, yes;
original = confirm.findViewById(R.id.successTV);
converted = confirm.findViewById(R.id.descTV);
Expand All @@ -530,8 +541,50 @@ public void onClick(View view) {
Toast.makeText(getApplicationContext(),"Changed morse",Toast.LENGTH_SHORT).show();
confirm.dismiss();
}
});*/
Log.d("popular_morse","true");
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)input.getLayoutParams();
setMargins(input,params.leftMargin,params.topMargin,params.rightMargin,2);
input.setBackground(ContextCompat.getDrawable(getApplicationContext(),R.drawable.bg_top_suggestion));
popularMorseSuggestionContainer.setVisibility(View.VISIBLE);

TextView suggestionTV = findViewById(R.id.suggestion_text_tv);
TextView replace = findViewById(R.id.replace_suggestion);
TextView ignore = findViewById(R.id.ignore_suggestion);

suggestionTV.setText("Did you mean " + popularMorseConversion.get(input.getText().toString())+ " (" + popularMorseConversionText.get(input.getText().toString()) +")?");
change(suggestionTV.getText().toString(),popularMorseConversion.get(input.getText().toString()), suggestionTV);

replace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
input.setText(popularMorseConversion.get(input.getText().toString()));
input.setSelection(input.getText().length());
Toast.makeText(getApplicationContext(),"Changed morse",Toast.LENGTH_SHORT).show();
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)input.getLayoutParams();
setMargins(input,params.leftMargin,params.topMargin,params.rightMargin,20);
input.setBackground(ContextCompat.getDrawable(getApplicationContext(),R.drawable.et_morse));
popularMorseSuggestionContainer.setVisibility(View.GONE);
}
});

ignore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)input.getLayoutParams();
setMargins(input,params.leftMargin,params.topMargin,params.rightMargin,20);
input.setBackground(ContextCompat.getDrawable(getApplicationContext(),R.drawable.et_morse));
popularMorseSuggestionContainer.setVisibility(View.GONE);
}
});
}
else {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)input.getLayoutParams();
setMargins(input,params.leftMargin,params.topMargin,params.rightMargin,20);
input.setBackground(ContextCompat.getDrawable(getApplicationContext(),R.drawable.et_morse));
popularMorseSuggestionContainer.setVisibility(View.GONE);
}

output.setText("");
String text = input.getText().toString();
String[] letters = text.split("\\s");
Expand Down Expand Up @@ -563,7 +616,13 @@ void flash_display() {

}


public static void setMargins (View v, int l, int t, int r, int b) {
if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
p.setMargins(l, t, r, b);
v.requestLayout();
}
}

ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
Expand Down Expand Up @@ -936,5 +995,13 @@ protected void onProgressUpdate(String... text) {

}
}

void change(String s, String newSuggestion, TextView t){
int i = s.indexOf(newSuggestion);
SpannableStringBuilder sb = new SpannableStringBuilder(s);
sb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getApplicationContext(),R.color.colorMorse)), i, i+newSuggestion.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
int k = s.indexOf("(");
sb.setSpan(new StyleSpan(Typeface.ITALIC), k+1, k+popularMorseConversionText.get(input.getText().toString()).length()+1, 0);
sb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getApplicationContext(),R.color.colorMorse)), k+1, k+popularMorseConversionText.get(input.getText().toString()).length() +1, 0);
t.setText(sb);
}
}
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/bg_bottom_suggestion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp" />
<solid
android:color="#292C33"/>
<stroke
android:color="#1E2129"
android:width="0.5dp" />
</shape>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/bg_top_suggestion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:topRightRadius="8dp"
android:topLeftRadius="8dp" />
<solid
android:color="#292C33"/>
<stroke
android:color="#1E2129"
android:width="0.5dp" />
</shape>
69 changes: 63 additions & 6 deletions app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,70 @@
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:textSize="15sp"
android:textSize="20sp"
android:gravity="top"
android:fontFamily="@font/overpass_regular"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"/>
<RelativeLayout
android:id="@+id/bottom_suggestion_container"
android:layout_width="match_parent"
android:layout_height="140dp"
android:visibility="gone"
android:textColor="@color/colorSecondaryText"
android:background="@drawable/bg_bottom_suggestion"
android:layout_below="@+id/input"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="20dp"
android:textSize="15sp"
android:gravity="top"
android:fontFamily="@font/overpass_regular"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingEnd="10dp"
android:paddingStart="20dp">
<TextView
android:id="@+id/suggestion_text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:textColor="@color/colorSecondaryText"
android:textSize="14sp"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:scrollbars = "vertical"
android:layout_above="@id/replace_suggestion"
android:fontFamily="@font/overpassmono_regular"/>
<TextView
android:id="@+id/ignore_suggestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="IGNORE"
android:textColor="@color/colorSecondaryText"
android:textSize="14sp"
android:layout_toStartOf="@id/replace_suggestion"
android:layout_alignParentBottom="true"

android:fontFamily="@font/overpassmono_regular"/>
<TextView
android:id="@+id/replace_suggestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="REPLACE"
android:textColor="@color/colorMorse"
android:textSize="14sp"
android:paddingEnd="-3dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:fontFamily="@font/overpassmono_regular"/>
</RelativeLayout>
</RelativeLayout>

<RelativeLayout
Expand All @@ -139,7 +196,7 @@
android:id="@+id/output"
android:layout_width="match_parent"
android:layout_height="80dp"
android:textSize="15sp"
android:textSize="20sp"
android:scrollbars="vertical"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
Expand Down Expand Up @@ -210,8 +267,8 @@
android:layout_centerVertical="true"
android:id="@+id/input_dot"
android:src="@drawable/input_dot"
android:layout_width="12dp"
android:layout_height="12dp" />
android:layout_width="36dp"
android:layout_height="36dp" />
</RelativeLayout>
<RelativeLayout
android:padding="45dp"
Expand All @@ -223,9 +280,9 @@
<ImageView
android:layout_centerVertical="true"
android:id="@+id/input_dash"
android:layout_width="18dp"
android:layout_width="30dp"
android:src="@drawable/input_dash"
android:layout_height="6dp" />
android:layout_height="8dp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
Expand Down
Loading

0 comments on commit 4359d36

Please sign in to comment.