Example usage for android.transition Transition addListener

List of usage examples for android.transition Transition addListener

Introduction

In this page you can find the example usage for android.transition Transition addListener.

Prototype

public Transition addListener(TransitionListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:com.kai.uGuide.ui.fragment.AdapterTransitionFragment.java

/**
 * Toggle the UI between ListView and GridView.
 *///  www.j a v  a  2 s . c o  m
public void toggle() {
    // We use mCover as the overlay on which we carry out the transition.
    mCover.setVisibility(View.VISIBLE);
    // This FrameLayout holds all the visible views in the current list or grid. We use this as
    // the starting Scene of the Transition later.
    FrameLayout before = copyVisibleViews();
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    mCover.addView(before, params);
    // Swap the actual list.
    swapAbsListView();
    // We also swap the icon for the toggle button.
    ActivityCompat.invalidateOptionsMenu(getActivity());
    // It is now ready to start the transition.
    mAbsListView.post(new Runnable() {
        @Override
        public void run() {
            // BEGIN_INCLUDE(transition_with_listener)
            Scene scene = new Scene(mCover, copyVisibleViews());
            Transition transition = new AutoTransition();
            transition.addListener(AdapterTransitionFragment.this);
            TransitionManager.go(scene, transition);
            // END_INCLUDE(transition_with_listener)
        }
    });
}

From source file:com.example.android.adaptertransition.AdapterTransitionFragment.java

/**
 * Toggle the UI between ListView and GridView.
 *///w  w  w  . j  a v a 2s.c o  m
private void toggle() {
    // We use mCover as the overlay on which we carry out the transition.
    mCover.setVisibility(View.VISIBLE);
    // This FrameLayout holds all the visible views in the current list or grid. We use this as
    // the starting Scene of the Transition later.
    FrameLayout before = copyVisibleViews();
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    mCover.addView(before, params);
    // Swap the actual list.
    swapAbsListView();
    // We also swap the icon for the toggle button.
    ActivityCompat.invalidateOptionsMenu(getActivity());
    // It is now ready to start the transition.
    mAbsListView.post(new Runnable() {
        @Override
        public void run() {
            // BEGIN_INCLUDE(transition_with_listener)
            Scene scene = new Scene(mCover, copyVisibleViews());
            Transition transition = new AutoTransition();
            transition.addListener(AdapterTransitionFragment.this);
            TransitionManager.go(scene, transition);
            // END_INCLUDE(transition_with_listener)
        }
    });
}

From source file:com.example.kent_zheng.sdk_adaptertransition.AdapterTransitionFragment.java

/**
 * Toggle the UI between ListView and GridView.
 *//*from   w  w  w .  ja  va 2 s .c  om*/
private void toggle() {
    // We use mCover as the overlay on which we carry out the transition.
    mCover.setVisibility(View.VISIBLE);
    // This FrameLayout holds all the visible views in the current list or grid. We use this as
    // the starting Scene of the Transition later.
    FrameLayout before = copyVisibleViews();
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    mCover.addView(before, params);
    // Swap the actual list.
    swapAbsListView();

    // We also swap the icon for the toggle button.
    ActivityCompat.invalidateOptionsMenu(getActivity());
    // It is now ready to start the transition.
    mAbsListView.post(new Runnable() {
        @Override
        public void run() {

            Scene scene = new Scene(mCover, copyVisibleViews());
            Transition transition = new AutoTransition();
            transition.addListener(AdapterTransitionFragment.this);
            TransitionManager.go(scene, transition);

        }
    });
}

From source file:com.andremion.louvre.preview.PreviewActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTransition() {
    TransitionInflater inflater = TransitionInflater.from(this);
    Transition sharedElementEnterTransition = inflater.inflateTransition(R.transition.shared_element);
    sharedElementEnterTransition.addListener(new TransitionCallback() {
        @Override/*from www.ja  va  2 s .c  o  m*/
        public void onTransitionEnd(Transition transition) {
            mAdapter.setDontAnimate(false);
        }
    });
    getWindow().setSharedElementEnterTransition(sharedElementEnterTransition);
}

From source file:com.example.android.activityscenetransitionbasic.DetailActivity.java

/**
 * Try and add a {@link Transition.TransitionListener} to the entering shared element
 * {@link Transition}. We do this so that we can load the full-size image after the transition
 * has completed.//w  w w  .  ja va 2  s  . c  om
 *
 * @return true if we were successful in adding a listener to the enter transition
 */
private boolean addTransitionListener() {
    final Transition transition = getWindow().getSharedElementEnterTransition();

    if (transition != null) {
        // There is an entering shared element transition so add a listener to it
        transition.addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionEnd(Transition transition) {
                // As the transition has ended, we can now load the full-size image
                loadFullSizeImage();

                // Make sure we remove ourselves as a listener
                transition.removeListener(this);
            }

            @Override
            public void onTransitionStart(Transition transition) {
                // No-op
            }

            @Override
            public void onTransitionCancel(Transition transition) {
                // Make sure we remove ourselves as a listener
                transition.removeListener(this);
            }

            @Override
            public void onTransitionPause(Transition transition) {
                // No-op
            }

            @Override
            public void onTransitionResume(Transition transition) {
                // No-op
            }
        });
        return true;
    }

    // If we reach here then we have not added a listener
    return false;
}

