Better version of ViewAnimator

Overview

Android Arsenal

CannyViewAnimator

CannyViewAnimator is an enhanced version of ViewAnimator. It allows to use Animators and Transitions to extend Visibility. The logic is taken from ViewAnimator of the Android SDK. The ViewAnimator can show only one view. If you show an other view then previous one will be hidden. All changes are taking with animations.

Top 1 example Top 2 example Top 3 example

Installation

Add compile 'com.livetyping:cannyviewanimator:0.8' in your dependencies.

U2020 example

Internal organization

CannyViewAnimator is divided into three layers of abstraction:

  • ViewAnimator - switches the visibility of child;
  • TransitionViewAnimator (extends ViewAnimator) - performs Transitions that extend Visibility;
  • CannyViewAnimator (extends TransitionViewAnimator) - performs Animators;
  • CannyTransition - interface for setting Transition for individual children;
  • InAnimator - interface for setting animator for appearing;
  • OutAnimator - interface for setting animator for disappearing.

ViewAnimator

Includes the following public methods:

  • setDisplayedChildIndex (int inChildIndex) - shows a child by its index in the parent;
  • setDisplayedChildId (@IdRes int id) - shows a child by its resID;
  • setDisplayedChild (View view) - shows a child by its object;
  • getDisplayedChildIndex () - obtains the index of the currently displayed child;
  • getDisplayedChild () - obtains the object of the currently displayed child;
  • getDisplayedChildId () – gets the resID of the currently displayed child;
  • bringChildToPosition (View child, int position) – changes the index of a child within the parent.

TransitionViewAnimator

(Use Transitions from AppCompat) Includes the following public methods:

  • startTransition() - launches Transition (starts by default after visibility changes)
  • setCannyTransition (CannyTransition cannyTransition) – interface setter for setting Transition for individual children

Transition example

animator.setCannyTransition(new CannyTransition() {
            @Override
            public Transition getTransition(View inChild, View outChild) {
                TransitionSet transitionSet = new TransitionSet();
                transitionSet.addTransition(new Fade(Fade.IN).addTarget(inChild));
                transitionSet.addTransition(new Fade(Fade.OUT).addTarget(outChild));
                return transitionSet;
            }
        });

CannyViewAnimator

Includes the following public methods:

  • setInAnimator (T ... inAnimators) – interface setter for fading in animation (using the parameters)
  • setInAnimator (List<? extends inAnimators) – interface setter for fading in animation (using the list)
  • setOutAnimator (T ... outAnimators) – interface setter for fading out animation (using the parameters)
  • setOutAnimator (List<? extends OutAnimator>outAnimators) – interface setter for fading out animation (using the list)
 animator.setInAnimator(new InAnimator() {
            @Override
            public Animator getInAnimator(View inChild, View outChild) {
                return ObjectAnimator.ofFloat(inChild, View.ALPHA, 0, 1);
            }
        });
        animator.setOutAnimator(new OutAnimator() {
            @Override
            public Animator getOutAnimator(View inChild, View outChild) {
                return ObjectAnimator.ofFloat(outChild, View.ALPHA, 1,0);
            }
        })

Flags

AnimateType - indicates the order in which the animation will run.

  • Sequentially
  • Together

animator.setAnimateType(CannyViewAnimator.TOGETHER);

LocationType - indicates the order in which the children will be placed in the parent. This flag makes sure that children don’t overlap with each other during animation.

  • For position
  • In always top
  • Out always top

animator.setLocationType(CannyViewAnimator.IN_ALWAYS_TOP);

DefaultCannyAnimators

This class group was originally created for testing, but in the end I decided to leave them because they help to make simple animations effortlessly. It is divided into two types:

  • PropertyAnimators - animators of View properties. [List] (library/src/main/java/com/livetyping/library/animators/property/PropertyAnimators.java)
  • RevealAnimators - CircularReveal animators. [List] (library/src/main/java/com/livetyping/library/animators/reveal/RevealAnimators.java)

Example:

 animator.setInAnimator(PropertyAnimators.ROTATION_180);
 animator.setInAnimator(PropertyAnimators.ROTATION_M180);

Helper classes

This group of classes is needed for easier creation of InAnimators and OutAnimators.

  • PropertyIn
  • PropertyOut
  • RevealIn
  • RevealOut

Example of parallax effect:

