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.gunz.carrental.Fragments.CarsFragment.java

private void addCar(final boolean isAddCar, final int position) {
    final Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.custom_dialog_car);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);/*  w w w . j av a2s.  c o  m*/
    TextView lblTitle = (TextView) dialog.findViewById(R.id.lblTitle);
    final MaterialEditText txBrand = (MaterialEditText) dialog.findViewById(R.id.txBrand);
    final MaterialEditText txModel = (MaterialEditText) dialog.findViewById(R.id.txModel);
    final MaterialEditText txLicense = (MaterialEditText) dialog.findViewById(R.id.txLicense);
    final MaterialEditText txFare = (MaterialEditText) dialog.findViewById(R.id.txFare);
    Button btnSave = (Button) dialog.findViewById(R.id.btnSave);
    ImageView imgClose = (ImageView) dialog.findViewById(R.id.imgClose);
    dialog.show();
    clearErrorMsg(dialog);

    if (!isAddCar) {
        lblTitle.setText(getActivity().getResources().getString(R.string.update_car_title));
        txBrand.setText(cars.get(position).brand);
        txModel.setText(cars.get(position).type);
        txLicense.setText(cars.get(position).licensePlat);
        txFare.setText(String.valueOf((int) cars.get(position).farePerDay));
    } else {
        lblTitle.setText(getActivity().getResources().getString(R.string.add_new_car_title));
    }

    btnSave.setOnClickListener(new OnOneClickListener() {
        @Override
        public void onOneClick(View v) {
            if (TextUtils.isEmpty(txBrand.getText().toString().trim())) {
                txBrand.setText("");
                txBrand.setError(getActivity().getResources().getString(R.string.validation_required));
                txBrand.requestFocus();
            } else if (TextUtils.isEmpty(txModel.getText().toString().trim())) {
                txModel.setText("");
                txModel.setError(getActivity().getResources().getString(R.string.validation_required));
                txModel.requestFocus();
            } else if (TextUtils.isEmpty(txLicense.getText().toString().trim())) {
                txLicense.setText("");
                txLicense.setError(getActivity().getResources().getString(R.string.validation_required));
                txLicense.requestFocus();
            } else if (TextUtils.isEmpty(txFare.getText().toString().trim())) {
                txFare.setText("");
                txFare.setError(getActivity().getResources().getString(R.string.validation_required));
                txFare.requestFocus();
            } else {
                String confirmText;
                if (isAddCar) {
                    confirmText = getActivity().getResources().getString(R.string.dialog_add_car_question);
                } else {
                    confirmText = getActivity().getResources().getString(R.string.dialog_update_car_question);
                }
                new SweetAlertDialog(getActivity(), SweetAlertDialog.NORMAL_TYPE)
                        .setTitleText(getActivity().getResources().getString(R.string.dialog_confirmation))
                        .setContentText(confirmText)
                        .setCancelText(getActivity().getResources().getString(R.string.btn_cancel))
                        .setConfirmText(getActivity().getResources().getString(R.string.btn_save))
                        .showCancelButton(true)
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sweetAlertDialog) {
                                if (isAddCar) {
                                    saveNewCar(dialog, txBrand.getText().toString().trim(),
                                            txModel.getText().toString().trim(),
                                            Integer.parseInt(txFare.getText().toString().trim()),
                                            txLicense.getText().toString().trim());
                                } else {
                                    updateCar(dialog, cars.get(position).id,
                                            txBrand.getText().toString().trim(),
                                            txModel.getText().toString().trim(),
                                            Integer.parseInt(txFare.getText().toString().trim()),
                                            txLicense.getText().toString().trim());
                                }
                                sweetAlertDialog.dismiss();
                            }
                        }).show();
            }
        }
    });

    imgClose.setOnClickListener(new OnOneClickListener() {
        @Override
        public void onOneClick(View v) {
            Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    dialog.dismiss();
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            v.startAnimation(animation);
        }
    });
}

From source file:com.geecko.QuickLyric.adapter.IntroScreenSlidePagerAdapter.java

