From adccce2f146ff981d6d1be0fafb5b92742dd0c64 Mon Sep 17 00:00:00 2001 From: mmk2410 Date: Mon, 3 Aug 2015 15:36:59 +0200 Subject: [PATCH] Multiple Line support, Fixed issus with appcompat 22 --- MorseConverter.iml | 2 +- app/app.iml | 22 +- app/build.gradle | 8 +- .../morseconverter/MainActivity.java | 199 +------------ .../engine/DecodeNormalMorseManager.java | 7 +- .../engine/DecodeWrittenMorseManager.java | 9 +- .../engine/EncodeNormalMorseManager.java | 17 +- .../engine/EncodeWrittenMorseManager.java | 19 +- .../fragments/AboutFragment.java | 170 +++++++++++ .../fragments/MainFragment.java | 100 +++++++ .../fragments/MorseFragment.java | 101 +++++++ .../res/layout-large-land/fragment_about.xml | 257 +++++++++-------- .../res/layout-large-land/fragment_main.xml | 272 +++++++++--------- .../res/layout-large-land/fragment_morse.xml | 267 ++++++++--------- .../main/res/layout-v19/fragment_about.xml | 57 ++-- app/src/main/res/layout/codeview.xml | 6 +- app/src/main/res/layout/fragment_about.xml | 56 ++-- app/src/main/res/layout/fragment_main.xml | 21 +- app/src/main/res/layout/fragment_morse.xml | 23 +- app/src/main/res/values/strings.xml | 1 + 20 files changed, 962 insertions(+), 652 deletions(-) diff --git a/MorseConverter.iml b/MorseConverter.iml index 0735af2..95bdf9f 100644 --- a/MorseConverter.iml +++ b/MorseConverter.iml @@ -8,7 +8,7 @@ - + diff --git a/app/app.iml b/app/app.iml index 670212a..7f4ef5b 100644 --- a/app/app.iml +++ b/app/app.iml @@ -12,10 +12,12 @@ - + @@ -85,15 +87,15 @@ - + - - - - - - + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index f23aec7..35c0710 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,10 +26,10 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:22.0.+' + compile 'com.android.support:appcompat-v7:22.2.1' compile 'it.neokree:MaterialNavigationDrawer:1.3.3' - compile 'com.android.support:cardview-v7:21.0.3' - compile 'com.android.support:support-v4:22.0.+' - compile 'com.android.support:recyclerview-v7:21.0.+' + compile 'com.android.support:cardview-v7:22.2.1' + compile 'com.android.support:support-v4:22.2.1' + compile 'com.android.support:recyclerview-v7:22.2.1' compile 'com.anjlab.android.iab.v3:library:1.0.+@aar' } diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java b/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java index 7fa011e..bea338a 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java @@ -25,28 +25,17 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; -import android.content.res.Configuration; import android.content.res.Resources; -import android.graphics.Point; -import android.net.Uri; import android.os.Bundle; -import android.support.v7.widget.CardView; +import android.support.v4.app.FragmentActivity; import android.util.DisplayMetrics; -import android.view.Display; -import android.view.Surface; import android.view.View; -import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; -import android.widget.TextView; import com.anjlab.android.iab.v3.BillingProcessor; import com.anjlab.android.iab.v3.TransactionDetails; -import de.marcelkapfer.morseconverter.engine.DecodeNormalMorseManager; -import de.marcelkapfer.morseconverter.engine.DecodeWrittenMorseManager; -import de.marcelkapfer.morseconverter.engine.EncodeNormalMorseManager; -import de.marcelkapfer.morseconverter.engine.EncodeWrittenMorseManager; import de.marcelkapfer.morseconverter.fragments.AboutFragment; import de.marcelkapfer.morseconverter.fragments.MainFragment; import de.marcelkapfer.morseconverter.fragments.MorseFragment; @@ -119,20 +108,19 @@ public class MainActivity extends MaterialNavigationDrawer implements BillingPro super.onDrawerClosed(view); } - public void onDrawerOpened(View view){ - super.onDrawerOpened(view); + public void onDrawerOpened(View view) { // This closes the soft keyboard, when the drawer is opened try { closeKeyboard(); } catch (Exception e){ e.printStackTrace(); } + super.onDrawerOpened(view); } }; this.setDrawerListener(mDrawerToggle); - } // IBillingHandler implementation @@ -176,11 +164,10 @@ public class MainActivity extends MaterialNavigationDrawer implements BillingPro public void onDestroy() { if (bp != null) bp.release(); - super.onDestroy(); } - public void closeKeyboard(){ + public void closeKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); if (getCurrentSection() == writtenMorse) { @@ -192,187 +179,17 @@ public class MainActivity extends MaterialNavigationDrawer implements BillingPro } } - public void normalMorseEncode(View view){ - try{ - EditText input = (EditText) findViewById(R.id.editTextNormalMorse); - TextView output = (TextView) findViewById(R.id.outputNormalMorse); - CardView cardView = (CardView) 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 normalMorseDecode(View view){ - try { - EditText input = (EditText) findViewById(R.id.editTextNormalMorse); - TextView output = (TextView) findViewById(R.id.outputNormalMorse); - CardView cardView = (CardView) findViewById(R.id.cardViewNormalMorseOutput); - if(cardView.getVisibility() == View.INVISIBLE){ - cardView.setVisibility(View.VISIBLE); - } - output.setText(DecodeNormalMorseManager.getDecodedString(input.getText().toString())); - closeKeyboard(); - } catch (Exception e){ - e.printStackTrace(); - } - } - - public void writtenMorseEncode(View view){ - try { - EditText input = (EditText) findViewById(R.id.editTextWrittenMorse); - TextView output = (TextView) findViewById(R.id.outputWrittenMorse); - CardView cardView = (CardView) findViewById(R.id.cardViewWrittenMorseOutput); - 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(View view){ - try { - EditText input = (EditText) findViewById(R.id.editTextWrittenMorse); - TextView output = (TextView) findViewById(R.id.outputWrittenMorse); - CardView cardView = (CardView) findViewById(R.id.cardViewWrittenMorseOutput); - if(cardView.getVisibility() == View.INVISIBLE){ - cardView.setVisibility(View.VISIBLE); - } - output.setText(DecodeWrittenMorseManager.getDecodedString(input.getText().toString())); - closeKeyboard(); - } catch (Exception e){ - e.printStackTrace(); - } - } - - - //called when clicking on the version entry in the about fragment - //opens the app page (de.marcelkapfer.morseconverter) - public void versionEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=de.marcelkapfer.morseconverter")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the developer entry in the about fragment - //opens the gplus profile of +MarcelMichaelKapfer - public void developerEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/+MarcelMichaelKapfer/posts")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the website entry in the about fragment - //opens marcel-kapfer.de/writtenmorse - public void websiteEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://marcel-kapfer.de/writtenmorse/")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the contact entry in the about fragment - //opens mail app with mail to marcelmichaelkapfer@yahoo.co.nz - public void contactEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:marcelmichaelkapfer@yahoo.co.nz")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the license entry in the about fragment - //opens the license web page - public void licenseEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://gnu.org/copyleft/gpl.html")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the developer entry in the about fragment - //opens mail app with mail to marcelmichaelkapfer@yahoo.co.nz - public void bugEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:marcelmichaelkapfer@yahoo.co.nz?subject=Bug Report")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the developer entry in the about fragment - //opens the howto webpage - public void howtoEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://marcel-kapfer.de/writtenmorse/#howto_android")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - //called when clicking on the developer entry in the about fragment - //opens mail app with mail to marcelmichaelkapfer@yahoo.co.nz - public void missingCodeEntry(View view){ - try{ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:marcelmichaelkapfer@yahoo.co.nz?subject=Missing Code")); - startActivity(browserIntent); - } catch(Exception e){ - e.printStackTrace(); - } - } - - public void shareWrittenMorse(View view){ - TextView message = (TextView) findViewById(R.id.outputWrittenMorse); - share(message.getText().toString()); - } - - public void shareNormalMorse(View view){ - TextView message = (TextView) findViewById(R.id.outputNormalMorse); - share(message.getText().toString()); - } - - public void share(String string){ + public static void share(String string, FragmentActivity fragmentActivity){ Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, string); sendIntent.setType("text/plain"); - startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); + fragmentActivity.startActivity(Intent.createChooser(sendIntent, fragmentActivity.getResources().getText(R.string.send_to))); } - public void copyWrittenMorse(View view){ - TextView message = (TextView) findViewById(R.id.outputWrittenMorse); - copy(message.getText().toString()); - } - - public void copyNormalMorse(View view){ - TextView message = (TextView) findViewById(R.id.outputNormalMorse); - copy(message.getText().toString()); - } - - public void copy(String string){ - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + public static void copy(String string, FragmentActivity fragmentActivity){ + ClipboardManager clipboard = (ClipboardManager) fragmentActivity.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Message", string); clipboard.setPrimaryClip(clip); } - } diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeNormalMorseManager.java b/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeNormalMorseManager.java index efa7fdc..4d35ffc 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeNormalMorseManager.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeNormalMorseManager.java @@ -1,7 +1,7 @@ package de.marcelkapfer.morseconverter.engine; /* - This is a Android application for converting writtenMorse and normal morse code. + This is a Java application for converting writtenMorse and normal morse code. Copyright (C) 2014-2015 Marcel Michael Kapfer This program is free software: you can redistribute it and/or modify @@ -63,6 +63,9 @@ public class DecodeNormalMorseManager { } output.append(" "); input.delete(0, 1); + } else if(input.toString().startsWith("\n")) { + output.append("\n"); + input.deleteCharAt(input.indexOf("\n")); } else if (input.toString().startsWith("A")) { output.append(".- "); input.delete(0, 1); @@ -232,7 +235,7 @@ public class DecodeNormalMorseManager { output.append("...-..- "); input.delete(0, 1); } else { - output.replace(0, output.length(), "Code not listed or wrong."); + return "Code not listed or wrong."; } } if (output.toString().endsWith(" ")) { diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeWrittenMorseManager.java b/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeWrittenMorseManager.java index 7eaef1c..3fa4f37 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeWrittenMorseManager.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/engine/DecodeWrittenMorseManager.java @@ -1,7 +1,7 @@ package de.marcelkapfer.morseconverter.engine; /* - This is a Android application for converting writtenMorse and normal morse code. + This is a Java application for converting writtenMorse and normal morse code. Copyright (C) 2014-2015 Marcel Michael Kapfer This program is free software: you can redistribute it and/or modify @@ -56,7 +56,7 @@ public class DecodeWrittenMorseManager { } else if (input.toString().equals("WORD SPACE")) { output.replace(0, output.length(), "+"); } else { - for (int c = input.length(); c > 0; c--) { + while (input.length() > 0) { if (input.toString().startsWith(" ")) { if (output.toString().endsWith("#")) { @@ -64,6 +64,9 @@ public class DecodeWrittenMorseManager { } output.append("+"); input.delete(0, 1); + } else if (input.toString().startsWith("\n")) { + output.append("\n"); + input.deleteCharAt(input.indexOf("\n")); } else if (input.toString().startsWith("A")) { output.append("01#"); input.delete(0, 1); @@ -233,7 +236,7 @@ public class DecodeWrittenMorseManager { output.append("0001001#"); input.delete(0, 1); } else { - output.replace(0, output.length(), "Code not listed or wrong."); + return "Code not listed or wrong."; } } if (output.toString().endsWith("#")) { diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeNormalMorseManager.java b/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeNormalMorseManager.java index 7b86e12..f8c8cd7 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeNormalMorseManager.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeNormalMorseManager.java @@ -1,7 +1,7 @@ package de.marcelkapfer.morseconverter.engine; /* - This is a Android application for converting writtenMorse and normal morse code. + This is a Java application for converting writtenMorse and normal morse code. Copyright (C) 2014-2015 Marcel Michael Kapfer This program is free software: you can redistribute it and/or modify @@ -49,7 +49,12 @@ public class EncodeNormalMorseManager { if (inputToSign.toString().startsWith(" ")) { output.append(" "); inputToSign.delete(d, d + 7); - } else if (inputToSign.toString().substring(d, d + 3).equals(" ")) { + } + if (inputToSign.toString().startsWith("\n")) { + output.append("\n"); + inputToSign.deleteCharAt(inputToSign.indexOf("\n")); + } + if (inputToSign.toString().substring(d, d + 3).equals(" ")) { if (d == 0) { inputToSign.delete(0, 3); } else { @@ -62,7 +67,7 @@ public class EncodeNormalMorseManager { d++; } } - if (sign.toString().equals(".-")) { + if(sign.toString().equals(".-")) { output.append("A"); } else if (sign.toString().equals("-...")) { output.append("B"); @@ -115,9 +120,9 @@ public class EncodeNormalMorseManager { } else if (sign.toString().equals("--..")) { output.append("Z"); } else if (sign.toString().equals("-----")) { - output.append(". (zero)"); + output.append("0"); } else if (sign.toString().equals(".----")) { - output.append("-"); + output.append("1"); } else if (sign.toString().equals("..---")) { output.append("2"); } else if (sign.toString().equals("...--")) { @@ -187,7 +192,7 @@ public class EncodeNormalMorseManager { } else if (sign.toString().equals("........")) { output.append("Error"); } else { - output.replace(0, output.length(), "Code not listed or wrong."); + return "Code not listed or wrong."; } } return output.toString(); diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeWrittenMorseManager.java b/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeWrittenMorseManager.java index 80293c5..6705507 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeWrittenMorseManager.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/engine/EncodeWrittenMorseManager.java @@ -1,7 +1,7 @@ package de.marcelkapfer.morseconverter.engine; /* - This is a Android application for converting writtenMorse and normal morse code. + This is a Java application for converting writtenMorse and normal morse code. Copyright (C) 2014-2015 Marcel Michael Kapfer This program is free software: you can redistribute it and/or modify @@ -46,12 +46,21 @@ public class EncodeWrittenMorseManager { StringBuffer sign = new StringBuffer(); while (signFull) { if (inputToSign.toString().charAt(d) == '+' - || inputToSign.toString().charAt(d) == '#') { + || inputToSign.toString().charAt(d) == '#' + || inputToSign.toString().startsWith("\n")) { if (d == 0) { if (inputToSign.toString().startsWith("+")) { output.append(" "); + inputToSign.deleteCharAt(0); + } + if (inputToSign.toString().startsWith("#")) { + inputToSign.deleteCharAt(0); + } + // Line break support + if (inputToSign.toString().startsWith("\n")) { // Detect line break + output.append("\n"); // Add line break to the output + inputToSign.deleteCharAt(inputToSign.indexOf("\n")); // Remove line break from the input } - inputToSign.deleteCharAt(0); } else { sign.replace(0, sign.length(), inputToSign .toString().substring(0, d)); @@ -115,7 +124,7 @@ public class EncodeWrittenMorseManager { } else if (sign.toString().equals("1100")) { output.append("Z"); } else if (sign.toString().equals("11111")) { - output.append("0 (zero)"); + output.append("0"); } else if (sign.toString().equals("01111")) { output.append("1"); } else if (sign.toString().equals("00111")) { @@ -187,7 +196,7 @@ public class EncodeWrittenMorseManager { } else if (sign.toString().equals("00000000")) { output.append("Error"); } else { - output.replace(0, output.length(), "Code not listed or wrong."); + return "Code not listed or wrong."; } } return output.toString(); diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/AboutFragment.java b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/AboutFragment.java index 16830f0..1e71646 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/AboutFragment.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/AboutFragment.java @@ -21,11 +21,14 @@ package de.marcelkapfer.morseconverter.fragments; */ +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import de.marcelkapfer.morseconverter.R; @@ -37,4 +40,171 @@ public class AboutFragment extends Fragment{ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ return inflater.inflate(R.layout.fragment_about, container, false); } + + @Override + public void onStart(){ + + LinearLayout versionEntryButton = (LinearLayout) getActivity().findViewById(R.id.versionEntry); + + versionEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + versionEntry(); + } + }); + + LinearLayout developerEntryButton = (LinearLayout) getActivity().findViewById(R.id.developerEntry); + + developerEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + developerEntry(); + } + }); + + LinearLayout websiteEntryButton = (LinearLayout) getActivity().findViewById(R.id.websiteEntry); + + websiteEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + websiteEntry(); + } + }); + + LinearLayout contactEntryButton = (LinearLayout) getActivity().findViewById(R.id.contactEntry); + + contactEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + contactEntry(); + } + }); + + LinearLayout licenseEntryButton = (LinearLayout) getActivity().findViewById(R.id.licenseEntry); + + licenseEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + licenseEntry(); + } + }); + + LinearLayout bugEntryButton = (LinearLayout) getActivity().findViewById(R.id.bugEntry); + + bugEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + bugEntry(); + } + }); + + LinearLayout howtoEntryButton = (LinearLayout) getActivity().findViewById(R.id.howtoEntry); + + howtoEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + howtoEntry(); + } + }); + + LinearLayout missingCodeEntryButton = (LinearLayout) getActivity().findViewById(R.id.missingCodeEntry); + + missingCodeEntryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + missingCodeEntry(); + } + }); + + super.onStart(); + } + + //called when clicking on the version entry in the about fragment + //opens the app page (de.marcelkapfer.morseconverter) + public void versionEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=de.marcelkapfer.morseconverter")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the developer entry in the about fragment + //opens the gplus profile of +MarcelMichaelKapfer + public void developerEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/+MarcelMichaelKapfer/posts")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the website entry in the about fragment + //opens marcel-kapfer.de/writtenmorse + public void websiteEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://marcel-kapfer.de/writtenmorse/")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the contact entry in the about fragment + //opens mail app with mail to marcelmichaelkapfer@yahoo.co.nz + public void contactEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:marcelmichaelkapfer@yahoo.co.nz")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the license entry in the about fragment + //opens the license web page + public void licenseEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://gnu.org/copyleft/gpl.html")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the developer entry in the about fragment + //opens mail app with mail to marcelmichaelkapfer@yahoo.co.nz + public void bugEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:marcelmichaelkapfer@yahoo.co.nz?subject=Bug Report")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the developer entry in the about fragment + //opens the howto webpage + public void howtoEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://marcel-kapfer.de/writtenmorse/#howto_android")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + + //called when clicking on the developer entry in the about fragment + //opens mail app with mail to marcelmichaelkapfer@yahoo.co.nz + public void missingCodeEntry(){ + try{ + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:marcelmichaelkapfer@yahoo.co.nz?subject=Missing Code")); + startActivity(browserIntent); + } catch(Exception e){ + e.printStackTrace(); + } + } + } 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 4b49a4b..338b3b9 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MainFragment.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MainFragment.java @@ -21,13 +21,23 @@ package de.marcelkapfer.morseconverter.fragments; */ +import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v7.widget.CardView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import de.marcelkapfer.morseconverter.MainActivity; import de.marcelkapfer.morseconverter.R; +import de.marcelkapfer.morseconverter.engine.DecodeWrittenMorseManager; +import de.marcelkapfer.morseconverter.engine.EncodeWrittenMorseManager; /** * Created by mmk on 2/14/15. @@ -37,4 +47,94 @@ public class MainFragment extends Fragment{ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ return inflater.inflate(R.layout.fragment_main, container, false); } + + @Override + public void onStart() { + + LinearLayout writtenMorseDecodeButton = (LinearLayout) getActivity().findViewById(R.id.writtenMorseDecodeButton); + + writtenMorseDecodeButton.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()); + } + }); + + LinearLayout writtenMorseCopy = (LinearLayout) getActivity().findViewById(R.id.copyWrittenMorse); + + writtenMorseCopy.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + copyWrittenMorse(getActivity()); + } + }); + + LinearLayout writtenMorseShare = (LinearLayout) getActivity().findViewById(R.id.shareWrittenMorse); + + writtenMorseShare.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + shareWrittenMorse(getActivity()); + } + }); + + super.onStart(); + } + + public void writtenMorseEncode(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(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); + } + output.setText(DecodeWrittenMorseManager.getDecodedString(input.getText().toString())); + closeKeyboard(); + } catch (Exception e){ + e.printStackTrace(); + } + } + + public void copyWrittenMorse(FragmentActivity fragmentActivity){ + TextView message = (TextView) fragmentActivity.findViewById(R.id.outputWrittenMorse); + MainActivity.copy(message.getText().toString(), fragmentActivity); + } + + public void shareWrittenMorse(FragmentActivity fragmentActivity){ + TextView message = (TextView) fragmentActivity.findViewById(R.id.outputWrittenMorse); + MainActivity.share(message.getText().toString(), fragmentActivity); + } + + public void closeKeyboard(){ + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService( + Context.INPUT_METHOD_SERVICE); + EditText myEditText = (EditText) getActivity().findViewById(R.id.editTextWrittenMorse); + imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); + + } } 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 26b64a8..06973b7 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MorseFragment.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/fragments/MorseFragment.java @@ -21,13 +21,24 @@ package de.marcelkapfer.morseconverter.fragments; */ +import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v7.widget.CardView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import de.marcelkapfer.morseconverter.MainActivity; import de.marcelkapfer.morseconverter.R; +import de.marcelkapfer.morseconverter.engine.DecodeNormalMorseManager; +import de.marcelkapfer.morseconverter.engine.EncodeNormalMorseManager; /** * Created by mmk on 2/14/15. @@ -37,4 +48,94 @@ public class MorseFragment extends Fragment{ 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()); + } + }); + + LinearLayout normalMorseCopy = (LinearLayout) getActivity().findViewById(R.id.copyNormalMorse); + + normalMorseCopy.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + copyNormalMorse(getActivity()); + } + }); + + LinearLayout normalMorseShare = (LinearLayout) getActivity().findViewById(R.id.shareNormalMorse); + + normalMorseShare.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + shareNormalMorse(getActivity()); + } + }); + + super.onStart(); + } + + public void normalMorseDecode(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(DecodeNormalMorseManager.getDecodedString(input.getText().toString())); + closeKeyboard(); + } 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){ + TextView message = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse); + MainActivity.copy(message.getText().toString(), fragmentActivity); + } + + public void shareNormalMorse(FragmentActivity fragmentActivity){ + TextView message = (TextView) fragmentActivity.findViewById(R.id.outputNormalMorse); + MainActivity.share(message.getText().toString(), fragmentActivity); + } + + public void closeKeyboard(){ + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService( + Context.INPUT_METHOD_SERVICE); + EditText myEditText = (EditText) getActivity().findViewById(R.id.editTextNormalMorse); + imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); + + } } \ No newline at end of file diff --git a/app/src/main/res/layout-large-land/fragment_about.xml b/app/src/main/res/layout-large-land/fragment_about.xml index 0e147f2..c507a73 100644 --- a/app/src/main/res/layout-large-land/fragment_about.xml +++ b/app/src/main/res/layout-large-land/fragment_about.xml @@ -54,153 +54,178 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + 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 00e537b..51266b3 100644 --- a/app/src/main/res/layout-large-land/fragment_main.xml +++ b/app/src/main/res/layout-large-land/fragment_main.xml @@ -40,83 +40,86 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - - - - + android:layout_height="wrap_content"> + android:id="@+id/linearLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginTop="24dp" + android:gravity="center" + android:minHeight="48dp" + android:orientation="vertical" + > + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + @@ -130,82 +133,85 @@ android:layout_height="match_parent" android:orientation="vertical"> - + - + - + - + - + - + - + - + - + - + - + - + - - + + \ No newline at end of file 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 c8fc6b1..a18f8cb 100644 --- a/app/src/main/res/layout-large-land/fragment_morse.xml +++ b/app/src/main/res/layout-large-land/fragment_morse.xml @@ -42,79 +42,82 @@ android:layout_height="fill_parent" android:orientation="vertical"> - - - - - - - - - - + android:layout_height="wrap_content"> + android:id="@+id/linearLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginTop="24dp" + android:gravity="center" + android:minHeight="48dp" + android:orientation="vertical" + > + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + @@ -130,83 +133,85 @@ android:layout_height="fill_parent" android:orientation="vertical"> - + - + - + - + - + - + + - + - + - + - + - - - + - - + + diff --git a/app/src/main/res/layout-v19/fragment_about.xml b/app/src/main/res/layout-v19/fragment_about.xml index 6af0fa4..fdce73f 100644 --- a/app/src/main/res/layout-v19/fragment_about.xml +++ b/app/src/main/res/layout-v19/fragment_about.xml @@ -40,149 +40,174 @@ + android:id="@+id/versionEntry" + android:clickable="true"> + android:text="@string/aboutVersion" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/developerEntry" + android:clickable="true"> + android:text="@string/aboutDeveloper" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/websiteEntry" + android:clickable="true"> + android:text="@string/aboutWebsite" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/contactEntry" + android:clickable="true"> + android:text="@string/aboutContact" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/licenseEntry" + android:clickable="true"> + android:text="@string/aboutLicense" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/bugEntry" + android:clickable="true"> + android:text="@string/aboutBug" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/howtoEntry" + android:clickable="true"> + android:text="@string/aboutHow" + android:textColor="@color/primary_text_default_material_light" /> + android:paddingBottom="70dp" + android:id="@+id/missingCodeEntry" + android:clickable="true"> + android:text="@string/aboutMissing" + android:textColor="@color/primary_text_default_material_light"/> diff --git a/app/src/main/res/layout/codeview.xml b/app/src/main/res/layout/codeview.xml index 2f01ead..11360a5 100644 --- a/app/src/main/res/layout/codeview.xml +++ b/app/src/main/res/layout/codeview.xml @@ -9,7 +9,8 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/hello_world" - android:gravity="center_vertical"/> + android:gravity="center_vertical" + android:textColor="@color/primary_text_default_material_light"/> + android:gravity="center_vertical" + android:textColor="@color/primary_text_default_material_light"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 8de66ba..7cdbf13 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -46,150 +46,174 @@ + android:id="@+id/versionEntry" + android:clickable="true"> + android:text="@string/aboutVersion" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/developerEntry" + android:clickable="true"> + android:text="@string/aboutDeveloper" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/websiteEntry" + android:clickable="true"> + android:text="@string/aboutWebsite" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/contactEntry" + android:clickable="true"> + android:text="@string/aboutContact" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/licenseEntry" + android:clickable="true"> + android:text="@string/aboutLicense" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/bugEntry" + android:clickable="true"> + android:text="@string/aboutBug" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/howtoEntry" + android:clickable="true"> + android:text="@string/aboutHow" + android:textColor="@color/primary_text_default_material_light" /> + android:id="@+id/missingCodeEntry" + android:clickable="true"> + android:text="@string/aboutMissing" + android:textColor="@color/primary_text_default_material_light"/> diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 9b964ad..3c5b5f8 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -69,7 +69,9 @@ android:scrollbars="vertical" android:minLines="5" android:singleLine="false" - android:background="@color/cardview_light_background"/> + android:background="@color/cardview_light_background" + android:textColor="@color/primary_text_default_material_light" + android:textColorHint="@color/hint_foreground_material_light"/> + android:id="@+id/writtenMorseDecodeButton" + android:clickable="true"> + android:text="@string/button_encode" + android:id="@+id/writtenMorseEncodeButton" + android:clickable="true"> + android:background="@color/cardview_light_background" + android:textColor="@color/primary_text_default_material_light"/> + android:id="@+id/copyWrittenMorse" + android:clickable="true"> + android:id="@+id/shareWrittenMorse" + android:clickable="true"> + android:minLines="5" + android:textColor="@color/primary_text_default_material_light" + android:textColorHint="@color/hint_foreground_material_light"> + android:layout_marginRight="8dp" + android:clickable="true" + android:id="@+id/normalMorseDecodeButton"> - + android:clickable="true" + android:id="@+id/normalMorseEncodeButton" > @@ -147,7 +150,8 @@ android:hint="@string/output_message" android:scrollbars="vertical" android:singleLine="false" - android:background="@color/cardview_light_background"/> + android:background="@color/cardview_light_background" + android:textColor="@color/primary_text_default_material_light"/> - + android:id="@+id/copyNormalMorse" + android:clickable="true"> @@ -178,7 +182,8 @@ + android:id="@+id/shareNormalMorse" + android:clickable="true"> About Normal Morse + writtenMorse SHARE COPY