animator.setInAnimator(new PropertyIn(View.TRANSLATION_X, width, 0).setDuration(1000));
animator.setOutAnimator(new PropertyOut(View.TRANSLATION_X, 0, -width / 2).setDuration(1000));
animator.setLocationType(CannyViewAnimator.IN_ALWAYS_TOP);
animator.setAnimateType(CannyViewAnimator.TOGETHER);

Parallax example

XML

Attribute list:

  • animate_type inmplementation setAnimateType
  • location_type inmplementation setLocationType
  • in set default in animator
  • out set default out animator
  • prelolipop_in set default in animator (without reveal animators)
  • prelolipop_out set default out animator (without reveal animators)

If the current Android version is lower than Lollipop, then animators will be taken from prelolipop_in, if prelolipop_in is empty, then animators will taken from in.

Example:

XML example

<com.livetyping.library.CannyViewAnimator
        android:id="@+id/xml_animator"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:animate_type="together"
        app:location_type="out_always_top"
        app:out="circular_center"
        app:pre_lollipop_out="scale_x|scale_y|alpha">

License

Copyright 2015 Danil Perevalov.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You might also like...
Android library for better Picker DialogFragments
Android library for better Picker DialogFragments

DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numbers, and other things.

:rocket: Ultimate Android Reference - Your Road to Become a Better Android Developer
:rocket: Ultimate Android Reference - Your Road to Become a Better Android Developer

The goal of this project is to provide a hand-picked collection of Android libraries, tools, open-source projects, books, blogs, tutorials - you name

Easier RxJava2 debugging with better stacktraces
Easier RxJava2 debugging with better stacktraces

Traceur Traceur enables easier debugging of RxJava2 exceptions, by appending the source of any asynchronous calls to the original exception. An exampl

A better ExpandableListView, with animated expandable views for each list item
A better ExpandableListView, with animated expandable views for each list item

SlideExpandableListView for Android Not happy with the Android ExpandableListView android offers? Want something like the Spotify app. This library al

[NO LONGER MAINTAINED] Android library for better Picker DialogFragments
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

A better calendar for Android
A better calendar for Android

Caldroid Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User ca

A better Android VideoView with more Media Controller customization. 一个更好用的Android VideoView
A better Android VideoView with more Media Controller customization. 一个更好用的Android VideoView

Android UniversalVideoView 中文版说明请点击这里 UniversalVideoView is a Android widget helps playing video easier, which is similar with the Android system nati

Material Design RatingBar with better appearance
Material Design RatingBar with better appearance

MaterialRatingBar Material Design RatingBar with better appearance, compatible with Android 3.0+. Why MaterialRatingBar? Consistent appearance on Andr

[NO LONGER MAINTAINED] Android library for better Picker DialogFragments
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Group of libraries to help you build better animations with Jetpack Compose
Group of libraries to help you build better animations with Jetpack Compose

Group of libraries to help you build better animations with Jetpack Compose

An Anime Watching App With Better player And Faster Servers
An Anime Watching App With Better player And Faster Servers

Kayuri An Android app to watch anime on your phone without ads.With GoogleServers and Manual Settings Toogles. This is a Fork Of Anime X Stream which

Disk Usage/Free Utility - a better 'df' alternative
Disk Usage/Free Utility - a better 'df' alternative

duf Disk Usage/Free Utility (Linux, BSD, macOS & Windows) Features User-friendly, colorful output Adjusts to your terminal's theme & width Sort the re

BTW-gradle is a development environment for the Better Than Wolves mod

BTW-gradle BTW-gradle is a development environment for the Better Than Wolves mod Quick Start Download the example Change settings.gradle and build.gr

Better P2P and memory card for Applied Energistics 2, requires Forgelin.
Better P2P and memory card for Applied Energistics 2, requires Forgelin.

BetterP2P Better P2P and memory card for Applied Energistics 2, requires Forgelin. Documentation is now available to read: https://lasmgratel.github.i

A tool for making your stay through
A tool for making your stay through "IC" a little better.

mr.r0bot-kt.v Mr.r0bot-kt.v is tool that handles computer logic calculations and provides a better experience through your stay at "IC". Warning Use m

Annotation processor that provides better navigation on android multi-modules projects 🛳.
Annotation processor that provides better navigation on android multi-modules projects 🛳.

FlowNav FlowNav is a mobile library for Android that helps and provider a better way to make multi-modules navigation. The main purpose of this librar

Bulletin helps you to
Bulletin helps you to "swipe" through your favorite events in the campus and gives you the perfect match for your better experience

