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.aniruddhc.acemusic.player.BrowserSubListActivity.BrowserSubListActivity.java

/**
 * Slides away the GridView.//from www  .j ava 2s .  com
 */
private void slideAwayGridView() {
    android.view.animation.TranslateAnimation animation = new android.view.animation.TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 2.0f);

    animation.setDuration(400);
    animation.setInterpolator(new AccelerateInterpolator(2.0f));
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            mListView.setVisibility(View.INVISIBLE);
            BrowserSubListActivity.super.onBackPressed();

        }

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

        }

        @Override
        public void onAnimationStart(Animation arg0) {

        }

    });

    mListView.startAnimation(animation);
}

From source file:com.aniruddhc.acemusic.player.BrowserSubGridActivity.BrowserSubGridActivity.java

/**
 * Slides away the GridView.//from   w ww .  j  ava 2 s  .  c  om
 */
private void slideAwayGridView() {
    android.view.animation.TranslateAnimation animation = new android.view.animation.TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 2.0f);

    animation.setDuration(400);
    animation.setInterpolator(new AccelerateInterpolator(2.0f));
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            mGridView.setVisibility(View.INVISIBLE);
            BrowserSubGridActivity.super.onBackPressed();

        }

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

        }

        @Override
        public void onAnimationStart(Animation arg0) {

        }

    });

    mGridView.startAnimation(animation);
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindSound(View view, Cursor cursor) {
    AppState appState = AppState.getInstance();

    final View card = view;
    final View downloadFrame = view.findViewById(R.id.sound_download_frame);
    final TextView tv = (TextView) view.findViewById(R.id.grid_text);
    final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image);
    final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav);
    final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu);

    final String soundName = cursor
            .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME));
    String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME));
    final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC));
    final boolean favorite = appState.favSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1;
    final boolean widget = appState.widgetSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1;
    final boolean downloaded = cursor
            .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0;

    new Handler().post(new Runnable() {
        @Override//  w w  w . j av a 2s  .  co  m
        public void run() {
            ContentValues cv = new ContentValues();
            File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg");

            if (downloaded && !sndFile.exists()) {
                cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0);
                mContext.getContentResolver().update(
                        Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null,
                        null);
            }
        }
    });

    final View.OnClickListener playSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String category = mContext.getString(R.string.ana_cat_sound);
            String action = mContext.getString(R.string.ana_act_play);

            Bundle extras = new Bundle();
            extras.putString(SoundFragment.SOUND_TO_PLAY, soundName);
            extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet());
            Intent intent = new Intent(mContext, SoundService.class);
            intent.putExtras(extras);

            mContext.startService(intent);
            AnalyticsUtils.sendEvent(category, action, soundName);
        }
    };

    final View.OnClickListener downloadSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            card.setOnClickListener(null);
            RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setInterpolator(new BounceInterpolator());
            animation.setFillAfter(true);
            animation.setFillEnabled(true);
            animation.setDuration(1000);
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.RESTART);
            downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation);

            DownloadService.startActionDownloadSound(mContext, soundName,
                    new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this));
        }
    };

    if (downloaded) {
        downloadFrame.setVisibility(View.GONE);
        downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation();
        card.setOnClickListener(playSound);
    } else {
        downloadFrame.setAlpha(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1);
        downloadFrame.setVisibility(View.VISIBLE);
        card.setOnClickListener(downloadSound);
    }

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ImageView menuIc = (ImageView) v;
            PopupMenu popup = new PopupMenu(mContext, menuIc);
            Menu menu = popup.getMenu();
            popup.getMenuInflater().inflate(R.menu.sound_menu, menu);

            if (favorite)
                menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris");
            if (widget)
                menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget");

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_sound_fav:
                        SoundUtils.addRemoveFavorite(mContext, soundName);
                        return true;
                    case R.id.action_sound_wid:
                        SoundUtils.addRemoveWidget(mContext, soundName);
                        return true;
                    /*case R.id.action_sound_add:
                       return true;*/
                    case R.id.action_sound_ring:
                        SoundUtils.addRingtone(mContext, soundName, description);
                        return true;
                    case R.id.action_sound_share:
                        AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext),
                                mContext.getString(R.string.ana_act_weblink), soundName);
                        ClipboardManager clipboard = (ClipboardManager) mContext
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show();
                        return true;
                    case R.id.action_sound_delete:
                        SoundUtils.delete(mContext, soundName);
                        return true;
                    default:
                        return false;
                    }
                }
            });

            popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark));
                }
            });
            menuIc.setColorFilter(mContext.getResources().getColor(R.color.black));

            popup.show();
        }
    });

    tv.setText(description);
    siv.setTag(imgId);

    if (appState.favSounds.contains(soundName)) {
        star.setVisibility(View.VISIBLE);
    } else if (favorite) {
        star.setVisibility(View.VISIBLE);
        appState.favSounds.add(soundName);
    } else {
        star.setVisibility(View.INVISIBLE);
    }

    File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg");
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv);
}