public void exitAction() {
    Animation slideOut = new TranslateAnimation(0f, -2000f, 0f, 0f);
    slideOut.setInterpolator(new AccelerateInterpolator());
    slideOut.setDuration(700);/*from  w  w  w.  j a  v  a  2s  .  c  o  m*/

    slideOut.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationEnd(Animation animation) {
            IntroScreenSlidePagerAdapter.this.onAnimationEnd();
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationStart(Animation animation) {
        }
    });
    if (mActivity instanceof AboutActivity)
        ((AboutActivity) mActivity).setStatusBarColor(null);
    else
        MainActivity.setStatusBarColor(mActivity.getWindow(), mActivity.getTheme(), null);
    MainActivity.setNavBarColor(mActivity.getWindow(), mActivity.getTheme(), null);
    ((RelativeLayout) mPager.getParent()).startAnimation(slideOut);
}

From source file:org.kontalk.ui.ConversationListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mAction = view.findViewById(R.id.action);
    mAction.setOnClickListener(new View.OnClickListener() {
        @Override/*  www. j  ava  2 s.  c  o m*/
        public void onClick(View v) {
            chooseContact();
        }
    });
    mActionVisible = true;

    getListView().setOnScrollListener(new AbsListViewScrollDetector() {
        @Override
        public void onScrollUp() {
            if (mActionVisible) {
                mActionVisible = false;
                if (isAnimating())
                    mAction.clearAnimation();

                Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.exit_to_bottom);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mAction.clearAnimation();
                        mAction.setVisibility(View.GONE);
                    }

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

        @Override
        public void onScrollDown() {
            if (!mActionVisible) {
                mActionVisible = true;
                if (isAnimating())
                    mAction.clearAnimation();

                Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.enter_from_bottom);
                mAction.startAnimation(anim);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        mAction.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mAction.clearAnimation();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                });
            }
        }

        private boolean isAnimating() {
            return mAction.getAnimation() != null;
        }
    });
}

From source file:com.findme.views.ExpandableTextView.java

@Override
public void onClick(View view) {
    if (mButton.getVisibility() != View.VISIBLE) {
        return;//  w  w  w  .j a va 2 s  .co m
    }

    mCollapsed = !mCollapsed;
    mButton.setImageDrawable(mCollapsed ? mExpandDrawable : mCollapseDrawable);

    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }

    // mark that the animation is in progress
    mAnimating = true;

    Animation animation;
    if (mCollapsed) {
        animation = new ExpandCollapseAnimation(this, getHeight(), mCollapsedHeight);
    } else {
        animation = new ExpandCollapseAnimation(this, getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTv.getHeight());
    }

    animation.setFillAfter(true);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            applyAlphaAnimation(mTv, mAnimAlphaStart);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // clear animation here to avoid repeated applyTransformation()
            // calls
            clearAnimation();
            // clear the animation flag
            mAnimating = false;
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });

    clearAnimation();
    startAnimation(animation);
}

From source file:com.example.camera360.ui.ImageDetailActivity.java

private void slideView(final float p1, final float p2, View view, AnimationListener animationListener) {
    view.setVisibility(View.VISIBLE);
    Animation animation = baseAnimate.animateTranslate(0, 0, p1, p2, DURATION_MILLIS, true);
    animation.setAnimationListener(animationListener);
    view.startAnimation(animation);/*from w w w  .  j  a v  a  2  s . c o  m*/
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWidgetPool.java

public void showWidget() {
    if (null != mAppCenter && mAppCenter.isShown()) {
        mAppCenter.notifyWidgetLoadFinish();
    }/*from  w w  w.  ja  v a  2s  . c o  m*/
    final EBrowserWidget showWidget = mWgtStack.peek();
    final EBrowserWidget hiddenWidget = mWgtStack.prev();
    int animiId = 0;
    long duration = 0;
    EWgtResultInfo inResult = showWidget.getResult();
    if (null != inResult) {
        animiId = inResult.getAnimiId();
        duration = inResult.getDuration();
    }
    Animation[] animPair = EBrowserAnimation.getAnimPair(animiId, duration);
    Animation showAnim = animPair[0];
    Animation hiddenAnim = animPair[1];
    showAnim.setStartOffset(500);
    hiddenAnim.setStartOffset(500);
    hiddenAnim.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation animation) {
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationEnd(Animation animation) {
            hiddenWidget.setVisibility(View.GONE);
            showWidget.notifyVisibilityChanged(0);
            hiddenWidget.notifyVisibilityChanged(1);
            showHover(true);
            WWidgetData wgtData = showWidget.getWidget();
            int wgtOrientation = wgtData.m_orientation;
            mContext.changeConfiguration(wgtOrientation);
        }
    });
    showWidget.setVisibility(View.VISIBLE);
    hiddenWidget.startAnimation(hiddenAnim);
    showWidget.startAnimation(showAnim);
}