From source file:com.andremion.louvre.home.GalleryActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTransition() {
    TransitionInflater inflater = TransitionInflater.from(this);
    getWindow().setExitTransition(inflater.inflateTransition(R.transition.gallery_exit));
    getWindow().setReenterTransition(inflater.inflateTransition(R.transition.gallery_reenter));
    Transition sharedElementExitTransition = inflater.inflateTransition(R.transition.shared_element);
    // Listener to reset shared element exit transition callbacks.
    sharedElementExitTransition.addListener(mSharedElementExitListener);
    getWindow().setSharedElementExitTransition(sharedElementExitTransition);
}

From source file:com.wangxinarhat.gankmvp.ui.activity.GirlDetailActivity.java

/**
 * Try and add a {@link Transition.TransitionListener} to the entering shared element
 * {@link Transition}. We do this so that we can load the full-size image after the transition
 * has completed.// w  w  w .  j a v a2s. c  o m
 *
 * @return true if we were successful in adding a listener to the enter transition
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean addTransitionListener() {
    final Transition transition = getWindow().getSharedElementEnterTransition();

    if (transition != null) {
        // There is an entering shared element transition so add a listener to it
        transition.addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionEnd(Transition transition) {
                // As the transition has ended, we can now load the full-size image
                loadFullSizeImage();

                // Make sure we remove ourselves as a listener
                transition.removeListener(this);
            }

            @Override
            public void onTransitionStart(Transition transition) {
                // No-op
            }

            @Override
            public void onTransitionCancel(Transition transition) {
                // Make sure we remove ourselves as a listener
                transition.removeListener(this);
            }

            @Override
            public void onTransitionPause(Transition transition) {
                // No-op
            }

            @Override
            public void onTransitionResume(Transition transition) {
                // No-op
            }
        });
        return true;
    }

    // If we reach here then we have not added a listener
    return false;
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarWallpaperActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.setTheme(Preferences.getPreferences(this).isDarkTheme() ? R.style.WallpaperThemeDark
            : R.style.WallpaperTheme);//from   w  w w.  j ava 2s  .  c o  m
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wallpaper);
    mIsEnter = true;

    mWallpaper = (ImageView) findViewById(R.id.wallpaper);
    mFab = (FloatingActionButton) findViewById(R.id.fab);
    mProgress = (ProgressBar) findViewById(R.id.progress);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    TextView toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
    TextView toolbarSubTitle = (TextView) findViewById(R.id.toolbar_subtitle);

    ViewHelper.resetViewBottomMargin(mFab);

    ColorHelper.setTransparentStatusBar(this, ContextCompat.getColor(this, R.color.wallpaperStatusBar));
    mColor = ColorHelper.getAttributeColor(this, R.attr.colorAccent);

    if (savedInstanceState != null) {
        mUrl = savedInstanceState.getString(URL);
        mName = savedInstanceState.getString(NAME);
        mAuthor = savedInstanceState.getString(AUTHOR);
    }

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        mUrl = bundle.getString(URL);
        mName = bundle.getString(NAME);
        mAuthor = bundle.getString(AUTHOR);
    }

    toolbarTitle.setText(mName);
    toolbarSubTitle.setText(mAuthor);
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
    setSupportActionBar(toolbar);

    mFab.setOnClickListener(this);

    mExitTransition = ActivityTransition.with(getIntent()).to(this, mWallpaper, "image").duration(300)
            .start(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && savedInstanceState == null) {
        Transition transition = getWindow().getSharedElementEnterTransition();

        if (transition != null) {
            transition.addListener(new Transition.TransitionListener() {
                @Override
                public void onTransitionStart(Transition transition) {

                }

                @Override
                public void onTransitionEnd(Transition transition) {
                    if (mIsEnter) {
                        mIsEnter = false;
                        Animator.startSlideDownAnimation(toolbar);
                        loadWallpaper(mUrl);
                    }
                }

                @Override
                public void onTransitionCancel(Transition transition) {

                }

                @Override
                public void onTransitionPause(Transition transition) {

                }

                @Override
                public void onTransitionResume(Transition transition) {

                }
            });
            return;
        }
    }

    mRunnable = () -> {
        toolbar.setVisibility(View.VISIBLE);
        loadWallpaper(mUrl);
        mRunnable = null;
        mHandler = null;
    };
    mHandler = new Handler();
    mHandler.postDelayed(mRunnable, 700);
}

From source file:com.maxwen.wallpaper.board.activities.WallpaperBoardPreviewActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.setTheme(Preferences.getPreferences(this).isDarkTheme() ? R.style.WallpaperThemeDark
            : R.style.WallpaperTheme);/*from ww w. ja va 2s  . c  o  m*/
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wallpaper_preview);
    ButterKnife.bind(this);
    ViewHelper.setApplicationWindowColor(this);
    ColorHelper.setTransparentStatusBar(this, ContextCompat.getColor(this, R.color.wallpaperStatusBar));
    mIsEnter = true;

    final Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
    TextView toolbarTitle = ButterKnife.findById(this, R.id.toolbar_title);
    TextView toolbarSubTitle = ButterKnife.findById(this, R.id.toolbar_subtitle);

    mColor = ColorHelper.getAttributeColor(this, R.attr.colorAccent);
    mProgress.getIndeterminateDrawable().setColorFilter(mColor, PorterDuff.Mode.SRC_IN);

    if (savedInstanceState != null) {
        mUrl = savedInstanceState.getString(Extras.EXTRA_URL);
        mName = savedInstanceState.getString(Extras.EXTRA_NAME);
        mAuthor = savedInstanceState.getString(Extras.EXTRA_AUTHOR);
    }

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        mUrl = bundle.getString(Extras.EXTRA_URL);
        mName = bundle.getString(Extras.EXTRA_NAME);
        mAuthor = bundle.getString(Extras.EXTRA_AUTHOR);
    }

    toolbarTitle.setText(mName);
    toolbarSubTitle.setText(mAuthor);
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
    setSupportActionBar(toolbar);

    mFab.setOnClickListener(this);

    mExitTransition = ActivityTransition.with(getIntent()).to(this, mWallpaper, Extras.EXTRA_IMAGE)
            .duration(300).start(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && savedInstanceState == null) {
        Transition transition = getWindow().getSharedElementEnterTransition();

        if (transition != null) {
            transition.addListener(new Transition.TransitionListener() {
                @Override
                public void onTransitionStart(Transition transition) {

                }

                @Override
                public void onTransitionEnd(Transition transition) {
                    if (mIsEnter) {
                        mIsEnter = false;
                        Animator.startSlideDownAnimation(toolbar, View.VISIBLE);
                        loadWallpaper(mUrl);
                    }
                }

                @Override
                public void onTransitionCancel(Transition transition) {

                }

                @Override
                public void onTransitionPause(Transition transition) {

                }

                @Override
                public void onTransitionResume(Transition transition) {

                }
            });
            return;
        }
    }

    mRunnable = new Runnable() {
        @Override
        public void run() {
            toolbar.setVisibility(View.VISIBLE);
            loadWallpaper(mUrl);
            mRunnable = null;
            mHandler = null;
        }
    };
    mHandler = new Handler();
    mHandler.postDelayed(mRunnable, 700);
}

