Example usage for android.view.animation Animation RELATIVE_TO_SELF

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

Introduction

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

Prototype

int RELATIVE_TO_SELF

To view the source code for android.view.animation Animation RELATIVE_TO_SELF.

Click Source Link

Document

The specified dimension holds a float and should be multiplied by the height or width of the object being animated.

Usage

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

public static void scaleView(View v, float startScaleX, float endScaleX, float startScaleY, float endScaleY) {
    Animation anim = new ScaleAnimation(startScaleX, endScaleX, // Start and end values for the X axis scaling
            startScaleY, endScaleY, // Start and end values for the Y axis scaling
            Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
            Animation.RELATIVE_TO_SELF, 0.5f); // Pivot point of Y scaling
    anim.setFillAfter(true); // Needed to keep the result of the animation
    v.startAnimation(anim);//  w  w  w  .  j a  v a  2s  . co  m
}

From source file:com.chuhan.privatecalc.fragment.os.FragmentManager.java

static Animation makeOpenCloseAnimation(Context context, float startScale, float endScale, float startAlpha,
        float endAlpha) {
    AnimationSet set = new AnimationSet(false);
    ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
            Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
    scale.setInterpolator(DECELERATE_QUINT);
    scale.setDuration(ANIM_DUR);//from www.j  a  va 2s  . com
    set.addAnimation(scale);
    AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
    alpha.setInterpolator(DECELERATE_CUBIC);
    alpha.setDuration(ANIM_DUR);
    set.addAnimation(alpha);
    return set;
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void initAnimation() {
    mLeftIn = new TranslateAnimation(Animation.RELATIVE_TO_SELF, (float) -1.0, Animation.RELATIVE_TO_SELF, 0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mLeftIn.setDuration(mAnimationDuration);
    mLeftIn.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mLeftIn.setRepeatCount(0);//from   w ww  .j a v  a 2 s .c  o m
    mLeftIn.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mIsToolBarOpen = true;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

    mLeftOut = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, (float) -1.0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mLeftOut.setDuration(mAnimationDuration);
    mLeftOut.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mLeftOut.setRepeatCount(0);
    mLeftOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mToolBar.setVisibility(View.GONE);
            mToolBarParent.setVisibility(View.INVISIBLE);
            mIsToolBarOpen = false;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

    mRightIn = new TranslateAnimation(Animation.RELATIVE_TO_SELF, (float) 1.0, Animation.RELATIVE_TO_SELF, 0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mRightIn.setDuration(mAnimationDuration);
    mRightIn.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mRightIn.setRepeatCount(0);
    mRightIn.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mIsToolBarOpen = true;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

    mRightOut = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, (float) 1.0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mRightOut.setDuration(mAnimationDuration);
    mRightOut.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mRightOut.setRepeatCount(0);
    mRightOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mToolBar.setVisibility(View.GONE);
            mToolBarParent.setVisibility(View.INVISIBLE);
            mIsToolBarOpen = false;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });
}

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

private void startViewAnimation(final View panel, boolean up) {
    Animation animation;//from  ww w. j a  va  2  s .  c o  m
    if (!up) {
        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:org.androfarsh.widget.DragGridLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final float x = ev.getX();
    final float y = ev.getY();
    if (mGestureDetector.onTouchEvent(ev)) {
        mPrevX = x;/*from  ww w .j av a2 s.  c o m*/
        mPrevY = y;
        return true;
    }

    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        if (mEditMode) {
            final View child = findIntersectChild(x, y);
            if (child != null) {
                if ((mDragNode != null) && (mDragNode.view != child)) {
                    return true;
                }
                mPrevX = x;
                mPrevY = y;

                stopAnimation(mDragNode != null ? mDragNode.view : null);

                mDragNode = new Node(child, requestPreferredRect(mTmpRect, child));
                Node.scale(mDragNode.currentRect, mScaleFactor);

                requestFreeCellRegion(child);
                requestHoveredCells(mDragNode);

                if (mDragListener != null) {
                    mDragListener.onDrag(mDragNode.view, this);
                }

                final Animation animation = new ScaleAnimation((1f - mScaleFactor) + 1f, 1f,
                        (1f - mScaleFactor) + 1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);

                animation.setDuration(DURATION);
                animation.setAnimationListener(new AbstractAnimationListener() {
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mTmpRect.set(mDragNode.startRect);

                        child.setAnimation(null);
                        child.requestLayout();
                        invalidate(mTmpRect);
                    }
                });

                requestLayout();
                child.startAnimation(animation);

                return true;
            }

            final Cell cell = findCellUnder(x, y);
            if (cell != null) {
                mPressedCell = cell;
                invalidate();
                return true;
            }

            mEditModeSwitchOff = true;
            return true;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mPressedCell != null) {
            final Cell cell = findCellUnder(x, y);
            if (mPressedCell != cell) {
                mPressedCell = null;
                invalidate();
                return true;
            }
        } else if (mDragNode != null) {
            mDragNode.currentRect.offset((int) (x - mPrevX), (int) (y - mPrevY));
            if (mDebugMode) {
                Log.w(VIEW_LOG_TAG, "ACTION_MOVE: x=" + x + " y=" + y + " prevX=" + mPrevX + " prevY=" + mPrevY
                        + " dX=" + (x - mPrevX) + " dY=" + (y - mPrevY));
            }

            requestHoveredCells(mDragNode);
            boolean dragged = (Math.abs(x - mPrevX) < DELTA) && (Math.abs(y - mPrevY) < DELTA);
            if (dragged) {
                requestReorderRevert();
            }
            if (!mHoveredCells.isEmpty() && dragged) {
                if (!mLoongHoveredRequested) {
                    mLoongHoveredRequested = true;
                    mHandler.sendEmptyMessageDelayed(LONGHOVER_MESSAGE, LONGPRESS_TIMEOUT + TAP_TIMEOUT);
                }
            } else if (mLoongHoveredRequested) {
                mLoongHoveredRequested = false;
                mHandler.removeMessages(LONGHOVER_MESSAGE);
            }

            mPrevX = x;
            mPrevY = y;

            requestLayout();
            invalidate();
            return true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mLoongHoveredRequested = false;
        mHandler.removeMessages(LONGHOVER_MESSAGE);
        if (mPressedCell != null) {
            if (mCellClickListener != null) {
                mCellClickListener.onClick(new Point(mPressedCell.rect.left, mPressedCell.rect.top), this);
            }
            mPressedCell = null;
            invalidate();
            return true;
        } else if (mDragNode != null) {
            mDragNode.currentRect.offset((int) (x - mPrevX), (int) (y - mPrevY));

            requestHoveredCells(mDragNode);
            requestReorderRevert();
            requestDrop(mDragNode);

            mPrevX = x;
            mPrevY = y;

            mTmpRect.set(mDragNode.currentRect);
            mTmpRect.union(mDragNode.startRect);

            final View child = mDragNode.view;
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            lp.mX = mDragNode.startRect.left;
            lp.mY = mDragNode.startRect.top;

            mNodes.clear();
            mDragNode.startRect.offset(lp.leftMargin, lp.topMargin);

            final AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new TranslateAnimation(mDragNode.currentRect.left - mDragNode.startRect.left,
                    0, mDragNode.currentRect.top - mDragNode.startRect.top, 0));
            animation.addAnimation(new ScaleAnimation(mScaleFactor, 1f, mScaleFactor, 1f));

            animation.setDuration(DURATION);
            animation.setAnimationListener(new AbstractAnimationListener() {
                @Override
                public void onAnimationEnd(final Animation a) {
                    mDragNode.dispose();
                    mDragNode = null;

                    child.setAnimation(null);

                    requestLayout();
                    invalidate();
                }
            });

            if (mDragListener != null) {
                mDragListener.onDrop(mDragNode.view, this);
            }

            mDragNode.currentRect.set(mDragNode.startRect);

            child.requestLayout();
            child.startAnimation(animation);
            invalidate(mTmpRect);
            return true;
        } else if (mEditModeSwitchOff) {
            setEditMode(false);
            mEditModeSwitchOff = false;
            return true;
        }
        break;
    }

    return super.onTouchEvent(ev);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private View switchViews(boolean forward, float xOffSet, float width, float velocity) {
    mAnimationDistance = width - xOffSet;

    float progress = Math.abs(xOffSet) / width;
    if (progress > 1.0f) {
        progress = 1.0f;//from  ww  w.ja va2s  .com
    }

    float inFromXValue, inToXValue;
    float outFromXValue, outToXValue;
    if (forward) {
        inFromXValue = 1.0f - progress;
        inToXValue = 0.0f;
        outFromXValue = -progress;
        outToXValue = -1.0f;
    } else {
        inFromXValue = progress - 1.0f;
        inToXValue = 0.0f;
        outFromXValue = progress;
        outToXValue = 1.0f;
    }

    final Time start = new Time(mBaseDate.timezone);
    start.set(mController.getTime());
    if (forward) {
        start.monthDay += mNumDays;
    } else {
        start.monthDay -= mNumDays;
    }
    mController.setTime(start.normalize(true));

    Time newSelected = start;

    if (mNumDays == 7) {
        newSelected = new Time(start);
        adjustToBeginningOfWeek(start);
    }

    final Time end = new Time(start);
    end.monthDay += mNumDays - 1;

    // We have to allocate these animation objects each time we switch views
    // because that is the only way to set the animation parameters.
    TranslateAnimation inAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, inFromXValue,
            Animation.RELATIVE_TO_SELF, inToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);

    TranslateAnimation outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, outFromXValue,
            Animation.RELATIVE_TO_SELF, outToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);

    long duration = calculateDuration(width - Math.abs(xOffSet), width, velocity);
    inAnimation.setDuration(duration);
    inAnimation.setInterpolator(mHScrollInterpolator);
    outAnimation.setInterpolator(mHScrollInterpolator);
    outAnimation.setDuration(duration);
    outAnimation.setAnimationListener(new GotoBroadcaster(start, end));

    mViewSwitcher.setInAnimation(inAnimation);
    mViewSwitcher.setOutAnimation(outAnimation);

    DayView view = (DayView) mViewSwitcher.getCurrentView();
    view.cleanup();
    mViewSwitcher.showNext();
    view = (DayView) mViewSwitcher.getCurrentView();
    view.setSelected(newSelected, true, false);
    view.requestFocus();
    view.reloadEvents();
    view.updateTitle();
    view.restartCurrentTimeUpdates();

    return view;
}

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java