From source file:com.daiv.android.twitter.settings.SettingsActivityOld.java

private void switchToSettingsList(boolean settings) {
    if (settings && settingsList.getVisibility() != View.VISIBLE) {
        // animate the settings list showing and other list hiding
        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        Animation out = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);
        in.setDuration(ANIM_TIME * 2);/*from  ww w .  j av  a 2 s.  c o m*/
        out.setDuration(ANIM_TIME);
        in.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                settingsList.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        out.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                otherList.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                otherList.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        settingsList.startAnimation(in);
        otherList.startAnimation(out);
    } else if (!settings && otherList.getVisibility() != View.VISIBLE) {
        // animate the other list showing and settings list hiding
        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        Animation out = AnimationUtils.loadAnimation(this, R.anim.slide_out_left);
        in.setDuration(ANIM_TIME * 2);
        out.setDuration(ANIM_TIME);
        in.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                otherList.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        out.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                settingsList.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                settingsList.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        settingsList.startAnimation(out);
        otherList.startAnimation(in);
    }
}

From source file:com.yahala.ui.Views.BaseFragment.java

@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {

    // HW layer support only exists on API 11+
    Animation animation = super.onCreateAnimation(transit, enter, nextAnim);

    // HW layer support only exists on API 11+
    if (Build.VERSION.SDK_INT >= 11) {
        if (animation == null && nextAnim != 0) {
            animation = AnimationUtils.loadAnimation(getActivity(), nextAnim);
        }/*from   ww w .j  a v a2 s.co m*/

        if (animation != null) {
            getView().setLayerType(View.LAYER_TYPE_HARDWARE, null);

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

                public void onAnimationEnd(Animation animation) {
                    try {
                        getView().setLayerType(View.LAYER_TYPE_NONE, null);
                        BaseFragment.this.onAnimationEnd();
                    } catch (Exception e) {
                    }
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

            });
        }
    }

    return animation;

    /*if (nextAnim != 0) {
    Animation animation = AnimationUtils.loadAnimation(getActivity(), nextAnim);
    if (Build.VERSION.SDK_INT >= 11) {
        getView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    animation.setAnimationListener(new Animation.AnimationListener() {
            
        public void onAnimationStart(Animation animation) {
            BaseFragment.this.onAnimationStart();
        }
            
        public void onAnimationRepeat(Animation animation) {
            
        }
            
        public void onAnimationEnd(Animation animation){
            BaseFragment.this.onAnimationEnd();
            if (Build.VERSION.SDK_INT >= 11) {
                getView().setLayerType(View.LAYER_TYPE_NONE, null);
          }
        }
    });
            
    return animation;
    } else {
    return super.onCreateAnimation(transit, enter, nextAnim);
    }*/
}

From source file:com.hippo.widget.Snackbar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 14) {
        ViewCompat.animate(mView).translationY(mView.getHeight())
                .setInterpolator(AnimationUtils2.SLOW_FAST_INTERPOLATOR).setDuration(ANIMATION_DURATION)
                .setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override/*  www. ja  v a2s.  c o m*/
                    public void onAnimationStart(View view) {
                        mView.animateChildrenOut(0, ANIMATION_FADE_DURATION);
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        onViewHidden(event);
                    }
                }).start();
    } else {
        Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_out);
        anim.setInterpolator(AnimationUtils2.SLOW_FAST_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new SimpleAnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.hippo.widget.Snackbar.java

private void animateViewIn() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewCompat.setTranslationY(mView, mView.getHeight());
        ViewCompat.animate(mView).translationY(0.0F).setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR)
                .setDuration(ANIMATION_DURATION).setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override//from   w ww  .ja va 2s . com
                    public void onAnimationStart(View view) {
                        mView.animateChildrenIn(70, ANIMATION_FADE_DURATION);
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        if (mCallback != null) {
                            mCallback.onShown(Snackbar.this);
                        }
                        SnackbarManager.getInstance().onShown(mManagerCallback);
                    }
                }).start();
    } else {
        Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_in);
        anim.setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new SimpleAnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                if (mCallback != null) {
                    mCallback.onShown(Snackbar.this);
                }
                SnackbarManager.getInstance().onShown(mManagerCallback);
            }
        });
        mView.startAnimation(anim);
    }
}