package com.ace_is_solutions.funfacts;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


public class FunFactsActivity extends Activity {

    public  static final String TAG = FunFactsActivity.class.getSimpleName();
    private static final String KEY_FACT = "KEY_FACT";
    private static final String KEY_COLOR = "KEY_COLOR";
    private FactBook       mFactBook = new FactBook();
    private ColorWheel     mColorWheel = new ColorWheel();
    private RelativeLayout mRelativeLayout;
    private TextView       mFactLabel;
    private Button         mShowFactButton;
    // init to Opening color/text style
    private String         mFact = mFactBook.mFactoid[0];
    private int            mColor = Color.parseColor(mColorWheel.mColorCd[8]);

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        // save state in case of change like rotation
        outState.putString(KEY_FACT, mFact);
        outState.putInt(KEY_COLOR, mColor);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        // re-load Fact (text)
        mFact = savedInstanceState.getString(KEY_FACT);
        mFactLabel.setText(mFact);
        // re-load Colors; text & BG
        mColor = savedInstanceState.getInt(KEY_COLOR);
        mRelativeLayout.setBackgroundColor(mColor);
        mShowFactButton.setTextColor(mColor);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fun_facts);
        // set our View vars and assign the Views from teh Layout file
        //final TextView factLabel = (TextView) findViewById(R.id.factTextView);
        //final Button showFactButton = (Button) findViewById(R.id.showFactButton);
        //final RelativeLayout relLayoutJ = (RelativeLayout) findViewById(R.id.relLayoutI);

        // Declare our View variables and assign them the Views from the layout file
        mFactLabel      = (TextView) findViewById(R.id.factTextView);
        mShowFactButton = (Button) findViewById(R.id.showFactButton);
        mRelativeLayout = (RelativeLayout) findViewById(R.id.relLayoutI);

        //Button opaqueActivityButton = (Button) findViewById(R.id.opaqueActivityButton);

        // set up Button/click event
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // get Fun Fact
                mFact = mFactBook.getFact();
                // update the Label with Fact
                mFactLabel.setText(mFact);
                // get Background Color n set
                mColor = mColorWheel.getColor();
                mRelativeLayout.setBackgroundColor(mColor);
                mShowFactButton.setTextColor(mColor);
            }
        };
        mShowFactButton.setOnClickListener(listener);
        // set up n display Toast n Log
        //
        // meth 1
        String msgTxt = "Hooray! ... ";
        Toast welcomeToast = Toast.makeText(this, msgTxt, Toast.LENGTH_LONG);
        welcomeToast.show();
        // meth 2
        Toast.makeText(this, "Activity was Created.", Toast.LENGTH_LONG).show();
        // and Log
        Log.d("FunFactsActn", "Fun Facts Activity successfully created.");
        // Log meth 2
        Log.d(TAG, "No, seriously ...");
    }

    // NOTE: this code extraneous and not needed until we add Menu Bar back in
    //
    //@Override
    //public boolean onCreateOptionsMenu(Menu menu) {
    //    // Inflate the menu; this adds items to the action bar if it is present.
    //    getMenuInflater().inflate(R.menu.fun_facts, 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();
    //    if (id == R.id.action_settings) {
    //        return true;
    //    }
    //    return super.onOptionsItemSelected(item);
    //}
}
