Giter Club home page Giter Club logo

circulartools's Introduction

CircularTools

Circle based animations for Android (min. API 11)

Currently implemented:

Reveal:YouTube Transform:YouTube Radial reaction:YouTube
Reveal DEMO Transform DEMO Radial reaction DEMO

Sample

Demo in the source and releases

Note

Limitations

For reveal and transform:

  • it will never use the native ViewAnimationUtils.createCircularReveal method
  • currently there is an issue: views with elevation cannot be animated correctly on Lollipop and above.
    • workaround A: set the LayerType of the target (or source) view to LayerType.SOFTWARE
    • workaround B: wrap your target or (source) view with a simple layout, without elevation, and animate that. Demo reveal uses this method.
  • hardware acceleration cannot be used in every situation. See table below:
API 11-17 API 18+
Reveal Software Hardware
Transform Software Hardware

For radial reaction

  • only one reaction can be animated at the same time, in the same RadialReactionParent
  • only one layout implemented yet: a LinearLayout.
  • once an affectedView is reached, it will be removed from the list in the RadialReactionParent. If you want to animate multiple times, you have to add the views again. See demo for details.

Usage

For reveal and transform you have to wrap your animated views with a CircularFrameLayout.

<hu.aut.utillib.circular.widget.CircularFrameLayout
        android:id="@+id/simple_reveal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <!-- Put any child views here if you want, it's stock FrameLayout  -->

</hu.aut.utillib.circular.widget.CircularFrameLayout>

Transform:

//myTargetView & mySourceView are children in the CircularFrameLayout
float finalRadius = CircularAnimationUtils.hypo(width, height);

//getCenter computes from 2 view: One is touched, and one will be animated, but you can use anything for center
int[] center = CircularAnimationUtils.getCenter(fab, myTargetView);

animator = CircularAnimationUtils.createCircularTransform(myTargetView, mySourceView, center[0], center[1], 0F, finalRadius);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(1500);
animator.start();

Reveal:

//myView is a child in the CircularFrameLayout
float finalRadius = CircularAnimationUtils.hypo(width, height);

//getCenter computes from 2 view: One is touched, and one will be animated, but you can use anything for center
int[] center = CircularAnimationUtils.getCenter(fab, myView);

animator = CircularAnimationUtils.createCircularReveal(myView, center[0], center[1], 0, finalRadius);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(1500);
animator.start();      

For radial reaction you have to wrap your views -that are affected by the radial reaction- with a RadialReactionParent.

  • Wrap your view
  • Add a listener to it (this listener will be notified when the invisible circle reaches an affected view)
  • Add views to the parent's watchlist by calling addAffectedView(View v)
  • Create animation and start it
  • Get notified when the radial reaction's invisible circle reaches one of the affected view
<hu.aut.utillib.circular.widget.RadialReactionLinearLayout 
    android:id="@+id/reaction_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

	<FrameLayout
		android:id="@+id/child_1"
		android:layout_width="80dp"
		android:layout_height="80dp"
		android:layout_alignParentTop="true"
		android:layout_margin="10dp"
		android:background="@color/material_deep_teal_500"
		android:visibility="invisible" />

    <!-- Put any child views here if you want, it's stock LinearLayout -->

</hu.aut.utillib.circular.widget.RadialReactionLinearLayout>

Radial reaction:

reactionParent = (RadialReactionParent) view.findViewById(R.id.reaction_parent);
reactionParent.addListener(this);

//add views
reactionParent.addAffectedView(child1);

ObjectAnimator animator = CircularAnimationUtils.createRadialReaction(reactionParent, fab, "action");
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(1500);
animator.start();

...

    @Override
    public void onRadialReaction(View affectedView, String action) {
	//Do what you want with the view    
    }

How to add dependency

This library is not released in Maven Central, but instead you can use JitPack

add remote maven url

	repositories {
	    maven {
	        url "https://jitpack.io"
	    }
	}

then add a library dependency

	dependencies {
	        compile 'com.github.AutSoft:CircularTools:1.1.0'
	}

License

The MIT License (MIT)

Copyright (c) 2015 AutSoft Kft.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

circulartools's People

Contributors

gordi90 avatar ozodrukh avatar jitpack-io avatar fahimk avatar shliama avatar inferjay avatar marbat87 avatar

Watchers

guoshichao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.