Example usage for android.view ViewGroup startAnimation

List of usage examples for android.view ViewGroup startAnimation

Introduction

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

Prototype

public void startAnimation(Animation animation) 

Source Link

Document

Start the specified animation now.

Usage

From source file:Main.java

public static void collapse(final ViewGroup v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override//from ww  w. ja va2 s  . c o m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.setAlpha(1 - interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void expand(final ViewGroup v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;//from  ww w.  j  a v a2  s .  c o  m
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.setAlpha(interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:com.luanthanhthai.android.liteworkouttimer.TimerFragment.java

/**
 * Animation for keypad slide up from bottom
 *//*  ww w .  ja  v a 2  s .c  om*/
public void animSlidePanelUp(ViewGroup slidePanelUp) {
    Animation slideUp = AnimationUtils.loadAnimation(getContext(), R.anim.panel_slide_up);
    slidePanelUp.startAnimation(slideUp);
    slidePanelUp.setVisibility(View.VISIBLE);
}

From source file:com.luanthanhthai.android.liteworkouttimer.TimerFragment.java

/**
 * Animation for keypad slide down and disappear
 *//*ww w. j av  a  2  s.co  m*/
public void animSlidePanelDown(ViewGroup slidePanelDown) {
    Animation slideDown = AnimationUtils.loadAnimation(getContext(), R.anim.panel_slide_down);
    slidePanelDown.startAnimation(slideDown);
    slidePanelDown.setVisibility(View.GONE);
}

From source file:org.ohmage.prompts.SurveyItemFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.prompt_basic, container, false);
    ((TextView) view.findViewById(R.id.text)).setText(getPromptText());
    mButtons = view.findViewById(R.id.buttons);
    skipButton = (TextView) view.findViewById(R.id.skip);
    okButton = (TextView) view.findViewById(R.id.ok);

    okButton.setOnClickListener(new OnClickListener() {
        @Override/*  www  .  j  a va2  s .  c  om*/
        public void onClick(View v) {
            mAnswered = true;
            onOkPressed();
        }
    });
    skipButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mAnswered = true;
            onSkipPressed();
        }
    });

    if (isSkippable()) {
        skipButton.setVisibility(View.VISIBLE);
    } else {
        skipButton.setVisibility(View.GONE);
    }

    if (isAnswered()) {
        mButtons.setVisibility(View.GONE);
    } else {
        updateCanContinue();
    }

    onCreatePromptView(inflater, (ViewGroup) view.findViewById(R.id.content), savedInstanceState);

    // Fade the prompt in
    if (!isAnswered()) {
        AlphaAnimation aa = new AlphaAnimation(0f, 1f);
        aa.setFillAfter(true);
        aa.setDuration(200);
        view.startAnimation(aa);
    }

    return view;
}

From source file:com.app.blockydemo.ui.adapter.BrickAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (draggedBrick != null && dragTargetPosition == position) {
        return insertionView;
    }//from  w  ww.j  ava  2  s .  c  om
    listItemCount = position + 1;

    Object item = getItem(position);

    if (item instanceof ScriptBrick && (!initInsertedBrick || position != positionOfInsertedBrick)) {
        View scriptBrickView = ((Brick) item).getView(context, position, this);
        if (draggedBrick == null) {
            scriptBrickView.setOnClickListener(this);
        }
        return scriptBrickView;
    }

    View currentBrickView;
    // dirty HACK
    // without the footer, position can be 0, and list.get(-1) caused an Indexoutofboundsexception
    // no clean solution was found
    if (position == 0) {
        if (item instanceof AllowedAfterDeadEndBrick && brickList.get(position) instanceof DeadEndBrick) {
            currentBrickView = ((AllowedAfterDeadEndBrick) item).getNoPuzzleView(context, position, this);
        } else {
            currentBrickView = ((Brick) item).getView(context, position, this);
        }
    } else {
        if (item instanceof AllowedAfterDeadEndBrick && brickList.get(position - 1) instanceof DeadEndBrick) {
            currentBrickView = ((AllowedAfterDeadEndBrick) item).getNoPuzzleView(context, position, this);
        } else {
            currentBrickView = ((Brick) item).getView(context, position, this);
        }
    }

    // this one is working but causes null pointer exceptions on movement and control bricks?!
    //      currentBrickView.setOnLongClickListener(longClickListener);

    // Hack!!!
    // if wrapper isn't used the longClick event won't be triggered
    ViewGroup wrapper = (ViewGroup) View.inflate(context, R.layout.brick_wrapper, null);
    if (currentBrickView.getParent() != null) {
        ((ViewGroup) currentBrickView.getParent()).removeView(currentBrickView);
    }

    wrapper.addView(currentBrickView);
    if (draggedBrick == null) {
        if ((selectMode == ListView.CHOICE_MODE_NONE)) {
            wrapper.setOnClickListener(this);
            if (!(item instanceof DeadEndBrick)) {
                wrapper.setOnLongClickListener(dragAndDropListView);
            }
        }
    }

    if (position == positionOfInsertedBrick && initInsertedBrick && (selectMode == ListView.CHOICE_MODE_NONE)) {
        initInsertedBrick = false;
        addingNewBrick = true;
        dragAndDropListView.setInsertedBrick(position);

        dragAndDropListView.setDraggingNewBrick();
        dragAndDropListView.onLongClick(currentBrickView);

        return insertionView;
    }

    if (animatedBricks.contains(brickList.get(position))) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.blink);
        wrapper.startAnimation(animation);
        animatedBricks.remove(brickList.get(position));
    }
    return wrapper;
}