Grav Android Library

repository·master·Indexed 25 days ago

https://github.com/glomadrian/grav

An Android library for creating complex, point-based animations. Grav allows developers to compose animations using various generators for points (Regular, Circular, Percent), shapes (Ball, Rectangle), colors (Single, Array), and movement (Shake, SideToSide, Alpha, BallSize, and Path animators) via the GravView component.

Tokens
2K
Snippets
6
Records
6
Agent score
33%

What's inside Grav

  1. Install Grav via Gradle

    master

    To use Grav in your Java project with Gradle, add the Bintray repository and the Grav dependency to your build.gradle file.

    repositories {
      maven {
        url "http://dl.bintray.com/glomadrian/maven"
      }
    }
    
    dependencies {
      compile 'com.github.glomadrian:Grav:1.1'
    }
  2. Configure Grav Generators

    master

    Grav generators determine the shape of the drawn points. Use the app:gravGenerator attribute to select a class.

    • BallGenerator: Draws balls. You can specify a random size range using app:ball_from_size and app:ball_to_size.
    • RectangleGenerator: Draws rectangles. Set dimensions using app:rectangle_width and app:rectangle_height.
    <!-- BallGenerator Example -->
    app:gravGenerator="com.github.glomadrian.grav.generator.grav.BallGenerator"
    app:ball_from_size="3dp"
    app:ball_to_size="16dp"
    
    <!-- RectangleGenerator Example -->
    app:gravGenerator="com.github.glomadrian.grav.generator.grav.RectangleGenerator"
    app:rectangle_width="15dp"
    app:rectangle_height="10dp"
  3. Configure Color Generators

    master

    Color generators decide how the Grav is painted. Use the app:colorGenerator attribute.

    • SingleColorGenerator: Paints all points in one color using app:single_color.
    • ArrayColorGenerator: Paints points using an array of colors via app:array_colors.
    <!-- SingleColorGenerator Example -->
    app:colorGenerator="com.github.glomadrian.grav.generator.paint.SingleColorGenerator"
    app:single_color="@color/colorPrimary"
    
    <!-- ArrayColorGenerator Example -->
    app:colorGenerator="com.github.glomadrian.grav.generator.paint.ArrayColorGenerator"
    app:array_colors="@array/Spectral"
  4. Configure Animation Generators

    master

    Animation generators handle the movement, size, and property changes of the Grav. You can use a single generator with app:animationGenerator or an array of generators with app:animationGenerators.

    Available Animators:

    • ShakeAnimator: Moves the Grav within a range. Requires app:shake_min_duration, app:shake_max_duration, app:shake_direction (horizontal or vertical), and app:shake_variance.
    • SideToSideAnimator: Translates the Grav to different sides. Requires app:side_to_side_min_duration, app:side_to_side_max_duration, and app:side_to_side_direction (leftToRight, rightToLeft, upToDown, or downToUp). Supports an optional side_to_side_interpolator.
    • AlphaAnimator: Animates transparency. Requires app:alpha_min_duration, app:alpha_max_duration, app:alpha_from (0-255), and app:alpha_to (0-255).
    • BallSizeAnimator: Animates ball size. Requires app:ball_size_min_duration, app:ball_size_max_duration, app:ball_size_from_size, and app:ball_size_to_size.
    • PathAnimator: Moves the Grav along a specific path. Requires app:path (a string path), app:path_original_width, app:path_original_height, app:path_variance_from, app:path_variance_to, and duration attributes.
    <!-- Array of Animators Example -->
    app:animationGenerators="@array/array_reference"
    
    <!-- ShakeAnimator Example -->
    app:animationGenerator="com.github.glomadrian.grav.generator.animation.ShakeAnimator"
    app:shake_min_duration="1000"
    app:shake_max_duration="3000"
    app:shake_direction="horizontal"
    app:shake_variance="15dp"
  5. Configure Point Generators

    master

    Point generators define the locations of the points to be drawn. Use the app:pointGenerator attribute to select a class. Available generators include:

    • RegularPointGenerator: Generates points based on a cell size and variance.
    • CircularPointGenerator: Generates points in a circular shape based on cell size and variance.
    • PercentPointGenerator: Generates points based on a percentage locations array defined in arrays.xml (where each pair of items represents width and height percent).
    <!-- RegularPointGenerator Example -->
    app:pointGenerator="com.github.glomadrian.grav.generator.point.RegularPointGenerator"
    app:regular_cell_size="200"
    app:regular_variance="20"
    
    <!-- CircularPointGenerator Example -->
    app:pointGenerator="com.github.glomadrian.grav.generator.point.CircularPointGenerator"
    app:regular_cell_size="200"
    app:regular_variance="200"
    
    <!-- PercentPointGenerator Example -->
    app:pointGenerator="com.github.glomadrian.grav.generator.point.PercentPointGenerator"
    app:percent_points_array="@array/walla_points_percent_points"
  6. Implement GravView in XML

    master

    To use Grav in your Android layout, add the com.github.glomadrian.grav.GravView component and compose it using various generators (Point, Grav, Color, and Animation).

    <com.github.glomadrian.grav.GravView
         android:id="@+id/grav"
         android:layout_centerInParent="true"
         android:layout_width="400dp"
         android:layout_height="400dp"
         app:colorGenerator="com.github.glomadrian.grav.generator.paint.ArrayColorGenerator"
         app:array_colors="@array/red"
         app:pointGenerator="com.github.glomadrian.grav.generator.point.RegularPointGenerator"
         app:regular_cell_size="150"
         app:regular_variance="100"
         app:gravGenerator="com.github.glomadrian.grav.generator.grav.BallGenerator"
         app:ball_size_from_size="3dp"
         app:ball_size_to_size="6dp"
         app:animationGenerators="@array/path"
         app:path_variance_from="-10dp"
         app:path_variance_to="12dp"
         app:path="@string/circle"
         app:path_original_width="@integer/circle_original_width"
         app:path_original_height="@integer/circle_original_height"
         app:path_min_duration="5000"
         app:path_max_duration="6000"
         />