package com.jshoresdevelopment.conversioncalculator;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends FragmentActivity {
    private TextView distance;
    private TextView volume;
    private TextView weight;
    private List<TextView> navButtons;
    private Fragment currentFragment;
    private MainFragment mainFragment;


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

        mainFragment = new MainFragment();

        getSupportFragmentManager().beginTransaction().replace(R.id.content, mainFragment)
                .commitAllowingStateLoss();
        currentFragment = mainFragment;

        initializeNavBar();
    }

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

    /** Resets nav bar buttons to original colors. */
    private void resetNavButtons() {
        for (TextView view : navButtons) {
            view.setBackgroundColor(Color.WHITE);
            view.setTextColor(Color.parseColor("#ff007223"));
        }
    }

    /** Initializes nav bar buttons. */
    private void initializeNavBar() {
        navButtons = new ArrayList<>();

        distance = (TextView) findViewById(R.id.distance_button);
        setNavButtonsOnClickListener(distance);
        navButtons.add(distance);

        volume = (TextView) findViewById(R.id.volume_button);
        setNavButtonsOnClickListener(volume);
        navButtons.add(volume);

        weight = (TextView) findViewById(R.id.weight_button);
        setNavButtonsOnClickListener(weight);
        navButtons.add(weight);
    }

    /** Standardized nav bar on click listener. */
    private void setNavButtonsOnClickListener(final TextView view) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                resetNavButtons();
                view.setBackgroundColor(Color.parseColor("#ff007223"));
                view.setTextColor(Color.WHITE);
            }
        });
    }

    /** Switch UI to the given fragment. */
    void switchToFragment(Fragment newFrag) {
        getSupportFragmentManager().beginTransaction().replace(R.id.content, newFrag)
                .commitAllowingStateLoss();
        currentFragment = newFrag;
    }
}

@@ -170,57 +170,8 @@
 ty;%0A
-import android.support.v7.app.ActionBarActivity;%0A
 impo
@@ -417,97 +417,8 @@
 y %7B%0A
-    private TextView distance;%0A    private TextView volume;%0A    private TextView weight;%0A
     
@@ -502,19 +502,25 @@
 private 
-Mai
+Conversio
 nFragmen
@@ -521,19 +521,25 @@
 ragment 
-mai
+conversio
 nFragmen
@@ -715,16 +715,29 @@
         
+MainFragment 
 mainFrag
@@ -762,16 +762,99 @@
 gment();
+%0A        conversionFragment = new ConversionFragment();%0A        initializeNavBar();
 %0A%0A      
@@ -1031,760 +1031,314 @@
     
-    initializeNavBar();%0A    %7D%0A%0A    @Override%0A    public boolean onCreateOptionsMenu(Menu menu) %7B%0A        // Inflate the menu; this adds items to the action bar if it is present.%0A        getMenuInflater().inflate(R.menu.menu_main, menu);%0A        return true
+%7D%0A%0A    @Override%0A    protected void onResume() %7B%0A        super.onResume();%0A        MainFragment mainFragment = new MainFragment()
 ;%0A    
-%7D%0A%0A
     
-@Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        // Handle action bar item clicks here. The action bar will%0A        // automatically handle clicks on the Home/Up button, so long%0A        // as you specify a parent activity in AndroidManifest.xml.%0A        int id = item.getItemId();%0A%0A        //noinspection SimplifiableIfStatement%0A        if (id == R.id.action_settings) %7B%0A            return true;%0A        %7D%0A%0A        return super.onOptionsItemSelected(item);
+getSupportFragmentManager().beginTransaction().replace(R.id.content, mainFragment)%0A                .commitAllowingStateLoss();%0A        currentFragment = mainFragment;%0A
 %0A   
@@ -1731,16 +1731,25 @@
         
+TextView 
 distance
@@ -1843,16 +1843,28 @@
 distance
+, %22Distance%22
 );%0A     
@@ -1901,16 +1901,25 @@
         
+TextView 
 volume =
@@ -2007,16 +2007,26 @@
 r(volume
+, %22Volume%22
 );%0A     
@@ -2061,16 +2061,25 @@
         
+TextView 
 weight =
@@ -2163,24 +2163,34 @@
 tener(weight
+, %22Weight%22
 );%0A        n
@@ -2335,16 +2335,39 @@
 iew view
+, final String headText
 ) %7B%0A    
@@ -2483,24 +2483,88 @@
 k(View v) %7B%0A
+                conversionFragment.setConversionType(headText);%0A
             
@@ -2710,21 +2710,8 @@
 E);%0A
-            %7D
 %0A   
@@ -2719,117 +2719,76 @@
     
-%7D);%0A
     
-%7D%0A%0A
     
-/** Switch UI to the given fragment. */%0A    void switchToFragment(Fragment newFrag) %7B%0A
+if (currentFragment != conversionFragment) %7B%0A       
         
 getS
@@ -2775,32 +2775,37 @@
 %0A               
+     
 getSupportFragme
@@ -2861,33 +2861,27 @@
 nt, 
-newFrag)%0A                
+conversionFragment)
 .com
@@ -2896,32 +2896,44 @@
 ingStateLoss();%0A
+            
         currentF
@@ -2946,21 +2946,262 @@
 t = 
-newFrag
+conversionFragment;%0A                %7D else %7B%0A                    if (conversionFragment.getConversionHead() != null) %7B%0A                        conversionFragment.setLayoutResources();%0A                    %7D%0A                %7D%0A            %7D%0A        %7D)
 ;%0A    %7D%0A
 %7D%0A
@@ -3198,10 +3198,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Implement frag switcher and conversion set type set up.