Example usage for android.view.animation TranslateAnimation TranslateAnimation

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

Introduction

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

Prototype

public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

From source file:com.zuzhili.ui.fragment.DefaultFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mListView = (PullRefreshListView) getListView();
    if (getArguments() != null && getArguments().getBoolean(Constants.ARG_SHOW_SEARCH_VIEW)) {
        mListView.addHeaderView(mHeader);
    } else {//from   ww  w .  j  a v a2  s  .c  o  m
        mQuickReturnView.setVisibility(View.GONE);
    }
    mListView.setOnRefreshListener(this);
    mListView.setOnRefreshStateChangeListener(this);

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mQuickReturnHeight = mQuickReturnView.getHeight();
            mListView.computeScrollY();
            mCachedVerticalScrollRange = mListView.getListHeight();
        }
    });

    mListView.setOnScrollListener(new OnScrollListener() {
        @SuppressLint("NewApi")
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            mListView.setFirstItemIndex(firstVisibleItem);

            mScrollY = 0;
            int translationY = 0;

            if (mListView.scrollYIsComputed()) {
                mScrollY = mListView.getComputedScrollY();
            }

            int rawY = mPlaceHolder.getTop()
                    - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);

            switch (mState) {
            case STATE_OFFSCREEN:
                if (rawY <= mMinRawY) {
                    mMinRawY = rawY;
                } else {
                    mState = STATE_RETURNING;
                }
                translationY = rawY;
                break;

            case STATE_ONSCREEN:
                if (rawY < -mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                translationY = rawY;
                break;

            case STATE_RETURNING:
                translationY = (rawY - mMinRawY) - mQuickReturnHeight;
                if (translationY > 0) {
                    translationY = 0;
                    mMinRawY = rawY - mQuickReturnHeight;
                }

                if (rawY > 0) {
                    mState = STATE_ONSCREEN;
                    translationY = rawY;
                }

                if (translationY < -mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                break;
            }

            /** this can be used if the build is below honeycomb **/
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                anim = new TranslateAnimation(0, 0, translationY, translationY);
                anim.setFillAfter(true);
                anim.setDuration(0);
                mQuickReturnView.startAnimation(anim);
            } else {
                mQuickReturnView.setTranslationY(translationY);
            }

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
}

From source file:com.snappy.SpikaApp.java

@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;
    /*For test purposes, we change this method*/
    mPreferences = new Preferences(this);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    /*end of new method*/

    gOpenFromBackground = true;/*from   ww w  .  j a  v a2  s .c o  m*/
    mFileDir = new FileDir(this);

    ImageLoader.initImageLoaderInstance(this);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    // Create typefaces
    mTfMyriadPro = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
    mTfMyriadProBold = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");

    setTransportBasedOnScreenDensity(42);

    // Example interpolator; could use linear or accelerate interpolator
    // instead
    final AccelerateDecelerateInterpolator accDecInterpolator = new AccelerateDecelerateInterpolator();
    final LinearInterpolator linearInterpolator = new LinearInterpolator();
    final int slidingDuration = getResources().getInteger(R.integer.sliding_duration);

    // Set up animations
    mSlideInLeft = new TranslateAnimation(-mTransport, 0, 0, 0);
    mSlideInLeft.setDuration(slidingDuration);
    // mSlideInLeft.setFillAfter(true); // hmm not sure
    mSlideInLeft.setFillEnabled(false);
    mSlideInLeft.setInterpolator(linearInterpolator);

    mSlideOutRight = new TranslateAnimation(0, mTransport, 0, 0);
    mSlideOutRight.setDuration(slidingDuration);
    mSlideOutRight.setFillAfter(true);
    mSlideOutRight.setFillEnabled(true);
    mSlideOutRight.setInterpolator(linearInterpolator);

    mSlideOutLeft = new TranslateAnimation(0, -mTransport, 0, 0);
    mSlideOutLeft.setDuration(slidingDuration);
    mSlideOutLeft.setInterpolator(linearInterpolator);

    mSlideInRight = new TranslateAnimation(mTransport, 0, 0, 0);
    mSlideInRight.setDuration(slidingDuration);
    mSlideInRight.setFillAfter(true);
    mSlideInRight.setFillEnabled(true);
    mSlideInRight.setInterpolator(linearInterpolator);

    mSlideFromTop.setFillAfter(true);
    mSlideFromTop.setFillEnabled(true);
    mSlideFromTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideFromTop.setInterpolator(linearInterpolator);

    mSlideOutTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideOutTop.setInterpolator(linearInterpolator);

    String strUUID = UUID.randomUUID().toString();
    Logger.debug("uuid", strUUID);

    mBaseUrl = mPreferences.getUserServerURL();

    sContext = getApplicationContext();
}

