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(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType,
        float fromYValue, int toYType, float toYValue) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

From source file:com.turingtechnologies.materialscrollbar.MaterialScrollBar.java

/**
 * @param context The app's context/*from ww w  .  j av a2  s.  c  o  m*/
 * @param recyclerView The recyclerView to which you wish to link the scrollBar
 * @param lightOnTouch Should the handle always be coloured or should it light up on touch and turn grey when released
 */
public MaterialScrollBar(Context context, RecyclerView recyclerView, boolean lightOnTouch) {
    super(context);

    if (!isInEditMode()) {
        a = (Activity) context;
    }

    background = new View(context);
    LayoutParams lp = new RelativeLayout.LayoutParams(Utils.getDP(8, this), LayoutParams.MATCH_PARENT);
    lp.addRule(ALIGN_PARENT_RIGHT);
    background.setLayoutParams(lp);
    background.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
    ViewHelper.setAlpha(background, 0.4F);

    handle = new View(context);
    lp = new RelativeLayout.LayoutParams(Utils.getDP(8, this), Utils.getDP(48, this));
    lp.addRule(ALIGN_PARENT_RIGHT);
    handle.setLayoutParams(lp);

    this.lightOnTouch = lightOnTouch;
    int colourToSet;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        handleColour = fetchAccentColour(context);
    } else {
        handleColour = Color.parseColor("#9c9c9c");
    }
    if (lightOnTouch) {
        colourToSet = Color.parseColor("#9c9c9c");
    } else {
        colourToSet = handleColour;
    }
    handle.setBackgroundColor(colourToSet);

    addView(background);
    addView(handle);

    setId(R.id.reservedNamedId);
    LayoutParams layoutParams = new LayoutParams(Utils.getDP(20, this), ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.addRule(ALIGN_RIGHT, recyclerView.getId());
    layoutParams.addRule(ALIGN_TOP, recyclerView.getId());
    layoutParams.addRule(ALIGN_BOTTOM, recyclerView.getId());
    ((ViewGroup) recyclerView.getParent()).addView(this, layoutParams);
    recyclerView.addOnScrollListener(new ScrollListener(this));
    this.recyclerView = recyclerView;

    setTouchIntercept();

    fade = new BarFade(this);
    fade.start();

    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
            0.0f);
    anim.setFillAfter(true);
    startAnimation(anim);
}

From source file:com.justwayward.reader.ui.activity.SubjectBookListActivity.java

private void hideTagGroup() {
    Animation mHiddenAction = 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);/*from www  .j av  a 2s  .  co m*/
    mHiddenAction.setDuration(400);
    rsvTags.startAnimation(mHiddenAction);
    rsvTags.setVisibility(View.GONE);
}

From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java

private Animation createTranslationOutAnimation() {
    int type = TranslateAnimation.RELATIVE_TO_SELF;
    TranslateAnimation an = new TranslateAnimation(type, 0, type, 0, type, 0, type, 1);
    an.setDuration(TRANSLATE_DURATION);/*from   w  w w .  j  av a 2s .  c  om*/
    an.setFillAfter(true);
    return an;
}

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

/**
 * Slides in the ListView./* w ww . j  a  va 2s  . c  o m*/
 */
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.aniruddhc.acemusic.player.ListViewFragment.ListViewFragment.java

/**
 * Displays the search field./*from   w w  w  .j  ava 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:enterprayz.megatools.Tools.java

public static void replace(View source, int xTo, int yTo, float xScale, float yScale) {
    AnimationSet replaceAnimation = new AnimationSet(false);
    replaceAnimation.setFillAfter(true);

    ScaleAnimation scale = new ScaleAnimation(1.0f, xScale, 1.0f, yScale);
    scale.setDuration(1000);//ww w.ja  v a2s. co m

    TranslateAnimation trans = new TranslateAnimation(0, 0, TranslateAnimation.ABSOLUTE, xTo - source.getLeft(),
            0, 0, TranslateAnimation.ABSOLUTE, yTo - source.getTop());
    trans.setDuration(1000);

    replaceAnimation.addAnimation(scale);
    replaceAnimation.addAnimation(trans);

    source.startAnimation(replaceAnimation);
}

From source file:com.example.fragment.PrimitiveFragment.java

public void testAnimation(float destX, float destY) {
    this.mDestX = Factory.getAdjustedX(destX);
    this.mDestY = Factory.getAdjustedY(destY);
    // SELECT LAYER
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;//w w  w. ja  v a2s . c  o  m
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF_START);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
}

From source file:com.github.shareme.gwsmaterialuikit.library.mscrollbar.MaterialScrollBar.java

private void generalSetup() {
    recyclerView.setVerticalScrollBarEnabled(false); // disable any existing scrollbars
    recyclerView.addOnScrollListener(new scrollListener()); // lets us read when the recyclerView scrolls

    setTouchIntercept(); // catches touches on the bar

    identifySwipeRefreshParents();//from   www  . j ava2 s. c o  m

    //Hides the view
    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_SELF, getHideRatio(), Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(0);
    anim.setFillAfter(true);
    hidden = true;
    startAnimation(anim);
}

From source file:com.emmasuzuki.quickreturnlistview.view.QuickReturnListView.java

private void animateQuickReturnViewToDest(final int destY) {
    // Pre-honeycomb style
    Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
            Animation.ABSOLUTE, 0, Animation.ABSOLUTE, destY - mQuickReturnView.getTop());
    animation.setFillEnabled(true);/*from  ww w .  jav  a  2s  .c om*/
    animation.setDuration(mSettleAnimationDuration);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            // Noop
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // TranslateAnimation does not change view's position, so
            // after the animation end, manually set quick return view position to destination
            setQuickReturnViewY(destY);
        }

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

    mQuickReturnView.startAnimation(animation);
}

From source file:com.watasan.infospider.fragment.PrimitiveFragment.java

/** SCRIPT ACTION AREA --------------------------------------------------> */

public void testAnimation(float destX, float destY) {
    this.mDestX = Factory.getAdjustedX(destX);
    this.mDestY = Factory.getAdjustedY(destY);
    // SELECT LAYER
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;/*from  w w  w .  j a  va  2  s .c  o  m*/
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF_START);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
}