Back to project page SMS-Morse.
The source code is released under:
GNU General Public License
If you think the Android project SMS-Morse listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jonathanmackenzie.sms_morse; /*w w w .j a v a 2s. c o m*/ import android.app.Activity; import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; /** * A small test activity to demonstrate * the morse code playback functionality * @author Jonathan Mackenzie * @email jonmac1@gmail.com */ public class MainActivity extends Activity { private SMSTone mTone; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.talk); btn.setText("Morse"); final EditText et = (EditText) findViewById(R.id.input); final TextView tv = (TextView) findViewById(R.id.morse); tv.setTextSize(32); tv.setTypeface(Typeface.createFromAsset(getAssets(), "DroidSansMono.ttf")); /** * Play the inputted text */ btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { (new Thread(new Runnable() { @Override public void run() { String message =et.getEditableText().toString(); final String dots = mTone.convertToDots(message); runOnUiThread(new Runnable() { public void run() { tv.setText(dots.replace("|", "").replace(".", "")); } }); mTone.play(dots); } })).start(); } }); } @Override public void onResume() { super.onResume(); mTone = new SMSTone(this); } @Override public void onPause() { super.onPause(); mTone.stopTone(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { Intent i = new Intent(this,SettingsActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(i); return true; } else if(id == R.id.action_reference) { Intent i = new Intent(this,ReferenceActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(i); return true; } return super.onOptionsItemSelected(item); } }