private void refreshOverlays(final MenuItem item) {

    // define the animation for rotation
    Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(1000);/*from   w  w  w .  j ava2 s. c om*/
    animation.setRepeatCount(Animation.INFINITE);

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

        @Override
        public void onAnimationEnd(Animation animation) {
            mToolbar.getMenu().getItem(menu_item_refresh).setActionView(null);
            mToolbar.getMenu().getItem(menu_item_refresh).setIcon(R.drawable.ic_menu_refresh);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    ImageView imageView = new ImageView(this, null, android.R.style.Widget_Material_ActionButton);
    imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_menu_refresh));
    imageView.setPadding(31, imageView.getPaddingTop(), 32, imageView.getPaddingBottom());
    imageView.startAnimation(animation);
    item.setActionView(imageView);

    if (mMap != null) {
        mapCameraViewModel.refreshCameras();
        mapHighwayAlertViewModel.refreshAlerts();
    }
}

From source file:com.money.manager.ex.home.MainActivity.java

private void startSyncIconRotation(MenuItem item) {
    if (item == null)
        return;//  w w w  . j a  v a  2  s  .  c  o m

    // define the animation for rotation
    Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(1200);
    //        animRotate = AnimationUtils.loadAnimation(this, R.anim.rotation);
    animation.setRepeatCount(Animation.INFINITE);

    ImageView imageView = new ImageView(this);
    UIHelper uiHelper = new UIHelper(this);
    imageView.setImageDrawable(
            uiHelper.getIcon(GoogleMaterial.Icon.gmd_cached).color(uiHelper.getToolbarItemColor()));
    imageView.setPadding(8, 8, 8, 8);
    //        imageView.setLayoutParams(new Toolbar.LayoutParams());

    imageView.startAnimation(animation);
    item.setActionView(imageView);
}