From source file:us.shandian.blacklight.ui.statuses.TimeLineFragment.java

@Override
public boolean onTouch(View v, MotionEvent ev) {

    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mLastY = ev.getY();/* w w  w.  ja  v a2s  . c o m*/
        break;
    case MotionEvent.ACTION_MOVE:
        if (mLastY == -1.0f)
            break;

        float y = ev.getY();

        if (!mNewHidden && y < mLastY) {
            mNew.clearAnimation();

            TranslateAnimation anim = new TranslateAnimation(0, 0, 0, mList.getHeight() - mNew.getTop());
            anim.setFillAfter(true);
            anim.setDuration(400);

            mNew.setAnimation(anim);
            anim.startNow();

            mNewHidden = true;
        } else if (mNewHidden && y > mLastY) {
            mNew.clearAnimation();

            TranslateAnimation anim = new TranslateAnimation(0, 0, mList.getHeight() - mNew.getTop(), 0);
            anim.setFillAfter(true);
            anim.setDuration(400);

            mNew.setAnimation(anim);
            anim.startNow();

            mNewHidden = false;
        }

        mLastY = y;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mLastY = -1.0f;
        break;
    }

    return false;
}

From source file:com.marshalchen.common.demoofui.quickreturnlistview.AnimationFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mListView = (QuickReturnListView) getListView();

    mQuickReturnView.setText("Animation");
    mListView.addHeaderView(mHeader);//from  ww  w  . j a  v a2s .c o m

    String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android",
            "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };

    setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.quick_return_listview_list_item, R.id.text1,
            array));

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mQuickReturnHeight = mQuickReturnView.getHeight();
            mListView.computeScrollY();
            mCachedVerticalScrollRange = mListView.getListHeight();
        }
    });

    mListView.setOnScrollListener(new OnScrollListener() {
        @SuppressLint("NewApi")
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            mScrollY = 0;
            int translationY = 0;

            if (mListView.scrollYIsComputed()) {
                mScrollY = mListView.getComputedScrollY();
            }

            rawY = mPlaceHolder.getTop()
                    - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);

            switch (mState) {
            case STATE_OFFSCREEN:
                if (rawY <= mMinRawY) {
                    mMinRawY = rawY;
                } else {
                    mState = STATE_RETURNING;
                }
                translationY = rawY;
                break;

            case STATE_ONSCREEN:
                if (rawY < -mQuickReturnHeight) {
                    System.out.println("test3");
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                translationY = rawY;
                break;

            case STATE_RETURNING:

                if (translationY > 0) {
                    translationY = 0;
                    mMinRawY = rawY - mQuickReturnHeight;
                }

                else if (rawY > 0) {
                    mState = STATE_ONSCREEN;
                    translationY = rawY;
                }

                else if (translationY < -mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;

                } else if (mQuickReturnView.getTranslationY() != 0 && !noAnimation) {
                    noAnimation = true;
                    anim = new TranslateAnimation(0, 0, -mQuickReturnHeight, 0);
                    anim.setFillAfter(true);
                    anim.setDuration(250);
                    mQuickReturnView.startAnimation(anim);
                    anim.setAnimationListener(new AnimationListener() {

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

                        }

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

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            noAnimation = false;
                            mMinRawY = rawY;
                            mState = STATE_EXPANDED;
                        }
                    });
                }
                break;

            case STATE_EXPANDED:
                if (rawY < mMinRawY - 2 && !noAnimation) {
                    noAnimation = true;
                    anim = new TranslateAnimation(0, 0, 0, -mQuickReturnHeight);
                    anim.setFillAfter(true);
                    anim.setDuration(250);
                    anim.setAnimationListener(new AnimationListener() {

                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            noAnimation = false;
                            mState = STATE_OFFSCREEN;
                        }
                    });
                    mQuickReturnView.startAnimation(anim);
                } else if (translationY > 0) {
                    translationY = 0;
                    mMinRawY = rawY - mQuickReturnHeight;
                }

                else if (rawY > 0) {
                    mState = STATE_ONSCREEN;
                    translationY = rawY;
                }

                else if (translationY < -mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                } else {
                    mMinRawY = rawY;
                }
            }
            /** this can be used if the build is below honeycomb **/
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                anim = new TranslateAnimation(0, 0, translationY, translationY);
                anim.setFillAfter(true);
                anim.setDuration(0);
                mQuickReturnView.startAnimation(anim);
            } else {
                mQuickReturnView.setTranslationY(translationY);
            }

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
}

