diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MainFragment.java b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MainFragment.java
index 338b3b9..84050f9 100644
--- a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MainFragment.java
+++ b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MainFragment.java
@@ -38,6 +38,7 @@ import de.marcelkapfer.morseconverter.MainActivity;
import de.marcelkapfer.morseconverter.R;
import de.marcelkapfer.morseconverter.engine.DecodeWrittenMorseManager;
import de.marcelkapfer.morseconverter.engine.EncodeWrittenMorseManager;
+import de.marcelkapfer.morseconverter.intelligentCodeRecognization.WrittenMorseCodeRecognization;
/**
* Created by mmk on 2/14/15.
@@ -51,21 +52,12 @@ public class MainFragment extends Fragment{
@Override
public void onStart() {
- LinearLayout writtenMorseDecodeButton = (LinearLayout) getActivity().findViewById(R.id.writtenMorseDecodeButton);
+ LinearLayout writtenMorseConvertButton = (LinearLayout) getActivity().findViewById(R.id.writtenMorseEncodeButton);
- writtenMorseDecodeButton.setOnClickListener(new View.OnClickListener() {
+ writtenMorseConvertButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- writtenMorseDecode(getActivity());
- }
- });
-
- LinearLayout writtenMorseEncodeButton = (LinearLayout) getActivity().findViewById(R.id.writtenMorseEncodeButton);
-
- writtenMorseEncodeButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- writtenMorseEncode(getActivity());
+ writtenMorseConvert(getActivity());
}
});
@@ -90,7 +82,7 @@ public class MainFragment extends Fragment{
super.onStart();
}
- public void writtenMorseEncode(FragmentActivity fragmentActivity){
+ public void writtenMorseConvert(FragmentActivity fragmentActivity){
try {
EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextWrittenMorse);
TextView output = (TextView) fragmentActivity.findViewById(R.id.outputWrittenMorse);
@@ -98,22 +90,12 @@ public class MainFragment extends Fragment{
if(cardView.getVisibility() == View.INVISIBLE){
cardView.setVisibility(View.VISIBLE);
}
- output.setText(EncodeWrittenMorseManager.getEncodedString(input.getText().toString()));
- closeKeyboard();
- } catch (Exception e){
- e.printStackTrace();
- }
- }
-
- public void writtenMorseDecode(FragmentActivity fragmentActivity){
- try {
- EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextWrittenMorse);
- TextView output = (TextView) fragmentActivity.findViewById(R.id.outputWrittenMorse);
- CardView cardView = (CardView) fragmentActivity.findViewById(R.id.cardViewWrittenMorseOutput);
- if(cardView.getVisibility() == View.INVISIBLE){
- cardView.setVisibility(View.VISIBLE);
+ String inputString = input.getText().toString();
+ if(WrittenMorseCodeRecognization.isCode(inputString)) {
+ output.setText(EncodeWrittenMorseManager.getEncodedString(inputString));
+ } else {
+ output.setText(DecodeWrittenMorseManager.getDecodedString(inputString));
}
- output.setText(DecodeWrittenMorseManager.getDecodedString(input.getText().toString()));
closeKeyboard();
} catch (Exception e){
e.printStackTrace();
diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MorseFragment.java b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MorseFragment.java
index 06973b7..4b6b83c 100644
--- a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MorseFragment.java
+++ b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MorseFragment.java
@@ -23,10 +23,15 @@ package de.marcelkapfer.morseconverter.fragments;
import android.app.Activity;
import android.content.Context;
+import android.inputmethodservice.KeyboardView;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.CardView;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.text.method.KeyListener;
+import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -39,34 +44,26 @@ import de.marcelkapfer.morseconverter.MainActivity;
import de.marcelkapfer.morseconverter.R;
import de.marcelkapfer.morseconverter.engine.DecodeNormalMorseManager;
import de.marcelkapfer.morseconverter.engine.EncodeNormalMorseManager;
+import de.marcelkapfer.morseconverter.intelligentCodeRecognization.NormalMorseCodeRecognization;
/**
* Created by mmk on 2/14/15.
*/
-public class MorseFragment extends Fragment{
+public class MorseFragment extends Fragment {
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_morse, container, false);
}
@Override
public void onStart() {
- LinearLayout normalMorseDecodeButton = (LinearLayout) getActivity().findViewById(R.id.normalMorseDecodeButton);
-
- normalMorseDecodeButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- normalMorseDecode(getActivity());
- }
- });
-
LinearLayout normalMorseEncodeButton = (LinearLayout) getActivity().findViewById(R.id.normalMorseEncodeButton);
normalMorseEncodeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- normalMorseEncode(getActivity());
+ normalMorseConvert(getActivity());
}
});
@@ -88,50 +85,41 @@ public class MorseFragment extends Fragment{
}
});
+
super.onStart();
}
- public void normalMorseDecode(FragmentActivity fragmentActivity){
+ public void normalMorseConvert(FragmentActivity fragmentActivity) {
try {
EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextNormalMorse);
TextView output = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse);
CardView cardView = (CardView) fragmentActivity.findViewById(R.id.cardViewNormalMorseOutput);
- if(cardView.getVisibility() == View.INVISIBLE){
+ if (cardView.getVisibility() == View.INVISIBLE) {
cardView.setVisibility(View.VISIBLE);
}
- output.setText(DecodeNormalMorseManager.getDecodedString(input.getText().toString()));
+ String inputString = input.getText().toString();
+ if (NormalMorseCodeRecognization.isCode(inputString)) {
+ output.setText(EncodeNormalMorseManager.getEncodedString(inputString));
+ } else {
+ output.setText(DecodeNormalMorseManager.getDecodedString(inputString));
+ }
closeKeyboard();
- } catch (Exception e){
+ } catch (Exception e) {
e.printStackTrace();
}
}
- public void normalMorseEncode(FragmentActivity fragmentActivity){
- try {
- EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextNormalMorse);
- TextView output = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse);
- CardView cardView = (CardView) fragmentActivity.findViewById(R.id.cardViewNormalMorseOutput);
- if(cardView.getVisibility() == View.INVISIBLE){
- cardView.setVisibility(View.VISIBLE);
- }
- output.setText(EncodeNormalMorseManager.getEncodedString(input.getText().toString()));
- closeKeyboard();
- } catch (Exception e){
- e.printStackTrace();
- }
- }
-
- public void copyNormalMorse(FragmentActivity fragmentActivity){
+ public void copyNormalMorse(FragmentActivity fragmentActivity) {
TextView message = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse);
MainActivity.copy(message.getText().toString(), fragmentActivity);
}
- public void shareNormalMorse(FragmentActivity fragmentActivity){
+ public void shareNormalMorse(FragmentActivity fragmentActivity) {
TextView message = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse);
MainActivity.share(message.getText().toString(), fragmentActivity);
}
- public void closeKeyboard(){
+ public void closeKeyboard() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
EditText myEditText = (EditText) getActivity().findViewById(R.id.editTextNormalMorse);
diff --git a/app/src/main/res/layout-large-land/fragment_main.xml b/app/src/main/res/layout-large-land/fragment_main.xml
index 51266b3..5063f52 100644
--- a/app/src/main/res/layout-large-land/fragment_main.xml
+++ b/app/src/main/res/layout-large-land/fragment_main.xml
@@ -92,25 +92,13 @@
-
-
-
-
-
-
+ android:text="@string/button_convert"/>
diff --git a/app/src/main/res/layout-large-land/fragment_morse.xml b/app/src/main/res/layout-large-land/fragment_morse.xml
index a18f8cb..17bb6ef 100644
--- a/app/src/main/res/layout-large-land/fragment_morse.xml
+++ b/app/src/main/res/layout-large-land/fragment_morse.xml
@@ -90,17 +90,6 @@
android:layout_gravity="right"
android:baselineAligned="false">
-
-
-
-
-
+ android:text="@string/button_convert" />
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index 3c5b5f8..047b7ed 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -89,27 +89,16 @@
android:layout_gravity="right"
android:baselineAligned="false">
-
-
-
-
-
+ android:text="@string/button_convert"/>
diff --git a/app/src/main/res/layout/fragment_morse.xml b/app/src/main/res/layout/fragment_morse.xml
index f9897b8..5ba8651 100644
--- a/app/src/main/res/layout/fragment_morse.xml
+++ b/app/src/main/res/layout/fragment_morse.xml
@@ -89,25 +89,13 @@
android:layout_gravity="right"
android:baselineAligned="false">
-
-
-
-
-
-
+ android:text="@string/button_convert" />
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index bb99cb6..1c15168 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -25,8 +25,7 @@
Morse Converter
Einstellungen
Geben Sie einen Text ein
- VERSCHLÜSSELN
- ENTSCHLÜSSELN
+ UMWANDELN
Ihr Text
Hallo Welt
Suche
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 40b7ee4..281118e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -25,8 +25,7 @@
Morse Converter
Settings
Enter a Message
- ENCRYPT
- DECRYPT
+ CONVERT
Your Message
Hello world!
Search