Example usage for android.view.animation Animation setAnimationListener

List of usage examples for android.view.animation Animation setAnimationListener

Introduction

In this page you can find the example usage for android.view.animation Animation setAnimationListener.

Prototype

public void setAnimationListener(AnimationListener listener) 

Source Link

Document

Binds an animation listener to this animation.

Usage

From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationActivity.java

void translate(float deltaX, final boolean finalAnim) {
    // mapFragment.mapView.setEnabled(false);
    float newX = posX + deltaX;
    if (slidden) {
        if (newX < -maxSlide)
            newX = -maxSlide;/* w w w.j a  va  2  s.  c  om*/
        else if (newX > 0)
            newX = 0;
    } else {
        if (newX < 0)
            newX = 0;
        else if (newX > maxSlide)
            newX = maxSlide;
    }

    if (((int) newX) <= 0) {
        mapDisabledView.setVisibility(View.GONE);
    }

    final boolean newSlidden = slidden ? newX > -SLIDE_THRESHOLD : newX > SLIDE_THRESHOLD;
    if (finalAnim) {
        newX = (slidden == newSlidden) ? 0 : (slidden ? -maxSlide : maxSlide);
    }

    if (animation != null && animation.isInitialized()) {
        animation.cancel();
        parentContainer.clearAnimation();
        leftContainer.invalidate();
    }
    animation = new TranslateAnimation(posX, newX, 0, 0);
    animation.setDuration(finalAnim ? 100 : 0);

    animation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (!finalAnim) {
                animation.setFillEnabled(true);
                animation.setFillAfter(true);
            } else {
                parentContainer.clearAnimation();
                if (slidden == newSlidden) {
                    if (!slidden) {
                        leftContainer.setVisibility(View.GONE);
                        mapDisabledView.setVisibility(View.GONE);
                        // mapFragment.mapView.setEnabled(true);
                        // mapFragment.mapView.invalidate();
                        leftContainer.invalidate();
                    } else {
                        leftContainer.setVisibility(View.VISIBLE);
                        mapDisabledView.setVisibility(View.VISIBLE);
                        leftContainer.invalidate();
                    }
                    return;
                }
                slidden = newSlidden;
                int leftmargin = slidden ? maxSlide : 0;
                int rightMargin = slidden ? 0 : maxSlide;
                RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) parentContainer
                        .getLayoutParams();
                lp.setMargins(leftmargin, lp.topMargin, rightMargin, lp.bottomMargin);
                parentContainer.setLayoutParams(lp);

                if (leftmargin == 0) {
                    leftContainer.setVisibility(View.GONE);
                    mapDisabledView.setVisibility(View.GONE);
                    // mapFragment.mapView.setEnabled(true);
                    // mapFragment.mapView.invalidate();
                    leftContainer.invalidate();
                }
                posX = 0;
            }
        }
    });

    posX = newX;

    parentContainer.startAnimation(animation);
}

From source file:org.telegram.ui.GalleryImageViewer.java

private void startViewAnimation(final View panel, boolean up) {
    Animation animation;
    if (!up) {//from w  w  w . ja  va  2s. co m
        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                panel.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        animation.setDuration(400);
    } else {
        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                panel.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        animation.setDuration(100);
    }
    panel.startAnimation(animation);
}

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

private void animateSelectedBricks() {
    if (!animatedBricks.isEmpty()) {

        for (final Brick animationBrick : animatedBricks) {
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.blink);

            animation.setAnimationListener(new AnimationListener() {

                @Override/*from  w  ww.j  a v a2  s .c  o  m*/
                public void onAnimationStart(Animation animation) {
                    animationBrick.setAnimationState(true);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    animationBrick.setAnimationState(false);
                }
            });
            int position = animatedBricks.indexOf(animationBrick);
            animationBrick.setAnimationState(true);
            View view = animationBrick.getView(context, position, this);

            if (view.hasWindowFocus()) {
                view.startAnimation(animation);
            }
        }

    }
    animatedBricks.clear();
}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

public void onBackPressed() {

    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    final View fragmentView = getView();

    if (fragmentView != null) {
        final float viewStartY = getView().getY();

        Animation animation = new Animation() {
            @Override/*from   www. j  av a2  s.  c om*/
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                fragmentView.setY((screenHeight - viewStartY) * interpolatedTime + viewStartY);
            }

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

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                getFragmentManager().popBackStack();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        animation.setDuration(SLIDE_EXIT_TIME);
        getView().startAnimation(animation);
    } else {
        getFragmentManager().popBackStack();
    }
}

From source file:com.box.myview.MyTopSnackBar.TSnackbar.java

private void animateViewIn() {
    Animation anim;
    if (appearDirection == APPEAR_FROM_TOP_TO_DOWN) {
        anim = getAnimationInFromTopToDown();
    } else {/*from w  ww. j  a v a  2 s .c o m*/
        anim = getAnimationInFromBottomToTop();
    }
    anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
    anim.setDuration(ANIMATION_DURATION);
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            onViewShown();
        }

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    mView.startAnimation(anim);
}

From source file:com.box.myview.MyTopSnackBar.TSnackbar.java

private void animateViewOut(final int event) {
    Animation anim;

    if (appearDirection == APPEAR_FROM_TOP_TO_DOWN) {
        anim = getAnimationOutFromTopToDown();
    } else {//from   w w w  .j a  v  a 2  s .c  om
        anim = getAnimationOutFromBottomToTop();
    }
    anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
    anim.setDuration(ANIMATION_DURATION);
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            onViewHidden(event);
        }

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    mView.startAnimation(anim);
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

