Intelligent Code recognization
This commit is contained in:
parent
adccce2f14
commit
bcd6deab0b
8 changed files with 40 additions and 118 deletions
|
@ -38,6 +38,7 @@ import de.marcelkapfer.morseconverter.MainActivity;
|
||||||
import de.marcelkapfer.morseconverter.R;
|
import de.marcelkapfer.morseconverter.R;
|
||||||
import de.marcelkapfer.morseconverter.engine.DecodeWrittenMorseManager;
|
import de.marcelkapfer.morseconverter.engine.DecodeWrittenMorseManager;
|
||||||
import de.marcelkapfer.morseconverter.engine.EncodeWrittenMorseManager;
|
import de.marcelkapfer.morseconverter.engine.EncodeWrittenMorseManager;
|
||||||
|
import de.marcelkapfer.morseconverter.intelligentCodeRecognization.WrittenMorseCodeRecognization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mmk on 2/14/15.
|
* Created by mmk on 2/14/15.
|
||||||
|
@ -51,21 +52,12 @@ public class MainFragment extends Fragment{
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
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
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
writtenMorseDecode(getActivity());
|
writtenMorseConvert(getActivity());
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
LinearLayout writtenMorseEncodeButton = (LinearLayout) getActivity().findViewById(R.id.writtenMorseEncodeButton);
|
|
||||||
|
|
||||||
writtenMorseEncodeButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
writtenMorseEncode(getActivity());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,7 +82,7 @@ public class MainFragment extends Fragment{
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writtenMorseEncode(FragmentActivity fragmentActivity){
|
public void writtenMorseConvert(FragmentActivity fragmentActivity){
|
||||||
try {
|
try {
|
||||||
EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextWrittenMorse);
|
EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextWrittenMorse);
|
||||||
TextView output = (TextView) fragmentActivity.findViewById(R.id.outputWrittenMorse);
|
TextView output = (TextView) fragmentActivity.findViewById(R.id.outputWrittenMorse);
|
||||||
|
@ -98,22 +90,12 @@ public class MainFragment extends Fragment{
|
||||||
if(cardView.getVisibility() == View.INVISIBLE){
|
if(cardView.getVisibility() == View.INVISIBLE){
|
||||||
cardView.setVisibility(View.VISIBLE);
|
cardView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
output.setText(EncodeWrittenMorseManager.getEncodedString(input.getText().toString()));
|
String inputString = input.getText().toString();
|
||||||
closeKeyboard();
|
if(WrittenMorseCodeRecognization.isCode(inputString)) {
|
||||||
} catch (Exception e){
|
output.setText(EncodeWrittenMorseManager.getEncodedString(inputString));
|
||||||
e.printStackTrace();
|
} else {
|
||||||
|
output.setText(DecodeWrittenMorseManager.getDecodedString(inputString));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
output.setText(DecodeWrittenMorseManager.getDecodedString(input.getText().toString()));
|
|
||||||
closeKeyboard();
|
closeKeyboard();
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -23,10 +23,15 @@ package de.marcelkapfer.morseconverter.fragments;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.inputmethodservice.KeyboardView;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v7.widget.CardView;
|
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.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -39,6 +44,7 @@ import de.marcelkapfer.morseconverter.MainActivity;
|
||||||
import de.marcelkapfer.morseconverter.R;
|
import de.marcelkapfer.morseconverter.R;
|
||||||
import de.marcelkapfer.morseconverter.engine.DecodeNormalMorseManager;
|
import de.marcelkapfer.morseconverter.engine.DecodeNormalMorseManager;
|
||||||
import de.marcelkapfer.morseconverter.engine.EncodeNormalMorseManager;
|
import de.marcelkapfer.morseconverter.engine.EncodeNormalMorseManager;
|
||||||
|
import de.marcelkapfer.morseconverter.intelligentCodeRecognization.NormalMorseCodeRecognization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mmk on 2/14/15.
|
* Created by mmk on 2/14/15.
|
||||||
|
@ -52,21 +58,12 @@ public class MorseFragment extends Fragment{
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
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);
|
LinearLayout normalMorseEncodeButton = (LinearLayout) getActivity().findViewById(R.id.normalMorseEncodeButton);
|
||||||
|
|
||||||
normalMorseEncodeButton.setOnClickListener(new View.OnClickListener() {
|
normalMorseEncodeButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
normalMorseEncode(getActivity());
|
normalMorseConvert(getActivity());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -88,10 +85,11 @@ public class MorseFragment extends Fragment{
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void normalMorseDecode(FragmentActivity fragmentActivity){
|
public void normalMorseConvert(FragmentActivity fragmentActivity) {
|
||||||
try {
|
try {
|
||||||
EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextNormalMorse);
|
EditText input = (EditText) fragmentActivity.findViewById(R.id.editTextNormalMorse);
|
||||||
TextView output = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse);
|
TextView output = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse);
|
||||||
|
@ -99,22 +97,12 @@ public class MorseFragment extends Fragment{
|
||||||
if (cardView.getVisibility() == View.INVISIBLE) {
|
if (cardView.getVisibility() == View.INVISIBLE) {
|
||||||
cardView.setVisibility(View.VISIBLE);
|
cardView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
output.setText(DecodeNormalMorseManager.getDecodedString(input.getText().toString()));
|
String inputString = input.getText().toString();
|
||||||
closeKeyboard();
|
if (NormalMorseCodeRecognization.isCode(inputString)) {
|
||||||
} catch (Exception e){
|
output.setText(EncodeNormalMorseManager.getEncodedString(inputString));
|
||||||
e.printStackTrace();
|
} else {
|
||||||
|
output.setText(DecodeNormalMorseManager.getDecodedString(inputString));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
closeKeyboard();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -92,25 +92,13 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/LinearLayoutButton"
|
style="@style/LinearLayoutButton"
|
||||||
android:layout_marginRight="8dp"
|
android:text="@string/button_convert"
|
||||||
android:id="@+id/writtenMorseDecodeButton"
|
|
||||||
android:clickable="true">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/LinearLayoutButtonText"
|
|
||||||
android:text="@string/button_decode"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
style="@style/LinearLayoutButton"
|
|
||||||
android:text="@string/button_encode"
|
|
||||||
android:id="@+id/writtenMorseEncodeButton"
|
android:id="@+id/writtenMorseEncodeButton"
|
||||||
android:clickable="true">
|
android:clickable="true">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/LinearLayoutButtonText"
|
style="@style/LinearLayoutButtonText"
|
||||||
android:text="@string/button_encode"/>
|
android:text="@string/button_convert"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -90,17 +90,6 @@
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
android:baselineAligned="false">
|
android:baselineAligned="false">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
style="@style/LinearLayoutButton"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:clickable="true"
|
|
||||||
android:id="@+id/normalMorseDecodeButton">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/LinearLayoutButtonText"
|
|
||||||
android:text="@string/button_decode"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/LinearLayoutButton"
|
style="@style/LinearLayoutButton"
|
||||||
|
@ -108,7 +97,7 @@
|
||||||
android:id="@+id/normalMorseEncodeButton" >
|
android:id="@+id/normalMorseEncodeButton" >
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/LinearLayoutButtonText"
|
style="@style/LinearLayoutButtonText"
|
||||||
android:text="@string/button_encode" />
|
android:text="@string/button_convert" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -89,27 +89,16 @@
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
android:baselineAligned="false">
|
android:baselineAligned="false">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
style="@style/LinearLayoutButton"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:id="@+id/writtenMorseDecodeButton"
|
|
||||||
android:clickable="true">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/LinearLayoutButtonText"
|
|
||||||
android:text="@string/button_decode"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/LinearLayoutButton"
|
style="@style/LinearLayoutButton"
|
||||||
android:text="@string/button_encode"
|
android:text="@string/button_convert"
|
||||||
android:id="@+id/writtenMorseEncodeButton"
|
android:id="@+id/writtenMorseEncodeButton"
|
||||||
android:clickable="true">
|
android:clickable="true">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/LinearLayoutButtonText"
|
style="@style/LinearLayoutButtonText"
|
||||||
android:text="@string/button_encode"/>
|
android:text="@string/button_convert"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -89,25 +89,13 @@
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
android:baselineAligned="false">
|
android:baselineAligned="false">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
style="@style/LinearLayoutButton"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:clickable="true"
|
|
||||||
android:id="@+id/normalMorseDecodeButton">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/LinearLayoutButtonText"
|
|
||||||
android:text="@string/button_decode"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/LinearLayoutButton"
|
style="@style/LinearLayoutButton"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:id="@+id/normalMorseEncodeButton" >
|
android:id="@+id/normalMorseEncodeButton" >
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/LinearLayoutButtonText"
|
style="@style/LinearLayoutButtonText"
|
||||||
android:text="@string/button_encode" />
|
android:text="@string/button_convert" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
<string name="app_name">Morse Converter</string>
|
<string name="app_name">Morse Converter</string>
|
||||||
<string name="action_settings">Einstellungen</string>
|
<string name="action_settings">Einstellungen</string>
|
||||||
<string name="edit_message">Geben Sie einen Text ein</string>
|
<string name="edit_message">Geben Sie einen Text ein</string>
|
||||||
<string name="button_decode">VERSCHLÜSSELN</string>
|
<string name="button_convert">UMWANDELN</string>
|
||||||
<string name="button_encode">ENTSCHLÜSSELN</string>
|
|
||||||
<string name="title_activity_display_message">Ihr Text</string>
|
<string name="title_activity_display_message">Ihr Text</string>
|
||||||
<string name="hello_world">Hallo Welt</string>
|
<string name="hello_world">Hallo Welt</string>
|
||||||
<string name="action_search">Suche</string>
|
<string name="action_search">Suche</string>
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
<string name="app_name">Morse Converter</string>
|
<string name="app_name">Morse Converter</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="edit_message">Enter a Message</string>
|
<string name="edit_message">Enter a Message</string>
|
||||||
<string name="button_decode">ENCRYPT</string>
|
<string name="button_convert">CONVERT</string>
|
||||||
<string name="button_encode">DECRYPT</string>
|
|
||||||
<string name="title_activity_display_message">Your Message</string>
|
<string name="title_activity_display_message">Your Message</string>
|
||||||
<string name="hello_world">Hello world!</string>
|
<string name="hello_world">Hello world!</string>
|
||||||
<string name="action_search">Search</string>
|
<string name="action_search">Search</string>
|
||||||
|
|
Reference in a new issue