Example usage for android.view.animation TranslateAnimation setAnimationListener

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

Introduction

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

Prototype

public void setAnimationListener(AnimationListener listener) 

Source Link

Document

Binds an animation listener to this animation.

Usage

From source file:com.breadwallet.presenter.activities.IntroActivity.java

private void animateSlide(final Fragment from, final Fragment to, int direction) {
    if (to instanceof IntroRecoverWalletFragment) {
        if (Utils.isUsingCustomInputMethod(to.getActivity()))
            ((IntroRecoverWalletFragment) to).disableEditText();
    }//from   w w w  .j ava 2s  . c o  m
    int screenWidth = screenParametersPoint.x;
    int screenHeigth = screenParametersPoint.y;

    showHideFragments(from, to);
    TranslateAnimation transFrom = direction == RIGHT ? new TranslateAnimation(0, -screenWidth, 0, 0)
            : new TranslateAnimation(0, screenWidth, 0, 0);
    transFrom.setDuration(BRAnimator.horizontalSlideDuration);
    transFrom.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
    View fromView = from.getView();
    if (fromView != null)
        fromView.startAnimation(transFrom);
    TranslateAnimation transTo = direction == RIGHT ? new TranslateAnimation(screenWidth, 0, 0, 0)
            : new TranslateAnimation(-screenWidth, 0, 0, 0);
    transTo.setDuration(BRAnimator.horizontalSlideDuration);
    transTo.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
    transTo.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            showHideFragments(to);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    View toView = to.getView();
    if (toView != null)
        toView.startAnimation(transTo);
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java

private void searchFood(final String item, final int page_num) {
    if (!NetworkConnectionStatus.isNetworkAvailable(getActivity())) {
        Toast.makeText(getActivity(), "Check your connection and try again", Toast.LENGTH_LONG).show();
    } else {//w w w  . jav  a 2 s  .  c  om
        mAsyncTask = new AsyncTask<String, String, String>() {
            @Override
            protected void onPreExecute() {
            }

            @Override
            protected String doInBackground(String... arg0) {
                JSONObject food = mFatSecretSearch.searchFood(item, page_num);
                JSONArray FOODS_ARRAY;
                try {
                    if (food != null) {
                        FOODS_ARRAY = food.getJSONArray("food");
                        if (FOODS_ARRAY != null) {
                            for (int i = 0; i < FOODS_ARRAY.length(); i++) {
                                JSONObject food_items = FOODS_ARRAY.optJSONObject(i);
                                String food_name = food_items.getString("food_name");
                                String food_description = food_items.getString("food_description");
                                String[] row = food_description.split("-");
                                String id = food_items.getString("food_type");
                                if (id.equals("Brand")) {
                                    brand = food_items.getString("brand_name");
                                }
                                if (id.equals("Generic")) {
                                    brand = "Generic";
                                }
                                String food_id = food_items.getString("food_id");
                                mItem.add(new SearchItemResult(food_name, row[1].substring(1), "" + brand,
                                        food_id));
                            }
                        }
                    }
                } catch (JSONException exception) {
                    exception.printStackTrace();
                    return "Error";
                }
                return "";
            }

            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);
                searchAdapter.notifyDataSetChanged();
                if (listContainer.getCount() > 0) {
                    searchBack.setVisibility(View.VISIBLE);
                    TranslateAnimation slide = new TranslateAnimation(0, 0, listContainer.getHeight(), 0);
                    slide.setStartTime(1000);
                    listContainer.setVisibility(View.VISIBLE);
                    slide.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {
                        }
                    });
                    slide.setDuration(400);
                    listContainer.startAnimation(slide);
                } else {
                    searchBack.setVisibility(View.GONE);
                    listContainer.setVisibility(View.GONE);
                }
            }

            @Override
            protected void onCancelled() {

            }
        };
        mAsyncTask.execute();
    }
}

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.MultiContactsPlugin.java

public void moveToLeft() {
    positionLayoutCenterX = moveLayout.getLeft();
    TranslateAnimation animation = new TranslateAnimation(0, -positionLayoutCenterX, 0.0f, 0.0f);
    animation.setDuration(500);//from ww w  . j ava2s  .c o  m
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            moveLayout.layout(0, 0, moveLayout.getWidth(), moveLayout.getHeight());
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    moveLayout.startAnimation(animation);
}

From source file:com.aniruddhc.acemusic.player.ListViewFragment.ListViewFragment.java

/**
 * Displays the search field.//  w  w w .j a v a  2  s  .com
 */
private void showSearch() {
    mSearchLayout.setVisibility(View.VISIBLE);
    final TranslateAnimation searchAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
            Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, -2f, Animation.RELATIVE_TO_SELF, 0f);
    searchAnim.setDuration(500l);
    searchAnim.setInterpolator(new AccelerateDecelerateInterpolator());

    final TranslateAnimation gridListAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
            Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 2f);

    gridListAnim.setDuration(500l);
    gridListAnim.setInterpolator(new LinearInterpolator());

    gridListAnim.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            mListView.setAdapter(null);

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            mSearchLayout.startAnimation(searchAnim);
            mSearchLayout.setVisibility(View.VISIBLE);

        }

    });

    searchAnim.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            if (mSearchEditText.requestFocus()) {
                mFragment.getActivity().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

    });

    mListView.startAnimation(gridListAnim);

}