public static void sizeTo(final View v, int finalWidth, int durationMS, Animation.AnimationListener listener) {
    final int initalWidth = v.getMeasuredWidth();

    final int diff = finalWidth - initalWidth;

    final int multiplier = diff < 0 ? -1 : 0;

    Animation a = new Animation() {
        @Override//from  ww  w  .  j a v a 2  s  . c o m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().width = initalWidth + ((int) (diff * interpolatedTime));
            v.requestLayout();
        }

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

    a.setAnimationListener(listener);

    if (durationMS < 0) {
        // 1dp/ms
        a.setDuration((int) ((diff * multiplier) / v.getContext().getResources().getDisplayMetrics().density));
    } else {
        a.setDuration(durationMS);
    }
    v.startAnimation(a);
}

From source file:de.grobox.liberario.fragments.DirectionsFragment.java

private void swapLocations() {
    Animation slideUp = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f);

    slideUp.setDuration(400);/*from   w w w  .  j  a  v  a  2  s .  c  om*/
    slideUp.setFillAfter(true);
    slideUp.setFillEnabled(true);
    ui.to.startAnimation(slideUp);

    Animation slideDown = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);

    slideDown.setDuration(400);
    slideDown.setFillAfter(true);
    slideDown.setFillEnabled(true);
    ui.from.startAnimation(slideDown);

    slideUp.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // swap location objects
            Location tmp = ui.to.getLocation();
            if (!ui.from.isSearching()) {
                ui.to.setLocation(ui.from.getLocation(),
                        getDrawableForLocation(getContext(), ui.from.getLocation()));
            } else {
                // TODO: GPS currently only supports from location, so don't swap it for now
                ui.to.clearLocation();
            }
            ui.from.setLocation(tmp, getDrawableForLocation(getContext(), tmp));

            ui.from.clearAnimation();
            ui.to.clearAnimation();
        }
    });
}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

private void saveSource() {

    final Intent sourceIntent = new Intent();

    String title = sourceTitle.getText().toString();
    String data = sourceData.getText().toString();

    if (type.equals(AppSettings.FOLDER)) {
        data = folderData;/*from ww  w. j  a  v  a  2 s .  c  o  m*/
    }

    if (title.equals("")) {
        Toast.makeText(appContext, "Title cannot be empty", Toast.LENGTH_SHORT).show();
        return;
    }
    if (data.equals("")) {
        Toast.makeText(appContext, "Data cannot be empty", Toast.LENGTH_SHORT).show();
        return;
    }

    int num = 0;
    try {
        num = Integer.parseInt(sourceNum.getText().toString());
    } catch (NumberFormatException e) {
        num = 1;
    }

    switch (type) {

    case AppSettings.WEBSITE:
        if (!data.contains("http")) {
            data = "http://" + data;
        }
        break;

    }

    if (sourcePosition == -1) {

        if (FileHandler.isDownloading) {
            Toast.makeText(appContext, "Cannot add source while downloading", Toast.LENGTH_SHORT).show();
            return;
        }

        sourceIntent.setAction(SourceListFragment.ADD_ENTRY);

    } else {

        if (!getArguments().getString("title").equals(title)) {
            FileHandler.renameFolder(getArguments().getString("title"), title);
        }

        if (FileHandler.isDownloading) {
            Toast.makeText(appContext, "Cannot edit while downloading", Toast.LENGTH_SHORT).show();
            return;
        }

        sourceIntent.setAction(SourceListFragment.SET_ENTRY);
    }

    sourceIntent.putExtra("type", type);
    sourceIntent.putExtra("title", sourceTitle.getText().toString());
    sourceIntent.putExtra("data", data);
    sourceIntent.putExtra("num", num);
    sourceIntent.putExtra("position", sourcePosition);
    sourceIntent.putExtra("use", sourceUse.isChecked());
    sourceIntent.putExtra("preview",
            ((CustomSwitchPreference) findPreference("source_show_preview")).isChecked());
    sourceIntent.putExtra("use_time", timePref.isChecked());
    sourceIntent.putExtra("time",
            String.format("%02d:%02d - %02d:%02d", startHour, startMinute, endHour, endMinute));

    try {
        InputMethodManager im = (InputMethodManager) appContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(getView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception e) {
        e.printStackTrace();
    }

    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    final View fragmentView = getView();

    if (fragmentView != null) {
        final float viewStartY = getView().getY();

        Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                fragmentView.setY((screenHeight - viewStartY) * interpolatedTime + viewStartY);
            }

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

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                LocalBroadcastManager.getInstance(appContext).sendBroadcast(sourceIntent);
                getFragmentManager().popBackStack();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        animation.setDuration(SLIDE_EXIT_TIME);
        getView().startAnimation(animation);
    } else {
        LocalBroadcastManager.getInstance(appContext).sendBroadcast(sourceIntent);
    }

}

From source file:com.sim2dial.dialer.InCallActivity.java

private void hideAnimatedPortraitCallOptions() {
    Animation animation = slideOutLeftToRight;
    animation.setAnimationListener(new AnimationListener() {
        @Override//from  w ww  .j ava  2  s  .c o  m
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (isTransferAllowed) {
                transfer.setVisibility(View.INVISIBLE);
            }
            // addCall.setVisibility(View.INVISIBLE);
            animation.setAnimationListener(null);
        }
    });
    if (isTransferAllowed) {
        transfer.startAnimation(animation);
    }
    addCall.startAnimation(animation);
}