Example usage for android.view View setTranslationY

List of usage examples for android.view View setTranslationY

Introduction

In this page you can find the example usage for android.view View setTranslationY.

Prototype

public void setTranslationY(float translationY) 

Source Link

Document

Sets the vertical location of this view relative to its #getTop() top position.

Usage

From source file:com.google.android.apps.muzei.MuzeiActivity.java

private void updateUiMode() {
    // TODO: this should really just use fragment transactions and transitions

    int newUiMode = UI_MODE_INTRO;
    if (mWallpaperActive) {
        newUiMode = UI_MODE_TUTORIAL;/*w  w w.  j a  va 2 s  .  c o m*/
        if (mSeenTutorial) {
            newUiMode = UI_MODE_ART_DETAIL;
        }
    }

    if (mUiMode == newUiMode) {
        return;
    }

    // Crossfade between main containers
    final View oldContainerView = getMainContainerForUiMode(mUiMode);
    final View newContainerView = getMainContainerForUiMode(newUiMode);

    if (oldContainerView != null) {
        oldContainerView.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {
            @Override
            public void run() {
                oldContainerView.setVisibility(View.GONE);
            }
        });
    }

    if (newContainerView != null) {
        if (newContainerView.getAlpha() == 1) {
            newContainerView.setAlpha(0);
        }
        newContainerView.setVisibility(View.VISIBLE);
        newContainerView.animate().alpha(1).setDuration(1000).withEndAction(null);
    }

    // Special work
    if (newUiMode == UI_MODE_INTRO) {
        final View activateButton = findViewById(R.id.activate_muzei_button);
        activateButton.setAlpha(0);
        final AnimatedMuzeiLogoFragment logoFragment = (AnimatedMuzeiLogoFragment) getFragmentManager()
                .findFragmentById(R.id.animated_logo_fragment);
        logoFragment.reset();
        logoFragment.setOnFillStartedCallback(new Runnable() {
            @Override
            public void run() {
                activateButton.animate().alpha(1f).setDuration(500);
            }
        });
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                logoFragment.start();
            }
        }, 1000);
    }

    if (mUiMode == UI_MODE_INTRO || newUiMode == UI_MODE_INTRO) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment demoFragment = fm.findFragmentById(R.id.demo_view_container);
        if (newUiMode == UI_MODE_INTRO && demoFragment == null) {
            fm.beginTransaction()
                    .add(R.id.demo_view_container, MuzeiRendererFragment.createInstance(true, true)).commit();
        } else if (newUiMode != UI_MODE_INTRO && demoFragment != null) {
            fm.beginTransaction().remove(demoFragment).commit();
        }
    }

    if (newUiMode == UI_MODE_TUTORIAL) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);

        View subTextView = findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);

        final View affordanceView = findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);

        View iconTextView = findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);

        AnimatorSet set = new AnimatorSet();
        set.setStartDelay(500);
        set.setDuration(250);
        set.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        set.start();

        set = new AnimatorSet();
        set.setStartDelay(2000);

        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        set.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    ImageView emanateView = (ImageView) findViewById(R.id.tutorial_icon_emanate);
                    AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                            .getDrawable(R.drawable.avd_tutorial_icon_emanate, getTheme());
                    emanateView.setImageDrawable(avd);
                    avd.start();
                }
            });
        }
        set.start();
    }

    mPanScaleProxyView.setVisibility(newUiMode == UI_MODE_ART_DETAIL ? View.VISIBLE : View.GONE);

    mUiMode = newUiMode;

    maybeUpdateArtDetailOpenedClosed();
}

