Intelligent Code recognization

This commit is contained in:
mmk2410 2015-08-03 16:43:36 +02:00
parent adccce2f14
commit bcd6deab0b
8 changed files with 40 additions and 118 deletions

View file

@ -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();

View file

@ -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);

View file

@ -92,25 +92,13 @@
<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
style="@style/LinearLayoutButton"
android:text="@string/button_encode"
android:text="@string/button_convert"
android:id="@+id/writtenMorseEncodeButton"
android:clickable="true">
<TextView
style="@style/LinearLayoutButtonText"
android:text="@string/button_encode"/>
android:text="@string/button_convert"/>
</LinearLayout>

View file

@ -90,17 +90,6 @@
android:layout_gravity="right"
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
style="@style/LinearLayoutButton"
@ -108,7 +97,7 @@
android:id="@+id/normalMorseEncodeButton" >
<TextView
style="@style/LinearLayoutButtonText"
android:text="@string/button_encode" />
android:text="@string/button_convert" />
</LinearLayout>

View file

@ -89,27 +89,16 @@
android:layout_gravity="right"
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
style="@style/LinearLayoutButton"
android:text="@string/button_encode"
android:text="@string/button_convert"
android:id="@+id/writtenMorseEncodeButton"
android:clickable="true">
<TextView
style="@style/LinearLayoutButtonText"
android:text="@string/button_encode"/>
android:text="@string/button_convert"/>
</LinearLayout>

View file

@ -89,25 +89,13 @@
android:layout_gravity="right"
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
style="@style/LinearLayoutButton"
android:clickable="true"
android:id="@+id/normalMorseEncodeButton" >
<TextView
style="@style/LinearLayoutButtonText"
android:text="@string/button_encode" />
android:text="@string/button_convert" />
</LinearLayout>

View file

@ -25,8 +25,7 @@
<string name="app_name">Morse Converter</string>
<string name="action_settings">Einstellungen</string>
<string name="edit_message">Geben Sie einen Text ein</string>
<string name="button_decode">VERSCHLÜSSELN</string>
<string name="button_encode">ENTSCHLÜSSELN</string>
<string name="button_convert">UMWANDELN</string>
<string name="title_activity_display_message">Ihr Text</string>
<string name="hello_world">Hallo Welt</string>
<string name="action_search">Suche</string>

View file

@ -25,8 +25,7 @@
<string name="app_name">Morse Converter</string>
<string name="action_settings">Settings</string>
<string name="edit_message">Enter a Message</string>
<string name="button_decode">ENCRYPT</string>
<string name="button_encode">DECRYPT</string>
<string name="button_convert">CONVERT</string>
<string name="title_activity_display_message">Your Message</string>
<string name="hello_world">Hello world!</string>
<string name="action_search">Search</string>