Example usage for android.view.animation ScaleAnimation ScaleAnimation

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

Introduction

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

Prototype

public ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue,
        int pivotYType, float pivotYValue) 

Source Link

Document

Constructor to use when building a ScaleAnimation from code

Usage

From source file:com.carver.paul.truesight.Ui.MainActivity.java

/**
 * Makes the camera pulse infinitely (will be stopped when loading completes)
 *//*ww w  .  j  a  v  a  2 s  . c  om*/
//TODO-nextversion: Make camera do something other than pulse - it implies you should press
// it!
private void pulseCameraImage() {
    //Code using the old Animation class, rather than the new ViewPropertyAnimator
    //Infinite repeat is easier to implement this way

    View cameraImage = findViewById(R.id.image_pulsing_camera);
    cameraImage.setVisibility(View.VISIBLE);
    cameraImage.setAlpha(1f);

    ScaleAnimation pulse = new ScaleAnimation(1f, 0.8f, 1f, 0.8f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    pulse.setDuration(250);
    pulse.setRepeatCount(Animation.INFINITE);
    pulse.setRepeatMode(Animation.REVERSE);
    cameraImage.startAnimation(pulse);

    View processingText = findViewById(R.id.text_processing_image);
    processingText.setAlpha(1f);
    processingText.setVisibility(View.VISIBLE);
}

From source file:de.dmxcontrol.activity.ControlActivity.java

private Dialog createSplashDialog() {
    Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
    dialog.setContentView(R.layout.dialog_splash);
    ImageView image = (ImageView) dialog.findViewById(R.id.image_splash);
    image.setImageResource(R.drawable.image_splash);

    AnimationSet set = new AnimationSet(true);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(500);//  w w w. j a va  2s .  c om
    animation.setInterpolator(
            AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_decelerate_interpolator));
    set.addAnimation(animation);
    animation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(1000);
    animation.setInterpolator(
            AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_decelerate_interpolator));
    set.addAnimation(animation);

    image.setAnimation(set);
    dismissSplashDelayed();
    return dialog;
}

From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java

private void mainAnmLoop() {

    AnimationSet anmSet = null;/*w  w  w . j a va  2s  . c o m*/

    if (onClickFlg == 1) {

        if (anmSet != null) {
            anmSet.cancel();
            anmSet.reset();
        }

        return;
    }

    // --- Loop through the frames
    int frm_nmbr = svg_data.frm.size();

    if (++frm_mbr >= frm_nmbr)
        frm_mbr = 0;

    // -- You need to turn the sprites on and off for the current frame
    LoadSVG.frame crt_frm = svg_data.frm.get(frm_mbr);
    String crt_frm_ordr = crt_frm.frm_ordr;
    ArrayList<String> sprt_ordr = svg_data.svg.ordr;
    int crt_dur = crt_frm.end - crt_frm.bgn;

    // - Loop through the sprites 
    int sprt_nmbr = sprt_ordr.size();
    int frm_sprt_mbr = 0;

    for (int sprt_mbr = 0; sprt_mbr < sprt_nmbr; sprt_mbr += 1) {

        String sprt_id = sprt_ordr.get(sprt_mbr);
        int sym_mbr = Integer.parseInt(sprt_id.substring(1, sprt_id.indexOf('_'))) - 2;

        if (sym_mbr >= 0) { // not g1 which is not loaded

            LoadSVG.symbol crt_sym = svg_data.symbl.get(sym_mbr);

            if (crt_frm_ordr.indexOf(sprt_id) >= 0) { // Sprite is present

                if (crt_sym.aud_id != null && !crt_sym.aud_id.equals("")) { // The sprite is audio

                    SoundPool mSoundPool = loadSVG.getMSoundPool();
                    int streamId = mSoundPool.play(svg_data.soundId[sym_mbr], 1.0f, 1.0f, 1, 0, 1.0f);
                    mSoundPool.setLoop(streamId, -1);
                } else { // The sprite is graphic
                    anim_view = anmViews.get(sprt_mbr);
                    anim_view.setAlpha(1f);
                    int xfm_idx = crt_frm.xfm_idx[frm_sprt_mbr];

                    if (xfm_idx >= 0) { // An animation tag is present

                        anmSet = new AnimationSet(false);
                        LoadSVG.xfrm crt_xfm = svg_data.xfm.get(xfm_idx);
                        ArrayList<Integer[]> pnts = crt_xfm.mov_path;
                        int init_scl = (int) (initScl[sprt_mbr] * 100);

                        if (pnts.size() > 0) {

                            final Path path = new Path();
                            ld_scl_pth_pnts(pnts, path);
                            PathAnimation pthAnm = new PathAnimation(path);
                            pthAnm.setDuration(crt_dur);
                            pthAnm.setInterpolator(new LinearInterpolator());
                            pthAnm.setFillAfter(true); // Needed to keep the result of the animation
                            anmSet.addAnimation(pthAnm);
                        }

                        if (crt_xfm.scl_bgn != init_scl) {

                            float crt_scl = crt_xfm.scl_bgn / init_scl;
                            float end_scl = crt_scl;

                            if (crt_xfm.scl_end != crt_xfm.scl_bgn)
                                end_scl = crt_xfm.scl_end / init_scl;

                            ScaleAnimation sclAnm = new ScaleAnimation(crt_scl, end_scl, crt_scl, end_scl,
                                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

                            sclAnm.setDuration(crt_dur);
                            anmSet.addAnimation(sclAnm);
                        }

                        if (crt_xfm.rot_bgn != 0) {

                            float crt_rot = crt_xfm.rot_bgn;
                            float end_rot = crt_rot;

                            if (crt_xfm.rot_end != crt_xfm.rot_bgn)
                                end_rot = crt_xfm.rot_end;

                            RotateAnimation rotAnm = new RotateAnimation(crt_rot, end_rot,
                                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

                            rotAnm.setDuration(crt_dur);
                            anmSet.addAnimation(rotAnm);
                        }

                        anim_view.startAnimation(anmSet); //start animation
                    }
                }

                frm_sprt_mbr++;
            } else { // The sprite is not present
                if (!(crt_sym.aud_id != null && !crt_sym.aud_id.equals(""))) { // The sprite is graphic
                    anim_view = anmViews.get(sprt_mbr);
                    anim_view.setAlpha(0f);
                }
            }
        } else { // g1

            if (crt_frm_ordr.indexOf(sprt_id) >= 0)
                frm_sprt_mbr++;
        }
    }

    waitDur(crt_dur);
}

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 ww . j  a  va 2  s  . 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  av a 2  s  .  co  m
    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: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 w  ww  .ja  v  a  2  s  .c  om
        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);
}