From source file:ga.aditya.udacity01sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

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

    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_forecast);

    // Set the layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    View emptyView = rootView.findViewById(R.id.recyclerview_forecast_empty);

    // Use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // The ForecastAdapter will take data from a source and
    // use it to populate the RecyclerView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), new ForecastAdapter.ForecastAdapterOnClickHandler() {
        @Override// www.  ja  va  2 s .c om
        public void onClick(Long date, ForecastAdapter.ForecastAdapterViewHolder vh) {
            String locationSetting = Utility.getPreferredLocation(getActivity());
            ((Callback) getActivity()).onItemSelected(
                    WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, date), vh);
        }
    }, emptyView, mChoiceMode);

    // specify an adapter (see also next example)
    mRecyclerView.setAdapter(mForecastAdapter);

    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    int max = parallaxView.getHeight();
                    if (dy > 0) {
                        parallaxView.setTranslationY(Math.max(-max, parallaxView.getTranslationY() - dy / 2));
                    } else {
                        parallaxView.setTranslationY(Math.min(0, parallaxView.getTranslationY() - dy / 2));
                    }
                }
            });
        }
    }

    final AppBarLayout appbarView = (AppBarLayout) rootView.findViewById(R.id.appbar);
    if (null != appbarView) {
        ViewCompat.setElevation(appbarView, 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    if (0 == mRecyclerView.computeVerticalScrollOffset()) {
                        appbarView.setElevation(0);
                    } else {
                        appbarView.setElevation(appbarView.getTargetElevation());
                    }
                }
            });
        }
    }

    // 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.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null) {
        mForecastAdapter.onRestoreInstanceState(savedInstanceState);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.harlie.android.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

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

    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_forecast);

    // Set the layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    View emptyView = rootView.findViewById(R.id.recyclerview_forecast_empty);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // The ForecastAdapter will take data from a source and
    // use it to populate the RecyclerView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), new ForecastAdapter.ForecastAdapterOnClickHandler() {
        @Override/*from  ww w.j  ava  2s.c  o  m*/
        public void onClick(Long date, ForecastAdapter.ForecastAdapterViewHolder vh) {
            String locationSetting = Utility.getPreferredLocation();
            ((Callback) getActivity()).onItemSelected(
                    WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, date), vh);
            mPosition = vh.getAdapterPosition();
        }
    }, emptyView, mChoiceMode);

    // specify an adapter (see also next example)
    mRecyclerView.setAdapter(mForecastAdapter);

    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    int max = parallaxView.getHeight();
                    if (dy > 0) {
                        parallaxView.setTranslationY(Math.max(-max, parallaxView.getTranslationY() - dy / 2));
                    } else {
                        parallaxView.setTranslationY(Math.min(0, parallaxView.getTranslationY() - dy / 2));
                    }
                }
            });
        }
    }

    final AppBarLayout appbarView = (AppBarLayout) rootView.findViewById(R.id.appbar);
    if (null != appbarView) {
        ViewCompat.setElevation(appbarView, 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    if (0 == mRecyclerView.computeVerticalScrollOffset()) {
                        appbarView.setElevation(0);
                    } else {
                        appbarView.setElevation(appbarView.getTargetElevation());
                    }
                }
            });
        }
    }

    // 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.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(SELECTED_KEY)) {
            // The Recycler View probably hasn't even been populated yet.  Actually perform the
            // swapout in onLoadFinished.
            mPosition = savedInstanceState.getInt(SELECTED_KEY);
        }
        mForecastAdapter.onRestoreInstanceState(savedInstanceState);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.ant.sunshine.app.fragments.ForecastFragment.java

private void initParallaxView(View rootView) {
    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override/*from   w  ww  .j a  v  a 2s  .  c o m*/
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    int max = parallaxView.getHeight();
                    if (dy > 0) {
                        parallaxView.setTranslationY(Math.max(-max, parallaxView.getTranslationY() - dy / 2));
                    } else {
                        parallaxView.setTranslationY(Math.min(0, parallaxView.getTranslationY() - dy / 2));
                    }
                }
            });
        }
    }
}

From source file:com.runmit.sweedee.view.flippablestackview.StackPageTransformer.java

