Example usage for android.view.animation BounceInterpolator BounceInterpolator

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

Introduction

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

Prototype

public BounceInterpolator() 

Source Link

Usage

From source file:com.rowland.hashtrace.ui.fragments.subfragment.TweetListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The ArrayAdapter will take data from a source and use it to populate the ListView it's attached to.
    mTweetListAdapter = new TweetListAdapter(getActivity(), null, 0);
    creator = new SwipeMenuCreator() {

        @Override//from  w w  w .  j  a  va  2s.  c  om
        public void create(SwipeMenu menu) {
            // create "share" item
            SwipeMenuItem shareItem = new SwipeMenuItem(getActivity().getApplicationContext());
            // set item background
            shareItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219)));
            // set item width
            shareItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics()));
            // set icon resource
            shareItem.setIcon(R.drawable.selector_swipemenuitem_share);
            // set item title
            shareItem.setTitle("Share");
            // set item title fontsize
            shareItem.setTitleSize(18);
            // set item title font color
            shareItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(shareItem);

            // create "favour" item
            SwipeMenuItem favourItem = new SwipeMenuItem(getActivity().getApplicationContext());
            // set item background
            favourItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219)));
            // set item width
            favourItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics()));
            // set icon resource
            favourItem.setIcon(R.drawable.selector_swipemenuitem_favorite);
            // set item title
            favourItem.setTitle("Like");
            // set item title fontsize
            favourItem.setTitleSize(18);
            // set item title font color
            favourItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(favourItem);
        }
    };

    View rootView = inflater.inflate(R.layout.fragment_tweet_list, container, false);

    mListView = (SwipeMenuListView) rootView.findViewById(android.R.id.list);

    ViewGroup parent = (ViewGroup) mListView.getParent();
    int lvIndex = parent.indexOfChild(mListView);
    if (mListView.getParent() != null) {
        parent.removeViewAt(lvIndex);
    }

    mListView.setVisibility(View.GONE);
    mPullToRefreshListView = new PullToRefreshSwipeMenuListView(getActivity());
    mPullToRefreshListView.setLayoutParams(mListView.getLayoutParams());
    parent.addView(mPullToRefreshListView, lvIndex, mListView.getLayoutParams());
    View emptyView = rootView.findViewById(R.id.empty_text_view);
    mPullToRefreshListView.setEmptyView(emptyView);
    mPullToRefreshListView.setAdapter(mTweetListAdapter);
    mPullToRefreshListView.setMenuCreator(creator);
    mPullToRefreshListView.setVerticalFadingEdgeEnabled(true);
    mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<SwipeMenuListView>() {

        @Override
        public void onRefresh(final PullToRefreshBase<SwipeMenuListView> refreshView) {
            // Do work to refresh the list here.
            updateTweet();
            // Call onRefreshComplete when the list has been refreshed.
            refreshView.onRefreshComplete();
            //mPullToRefreshListView.onRefreshComplete();
        }
    });
    //This somehow refuses to work , I really have no idea why
    /*   mPullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowId)
          {
            
    Cursor cursor = mTweetListAdapter.getCursor();
    if (cursor != null && cursor.moveToPosition(position))
    {
       ((onTweetItemSelectedCallback) getActivity()).onTweetItemSelected(cursor.getString(COL_TWEET_TEXT_DATE));
       Log.d("ROWSELECT", "" + rowId );
            
    }
    mPosition = position;
          }
       });*/
    mPullToRefreshListView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long rowId) {
            // Do the onItemLongClick action
            mPullToRefreshListView.smoothOpenMenu(position);

            return true;
        }
    });
    mPullToRefreshListView.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            switch (index) {
            case 0:
                // Share
                shareTweet();
                break;
            case 1:
                // Favourite
                favouriteTweet();
                break;
            }
            // false : close the menu; true : not close the menu
            return false;
        }
    });
    /**
     * Add Sound Event Listener
     */
    SoundPullEventListener<SwipeMenuListView> soundListener = new SoundPullEventListener<SwipeMenuListView>(
            getActivity());
    soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event_mp3);
    soundListener.addSoundEvent(State.RESET, R.raw.reset_sound_mp3);
    soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound_mp3);
    mPullToRefreshListView.setOnPullEventListener(soundListener);
    mPullToRefreshListView.setCloseInterpolator(new BounceInterpolator());

    // If there's instance state, mine it for useful information. The end-goal here is that
    // the user never knows that turning their device sideways does crazy lifecycle related things.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet. Actually
        // perform the swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:fashiome.android.fragments.MapListFragment.java

