List of usage examples for android.view.animation DecelerateInterpolator DecelerateInterpolator
public DecelerateInterpolator()
From source file:org.michaelbel.bottomsheet.BottomSheet.java
private void startOpenAnimation() { containerView.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= 20) { container.setLayerType(View.LAYER_TYPE_HARDWARE, null); }/*from w ww .j a v a2 s. co m*/ containerView.setTranslationY(containerView.getMeasuredHeight()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0), ObjectAnimator.ofInt(backDrawable, "alpha", 51)); animatorSet.setDuration(200); animatorSet.setStartDelay(20); animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) { currentSheetAnimation = null; container.setLayerType(View.LAYER_TYPE_NONE, null); } } @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) { currentSheetAnimation = null; } } }); animatorSet.start(); currentSheetAnimation = animatorSet; }
From source file:self.philbrown.droidQuery.$.java
/** * This reusable chunk of code can set up the given animation using the given animation options * @param options the options used to manipulate how the animation behaves * @return the container for placing views that will be animated using the given options */// w w w.j a v a2s . c o m private AnimatorSet animationWithOptions(final AnimationOptions options, List<Animator> animators) { AnimatorSet animation = new AnimatorSet(); animation.playTogether(animators); animation.setDuration(options.duration()); animation.addListener(new AnimatorListener() { @Override public void onAnimationCancel(Animator animation) { if (options.fail() != null) options.fail().invoke($.this); if (options.complete() != null) options.complete().invoke($.this); } @Override public void onAnimationEnd(Animator animation) { if (options.success() != null) options.success().invoke($.this); if (options.complete() != null) options.complete().invoke($.this); } @Override public void onAnimationRepeat(Animator animation) { } @Override public void onAnimationStart(Animator animation) { } }); Interpolator interpolator = null; if (options.easing() == null) options.easing(Easing.LINEAR); final Easing easing = options.easing(); switch (easing) { case ACCELERATE: { interpolator = new AccelerateInterpolator(); break; } case ACCELERATE_DECELERATE: { interpolator = new AccelerateDecelerateInterpolator(); break; } case ANTICIPATE: { interpolator = new AnticipateInterpolator(); break; } case ANTICIPATE_OVERSHOOT: { interpolator = new AnticipateOvershootInterpolator(); break; } case BOUNCE: { interpolator = new BounceInterpolator(); break; } case DECELERATE: { interpolator = new DecelerateInterpolator(); break; } case OVERSHOOT: { interpolator = new OvershootInterpolator(); break; } //linear is default. case LINEAR: default: interpolator = new LinearInterpolator(); break; } //allow custom interpolator if (options.specialEasing() != null) interpolator = options.specialEasing(); animation.setInterpolator(interpolator); return animation; }
From source file:com.adityarathi.muo.ui.activities.NowPlayingActivity.java
/** * Smoothly scrolls the seekbar to the indicated position. *///w w w.j av a 2 s . c o m private void smoothScrollSeekbar(int progress) { ObjectAnimator animation = ObjectAnimator.ofInt(mSeekbar, "progress", progress); animation.setDuration(200); animation.setInterpolator(new DecelerateInterpolator()); animation.start(); }
From source file:com.klinker.android.sliding.MultiShrinkScroller.java
public void reverseExpansionAnimation() { final Interpolator interpolator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in); } else {//w w w. j a v a 2 s .c om interpolator = new DecelerateInterpolator(); } WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int screenHeight = size.y; int screenWidth = size.x; final ValueAnimator heightExpansion = ValueAnimator.ofInt(screenHeight, expansionViewHeight); heightExpansion.setInterpolator(interpolator); heightExpansion.setDuration(ANIMATION_DURATION); heightExpansion.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int val = (int) animation.getAnimatedValue(); ViewGroup.LayoutParams params = getLayoutParams(); params.height = val; setLayoutParams(params); } }); heightExpansion.start(); final ValueAnimator widthExpansion = ValueAnimator.ofInt(getWidth(), expansionViewWidth); widthExpansion.setInterpolator(interpolator); widthExpansion.setDuration(ANIMATION_DURATION); widthExpansion.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int val = (int) animation.getAnimatedValue(); ViewGroup.LayoutParams params = getLayoutParams(); params.width = val; setLayoutParams(params); } }); widthExpansion.start(); ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, 0f, expansionLeftOffset); translationX.setInterpolator(interpolator); translationX.setDuration(ANIMATION_DURATION); translationX.start(); ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0f, expansionTopOffset); translationY.setInterpolator(interpolator); translationY.setDuration(ANIMATION_DURATION); translationY.addListener(exitAnimationListner); translationY.start(); }
From source file:com.offers.couponempire.ui.BaseActivity.java
protected void onActionBarAutoShowOrHide(boolean shown) { if (mStatusBarColorAnimator != null) { mStatusBarColorAnimator.cancel(); }//w w w. j a v a2s .com mStatusBarColorAnimator = ObjectAnimator .ofInt((mDrawerLayout != null) ? mDrawerLayout : mLPreviewUtils, (mDrawerLayout != null) ? "statusBarBackgroundColor" : "statusBarColor", shown ? Color.BLACK : mNormalStatusBarColor, shown ? mNormalStatusBarColor : Color.BLACK) .setDuration(250); if (mDrawerLayout != null) { mStatusBarColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { ViewCompat.postInvalidateOnAnimation(mDrawerLayout); } }); } mStatusBarColorAnimator.setEvaluator(ARGB_EVALUATOR); mStatusBarColorAnimator.start(); for (View view : mHideableHeaderViews) { if (shown) { view.animate().translationY(0).alpha(1).setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } else { view.animate().translationY(-view.getBottom()).alpha(0).setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } } }
From source file:com.irccloud.android.activity.MainActivity.java
private void update_suggestions(boolean force) { if (buffer != null && suggestionsContainer != null && messageTxt != null && messageTxt.getText() != null) { String text;/*w w w . j ava2 s. c o m*/ try { text = messageTxt.getText().toString(); } catch (Exception e) { text = ""; } if (text.lastIndexOf(' ') > 0 && text.lastIndexOf(' ') < text.length() - 1) { text = text.substring(text.lastIndexOf(' ') + 1); } if (text.endsWith(":")) text = text.substring(0, text.length() - 1); text = text.toLowerCase(); final ArrayList<String> sugs = new ArrayList<String>(); HashSet<String> sugs_set = new HashSet<String>(); if (text.length() > 2 || force || (text.length() > 0 && suggestionsAdapter.activePos != -1)) { ArrayList<ChannelsDataSource.Channel> channels = sortedChannels; if (channels == null) { channels = ChannelsDataSource.getInstance().getChannels(); Collections.sort(channels, new Comparator<ChannelsDataSource.Channel>() { @Override public int compare(ChannelsDataSource.Channel lhs, ChannelsDataSource.Channel rhs) { return lhs.name.compareTo(rhs.name); } }); sortedChannels = channels; } if (buffer != null && messageTxt.getText().length() > 0 && buffer.type.equals("channel") && buffer.name.toLowerCase().startsWith(text) && !sugs_set.contains(buffer.name)) { sugs_set.add(buffer.name); sugs.add(buffer.name); } if (channels != null) { for (ChannelsDataSource.Channel channel : channels) { if (text.length() > 0 && text.charAt(0) == channel.name.charAt(0) && channel.name.toLowerCase().startsWith(text) && !sugs_set.contains(channel.name)) { sugs_set.add(channel.name); sugs.add(channel.name); } } } JSONObject disableAutoSuggest = null; if (NetworkConnection.getInstance().getUserInfo() != null && NetworkConnection.getInstance().getUserInfo().prefs != null) { try { if (NetworkConnection.getInstance().getUserInfo().prefs.has("channel-disableAutoSuggest")) disableAutoSuggest = NetworkConnection.getInstance().getUserInfo().prefs .getJSONObject("channel-disableAutoSuggest"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } boolean disabled; try { disabled = disableAutoSuggest != null && disableAutoSuggest.has(String.valueOf(buffer.bid)) && disableAutoSuggest.getBoolean(String.valueOf(buffer.bid)); } catch (JSONException e) { disabled = false; } ArrayList<UsersDataSource.User> users = sortedUsers; if (users == null && buffer != null && (force || !disabled)) { users = UsersDataSource.getInstance().getUsersForBuffer(buffer.bid); if (users != null) { Collections.sort(users, new Comparator<UsersDataSource.User>() { @Override public int compare(UsersDataSource.User lhs, UsersDataSource.User rhs) { if (lhs.last_mention > rhs.last_mention) return -1; if (lhs.last_mention < rhs.last_mention) return 1; return lhs.nick.compareToIgnoreCase(rhs.nick); } }); } sortedUsers = users; } if (users != null) { for (UsersDataSource.User user : users) { String nick = user.nick_lowercase; if (text.matches("^[a-zA-Z0-9]+.*")) nick = nick.replaceFirst("^[^a-zA-Z0-9]+", ""); if (nick.startsWith(text) && !sugs_set.contains(user.nick)) { sugs_set.add(user.nick); sugs.add(user.nick); } } } } if (Build.VERSION.SDK_INT >= 14 && text.startsWith(":") && text.length() > 1) { String q = text.toLowerCase().substring(1); for (String emocode : ColorFormatter.emojiMap.keySet()) { if (emocode.startsWith(q)) { String emoji = ColorFormatter.emojiMap.get(emocode); if (!sugs_set.contains(emoji)) { sugs_set.add(emoji); sugs.add(emoji); } } } } if (sugs.size() == 0 && suggestionsContainer.getVisibility() == View.INVISIBLE) return; runOnUiThread(new Runnable() { @Override public void run() { if (sugs.size() > 0) { if (suggestionsAdapter.activePos == -1) { suggestionsAdapter.clear(); for (String s : sugs) { suggestionsAdapter.add(s); } suggestionsAdapter.notifyDataSetChanged(); suggestions.smoothScrollToPosition(0); } if (suggestionsContainer.getVisibility() == View.INVISIBLE) { if (Build.VERSION.SDK_INT < 16) { AlphaAnimation anim = new AlphaAnimation(0, 1); anim.setDuration(250); anim.setFillAfter(true); suggestionsContainer.startAnimation(anim); } else { suggestionsContainer.setAlpha(0); suggestionsContainer.setTranslationY(1000); suggestionsContainer.animate().alpha(1).translationY(0) .setInterpolator(new DecelerateInterpolator()); } suggestionsContainer.setVisibility(View.VISIBLE); runOnUiThread(new Runnable() { @Override public void run() { if (suggestionsContainer.getHeight() < 48) { getSupportActionBar().hide(); } } }); } } else { if (suggestionsContainer.getVisibility() == View.VISIBLE) { if (Build.VERSION.SDK_INT < 16) { AlphaAnimation anim = new AlphaAnimation(1, 0); anim.setDuration(250); anim.setFillAfter(true); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { suggestionsContainer.setVisibility(View.INVISIBLE); suggestionsAdapter.clear(); suggestionsAdapter.notifyDataSetChanged(); } @Override public void onAnimationRepeat(Animation animation) { } }); suggestionsContainer.startAnimation(anim); } else { suggestionsContainer.animate().alpha(1).translationY(1000) .setInterpolator(new AccelerateInterpolator()) .withEndAction(new Runnable() { @Override public void run() { suggestionsContainer.setVisibility(View.INVISIBLE); suggestionsAdapter.clear(); suggestionsAdapter.notifyDataSetChanged(); } }); } sortedUsers = null; sortedChannels = null; if (!getSupportActionBar().isShowing()) getSupportActionBar().show(); } } } }); } }
From source file:com.mome.main.business.widget.pulltorefresh.PullToRefreshBase.java
private final void smoothScrollTo(int newScrollValue, long duration, long delayMillis, OnSmoothScrollFinishedListener listener) { if (null != mCurrentSmoothScrollRunnable) { mCurrentSmoothScrollRunnable.stop(); }//from w w w .jav a 2 s. c om final int oldScrollValue; switch (getPullToRefreshScrollDirection()) { case HORIZONTAL: oldScrollValue = getScrollX(); break; case VERTICAL: default: oldScrollValue = getScrollY(); break; } if (oldScrollValue != newScrollValue) { if (null == mScrollAnimationInterpolator) { // Default interpolator is a Decelerate Interpolator mScrollAnimationInterpolator = new DecelerateInterpolator(); } mCurrentSmoothScrollRunnable = new SmoothScrollRunnable(oldScrollValue, newScrollValue, duration, listener); if (delayMillis > 0) { postDelayed(mCurrentSmoothScrollRunnable, delayMillis); } else { post(mCurrentSmoothScrollRunnable); } } }
From source file:org.telegram.ui.SettingsActivity.java
private void needLayout() { FrameLayout.LayoutParams layoutParams; int newTop = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight(); if (listView != null) { layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); if (layoutParams.topMargin != newTop) { layoutParams.topMargin = newTop; listView.setLayoutParams(layoutParams); extraHeightView.setTranslationY(newTop); }//from w w w .jav a2 s. c om } if (avatarContainer != null) { float diff = extraHeight / (float) AndroidUtilities.dp(88); extraHeightView.setScaleY(diff); shadowView.setTranslationY(newTop + extraHeight); writeButton.setTranslationY((actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight() + extraHeight - AndroidUtilities.dp(29.5f)); final boolean setVisible = diff > 0.2f; boolean currentVisible = writeButton.getTag() == null; if (setVisible != currentVisible) { if (setVisible) { writeButton.setTag(null); writeButton.setVisibility(View.VISIBLE); } else { writeButton.setTag(0); } if (writeButtonAnimation != null) { AnimatorSet old = writeButtonAnimation; writeButtonAnimation = null; old.cancel(); } writeButtonAnimation = new AnimatorSet(); if (setVisible) { writeButtonAnimation.setInterpolator(new DecelerateInterpolator()); writeButtonAnimation.playTogether(ObjectAnimator.ofFloat(writeButton, "scaleX", 1.0f), ObjectAnimator.ofFloat(writeButton, "scaleY", 1.0f), ObjectAnimator.ofFloat(writeButton, "alpha", 1.0f)); } else { writeButtonAnimation.setInterpolator(new AccelerateInterpolator()); writeButtonAnimation.playTogether(ObjectAnimator.ofFloat(writeButton, "scaleX", 0.2f), ObjectAnimator.ofFloat(writeButton, "scaleY", 0.2f), ObjectAnimator.ofFloat(writeButton, "alpha", 0.0f)); } writeButtonAnimation.setDuration(150); writeButtonAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (writeButtonAnimation != null && writeButtonAnimation.equals(animation)) { writeButton.setVisibility(setVisible ? View.VISIBLE : View.GONE); writeButtonAnimation = null; } } }); writeButtonAnimation.start(); } avatarContainer.setScaleX((42 + 18 * diff) / 42.0f); avatarContainer.setScaleY((42 + 18 * diff) / 42.0f); avatarProgressView.setSize(AndroidUtilities.dp(26 / avatarContainer.getScaleX())); avatarProgressView.setStrokeWidth(3 / avatarContainer.getScaleX()); float avatarY = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight() / 2.0f * (1.0f + diff) - 21 * AndroidUtilities.density + 27 * AndroidUtilities.density * diff; avatarContainer.setTranslationY((float) Math.ceil(avatarY)); nameTextView.setTranslationY((float) Math.floor(avatarY) - (float) Math.ceil(AndroidUtilities.density) + (float) Math.floor(7 * AndroidUtilities.density * diff)); onlineTextView.setTranslationY((float) Math.floor(avatarY) + AndroidUtilities.dp(22) + (float) Math.floor(11 * AndroidUtilities.density) * diff); nameTextView.setScaleX(1.0f + 0.12f * diff); nameTextView.setScaleY(1.0f + 0.12f * diff); if (LocaleController.isRTL) { avatarContainer.setTranslationX(AndroidUtilities.dp(47) * diff); nameTextView.setTranslationX(21 * AndroidUtilities.density * diff); onlineTextView.setTranslationX(21 * AndroidUtilities.density * diff); } else { avatarContainer.setTranslationX(-AndroidUtilities.dp(47) * diff); nameTextView.setTranslationX(-21 * AndroidUtilities.density * diff); onlineTextView.setTranslationX(-21 * AndroidUtilities.density * diff); } } }
From source file:de.mrapp.android.sidebar.Sidebar.java
/** * Handles when a drag gesture has been ended by the user. *///from w ww. j a va 2 s. co m private void handleRelease() { dragHelper.reset(); float thresholdPosition = calculatePositionWhereDragThresholdIsReached(); float speed = Math.max(dragHelper.getDragSpeed(), animationSpeed); if (getLocation() == Location.LEFT) { if (sidebarView.getRight() - sidebarView.getShadowWidth() > thresholdPosition) { animateShowSidebar(calculateAnimationDistance(true), speed, new DecelerateInterpolator()); } else { animateHideSidebar(calculateAnimationDistance(false), speed, new DecelerateInterpolator()); } } else { if (sidebarView.getLeft() + sidebarView.getShadowWidth() < thresholdPosition) { animateShowSidebar(calculateAnimationDistance(true), speed, new DecelerateInterpolator()); } else { animateHideSidebar(calculateAnimationDistance(false), speed, new DecelerateInterpolator()); } } }
From source file:de.mrapp.android.bottomsheet.BottomSheet.java
/** * Creates and returns a listener, which allows to immediately maximize the bottom sheet after * it has been shown.//from w ww . ja v a 2s . c o m * * @return The listener, which has been created, as an instance of the type {@link * OnShowListener} */ @TargetApi(Build.VERSION_CODES.FROYO) private OnShowListener createOnShowListener() { return new OnShowListener() { @Override public void onShow(final DialogInterface dialog) { if (onShowListener != null) { onShowListener.onShow(dialog); } if (maximize) { maximize = false; rootView.maximize(new DecelerateInterpolator()); } } }; }