@Override
public void transformPage(View view, float position) {
    int dimen = view.getHeight();

    if (!mInitialValuesCalculated) {
        mInitialValuesCalculated = true;
        calculateInitialValues(dimen);/*from  www  .j av  a2 s  .  co  m*/
    }

    view.setRotationX(0);
    view.setPivotY(dimen / 2f);
    view.setPivotX(view.getWidth() / 2f);

    if (position < -mNumberOfStacked - 1) {
        view.setAlpha(0f);
    } else if (position <= 0) {
        float scale = mZeroPositionScale + (position * mStackedScaleFactor);
        float baseTranslation = (-position * dimen);
        float shiftTranslation = calculateShiftForScale(position, scale, dimen);
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(1.0f + (position * mAlphaFactor));
        Log.d("position", "baseTranslation=" + baseTranslation + ",shiftTranslation=" + shiftTranslation
                + ",transY=" + (baseTranslation + shiftTranslation));
        view.setTranslationY(baseTranslation + shiftTranslation);
    } else if (position <= 1) {
        view.bringToFront();
        float baseTranslation = position * dimen;
        float scale = mZeroPositionScale
                - mValueInterpolator.map(mScaleInterpolator.getInterpolation(position));
        scale = (scale < 0) ? 0f : scale;
        float shiftTranslation = (1.0f - position) * mOverlap;
        float rotation = -mRotationInterpolator.getInterpolation(position) * 90;
        rotation = (rotation < -90) ? -90 : rotation;
        float alpha = 1.0f - position;
        alpha = (alpha < 0) ? 0f : alpha;
        view.setAlpha(alpha);
        view.setPivotY(dimen);
        view.setRotationX(rotation);
        view.setScaleX(mZeroPositionScale);
        view.setScaleY(scale);
        view.setTranslationY(-baseTranslation - mBelowStackSpace - shiftTranslation);
    } else if (position > 1) {
        view.setAlpha(0f);
    }
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    fromX += holder.itemView.getTranslationX();
    fromY += holder.itemView.getTranslationY();
    endAnimation(holder);/*from  ww  w. j a  va 2  s . co m*/
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        view.setTranslationX(-deltaX);
    }
    if (deltaY != 0) {
        view.setTranslationY(-deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}

From source file:com.geecko.QuickLyric.fragment.LocalLyricsFragment.java

public void addObserver(final LongSparseArray<Integer> itemIdTopMap) {
    final boolean[] firstAnimation = { true };
    final ViewTreeObserver observer = megaListView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
            observer.removeOnPreDrawListener(this);
            firstAnimation[0] = true;//w  w  w . j  a  va2  s.c  om
            int firstVisiblePosition = megaListView.getFirstVisiblePosition();
            for (int i = 0; i < megaListView.getChildCount(); ++i) {
                final View child = megaListView.getChildAt(i);
                int position = firstVisiblePosition + i;
                long itemId = getListView().getAdapter().getItemId(position);
                Integer formerTop = itemIdTopMap.get(itemId);
                int newTop = child.getTop();
                if (formerTop != null) {
                    if (formerTop != newTop) {
                        int delta = formerTop - newTop;
                        child.setTranslationY(delta);
                        int MOVE_DURATION = 500;
                        child.animate().setDuration(MOVE_DURATION).translationY(0);
                        if (firstAnimation[0]) {
                            child.animate().setListener(new AnimatorActionListener(new Runnable() {
                                public void run() {
                                    mSwiping = false;
                                    getListView().setEnabled(true);
                                }
                            }, AnimatorActionListener.ActionType.END));
                            firstAnimation[0] = false;
                        }
                    }
                } else {
                    // Animate new views along with the others. The catch is that they did not
                    // exist in the start state, so we must calculate their starting position
                    // based on neighboring views.
                    int childHeight = child.getHeight() + megaListView.getDividerHeight();
                    boolean isFurthest = true;
                    for (int j = 0; j < itemIdTopMap.size(); j++) {
                        Integer top = itemIdTopMap.valueAt(j);
                        if (top - childHeight > newTop) {
                            isFurthest = false;
                            break;
                        }
                    }
                    formerTop = newTop + (i > 0 ? childHeight : -childHeight);
                    int delta = formerTop - newTop;
                    int MOVE_DURATION = 500;
                    if (isFurthest) {
                        child.setTranslationY(delta);
                        child.animate().setDuration(MOVE_DURATION).translationY(0);
                    } else {
                        int translationX = formerTop > childHeight ? child.getWidth() : 0;
                        child.setTranslationX(translationX);
                        if (translationX == 0)
                            child.setTranslationY(formerTop - newTop);
                        child.animate().setDuration(MOVE_DURATION).translationX(0).translationY(0);
                    }
                    if (firstAnimation[0]) {
                        child.animate().setListener(new AnimatorActionListener(new Runnable() {
                            public void run() {
                                getListView().setEnabled(true);
                                mSwiping = false;
                            }
                        }, AnimatorActionListener.ActionType.END));
                        firstAnimation[0] = false;
                    }
                }
            }
            if (firstAnimation[0]) {
                mSwiping = false;
                getListView().setEnabled(true);
                firstAnimation[0] = false;
            }
            itemIdTopMap.clear();
            return true;
        }
    });
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

@Override
public void endAnimation(ViewHolder item) {
    final View view = item.itemView;
    // this will trigger end callback which should set properties to their target values.
    view.animate().cancel();//from w w w  .jav a  2s  . c om
    // TODO if some other animations are chained to end, how do we cancel them as well?
    for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
        MoveInfo moveInfo = mPendingMoves.get(i);
        if (moveInfo.holder == item) {
            view.setTranslationY(0);
            view.setTranslationX(0);
            dispatchMoveFinished(item);
            mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(mPendingChanges, item);
    if (mPendingRemovals.remove(item)) {
        reset(item.itemView);
        dispatchRemoveFinished(item);
    }
    if (mPendingAdditions.remove(item)) {
        reset(item.itemView);
        dispatchAddFinished(item);
    }

    for (int i = mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            mChangesList.remove(i);
        }
    }
    for (int i = mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = mMovesList.get(i);
        for (int j = moves.size() - 1; j >= 0; j--) {
            MoveInfo moveInfo = moves.get(j);
            if (moveInfo.holder == item) {
                view.setTranslationY(0);
                view.setTranslationX(0);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    mMovesList.remove(i);
                }
                break;
            }
        }
    }
    for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = mAdditionsList.get(i);
        if (additions.remove(item)) {
            reset(item.itemView);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                mAdditionsList.remove(i);
            }
        }
    }

    // animations should be ended by the cancel above.
    if (mRemoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mRemoveAnimations list");
    }

    if (mAddAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mAddAnimations list");
    }

    if (mChangeAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mChangeAnimations list");
    }

    if (mMoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mMoveAnimations list");
    }
    dispatchFinishedWhenDone();
}

