Git Product home page Git Product logo

animatedpathview's Introduction

AnimatedPathView

Android Arsenal

An animated path view following the methods in a blog post from Romain Guy here:
http://www.curious-creature.org/2013/12/21/android-recipe-4-path-tracing/
Per the blog post, I will be adding SVG support soon.

Usage

You can set the path by calling:

animatedPathView.setPath(Path p);

And you can set the percentage (0.0f to 1.0f) of the path being shown by calling:

animatedPathView.setPercentage(float f);

You can also set the resize the path you created by calling:

animatedPathView.scalePathBy(float x, float y);

FYI: As of right now, WRAP_CONTENT is disabled in order set paths relative to view with view.getWidth() and such.
I will be fixing this in the future. So layout_width and layout_height must be specified!

Example: This will create a path that will draw a border around the top half of the screen and an X through the middle of it.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.mattkula.animatedpathview.sample"
    android:orientation="vertical" 
    android:layout_width="fill_parent"     
    android:layout_height="fill_parent">
    
    <com.mattkula.animatedpathview.library.AnimatedPathView 
        android:id="@+id/animated_path" 
        android:layout_width="fill_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        app:strokeColor="@android:color/holo_red_light" 
        app:strokeWidth="10"/>
        
    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:text="Press top half of screen"/>
        
</LinearLayout>
final AnimatedPathView view = (AnimatedPathView)findViewById(R.id.animated_path);

view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        view.getViewTreeObserver().removeGlobalOnLayoutListener(this);

        Path p = new Path();
        p.moveTo(0, 0);
        p.lineTo(view.getWidth(), 0);
        p.lineTo(view.getWidth(), view.getHeight());
        p.lineTo(0, view.getHeight());
        p.lineTo(0, 0);
        p.lineTo(view.getWidth(), view.getHeight());
        p.lineTo(view.getWidth(), 0);
        p.lineTo(0, view.getHeight());
        view.setPath(p);
    }
});

view.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "percentage", 0.0f, 1.0f);
        anim.setDuration(2000);
        anim.setInterpolator(new LinearInterpolator());
        anim.start();
    }
}); 

If you just want to use straight lines, you can use an array of points to specify your path such as:

float[][] points = new float[][]{
        {0, 0},
        {view.getWidth(), 0},
        {view.getWidth(), view.getHeight()},
        {0, view.getHeight()},
        {0, 0},
        {view.getWidth(), view.getHeight()},
        {view.getWidth(), 0},
        {0, view.getHeight()}
};
view.setPath(points);

animatedpathview's People

Contributors

matthewrkula avatar

Watchers

 avatar  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.