Example usage for android.view.animation AnimationSet addAnimation

List of usage examples for android.view.animation AnimationSet addAnimation

Introduction

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

Prototype

public void addAnimation(Animation a) 

Source Link

Document

Add a child animation to this animation set.

Usage

From source file:com.androzic.vnspeech.MapFragment.java

private void onUpdateNavigationStatus() {
    if (!application.isNavigating())
        return;/*from   w ww. ja  va  2s  .c  o  m*/

    if (!map.isFollowing())
        map.refreshMap();

    long now = System.currentTimeMillis();

    double distance = application.navigationService.navDistance;
    double bearing = application.navigationService.navBearing;
    long turn = application.navigationService.navTurn;
    double vmg = application.navigationService.navVMG;
    int ete = application.navigationService.navETE;

    String[] dist = StringFormatter.distanceC(distance, StringFormatter.precisionFormat);
    String eteString = (ete == Integer.MAX_VALUE) ? getString(R.string.never)
            : (String) DateUtils.getRelativeTimeSpanString(now + (ete + 1) * 60000, now,
                    DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
    String extra = StringFormatter.speedH(vmg) + " | " + eteString;

    String trnsym = "";
    if (turn > 0) {
        trnsym = "R";
    } else if (turn < 0) {
        trnsym = "L";
        turn = -turn;
    }

    bearing = application.fixDeclination(bearing);
    distanceValue.setText(dist[0]);
    distanceUnit.setText(dist[1]);
    bearingValue.setText(StringFormatter.angleC(bearing));
    turnValue.setText(StringFormatter.angleC(turn) + trnsym);
    waypointExtra.setText(extra);

    if (application.navigationService.isNavigatingViaRoute()) {
        View rootView = getView();
        boolean hasNext = application.navigationService.hasNextRouteWaypoint();
        if (distance < application.navigationService.navProximity * 3 && !animationSet) {
            AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new AlphaAnimation(1.0f, 0.3f));
            animation.addAnimation(new AlphaAnimation(0.3f, 1.0f));
            animation.setDuration(500);
            animation.setRepeatCount(10);
            rootView.findViewById(R.id.waypointinfo).startAnimation(animation);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).startAnimation(animation);
            }
            animationSet = true;
        } else if (animationSet) {
            rootView.findViewById(R.id.waypointinfo).setAnimation(null);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).setAnimation(null);
            }
            animationSet = false;
        }

        if (application.navigationService.navXTK == Double.NEGATIVE_INFINITY) {
            xtkValue.setText("--");
            xtkUnit.setText("--");
        } else {
            String xtksym = application.navigationService.navXTK == 0 ? ""
                    : application.navigationService.navXTK > 0 ? "R" : "L";
            String[] xtks = StringFormatter.distanceC(Math.abs(application.navigationService.navXTK));
            xtkValue.setText(xtks[0] + xtksym);
            xtkUnit.setText(xtks[1]);
        }

        double navDistance = application.navigationService.navRouteDistanceLeft();
        int eta = application.navigationService.navRouteETE(navDistance);
        if (eta < Integer.MAX_VALUE)
            eta += application.navigationService.navETE;
        String etaString = (eta == Integer.MAX_VALUE) ? getString(R.string.never)
                : (String) DateUtils.getRelativeTimeSpanString(now + (eta + 1) * 60000, now,
                        DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
        extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + etaString;
        routeExtra.setText(extra);
    }
}

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

/***
 * ?/*from  w  w  w  . j  a  v  a  2 s  . c o  m*/
 * **/
private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:com.PPRZonDroid.MainActivity.java

/**
 * Refresh block lisst on right/*from w  w w  . j a va2s  .  c  o m*/
 */
private void refresh_block_list() {

    int i;
    BlList.clear();

    for (i = 0; i < AC_DATA.AircraftData[AC_DATA.SelAcInd].BlockCount; i++) {
        BlList.add(new BlockModel(AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_Blocks[i].BlName));
    }
    mBlListAdapter.BlColor = AC_DATA.muiGraphics.get_color(AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_Color);
    mBlListAdapter.SelectedInd = AC_DATA.AircraftData[AC_DATA.SelAcInd].SelectedBlock;

    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, +1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(250);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);
    BlListView.setLayoutAnimation(controller);

    mBlListAdapter.notifyDataSetChanged();
}

From source file:com.juick.android.MainActivity.java

