Search in sources :

Example 16 with Painting

use of com.alexvasilkov.gestures.sample.ex.utils.Painting in project GestureViews by alexvasilkov.

the class RecyclerToPagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_recycler_screen);
    setTitle(R.string.example_list_transitions_1_N);
    final Painting[] paintings = Painting.list(getResources());
    // Initializing ListView
    list = findViewById(R.id.recycler_list);
    list.setLayoutManager(new LinearLayoutManager(this));
    list.setAdapter(new RecyclerAdapter(paintings, this::onPaintingClick));
    // Initializing ViewPager
    pager = findViewById(R.id.recycler_pager);
    pagerAdapter = new PagerAdapter(pager, paintings, getSettingsController());
    pager.setAdapter(pagerAdapter);
    pager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.view_pager_margin));
    // Initializing images animator. It requires us to provide FromTracker and IntoTracker items
    // that are used to find images views for particular item IDs in the list and in the pager
    // to keep them in sync.
    // In this example we will use SimpleTracker which will track images by their positions,
    // if you have a more complicated case see further examples.
    final SimpleTracker listTracker = new SimpleTracker() {

        @Override
        public View getViewAt(int position) {
            RecyclerView.ViewHolder holder = list.findViewHolderForLayoutPosition(position);
            return holder == null ? null : RecyclerAdapter.getImageView(holder);
        }
    };
    final SimpleTracker pagerTracker = new SimpleTracker() {

        @Override
        public View getViewAt(int position) {
            RecyclePagerAdapter.ViewHolder holder = pagerAdapter.getViewHolder(position);
            return holder == null ? null : PagerAdapter.getImageView(holder);
        }
    };
    animator = GestureTransitions.from(list, listTracker).into(pager, pagerTracker);
    // Setting up background animation during image transition
    background = findViewById(R.id.recycler_full_background);
    animator.addPositionUpdateListener((pos, isLeaving) -> applyImageAnimationState(pos));
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) SimpleTracker(com.alexvasilkov.gestures.transition.tracker.SimpleTracker) Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Example 17 with Painting

use of com.alexvasilkov.gestures.sample.ex.utils.Painting in project GestureViews by alexvasilkov.

the class RecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final Painting painting = paintings[position];
    // Storing item position for click handler
    holder.itemView.setTag(R.id.tag_item, position);
    GlideHelper.loadThumb(holder.image, painting.thumbId);
    CharSequence text = new SpannableBuilder(holder.title.getContext()).createStyle().setFont(Typeface.DEFAULT_BOLD).apply().append(painting.author).append("\n").clearStyle().append(painting.title).build();
    holder.title.setText(text);
}
Also used : SpannableBuilder(com.alexvasilkov.android.commons.texts.SpannableBuilder) Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Example 18 with Painting

use of com.alexvasilkov.gestures.sample.ex.utils.Painting in project GestureViews by alexvasilkov.

the class FullImageActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_cross_animation_to_screen);
    setTitle(R.string.example_image_animation_cross_target);
    image = findViewById(R.id.single_image_to);
    background = findViewById(R.id.single_image_to_back);
    // Loading image. Note, that this image should already be cached in the memory to ensure
    // very fast loading. Consider using same image or its thumbnail as on prev screen.
    final int paintingId = getIntent().getIntExtra(EXTRA_PAINTING_ID, 0);
    Painting painting = Painting.list(getResources())[paintingId];
    GlideHelper.loadFull(image, painting.imageId, painting.thumbId);
    // Listening for animation state and updating our view accordingly
    image.getPositionAnimator().addPositionUpdateListener(this::applyImageAnimationState);
    // Enter animation should only be played if activity is not created from saved state
    enterFullImage(savedInstanceState == null);
    // Hiding original image only once image is drawn for the first time to prevent
    // image blinking on activity start
    runAfterImageDraw(() -> Events.create(CrossEvents.SHOW_IMAGE).param(false).post());
}
Also used : Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Example 19 with Painting

use of com.alexvasilkov.gestures.sample.ex.utils.Painting in project GestureViews by alexvasilkov.

the class ImageCrossAnimationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_cross_animation_from_screen);
    setTitle(R.string.example_image_animation_cross);
    getSupportActionBarNotNull().setDisplayHomeAsUpEnabled(true);
    image = findViewById(R.id.single_image_from);
    // Loading image
    Painting painting = Painting.list(getResources())[PAINTING_ID];
    GlideHelper.loadThumb(image, painting.thumbId);
    // Setting image click listener
    image.setOnClickListener(this::showFullImage);
    // Image position may change (e.g. when screen orientation is changed), so we should update
    // fullscreen image to ensure exit animation will return image into correct position.
    image.getViewTreeObserver().addOnGlobalLayoutListener(this::onLayoutChanges);
}
Also used : Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Example 20 with Painting

use of com.alexvasilkov.gestures.sample.ex.utils.Painting in project GestureViews by alexvasilkov.

the class ViewPagerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    // Applying settings from toolbar menu, see BaseExampleActivity
    settingsController.apply(holder.image);
    Painting painting = paintings[position];
    GlideHelper.loadFull(holder.image, painting.imageId, painting.thumbId);
}
Also used : Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Aggregations

Painting (com.alexvasilkov.gestures.sample.ex.utils.Painting)23 SpannableBuilder (com.alexvasilkov.android.commons.texts.SpannableBuilder)4 RecyclePagerAdapter (com.alexvasilkov.gestures.commons.RecyclePagerAdapter)3 SimpleTracker (com.alexvasilkov.gestures.transition.tracker.SimpleTracker)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1