package com.aragaer.yama;

import java.io.OutputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;


public class EditActivity extends Activity {

    EditText memo;

    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setContentView(R.layout.edit);
	memo = (EditText) findViewById(R.id.memo_edit);
    }

    MenuItem.OnMenuItemClickListener cancelListener = new MenuItem.OnMenuItemClickListener() {
	    public boolean onMenuItemClick(MenuItem item) {
		EditActivity.this.setResult(Activity.RESULT_CANCELED);
		EditActivity.this.finish();
		return true;
	    }
	};

    MenuItem.OnMenuItemClickListener doneListener = new MenuItem.OnMenuItemClickListener() {
	    public boolean onMenuItemClick(MenuItem item) {
		EditActivity.this.saveMemo(memo.getText().toString());
		EditActivity.this.finish();
		return true;
	    }
	};

    MenuItem.OnMenuItemClickListener deleteListener = new MenuItem.OnMenuItemClickListener() {
	    public boolean onMenuItemClick(MenuItem item) {
		EditActivity.this.saveMemo("");
		EditActivity.this.finish();
		return true;
	    }
	};

    private void saveMemo(String memo) {
	Intent result = new Intent().putExtra("edited", memo);
	Toast.makeText(this, memo.isEmpty() ? "Deleted" : "Saved", Toast.LENGTH_SHORT).show();
	setResult(RESULT_OK, result);
    }

    @Override public void onBackPressed() {
	saveMemo(memo.getText().toString());
	finish();
    }

    public boolean onCreateOptionsMenu(Menu menu) {
	MenuItem done = menu.add("Done");
	MenuItem cancel = menu.add("Cancel");
	MenuItem delete = menu.add("Delete");
	done.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	done.setOnMenuItemClickListener(doneListener);
	cancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	cancel.setOnMenuItemClickListener(cancelListener);
	delete.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	delete.setOnMenuItemClickListener(deleteListener);
	return true;
    }
}

@@ -547,24 +547,75 @@
 memo_edit);%0A
+%09memo.setText(getIntent().getStringExtra(%22memo%22));%0A
     %7D%0A%0A    M

Fix memo editing