package net.colindodd.sample.gradientlayout;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.colindodd.gradientlayout.GradientRelativeLayout;

public class MainActivity extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    private SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    private ViewPager mViewPager;

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        public PlaceholderFragment() {
        }

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            GradientRelativeLayout layout = (GradientRelativeLayout) rootView.findViewById(R.id.fragment_root);
            generateBackgroundForSection(layout, getArguments().getInt(ARG_SECTION_NUMBER));
            return rootView;
        }

        private void generateBackgroundForSection(final GradientRelativeLayout layout, final int section) {
            switch (section) {
                case 1:
                    layout.setGradientBackgroundConfig(Color.parseColor("#7B1FA2"), Color.parseColor("#009688"), GradientDrawable.Orientation.BL_TR);
                    break;
                case 2:
                    layout.setGradientBackgroundConfig(-1, Color.parseColor("#7B1FA2"), GradientDrawable.Orientation.TOP_BOTTOM);
                    break;
                case 3:
                    layout.setGradientBackgroundConfig(Color.parseColor("#689F38"), -1, GradientDrawable.Orientation.LEFT_RIGHT);
                    break;
                case 4:
                    layout.setGradientBackgroundConfig(Color.parseColor("#E91E63"), Color.parseColor("#FFCDD2"), GradientDrawable.Orientation.RIGHT_LEFT);
                    break;
                case 5:
                    layout.setGradientBackgroundConfig(Color.parseColor("#FF5722"), Color.parseColor("#FFC107"), GradientDrawable.Orientation.TR_BL);
                    break;
            }
        }
    }

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(final int position) {
            return PlaceholderFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            return 5;
        }
    }
}

@@ -3393,57 +3393,48 @@
 lor.
-parseColor(%22#7B1FA2%22), Color.parseColor(%22#009688%22
+rgb(123, 31, 162), Color.rgb(0, 150, 136
 ), G
@@ -3554,494 +3554,411 @@
 .set
-GradientBackgroundConfig(-1, Color.parseColor(%22#7B1FA2%22), GradientDrawable.Orientation.TOP_BOTTOM);%0A                    break;%0A                case 3:%0A                    layout.setGradientBackgroundConfig(Color.parseColor(%22#689F38%22), -1, GradientDrawable.Orientation.LEFT_RIGHT);%0A                    break;%0A                case 4:%0A                    layout.setGradientBackgroundConfig(Color.parseColor(%22#E91E63%22), Color.parseColor(%22#FFCDD2%22), GradientDrawable.Orientation.RIGHT_LEFT);
+EndColor(Color.rgb(123,31,162));%0A                    break;%0A                case 3:%0A                    layout%0A                            .setEndColor(Color.rgb(104,159,56))%0A                            .setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);%0A                    break;%0A                case 4:%0A                    layout%0A                            .setStartColor(Color.rgb(255,87,34))
 %0A   
@@ -3970,39 +3970,32 @@
             
-break;%0A
         
         case
@@ -3986,137 +3986,87 @@
     
-        case 5:%0A                    layout.setGradientBackgroundConfig(Color.parseColor(%22#FF5722%22), Color.parseColor(%22#FFC107%22), 
+.setEndColor(Color.rgb(255,193,7))%0A                            .setOrientation(
 Grad
@@ -4670,17 +4670,17 @@
  return 
-5
+4
 ;%0A      

Rewrite smaple to use builder pattern