Bulletin helps you to "swipe" through your favorite events in the campus and gives you the perfect match for your better experience. Right swipe to add event to your calendar and left swipe to view the next event.

A sussy 1.17.1 Airplane fork that (hopefully) has better performance and relatively stable
A sussy 1.17.1 Airplane fork that (hopefully) has better performance and relatively stable

Fiadelity A sussy Minecraft server software This project is experimental, its usage in production environment is discouraged if you are not ready to f

A Simple Privacy Browser - Some ScreenShots(Actual App Even Looks Better 😃 ):
A Simple Privacy Browser - Some ScreenShots(Actual App Even Looks Better 😃 ):

Lets_Browse A Simple Privacy Browser. Some ScreenShots(Actual App Even Looks Better 😃 ): Features 👇 : Bookmark Webpage Save Webpage as Pdf(Once Page

Comments
  • Fixed Android Arsenal badge

    Fixed Android Arsenal badge

    Hi, Thanks for the great library! I've noticed that there's a small typo in the Android Arsenal badge in README which stops it from rendering correctly. Please let me know if this should be merged to the develop branch instead!

    opened by zawadz88 1
  • On rotate device.

    On rotate device.

    First of all thank you for your good work on this library. When I add animation, to a content of views like this: In onCreateView() of my Fragment, using ButterKnife.bind(this, view);

    itisfListLayout.setInAnimator(new PropertyIn(View.TRANSLATION_Y, itisfRootLayout.getHeight(), 0).setDuration(500));
     itisfListLayout.setOutAnimator(new PropertyOut(View.TRANSLATION_Y, 0, -itisfRootLayout.getHeight()).setDuration(500));
     itisfListLayout.setLocationType(CannyViewAnimator.IN_ALWAYS_TOP);
     itisfListLayout.setAnimateType(CannyViewAnimator.TOGETHER);
     itisfListLayout.setDisplayedChildIndex(itisfListLayout.getDisplayedChildIndex() + 1);
    

    The animation works well, but when I rotate de device NullPointerException error appears: Caused by: java.lang.NullPointerException at com.livetyping.library.CannyViewAnimator.changeVisibility(CannyViewAnimator.java:114) at com.livetyping.library.ViewAnimator.setDisplayedChildIndex(ViewAnimator.java:37) at com.livetyping.library.ViewAnimator.onRestoreInstanceState(ViewAnimator.java:170) at android.view.View.dispatchRestoreInstanceState(View.java:12284) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2620) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626) at android.view.View.restoreHierarchyState(View.java:12262)

    Any idea how is this happening? Thank you.

    opened by ikermart 1
Owner
Live Typing
Mobile and Web App Development Company
Live Typing
:rocket: Ultimate Android Reference - Your Road to Become a Better Android Developer

The goal of this project is to provide a hand-picked collection of Android libraries, tools, open-source projects, books, blogs, tutorials - you name

Aritra Roy 7.6k Jan 4, 2023
Group of libraries to help you build better animations with Jetpack Compose

Group of libraries to help you build better animations with Jetpack Compose

null 36 May 12, 2022
An Anime Watching App With Better player And Faster Servers

Kayuri An Android app to watch anime on your phone without ads.With GoogleServers and Manual Settings Toogles. This is a Fork Of Anime X Stream which

Killerpac 380 Oct 23, 2022
DuGuang 1k Dec 14, 2022
ActSwitchAnimTool make the Animation easy to implements, and it compat the version of Android 4.0 or above.

ActSwitchAnimTool As well as we know, Android 5.0 has been support more Animation(just like ViewAnimationUtils~). Maybe some developers can implements

Acropolis 573 Nov 23, 2022
ViewAnimator view with a lollipop style reveal effect

ViewRevealAnimator Widget ViewAnimator view with a lollipop style reveal effect. Regular animation can be set (just like the default ViewAnimator) for

Alessandro Crugnola 339 Jun 3, 2022
Kotlin Multiplatform Mobile version of Tisdagsgolfen... yet another version.

TheCube in Kotlin Multiplatform Experimenting with KMM, and Kotlin, Jetpack, SwiftUI, and all the other new stuff... https://kotlinlang.org/docs/kmm-g

Kim Fransman 0 Dec 25, 2022
Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

EventBus EventBus is a publish/subscribe event bus for Android and Java. EventBus... simplifies the communication between components decouples event s

Markus Junginger 24.2k Jan 7, 2023
A better calendar for Android

Caldroid Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User ca

Roomorama 1.4k Nov 29, 2022