package com.netfluke.sergey.greeter;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class EditActivity extends AppCompatActivity {

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

    public void onClick(View v) {
        Log.d("CLICK", "Edit Button Clicked");

        // Find the EditText element, retrieve its contents
        EditText te = (EditText) findViewById(R.id.txtUsername);
        String name = te.getText().toString();

        // This intent will be sent back to the calling Activity on finish().
        //  Intents take URIs as data (because requests to other activities often
        //   involve a single URI or URL). So we abuse it by treating our string as a URI.
        //   We could have used the extras facility of the Intent, for slightly more lengthy code.
        // The details for the Intent will be filled by setResult().
        Intent data = new Intent();
        data.setData(Uri.parse(name));
        setResult(RESULT_OK, data);  // the result is going to be passed to onActivityResult()

        // Actually finish; this closes the activity and restores the calling Activity
        finish();
    }
}