public void openNavigationMenu(boolean animate) {
    if (isNavigationMenuShown())
        return;//from w  w  w .j a  v a 2  s .c o  m
    navigationMenuShown = true;
    final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel);
    navigationPanel.setVisibility(View.VISIBLE);
    final View frag = (ViewGroup) findViewById(R.id.messagesfragment);
    if (animate) {
        AnimationSet set = new AnimationSet(true);
        TranslateAnimation translate = new TranslateAnimation(0, navigationPanel.getWidth(), 0, 0);
        translate.setFillAfter(false);
        translate.setFillEnabled(true);
        translate.setDuration(400);
        set.addAnimation(translate);
        set.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                frag.clearAnimation();
                layoutNavigationPane();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        frag.startAnimation(set);
    } else {
        layoutNavigationPane();
    }
}

From source file:com.juick.android.MainActivity.java

public void closeNavigationMenu(boolean animate, boolean immediate) {
    if (!isNavigationMenuShown())
        return;/*from   w w w. j  a va  2s  . c  om*/
    final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel);
    final View frag = findViewById(R.id.messagesfragment);
    final DragSortListView navigationList = (DragSortListView) findViewById(R.id.navigation_list);
    if (navigationList.isDragEnabled()) {
        navigationList.setDragEnabled(false);
        updateNavigation();
    }
    if (animate) {
        final AnimationSet set = new AnimationSet(true);
        TranslateAnimation translate = new TranslateAnimation(0, -navigationPanel.getWidth(), 0, 0);
        translate.setFillAfter(false);
        translate.setFillEnabled(true);
        translate.setDuration(400);
        set.addAnimation(translate);
        set.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                navigationMenuShown = false;
                frag.clearAnimation();
                layoutNavigationPane();
                //navigationPanel.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                frag.startAnimation(set);
                getActivity().findViewById(R.id.layout_container).invalidate();
            }
        }, immediate ? 1 : 200); // to smooth the slide

    } else {
        navigationMenuShown = false;
        layoutNavigationPane();
    }
}

From source file:com.androzic.MapActivity.java

protected void updateNavigationInfo() {
    if (navigationService == null || !navigationService.isNavigating())
        return;/*from  w  w  w.j a v  a2 s .co  m*/

    double distance = navigationService.navDistance;
    double bearing = navigationService.navBearing;
    long turn = navigationService.navTurn;
    double vmg = navigationService.navVMG * speedFactor;
    int ete = navigationService.navETE;

    String[] dist = StringFormatter.distanceC(distance, precisionFormat);
    String extra = String.format(precisionFormat, vmg) + " " + speedAbbr + " | " + StringFormatter.timeH(ete);

    String trnsym = "";
    if (turn > 0) {
        trnsym = "R";
    } else if (turn < 0) {
        trnsym = "L";
        turn = -turn;
    }

    bearing = application.fixDeclination(bearing);
    distanceValue.setText(dist[0]);
    distanceUnit.setText(dist[1]);
    bearingValue.setText(String.valueOf(Math.round(bearing)));
    turnValue.setText(String.valueOf(Math.round(turn)) + trnsym);
    waypointExtra.setText(extra);

    if (navigationService.isNavigatingViaRoute()) {
        boolean hasNext = navigationService.hasNextRouteWaypoint();
        if (distance < navigationService.navProximity * 3 && !animationSet) {
            AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new AlphaAnimation(1.0f, 0.3f));
            animation.addAnimation(new AlphaAnimation(0.3f, 1.0f));
            animation.setDuration(500);
            animation.setRepeatCount(10);
            findViewById(R.id.waypointinfo).startAnimation(animation);
            if (!hasNext) {
                findViewById(R.id.routeinfo).startAnimation(animation);
            }
            animationSet = true;
        } else if (animationSet) {
            findViewById(R.id.waypointinfo).setAnimation(null);
            if (!hasNext) {
                findViewById(R.id.routeinfo).setAnimation(null);
            }
            animationSet = false;
        }

        if (navigationService.navXTK == Double.NEGATIVE_INFINITY) {
            xtkValue.setText("--");
            xtkUnit.setText("--");
        } else {
            String xtksym = navigationService.navXTK == 0 ? "" : navigationService.navXTK > 0 ? "R" : "L";
            String[] xtks = StringFormatter.distanceC(Math.abs(navigationService.navXTK));
            xtkValue.setText(xtks[0] + xtksym);
            xtkUnit.setText(xtks[1]);
        }

        double navDistance = navigationService.navRouteDistanceLeft();
        int eta = navigationService.navRouteETE(navDistance);
        if (eta < Integer.MAX_VALUE)
            eta += navigationService.navETE;
        extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + StringFormatter.timeH(eta);
        routeExtra.setText(extra);
    }
}

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

private void mainAnmLoop() {

    AnimationSet anmSet = null;

    if (onClickFlg == 1) {

        if (anmSet != null) {
            anmSet.cancel();// w  ww  .j  av  a  2s .  co  m
            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);
}