From source file:org.onebusaway.android.ui.ArrivalsListHeader.java

/**
 * Creates and returns a new rotation animation for the expand/collapse image based on the
 * provided startState and endState.//from   w  w w .j  av a 2  s  .  c  o  m
 *
 * @param startState beginning state of the image, either ANIM_STATE_NORMAL or
 *                   ANIM_STATE_INVERTED
 * @param endState   end state of the image, either ANIM_STATE_NORMAL or ANIM_STATE_INVERTED
 * @return a new rotation animation for the expand/collapse image
 */
private static RotateAnimation getRotation(float startState, float endState) {
    RotateAnimation r = new RotateAnimation(startState, endState, Animation.RELATIVE_TO_SELF, ANIM_PIVOT_VALUE,
            Animation.RELATIVE_TO_SELF, ANIM_PIVOT_VALUE);
    r.setDuration(ANIM_DURATION);
    r.setFillAfter(true);
    return r;
}

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  va2  s.co m*/
    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:de.grobox.liberario.fragments.DirectionsFragment.java

private void swapLocations() {
    Animation slideUp = 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);

    slideUp.setDuration(400);/*from   w w w.  j  a  va2  s . c o  m*/
    slideUp.setFillAfter(true);
    slideUp.setFillEnabled(true);
    ui.to.startAnimation(slideUp);

    Animation slideDown = 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);

    slideDown.setDuration(400);
    slideDown.setFillAfter(true);
    slideDown.setFillEnabled(true);
    ui.from.startAnimation(slideDown);

    slideUp.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // swap location objects
            Location tmp = ui.to.getLocation();
            if (!ui.from.isSearching()) {
                ui.to.setLocation(ui.from.getLocation(),
                        getDrawableForLocation(getContext(), ui.from.getLocation()));
            } else {
                // TODO: GPS currently only supports from location, so don't swap it for now
                ui.to.clearLocation();
            }
            ui.from.setLocation(tmp, getDrawableForLocation(getContext(), tmp));

            ui.from.clearAnimation();
            ui.to.clearAnimation();
        }
    });
}

From source file:com.PPRZonDroid.MainActivity.java

/**
 * Refresh block lisst on right//from  w  w w  . ja va2  s.  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.github.shareme.gwsmaterialuikit.library.mscrollbar.MaterialScrollBar.java

/**
 * Animates the bar out of view/*from w ww.j ava 2s . c  om*/
 */
void fadeOut() {
    if (!hidden) {
        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(150);
        anim.setFillAfter(true);
        hidden = true;
        startAnimation(anim);
        postDelayed(new Runnable() {
            @Override
            public void run() {
                handle.expandHandle();
            }
        }, anim.getDuration() / 3);
    }
}

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

private void mainAnmLoop() {

    AnimationSet anmSet = null;//w  w w.j ava  2  s. co 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.github.shareme.gwsmaterialuikit.library.mscrollbar.MaterialScrollBar.java

/**
 * Animates the bar into view//from w w w.  j  a  v a2  s . c  om
 */
void fadeIn() {
    if (hidden && getHide() && !hiddenByUser) {
        hidden = false;
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, getHideRatio(),
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        anim.setDuration(150);
        anim.setFillAfter(true);
        startAnimation(anim);
        handle.collapseHandle();
    }
}