package org.plezervikt.firstapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements View.OnClickListener {

    private final static int REQUEST_CODE = 88;

    private Button first;
    private Button second;
    private Button third;
    private Button fourth;
    private Button fifth;
    private Button sixth;

    private void l(String msg) {
        Log.d(Globals.LOGTAG, msg);
    }

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

        first = (Button) findViewById(R.id.firstbutton);
        second = (Button) findViewById(R.id.secondbutton);
        third = (Button) findViewById(R.id.thirdbutton);
        fourth = (Button) findViewById(R.id.fourthbutton);
        fifth = (Button) findViewById(R.id.fifthbutton);
        sixth = (Button) findViewById(R.id.sixthbutton);

        first.setOnClickListener(this);
        second.setOnClickListener(this);
        third.setOnClickListener(this);
        fourth.setOnClickListener(this);
        fifth.setOnClickListener(this);
        sixth.setOnClickListener(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        l("onStart");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.firstbutton:
                Toast.makeText(this, getString(R.string.app_name), Toast.LENGTH_LONG).show();
                break;
            case R.id.secondbutton:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle(R.string.app_name);
                builder.setMessage(R.string.hello_world);
                builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this, getString(R.string.youpressedcancel), Toast.LENGTH_LONG).show();
                    }
                });
                // nem muszáj kezelnünk az eseményt, ebben az esetben csak eltűnik a dialógus:
                builder.setPositiveButton(android.R.string.yes, null);
                builder.show();
                break;
            case R.id.thirdbutton:
                Toast.makeText(this, getString(R.string.log), Toast.LENGTH_SHORT).show();
                Log.d(Globals.LOGTAG, "ide jön a logüzenet");
                break;
            case R.id.fourthbutton:
                Intent i = new Intent(this, ThirdActivity.class);
                i.putExtra(Globals.INTENT_KEY_LAYOUT, 0);
                startActivity(i);
                // finish();
                break;
            case R.id.fifthbutton:
                Intent i2 = new Intent(this, ThirdActivity.class);
                i2.putExtra(Globals.INTENT_KEY_LAYOUT, 1);
                startActivity(i2);
                break;
            case R.id.sixthbutton:
                startActivityForResult(new Intent(this, SecondActivity.class), REQUEST_CODE);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
            String adat = data.getStringExtra("SZOVEG");
            Toast.makeText(this, "Hello " + adat, Toast.LENGTH_LONG).show();
        }
    }
}
