2015-01-02 11:43:24 +01:00
|
|
|
package de.marcelkapfer.morseconverter;
|
|
|
|
|
2015-02-17 03:13:59 +01:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
|
|
|
import android.content.Context;
|
2015-02-15 02:26:06 +01:00
|
|
|
import android.content.Intent;
|
2015-02-14 18:45:28 +01:00
|
|
|
import android.content.res.Resources;
|
2015-02-15 02:26:06 +01:00
|
|
|
import android.net.Uri;
|
2015-01-02 11:43:24 +01:00
|
|
|
import android.os.Bundle;
|
2015-02-16 00:55:37 +01:00
|
|
|
import android.support.v7.widget.CardView;
|
2015-02-15 10:04:11 +01:00
|
|
|
import android.view.View;
|
2015-02-16 00:55:37 +01:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.TextView;
|
2015-02-15 10:04:11 +01:00
|
|
|
|
2015-02-14 17:31:42 +01:00
|
|
|
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
|
|
|
|
import it.neokree.materialnavigationdrawer.elements.MaterialSection;
|
2015-01-02 11:43:24 +01:00
|
|
|
|
2015-01-04 20:50:43 +01:00
|
|
|
|
2015-02-14 17:31:42 +01:00
|
|
|
public class MainActivity extends MaterialNavigationDrawer {
|
2015-01-04 20:50:43 +01:00
|
|
|
|
2015-02-15 10:04:11 +01:00
|
|
|
//Declaring the Material Sections
|
2015-02-14 17:45:23 +01:00
|
|
|
private MaterialSection writtenMorse, normalMorse, about;
|
2015-01-02 11:43:24 +01:00
|
|
|
|
2015-02-15 10:04:11 +01:00
|
|
|
//The MaterialNavigationDrawer init() methode replaces the normal onCreate() methode
|
2015-01-02 11:43:24 +01:00
|
|
|
@Override
|
2015-02-14 17:31:42 +01:00
|
|
|
public void init(Bundle savedInstanceState) {
|
2015-02-14 18:45:28 +01:00
|
|
|
Resources res = getResources();
|
2015-02-15 10:04:11 +01:00
|
|
|
//Declaring the Material Sections
|
2015-02-14 17:31:42 +01:00
|
|
|
writtenMorse = this.newSection("writtenMorse", new MainFragment());
|
2015-02-14 18:45:28 +01:00
|
|
|
normalMorse = this.newSection(res.getString(R.string.normalMorse), new MorseFragment());
|
|
|
|
about = this.newSection(res.getString(R.string.about), new AboutFragment());
|
2015-02-15 10:04:11 +01:00
|
|
|
//Adding the Sections
|
2015-02-14 17:31:42 +01:00
|
|
|
this.addSection(writtenMorse);
|
2015-02-14 17:45:23 +01:00
|
|
|
this.addSection(normalMorse);
|
2015-02-14 18:45:28 +01:00
|
|
|
this.addDivisor();
|
|
|
|
this.addSection(about);
|
2015-02-15 10:04:11 +01:00
|
|
|
//set drawer image
|
2015-02-14 17:31:42 +01:00
|
|
|
this.setDrawerHeaderImage(this.getResources().getDrawable(R.drawable.feature_graphics));
|
2015-02-15 10:04:11 +01:00
|
|
|
allowArrowAnimation(); //Drawer Arrow rotations
|
|
|
|
this.disableLearningPattern(); //Doesn't open the drawer always when the app starts
|
|
|
|
}
|
|
|
|
|
2015-02-15 17:58:56 +01:00
|
|
|
public void normalMorseEncode(View view){
|
2015-02-17 03:13:59 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
EncodeNormalMorseManager message = new EncodeNormalMorseManager(input.getText().toString());
|
|
|
|
output.setText(message.getEncodedString());
|
|
|
|
} catch (Exception e){
|
|
|
|
e.printStackTrace();
|
2015-02-16 00:55:37 +01:00
|
|
|
}
|
2015-02-15 17:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void normalMorseDecode(View view){
|
2015-02-17 03:13:59 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
DecodeNormalMorseManager message = new DecodeNormalMorseManager(input.getText().toString());
|
|
|
|
output.setText(message.getDecodedString());
|
|
|
|
} catch (Exception e){
|
|
|
|
e.printStackTrace();
|
2015-02-16 00:55:37 +01:00
|
|
|
}
|
2015-02-15 17:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void writtenMorseEncode(View view){
|
2015-02-17 03:13:59 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
EncodeWrittenMorseManager message = new EncodeWrittenMorseManager(input.getText().toString());
|
|
|
|
output.setText(message.getEncodedString());
|
|
|
|
} catch (Exception e){
|
|
|
|
e.printStackTrace();
|
2015-02-16 00:55:37 +01:00
|
|
|
}
|
2015-02-15 17:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void writtenMorseDecode(View view){
|
2015-02-17 03:13:59 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
DecodeWrittenMorseManager message = new DecodeWrittenMorseManager(input.getText().toString());
|
|
|
|
output.setText(message.getDecodedString());
|
|
|
|
} catch (Exception e){
|
|
|
|
e.printStackTrace();
|
2015-02-16 00:55:37 +01:00
|
|
|
}
|
2015-02-15 17:58:56 +01:00
|
|
|
}
|
|
|
|
|
2015-02-15 10:04:11 +01:00
|
|
|
//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();
|
|
|
|
}
|
2015-01-02 11:43:24 +01:00
|
|
|
}
|
2015-02-15 02:26:06 +01:00
|
|
|
|
2015-02-15 10:04:11 +01:00
|
|
|
//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();
|
|
|
|
}
|
2015-02-15 02:26:06 +01:00
|
|
|
}
|
|
|
|
|
2015-02-15 10:04:11 +01:00
|
|
|
//called when clicking on the website entry in the about fragment
|
|
|
|
//opens marcel-kapfer.de/projects/morse/
|
|
|
|
public void websiteEntry(View view){
|
|
|
|
try{
|
|
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://marcel-kapfer.de/projects/morse/"));
|
|
|
|
startActivity(browserIntent);
|
|
|
|
} catch(Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2015-02-15 02:26:06 +01:00
|
|
|
|
2015-02-15 10:04:11 +01:00
|
|
|
//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/projects/morse/index.html#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();
|
|
|
|
}
|
|
|
|
}
|
2015-02-17 03:13:59 +01:00
|
|
|
|
|
|
|
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){
|
|
|
|
Intent intent = getIntent();
|
|
|
|
String message = intent.getStringExtra(string);
|
|
|
|
Intent sendIntent = new Intent();
|
|
|
|
sendIntent.setAction(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
startActivity(Intent.createChooser(sendIntent, 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);
|
|
|
|
ClipData clip = ClipData.newPlainText("Message", string);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
2015-01-02 11:43:24 +01:00
|
|
|
}
|