package com.github.paolorotolo.appintroexample;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import com.github.paolorotolo.appintro.AppIntro;

/**
 * Created by hangshi on 2016-04-12.
 */
public class ChangeJarIntro extends AppIntro{

    private ImageView image;

    @Override
    public void init(Bundle savedInstanceState) {

        LinearLayout LL = new LinearLayout(this);

        LL.setBackgroundColor(Color.GRAY);
        LL.setOrientation(LinearLayout.VERTICAL);

        LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);

        LL.setWeightSum(3f);
        LL.setLayoutParams(LLParams);

        image = new ImageView(this);
        image.setImageResource(R.drawable.onboarding_1);
        image.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 2f));

        LL.addView(image);

        TextView sepratorView = (TextView)findViewById(R.id.bottom_separator);
        sepratorView.setVisibility(View.INVISIBLE);

        View viewPager = findViewById(R.id.view_pager);
        ViewGroup rl = ((ViewGroup)viewPager.getParent());
        ((ViewGroup)rl.getParent()).removeView(rl);
        rl.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f));
        LL.addView(rl);

        setContentView(LL);


//        addSlide(SampleSlide.newInstance(R.layout.intro_layout));

        addSlide(SampleSlide.newInstance(R.layout.changejar_intro_1));
        addSlide(SampleSlide.newInstance(R.layout.changejar_intro_2));
        addSlide(SampleSlide.newInstance(R.layout.changejar_intro_3));

    }

    private void loadMainActivity(){
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

    @Override
    public void onNextPressed() {
    }

    @Override
    public void onSkipPressed() {
        loadMainActivity();
        Toast.makeText(getApplicationContext(),
                getString(R.string.skip), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDonePressed() {
        loadMainActivity();
    }

    @Override
    public void onSlideChanged() {

        int imageId = 0;
        switch (this.pager.getCurrentItem()) {
            case 0:
                imageId = R.drawable.onboarding_1;
                break;
            case 1:
                imageId = R.drawable.onboarding_2;
                break;
            case 2:
                imageId = R.drawable.onboarding_3;
                break;
        }

//        System.out.println(R.id.changejar_icon1);

//        ImageView image = (ImageView)findViewById(R.id.changejar_icon1);
        if (image != null) {
            image.setImageResource(imageId);
        }
    }

    public void getStarted(View v){
        loadMainActivity();
    }
}

@@ -643,1040 +643,21 @@
     
-LinearLayout LL = new LinearLayout(this);%0A%0A        LL.setBackgroundColor(Color.GRAY);%0A        LL.setOrientation(LinearLayout.VERTICAL);%0A%0A        LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);%0A%0A        LL.setWeightSum(3f);%0A        LL.setLayoutParams(LLParams);%0A%0A        image = new ImageView(this);%0A        image.setImageResource(R.drawable.onboarding_1);%0A        image.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 2f));%0A%0A        LL.addView(image);%0A%0A        TextView sepratorView = (TextView)findViewById(R.id.bottom_separator);%0A        sepratorView.setVisibility(View.INVISIBLE);%0A%0A        View viewPager = findViewById(R.id.view_pager);%0A        ViewGroup rl = ((ViewGroup)viewPager.getParent());%0A        ((ViewGroup)rl.getParent()).removeView(rl);%0A        rl.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f));%0A        LL.addView(rl);%0A%0A        setContentView(LL);%0A%0A%0A//        addSlide(SampleSlide.newInstance(R.layout.intro_layout)
+changeLayout(
 );%0A%0A
@@ -866,24 +866,53 @@
 intro_3));%0A%0A
+        setFadeAnimation();%0A%0A
     %7D%0A%0A    p
@@ -1801,136 +1801,8 @@
  %7D%0A%0A
-//        System.out.println(R.id.changejar_icon1);%0A%0A//        ImageView image = (ImageView)findViewById(R.id.changejar_icon1);%0A
     
@@ -1957,11 +1957,1432 @@
 );%0A    %7D
+%0A%0A    public void changeLayout() %7B%0A        LinearLayout linearLayout = new LinearLayout(this);%0A%0A        linearLayout.setBackgroundColor(Color.GRAY);%0A        linearLayout.setOrientation(LinearLayout.VERTICAL);%0A%0A        LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);%0A%0A        linearLayout.setWeightSum(3f);%0A        linearLayout.setLayoutParams(LLParams);%0A%0A        image = new ImageView(this);%0A        image.setImageResource(R.drawable.onboarding_1);%0A        image.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 2f));%0A%0A        // formula: http://developer.android.com/guide/practices/screens_support.html#dips-pels%0A        float scale = getResources().getDisplayMetrics().density;%0A        int dpAsPixels = (int) (16*scale + 0.5f);%0A        image.setPadding(dpAsPixels, 0, dpAsPixels, 0);%0A        image.setScaleType(ImageView.ScaleType.FIT_END);%0A%0A        linearLayout.addView(image);%0A%0A        TextView sepratorView = (TextView)findViewById(R.id.bottom_separator);%0A        sepratorView.setVisibility(View.INVISIBLE);%0A%0A        View viewPager = findViewById(R.id.view_pager);%0A        ViewGroup rl = ((ViewGroup) viewPager.getParent());%0A        ((ViewGroup) rl.getParent()).removeView(rl);%0A        rl.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f));%0A        linearLayout.addView(rl);%0A%0A        setContentView(linearLayout);%0A    %7D
 %0A%7D%0A

Add some styles programmatically