package com.chrisplus.universalcardreader;

import com.astuetz.PagerSlidingTabStrip;
import com.chrisplus.universalcardreader.adapters.TabAdapter;
import com.readystatesoftware.systembartint.SystemBarTintManager;

import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewpager;
    private PagerSlidingTabStrip tabStrip;
    private TabAdapter adapter;
    private SystemBarTintManager tintManager;
    private Toolbar toolBar;
    private Drawable oldBackground = null;
    private int currentColor;


    private final ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    changeColor(getResources().getColor(R.color.color_card_info));
                    break;
                case 1:
                    changeColor(getResources().getColor(R.color.color_transaction));
                    break;
                case 2:
                    changeColor(getResources().getColor(R.color.color_log));
                    break;
                default:
                    changeColor(getResources().getColor(R.color.color_card_info));
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

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

        viewpager = (ViewPager) findViewById(R.id.viewpager);
        tabStrip = (PagerSlidingTabStrip) findViewById(R.id.tabs);
        toolBar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolBar);
        tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);

        adapter = new TabAdapter(getSupportFragmentManager());

        viewpager.setAdapter(adapter);
        tabStrip.setViewPager(viewpager);
        tabStrip.setOnPageChangeListener(onPageChangeListener);

        changeColor(getResources().getColor(R.color.color_card_info));
    }

    private void changeColor(int newColor) {
        tabStrip.setBackgroundColor(newColor);
        tintManager.setTintColor(newColor);

        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));

        LayerDrawable ld = new LayerDrawable(new Drawable[]{colorDrawable, bottomDrawable});
        if (oldBackground == null) {
            getSupportActionBar().setBackgroundDrawable(ld);
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[]{oldBackground, ld});
            getSupportActionBar().setBackgroundDrawable(td);
            td.startTransition(200);
        }

        oldBackground = ld;
        currentColor = newColor;
    }
}

@@ -643,24 +643,25 @@
  viewpager;%0A
+%0A
     private 
@@ -691,16 +691,17 @@
 bStrip;%0A
+%0A
     priv
@@ -720,24 +720,25 @@
 er adapter;%0A
+%0A
     private 
@@ -771,16 +771,17 @@
 anager;%0A
+%0A
     priv
@@ -805,82 +805,8 @@
 ar;%0A
-    private Drawable oldBackground = null;%0A    private int currentColor;%0A%0A
 %0A   
@@ -871,16 +871,28 @@
 Listener
+%0A           
  = new V
@@ -2841,16 +2841,33 @@
 rawable(
+%0A                
 getResou
@@ -2909,25 +2909,24 @@
 nsparent));%0A
-%0A
         Laye
@@ -3018,31 +3018,39 @@
     if (
-oldBackground =
+getSupportActionBar() !
 = null) 
@@ -3125,280 +3125,8 @@
    %7D
- else %7B%0A            TransitionDrawable td = new TransitionDrawable(new Drawable%5B%5D%7BoldBackground, ld%7D);%0A            getSupportActionBar().setBackgroundDrawable(td);%0A            td.startTransition(200);%0A        %7D%0A%0A        oldBackground = ld;%0A        currentColor = newColor;
 %0A   

REMOVE change color animation