From source file:com.umeng.comm.ui.fragments.CommentTabFragment.java

private void moveTabCurosr(int position) {
    float endPosition;
    float startPosition;

    if (mCurrentTab == position) {
        return;/* ww w. j a v a  2 s . co  m*/
    }

    if (mCurrentTab == 0) {
        startPosition = mTabDistance;
    } else {
        startPosition = CommonUtils.dip2px(getActivity(), 80) + mTabDistance * 3;
    }

    if (position == 0) {
        endPosition = mTabDistance;
    } else {
        endPosition = CommonUtils.dip2px(getActivity(), 80) + mTabDistance * 3;
    }

    mCurrentTab = position;
    TranslateAnimation animation = new TranslateAnimation(startPosition, endPosition, 0, 0);
    animation.setDuration(180);//?
    animation.setFillAfter(true);
    mTabCursor.startAnimation(animation);
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateScanResultFragment() {
    try {/*  ww  w. ja  va 2  s .c o  m*/
        final MainActivity app = MainActivity.app;
        if (app == null || scanResultFragmentOn)
            return;
        CustomPagerAdapter.adapter.showFragments(false, app);
        scanResultFragmentOn = true;
        InputMethodManager keyboard = (InputMethodManager) app.getSystemService(Context.INPUT_METHOD_SERVICE);

        try {
            keyboard.hideSoftInputFromWindow(
                    CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        app.setBurgerButtonImage(BRConstants.BACK);
        //Disabled inspection: <Expected resource type anim>
        final FragmentManager fragmentManager = app.getFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        final FragmentScanResult scanResult = new FragmentScanResult();
        fragmentTransaction.replace(R.id.main_layout, scanResult, FragmentScanResult.class.getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(500);
                trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                View view = scanResult.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.uf.togathor.Togathor.java

@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;
    mPreferences = new Preferences(this);
    mPreferences.clearFlagsForTutorialEachBoot(getApplicationContext().getPackageName());
    gOpenFromBackground = true;/* ww w.j av  a  2 s .  c o m*/
    mFileDir = new FileDir(this);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    googleAPIService = new GoogleAPIService(this);
    messagesDataSource = new MessagesDataSource(this);
    eventMessagesDataSource = new EventMessagesDataSource(this);
    contactsDataSource = new ContactsDataSource(this);
    startEventService();
    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("s3lab", "S3LAB!!".toCharArray());
        }
    });

    // Create typefaces
    mTfMyriadPro = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
    mTfMyriadProBold = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");

    setTransportBasedOnScreenDensity(42);

    // Example interpolator; could use linear or accelerate interpolator
    // instead
    final AccelerateDecelerateInterpolator accDecInterpolator = new AccelerateDecelerateInterpolator();
    final LinearInterpolator linearInterpolator = new LinearInterpolator();
    final int slidingDuration = getResources().getInteger(R.integer.sliding_duration);

    // Set up animations
    mSlideInLeft = new TranslateAnimation(-mTransport, 0, 0, 0);
    mSlideInLeft.setDuration(slidingDuration);
    // mSlideInLeft.setFillAfter(true); // hmm not sure
    mSlideInLeft.setFillEnabled(false);
    mSlideInLeft.setInterpolator(linearInterpolator);

    mSlideOutRight = new TranslateAnimation(0, mTransport, 0, 0);
    mSlideOutRight.setDuration(slidingDuration);
    mSlideOutRight.setFillAfter(true);
    mSlideOutRight.setFillEnabled(true);
    mSlideOutRight.setInterpolator(linearInterpolator);

    mSlideOutLeft = new TranslateAnimation(0, -mTransport, 0, 0);
    mSlideOutLeft.setDuration(slidingDuration);
    mSlideOutLeft.setInterpolator(linearInterpolator);

    mSlideInRight = new TranslateAnimation(mTransport, 0, 0, 0);
    mSlideInRight.setDuration(slidingDuration);
    mSlideInRight.setFillAfter(true);
    mSlideInRight.setFillEnabled(true);
    mSlideInRight.setInterpolator(linearInterpolator);

    mSlideFromTop.setFillAfter(true);
    mSlideFromTop.setFillEnabled(true);
    mSlideFromTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideFromTop.setInterpolator(linearInterpolator);

    mSlideOutTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideOutTop.setInterpolator(linearInterpolator);

    String strUUID = UUID.randomUUID().toString();
    Logger.debug("uuid", strUUID);

    mBaseUrl = mPreferences.getUserServerURL();
}

From source file:gov.whitehouse.ui.activities.BaseDashboardActivity.java

public void hideSearch() {
    final int height = mSearchFragment.getView().getHeight();
    TranslateAnimation slideUpAnim = new TranslateAnimation(0, 0, 0, -height);
    slideUpAnim.setDuration(SEARCH_FRAGMENT_ANIMATION_DURATION);
    slideUpAnim.setAnimationListener(new Animation.AnimationListener() {
        @Override// w  w  w  .  ja va  2 s. co  m
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            getSupportFragmentManager().beginTransaction().hide(mSearchFragment).commitAllowingStateLoss();
            mSearchField.setText("");
            mSearchField.clearFocus();
            mDrawerGarment.setDrawerEnabled(true);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchFragment.getView().startAnimation(slideUpAnim);
    mShowingSearch = false;
}

From source file:com.umeng.comm.ui.fragments.CommentTabFragment.java

private void initTab() {
    changeSelectedTab(0);/*w w w  .  ja  v  a2 s  . com*/

    mTabDistance = (mScreenWidth - CommonUtils.dip2px(getActivity(), 80 * 2)) / 4;
    TranslateAnimation animation = new TranslateAnimation(0, mTabDistance, 0, 0);
    animation.setDuration(0);//?
    animation.setFillAfter(true);
    mTabCursor.startAnimation(animation);
}

From source file:com.umeng.simplify.ui.fragments.CommentTabFragment.java

private void moveTabCurosr(int position) {
    float endPosition;
    float startPosition;

    if (mCurrentTab == position) {
        return;/*from  www .  j  av a2  s. c  o m*/
    }

    if (mCurrentTab == 0) {
        startPosition = 0;
    } else {
        startPosition = mTabDistance;
    }

    if (position == 0) {
        endPosition = 0;
    } else {
        endPosition = mTabDistance;
    }

    mCurrentTab = position;
    TranslateAnimation animation = new TranslateAnimation(startPosition, endPosition, 0, 0);
    animation.setDuration(180);//?
    animation.setFillAfter(true);
    mTabCursor.startAnimation(animation);
}