package com.example.estremot.ex1funec;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final TextView lblsit = (TextView) findViewById(R.id.lblSituacao);
        final TextView lblmed = (TextView) findViewById(R.id.lblMedia);

        final EditText edtnota1 = (EditText)findViewById(R.id.txtNota1);
        final EditText edtnota2 = (EditText)findViewById(R.id.txtNota2);

        final Button btncalcular = (Button) findViewById(R.id.btnCalcular);
        final Button btnlimpar = (Button) findViewById(R.id.btnLimpar);

        btncalcular.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                float v1, v2, m;

                v1 = Float.parseFloat(edtnota1.getText().toString());
                v2 = Float.parseFloat(edtnota2.getText().toString());

                m = (v1+v2)/2;

                lblmed.setText(""+m);

                if(m>=7)
                {
                    lblsit.setText("Aprovado");
                }
                else{
                    lblsit.setText("Reprovado");
                }
            }
        });

        btnlimpar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lblsit.setText(null);
                lblmed.setText(null);
                edtnota1.setText(null);
                edtnota2.setText(null);

            }
        });
        
    }


    @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);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.activity_main, container, false);
            return rootView;
        }
    }
}