From source file:com.example.barni.sunshine.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

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

    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_forecast);

    // Set the layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    View emptyView = rootView.findViewById(R.id.recyclerview_forecast_empty);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // The ForecastAdapter will take data from a source and
    // use it to populate the RecyclerView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), new ForecastAdapter.ForecastAdapterOnClickHandler() {
        @Override/*w  ww .j a v a 2 s  .  com*/
        public void onClick(Long date, ForecastAdapter.ForecastAdapterViewHolder vh) {
            String locationSetting = Utility.getPreferredLocation(getActivity());
            ((Callback) getActivity()).onItemSelected(
                    WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, date));
            mPosition = vh.getAdapterPosition();
        }
    }, emptyView, mChoiceMode);

    // specify an adapter (see also next example)
    mRecyclerView.setAdapter(mForecastAdapter);

    final View parallaxView = rootView.findViewById(R.id.parallax_bar);
    if (null != parallaxView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    int max = parallaxView.getHeight();
                    if (dy > 0) {
                        float y = Math.max(-max, parallaxView.getTranslationY() - dy / 2);
                        parallaxView.setTranslationY(y);
                    } else {
                        float y = Math.min(0, parallaxView.getTranslationY() - dy / 2);
                        parallaxView.setTranslationY(y);
                    }
                }
            });
        }
    }

    // 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.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(SELECTED_KEY)) {
            // The Recycler View probably hasn't even been populated yet.  Actually perform the
            // swapout in onLoadFinished.
            mPosition = savedInstanceState.getInt(SELECTED_KEY);
        }
        mForecastAdapter.onRestoreInstanceState(savedInstanceState);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.fastbootmobile.encore.app.ArtistActivity.java

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_artist);

    mHandler = new Handler();

    FragmentManager fm = getSupportFragmentManager();
    mActiveFragment = (ArtistFragment) fm.findFragmentByTag(TAG_FRAGMENT);

    if (savedInstanceState == null) {
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = getIntent().getExtras();
    } else {/*w  w  w.  ja  v a  2s. c  o  m*/
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = savedInstanceState.getBundle(EXTRA_RESTORE_INTENT);
    }

    if (mActiveFragment == null) {
        mActiveFragment = new ArtistFragment();
        fm.beginTransaction().add(R.id.container, mActiveFragment, TAG_FRAGMENT).commit();
    }

    mActiveFragment.setArguments(mHero, mInitialIntent);

    // Remove the activity title as we don't want it here
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setTitle("");
    }

    mIsEntering = true;

    if (Utils.hasLollipop()) {
        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                View fab = mActiveFragment.findViewById(R.id.fabPlay);
                fab.setVisibility(View.VISIBLE);

                // get the center for the clipping circle
                int cx = fab.getMeasuredWidth() / 2;
                int cy = fab.getMeasuredHeight() / 2;

                // get the final radius for the clipping circle
                final int finalRadius = fab.getWidth();

                // create and start the animator for this view
                // (the start radius is zero)
                Animator anim;
                if (mIsEntering) {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, 0, finalRadius);
                } else {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, finalRadius, 0);
                }
                anim.setInterpolator(new DecelerateInterpolator());
                anim.start();

                fab.setTranslationX(-fab.getMeasuredWidth() / 4.0f);
                fab.setTranslationY(-fab.getMeasuredHeight() / 4.0f);
                fab.animate().translationX(0.0f).translationY(0.0f)
                        .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
                        .setInterpolator(new DecelerateInterpolator()).start();

                final View artistName = mActiveFragment.findViewById(R.id.tvArtist);
                if (artistName != null) {
                    cx = artistName.getMeasuredWidth() / 4;
                    cy = artistName.getMeasuredHeight() / 2;
                    final int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
                    final int radius = Utils.getEnclosingCircleRadius(artistName, cx, cy);

                    if (mIsEntering) {
                        artistName.setVisibility(View.INVISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, 0, radius, duration, 300);
                    } else {
                        artistName.setVisibility(View.VISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, radius, 0, duration, 0);
                    }
                }
            }
        });
    }

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}