From source file:com.aniruddhc.acemusic.player.BrowserSubGridActivity.BrowserSubGridActivity.java

/**
 * Slides away the header layout./*  w ww  . ja  va2  s  .  c o  m*/
 */
private void slideAwayHeader() {
    TranslateAnimation slideDown = new TranslateAnimation(mHeaderLayout, 400, new AccelerateInterpolator(2.0f),
            View.INVISIBLE, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -2.0f);

    slideDown.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            mHeaderLayout.setVisibility(View.VISIBLE);

        }

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

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    slideDown.animate();
}

From source file:org.mariotaku.gallery3d.ImageViewerGLActivity.java

private void hideBars() {
    if (!mShowBars || isSwiping())
        return;//w ww. j a  v a2  s .  c  o  m
    mShowBars = false;
    mActionBar.hide();
    final TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1);
    anim.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    anim.setAnimationListener(new AnimationListener() {

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

        @Override
        public void onAnimationRepeat(final Animation animation) {

        }

        @Override
        public void onAnimationStart(final Animation animation) {

        }
    });
    mMenuBar.startAnimation(anim);
    mHandler.removeMessages(MSG_HIDE_BARS);
}

From source file:com.aniruddhc.acemusic.player.BrowserSubListActivity.BrowserSubListActivity.java

/**
 * Slides away the GridView.//  ww  w .j a  va  2 s .co  m
 */
private void slideAwayGridView() {
    android.view.animation.TranslateAnimation animation = new android.view.animation.TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 2.0f);

    animation.setDuration(400);
    animation.setInterpolator(new AccelerateInterpolator(2.0f));
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            mListView.setVisibility(View.INVISIBLE);
            BrowserSubListActivity.super.onBackPressed();

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation arg0) {

        }

    });

    mListView.startAnimation(animation);
}

From source file:com.aniruddhc.acemusic.player.BrowserSubGridActivity.BrowserSubGridActivity.java

/**
 * Slides away the GridView.//from   w  ww.  ja  va 2s  .c  o  m
 */
private void slideAwayGridView() {
    android.view.animation.TranslateAnimation animation = new android.view.animation.TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 2.0f);

    animation.setDuration(400);
    animation.setInterpolator(new AccelerateInterpolator(2.0f));
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            mGridView.setVisibility(View.INVISIBLE);
            BrowserSubGridActivity.super.onBackPressed();

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation arg0) {

        }

    });

    mGridView.startAnimation(animation);
}

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

/**
 * Slides in the ListView./*from  www . j  ava  2s . c om*/
 */
private void slideUpListView() {

    getDir(rootDir, null);

    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 2.0f, Animation.RELATIVE_TO_SELF,
            0.0f);

    animation.setDuration(600);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation arg0) {
            listView.setVisibility(View.VISIBLE);

        }

    });

    listView.startAnimation(animation);
}

From source file:com.linkbubble.ui.BubbleFlowView.java

public boolean expand(long time, final AnimationEventListener animationEventListener) {
    CrashTracking.log("BubbleFlowView.expand(" + time + "), mIsExpanded:" + mIsExpanded);
    if (mIsExpanded) {
        return false;
    }//  ww  w  .  j  av  a  2 s  . co  m

    mDoingCollapse = false;

    mStillTouchFrameCount = -1;
    if (DEBUG) {
        //Log.d(TAG, "[longpress] expand(): mStillTouchFrameCount=" + mStillTouchFrameCount);
    }

    int size = mViews.size();
    int centerIndex = getCenterIndex();
    if (centerIndex == -1) { // fixes #343
        return false;
    }
    View centerView = mViews.get(centerIndex);
    boolean addedAnimationListener = false;
    for (int i = 0; i < size; i++) {
        View view = mViews.get(i);
        if (centerView != view) {
            int xOffset = (int) (centerView.getX() - ((i * mItemWidth) + mEdgeMargin));
            TranslateAnimation anim = new TranslateAnimation(xOffset, 0, 0, 0);
            anim.setDuration(time);
            anim.setFillAfter(true);
            if (addedAnimationListener == false) {
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        if (animationEventListener != null) {
                            animationEventListener.onAnimationEnd(BubbleFlowView.this);
                        }
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                addedAnimationListener = true;
            }
            view.startAnimation(anim);
        }
    }

    if (centerIndex == 0 && mViews.size() == 1) {
        if (animationEventListener != null) {
            animationEventListener.onAnimationEnd(this);
        }
    }

    bringTabViewToFront(centerView);
    mIsExpanded = true;
    return true;
}