Search in sources :

Example 1 with DetailSharedElementEnterCallback

use of com.example.android.unsplash.ui.DetailSharedElementEnterCallback in project atlas by alibaba.

the class DetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_detail);
    postponeEnterTransition();
    TransitionSet transitions = new TransitionSet();
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    transitions.addTransition(slide);
    transitions.addTransition(new Fade());
    getWindow().setEnterTransition(transitions);
    Intent intent = getIntent();
    sharedElementCallback = new DetailSharedElementEnterCallback(intent);
    setEnterSharedElementCallback(sharedElementCallback);
    try {
        initialItem = Integer.parseInt(intent.getData().getLastPathSegment());
    } catch (NumberFormatException e) {
        initialItem = 0;
    }
    PhotoService.getInstance().getPhotosAsync(new PhotoService.PhotoCallback() {

        @Override
        public void success(ArrayList<Photo> photos) {
            setUpViewPager(photos);
            findViewById(android.R.id.empty).setVisibility(View.GONE);
        }

        @Override
        public void error() {
            finishAfterTransition();
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(navigationOnClickListener);
    super.onCreate(savedInstanceState);
}
Also used : DetailSharedElementEnterCallback(com.example.android.unsplash.ui.DetailSharedElementEnterCallback) TransitionSet(android.transition.TransitionSet) Slide(android.transition.Slide) PhotoService(com.example.android.unsplash.data.PhotoService) Intent(android.content.Intent) Photo(com.example.android.unsplash.data.model.Photo) Fade(android.transition.Fade) Toolbar(android.widget.Toolbar)

Example 2 with DetailSharedElementEnterCallback

use of com.example.android.unsplash.ui.DetailSharedElementEnterCallback in project atlas by alibaba.

the class MainActivity method onActivityReenter.

@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });
    if (data == null) {
        return;
    }
    final int selectedItem = data.getIntExtra(IntentUtil.INSTANCE.getSELECTED_ITEM_POSITION(), 0);
    grid.scrollToPosition(selectedItem);
    PhotoViewHolder holder = (PhotoViewHolder) grid.findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }
    DetailSharedElementEnterCallback callback = new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);
}
Also used : DetailSharedElementEnterCallback(com.example.android.unsplash.ui.DetailSharedElementEnterCallback) PhotoViewHolder(com.example.android.unsplash.ui.grid.PhotoViewHolder) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

DetailSharedElementEnterCallback (com.example.android.unsplash.ui.DetailSharedElementEnterCallback)2 Intent (android.content.Intent)1 Fade (android.transition.Fade)1 Slide (android.transition.Slide)1 TransitionSet (android.transition.TransitionSet)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Toolbar (android.widget.Toolbar)1 PhotoService (com.example.android.unsplash.data.PhotoService)1 Photo (com.example.android.unsplash.data.model.Photo)1 PhotoViewHolder (com.example.android.unsplash.ui.grid.PhotoViewHolder)1