package com.android.audiomodem;

import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;


public class MainActivity extends ActionBarActivity {

    private EditText editText = null;
    private Thread tx = null;
    private Receiver rx = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = (EditText) findViewById(R.id.editText);

        // Get intent, action and MIME type
        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();

        if (Intent.ACTION_SEND.equals(action) && type != null && "text/plain".equals(type)) {
            String str = intent.getStringExtra(Intent.EXTRA_TEXT);
            editText.setText(str);
        }
    }

    public void onReceive(View v) {
        rx = new Receiver() {
            @Override
            protected void onPostExecute(String result) {
                editText.setText(result);
            }
        };
        rx.execute();
    }

    public void onSend(View v) {
        byte[] msg = editText.getText().toString().getBytes();
        tx = new Sender(msg);
        tx.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -57,16 +57,47 @@
 Intent;%0A
+import android.graphics.Color;%0A
 import a
@@ -274,16 +274,46 @@
 w.View;%0A
+import android.widget.Button;%0A
 import a
@@ -423,32 +423,107 @@
 ditText = null;%0A
+    private Button buttonRecv = null;%0A    private Color origColor = null;%0A%0A
     private Thre
@@ -791,16 +791,77 @@
 itText);
+%0A        buttonRecv = (Button) findViewById(R.id.buttonRecv);
 %0A%0A      
@@ -1437,19 +1437,102 @@
     
-%7D%0A        %7D
+    buttonRecv.setEnabled(true);%0A            %7D%0A        %7D;%0A        buttonRecv.setEnabled(false)
 ;%0A  

disable RX button during receiving