private void dropPinEffect(final Marker marker) {
    // Handler allows us to repeat a code block after a specified delay
    final android.os.Handler handler = new android.os.Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1500;

    // Use the bounce interpolator
    final android.view.animation.Interpolator interpolator = new BounceInterpolator();

    // Animate marker with a bounce updating its position every 15ms
    handler.post(new Runnable() {
        @Override/*from  w w w.j  a v a 2 s  . c  om*/
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            // Calculate t for bounce based on elapsed time
            float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
            // Set the anchor
            marker.setAnchor(0.5f, 1.0f + 14 * t);

            if (t > 0.0) {
                // Post this event again 15ms from now.
                handler.postDelayed(this, 15);
            } else { // done elapsing, show window
                marker.showInfoWindow();
            }
        }
    });
}

From source file:com.example.testtab.fragment.TwitEyesPageFragment.java

public void showProgressBar(int percent) {
    TextView textLayer = (TextView) this.mRootView.findViewById(R.id.progress_bar);
    AnimationSet set = new AnimationSet(true);

    // ALPHA/*from w w  w  . java2  s . co  m*/
    AlphaAnimation alpha;
    switch (percent) {
    case 100:
        alpha = new AlphaAnimation(1.0f, 0.0f);
        break;
    case 0:
        alpha = new AlphaAnimation(0.0f, 1.0f);
        break;
    default:
        alpha = new AlphaAnimation(0.8f, 1.0f);
    }
    alpha.setDuration(500);

    TranslateAnimation translate;
    float toX = ((float) percent - 100.0f) / 100.0f;
    float fromX = toX - 0.1f;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    translate.setDuration(500);
    translate.setInterpolator(new BounceInterpolator());

    set.addAnimation(alpha);
    set.addAnimation(translate);
    //         set.setDuration(500);
    set.setFillBefore(true);
    set.setFillAfter(true);

    textLayer.startAnimation(set);
}

From source file:de.quist.app.maps.example.MarkerDemoActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/* w  w  w. java2s. co  m*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(
                BuildConfig.MAP_BINDING.bitmapDescriptorFactory().defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }

    mLastSelectedMarker = marker;
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:com.kaltura.playersdk.PlayerViewController.java

/**
 * slides with animation according the given values
 *
 * @param x//from  w  ww  .j  a va 2s.c  o  m
 *            x offset to slide
 * @param duration
 *            animation time in milliseconds
 */
public void slideView(int x, int duration) {
    this.animate().xBy(x).setDuration(duration).setInterpolator(new BounceInterpolator());
}

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//from  www  .  java 2  s . c o  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:com.campusclipper.android.MyLocationActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/*  www.ja  v a 2  s.  c  om*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:com.miris.ui.view.WaveView.java

public void startWaveAnimation(float h) {
    h = Math.min(h, MAX_WAVE_HEIGHT) * mWidth;
    mWaveReverseAnimator = ValueAnimator.ofFloat(h, 0.f);
    mWaveReverseAnimator.setDuration(WAVE_ANIMATOR_DURATION);
    mWaveReverseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from w ww .  jav  a  2  s.  co m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float h = (Float) valueAnimator.getAnimatedValue();
            mWavePath.moveTo(0, 0);
            mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h * 0.5f);
            mWavePath.quadTo(mWidth * 0.5f, h * 1.4f, 0.666f * mWidth, h * 0.5f);
            mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0);
            postInvalidate();
        }
    });
    mWaveReverseAnimator.setInterpolator(new BounceInterpolator());
    mWaveReverseAnimator.start();
}

From source file:com.trackdroid.activities.ShowInMapActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it
        // is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override//from  w  w w.j  a v  a  2s . c o  m
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }
    // We return false to indicate that we have not consumed the event and
    // that we wish
    // for the default behavior to occur (which is for the camera to move
    // such that the
    // marker is centered and for the marker's info window to open, if it
    // has one).
    return false;
}

From source file:chinanurse.cn.nurse.list.WaveView.java

/**
 * @param h ???//from ww  w  .ja v  a2 s  .  c  om
 */
public void startWaveAnimation(float h) {
    h = Math.min(h, MAX_WAVE_HEIGHT) * mWidth;
    mWaveReverseAnimator = ValueAnimator.ofFloat(h, 0.f);
    mWaveReverseAnimator.setDuration(WAVE_ANIMATOR_DURATION);
    mWaveReverseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float h = (Float) valueAnimator.getAnimatedValue();
            mWavePath.moveTo(0, 0);
            mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h * 0.5f);
            mWavePath.quadTo(mWidth * 0.5f, h * 1.4f, 0.666f * mWidth, h * 0.5f);
            mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0);
            postInvalidate();
        }
    });
    mWaveReverseAnimator.setInterpolator(new BounceInterpolator());
    mWaveReverseAnimator.start();
}