Example usage for android.view ViewGroup setAnimation

List of usage examples for android.view ViewGroup setAnimation

Introduction

In this page you can find the example usage for android.view ViewGroup setAnimation.

Prototype

public void setAnimation(Animation animation) 

Source Link

Document

Sets the next animation to play for this view.

Usage

From source file:com.cairoconfessions.MainActivity.java

public View addConfession(String confess, String desc) {
    final ViewGroup confession = (ViewGroup) LayoutInflater.from(this)
            .inflate(R.layout.confession_list_item_example, null);
    final TextView newConfess = (TextView) confession.findViewById(R.id.text_main);
    newConfess.setText(confess);// ww w .j ava 2 s.c  om
    final float scale = getResources().getDisplayMetrics().density;
    if (!desc.equals("")) {
        confession.setContentDescription(desc);
        if (desc.equals("Love"))
            newConfess.setBackgroundResource(R.color.love);
        if (desc.equals("Pain"))
            newConfess.setBackgroundResource(R.color.pain);
        if (desc.equals("Guilt"))
            newConfess.setBackgroundResource(R.color.guilt);
        if (desc.equals("Fantasy"))
            newConfess.setBackgroundResource(R.color.fantasy);
        if (desc.equals("Dream"))
            newConfess.setBackgroundResource(R.color.dream);
    } else {
        switch ((new Random().nextInt(5)) % 5) {
        case 0:
            newConfess.setBackgroundResource(R.color.love);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
            confession.setContentDescription("Love");
            break;
        case 1:
            newConfess.setBackgroundResource(R.color.pain);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Cairo");
            confession.setContentDescription("Pain");
            break;
        case 2:
            newConfess.setBackgroundResource(R.color.guilt);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
            confession.setContentDescription("Guilt");
            break;
        case 3:
            newConfess.setBackgroundResource(R.color.fantasy);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
            confession.setContentDescription("Fantasy");
            break;
        case 4:
            newConfess.setBackgroundResource(R.color.dream);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
            confession.setContentDescription("Dream");
            break;
        }
    }
    switch ((new Random().nextInt(3)) % 3) {
    case 0:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
        break;
    case 1:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("Cairo");
        break;
    case 2:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
        break;
    }
    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setDuration(1000);
    confession.setAnimation(fadeIn);
    confession.getChildAt(0).setPadding((int) (scale * 1.5 + 0.5f), (int) (scale * 1.5 + 0.5f),
            (int) (scale * 1.5 + 0.5f), (int) (scale * 1.5 + 0.5f));
    confession.getChildAt(0).setBackgroundResource(R.drawable.border);
    mPager.setCurrentItem(1);
    if (!desc.equals("")) {
        ((ScrollView) findViewById(R.id.feed)).fullScroll(ScrollView.FOCUS_UP);
        ((LinearLayout) findViewById(R.id.confession_list)).addView(confession, 0);
    } else {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {

                ((ScrollView) findViewById(R.id.feed)).fullScroll(ScrollView.FOCUS_UP);
                ((LinearLayout) findViewById(R.id.confession_list)).post(new Runnable() {

                    public void run() {
                        ((LinearLayout) findViewById(R.id.confession_list)).addView(confession, 0);
                    }
                });
            }
        }, 1000);
    }
    return confession;

}