Git Product home page Git Product logo

dynamicsinewaveview's Introduction

DynamicSineWaveView

A View that can display the animated sine wave, and the wave properties can be dynamic change.

Dynamic Sine Wave

Usage

  1. Copy the View (no resource needed) to your project.
  2. Layout with the me.tankery.app.dynamicsinewave.DynamicSineWaveView
  3. Add waves for the view programatically.

The layout:

<me.tankery.app.dynamicsinewave.DynamicSineWaveView
    android:id="@+id/view_sine_wave"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

The addWave method.

/**
 * Add new wave to the view.
 *
 * The first added wave will become the 'base wave', which ignored the color & stroke, and
 * other wave will multiple with the 'base wave'.
 *
 * @param amplitude wave amplitude, relative to view, range from 0 ~ 0.5
 * @param cycle contains how many cycles in scene
 * @param speed space per second, relative to view. X means the wave move X times of width per second
 * @param color the wave color, ignored when add the 'base wave'
 * @param stroke wave stroke width, in pixel, ignored when add the 'base wave'
 * @return wave count (exclude the base wave).
 */
public int addWave(float amplitude, float cycle, float speed, int color, float stroke);

How to use in code:

wavesView = (DynamicSineWaveView) findViewById(R.id.view_sine_wave);
wavesView.addWave(0.5f, 0.5f, 0, 0, 0); // Fist wave is for the shape of other waves.
wavesView.addWave(0.5f, 2f, 0.5f, getResources().getColor(android.R.color.holo_red_dark), stroke);
wavesView.addWave(0.1f, 2f, 0.7f, getResources().getColor(android.R.color.holo_blue_dark), stroke);
wavesView.startAnimation();

If you need to stop the animation, call:

wavesView.stopAnimation();

What's more, you can even change the amplitude when need (useful when you need to response for a voice input):

wavesView.setBaseWaveAmplitudeScale(1);

dynamicsinewaveview's People

Contributors

tankery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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