Skip to content
Reveal an activity or a fragment with a circular animation
Kotlin
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea chore(Kotlin): update version Oct 3, 2017
app chore(Kotlin): update version + improve style Dec 8, 2017
gradle/wrapper chore(Kotlin): update version Oct 3, 2017
.gitignore Initial commit Aug 22, 2017
README.md Update README.md Dec 17, 2017
build.gradle chore(Kotlin): update version + improve style Dec 8, 2017
gradle.properties Initial commit Aug 22, 2017
gradlew Initial commit Aug 22, 2017
gradlew.bat Initial commit Aug 22, 2017
settings.gradle Initial commit Aug 22, 2017

README.md

KRevealCircle Android

Start any fragment, activity or view with a circular reveal effect.

Visit our blog post to see how it works deeply Part 1 Fragment & Views and Part 2 Activities

How to use

The main class allowing to achieve circular reveal animation is achieved with RevealCircleAnimatorHelper. It is essentialy based on ViewAnimationUtils #createCircularReveal.

View

Use it with a targeted view.

public fun getCircularAnimator(targetView: View, sourceX: Int, sourceY: Int, speed: Long): Animator {
        val finalRadius = Math.hypot(targetView.width.toDouble(), targetView.height.toDouble()).toFloat()
        return ViewAnimationUtils.createCircularReveal(targetView, sourceX, sourceY, 0f, finalRadius).apply {
            interpolator = AccelerateDecelerateInterpolator()
            duration = speed
        }
    }

Fragment

Assuming you are using StarterPattern just call RevealCircleAnimatorHelper#addBundleValues(Bundle, View) in builder function and start animation in onCreateView.

class RevealFragment : Fragment() {
    
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val root = inflater!!.inflate(R.layout.dummy_fragment, container, false)
        RevealCircleAnimatorHelper.create(this, container)
                                  .start(root)
        return root
    }

    ...
    
    companion object {
        fun newInstance(sourceView: View? = null) = RevealFragment().apply {
            arguments = Bundle()
            RevealCircleAnimatorHelper.addBundleValues(arguments, sourceView)
        }
    }
}

Activity

Firstly make your Activity use the following attributes in your theme.

    <style name="AppTheme.Circled" parent="AppTheme.NoActionBar">
        <item name="android:windowIsTranslucent">true</item>
        <item name="colorPrimary">@color/colorAccent</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

Assuming you are using StarterPattern just call RevealCircleAnimatorHelper#addBundleValues(Bundle, View) in builder function and start animation in onCreate.

class RevealActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_circled)
        RevealCircleAnimatorHelper
                .create(this)
                .start(root, getThemeColor(R.attr.colorAccent), getColor(R.color.background_default, theme))
    }
    
    companion object {
    
        fun newIntent(context: Context, sourceView: View? = null): Intent {
            return Intent(context, RevealActivity::class.java).also {
                RevealCircleAnimatorHelper.addBundleValues(it, sourceView)
            }
        }
    }

License

Copyright 2017 PagesJaunes

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 can’t perform that action at this time.