From source file:com.dm.wallpaper.board.activities.WallpaperBoardPreviewActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.setTheme(Preferences.get(this).isDarkTheme() ? R.style.WallpaperThemeDark : R.style.WallpaperTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wallpaper_preview);
    ButterKnife.bind(this);

    ViewHelper.resetViewBottomMargin(mFab);
    ColorHelper.setStatusBarColor(this, ColorHelper.get(this, R.color.wallpaperStatusBar), true);
    mIsEnter = true;//from   w  ww  .  j a  v  a 2s  .  c  o m

    Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
    TextView toolbarTitle = ButterKnife.findById(this, R.id.toolbar_title);
    TextView toolbarSubTitle = ButterKnife.findById(this, R.id.toolbar_subtitle);

    mColor = ColorHelper.getAttributeColor(this, R.attr.colorAccent);
    mProgress.getIndeterminateDrawable().setColorFilter(Color.parseColor("#CCFFFFFF"), PorterDuff.Mode.SRC_IN);
    mBottomProgress.getProgressDrawable().setColorFilter(Color.parseColor("#EEFFFFFF"), PorterDuff.Mode.SRC_IN);

    if (savedInstanceState != null) {
        mUrl = savedInstanceState.getString(Extras.EXTRA_URL);
        mName = savedInstanceState.getString(Extras.EXTRA_NAME);
        mAuthor = savedInstanceState.getString(Extras.EXTRA_AUTHOR);
        mIsResumed = savedInstanceState.getBoolean(Extras.EXTRA_RESUMED);
    }

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        mUrl = bundle.getString(Extras.EXTRA_URL);
        mName = bundle.getString(Extras.EXTRA_NAME);
        mAuthor = bundle.getString(Extras.EXTRA_AUTHOR);
    }

    toolbarTitle.setText(mName);
    toolbarSubTitle.setText(mAuthor);
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
    setSupportActionBar(toolbar);

    mFab.setOnClickListener(this);

    if (!mIsResumed) {
        mExitTransition = ActivityTransition.with(getIntent()).to(this, mWallpaper, Extras.EXTRA_IMAGE)
                .duration(300).start(savedInstanceState);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && savedInstanceState == null) {
        Transition transition = getWindow().getSharedElementEnterTransition();

        if (transition != null) {
            transition.addListener(new Transition.TransitionListener() {
                @Override
                public void onTransitionStart(Transition transition) {

                }

                @Override
                public void onTransitionEnd(Transition transition) {
                    if (mIsEnter) {
                        mIsEnter = false;
                        AnimationHelper.slideDownIn(toolbar).duration(300)
                                .interpolator(new LinearOutSlowInInterpolator()).start();

                        loadWallpaper(mUrl);
                    }
                }

                @Override
                public void onTransitionCancel(Transition transition) {

                }

                @Override
                public void onTransitionPause(Transition transition) {

                }

                @Override
                public void onTransitionResume(Transition transition) {

                }
            });
            return;
        }
    }

    mRunnable = () -> {
        toolbar.setVisibility(View.VISIBLE);
        loadWallpaper(mUrl);
        mRunnable = null;
        mHandler = null;
    };
    mHandler = new Handler();
    mHandler.postDelayed(mRunnable, 700);
}