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; /* www .j av a 2 s . co m*/ import android.app.Activity; import android.content.Context; import android.graphics.Typeface; import android.os.Bundle; import android.util.Log; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class ReferenceActivity extends Activity { Typeface monospace; private static final String TAG = ReferenceActivity.class.getSimpleName(); private SMSTone mTone; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ListView lv = new ListView(this); monospace = Typeface.createFromAsset(getAssets(),"DroidSansMono.ttf"); lv.setAdapter(new SparseStringsAdapter(this, SMSTone.morseTable)); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { (new Thread(new Runnable() { @Override public void run() { String key = ((TextView)view.findViewById(android.R.id.text1)).getText().toString(); String message = ((TextView)view.findViewById(android.R.id.text2)).getText().toString(); Log.i(TAG,"Playing: "+key+" "+message); mTone.play(message); } })).start(); } }); setContentView(lv); } public abstract class SparseArrayAdapter<E> extends BaseAdapter { private SparseArray<E> mData; public void setData(SparseArray<E> data) { mData = data; } @Override public int getCount() { return mData.size(); } @Override public E getItem(int position) { return mData.valueAt(position); } @Override public long getItemId(int position) { return mData.keyAt(position); } public int getKey(int position) { return mData.keyAt(position); } } public class SparseStringsAdapter extends SparseArrayAdapter<String> { private final LayoutInflater mInflater; public SparseStringsAdapter(Context context, SparseArray<String> data) { mInflater = LayoutInflater.from(context); setData(data); } @Override public View getView(int position, View convertView, ViewGroup parent) { View result = convertView; if (result == null) { result = mInflater.inflate(R.layout.morse_list_item,null); } char key =(char) getKey(position); TextView tvLeft = (TextView) result.findViewById(android.R.id.text1); TextView tvRight = (TextView) result.findViewById(android.R.id.text2); tvLeft.setText(Character.toString(key)); tvRight.setTypeface(monospace); tvRight.setText(getItem(position).replace(".", "")); return result; } } @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.reference, 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) { return true; } return super.onOptionsItemSelected(item); } }